Use of arrays, per LRM 2.3.1

69 views
Skip to first unread message

rdk

unread,
Apr 16, 2013, 1:26:50 PM4/16/13
to cmc-ve...@googlegroups.com
I'm currently refining array support, see ambiguity in the LRM regarding various implementation issues, and am seeking clarification:

Can a whole array be assigned to another array? 

For example, is the following valid:

real ar1[0:10],ar2[0:10];
          analog begin
              ar1=ar2;
          end

          I think the answer is NO.

Can an element of an array be passed as a scalar to an analog function?

For example, is the following valid:

analog function real func1
   input x;
   inout y;
   real x,y;
   begin
       y=y+x;
       func1=y;
   end
endfunction

real z,ar1[0:10];
begin
   z=func1(2.4,ar1[3]);
end

I think the answer is YES.

Can the directionality of array arguments to analog functions be split according to element ranges?

Consider the following function:

analog function real func3
    input [0:4] x;
    inout [5:8] x;
    output[9:10] x;
    real x[0:10];
...
endfunction

I always thought the the duplication of a range specification on the port specifications was redundant, unless it could mean that we can split up the directionality of the elements. I don't see this indicated anywhere, and I think the answer is NO.

What happens to results of a temporary array for an inout or output argument to an analog function?

Consider the following example:

analog function real func2
    input x;
    output [0:2] ar;
    real x,ar[0:2];
    begin
        ar[0]=x+1;
        ar[1]=x+2;
        ar[3]=x+3;
        func2=0;
    end
endfunction

real result,z1,z2,z3;
begin
    result=func2(9.7,`{z1,z2,z3});
end

After the call to func2 occurs, what is the value of z1, z2, z3? Are they still their original value? Another way of asking this is? Are temporary inline vectors constructed by value? I think the answer is YES, meaning the temporary accumulates the results of the function call, but then discards them.

 What is the reasoning behind this statement in LRM 2.3.1, section 4.7.2.3?

inout arguments are not “pass by reference”, but more closely related to “copy in” and “copy out”.    

 That is a somewhat vague statement. What exactly are the requirements being met here? By stating that we cannot pass by reference, and instead must copy, there is a big inefficiency introduced,  in particular for large arrays. For this reason, my preference is to pass by reference. Why not?

Are compilers expected to properly generate partial derivatives whose numerators and/or denominators pass through arrays? 

This task might be somewhat manageable for arrays in the analog block, but becomes rather tangled when we introduce the use of index variables and use analog functions to various depths. I would like to ban the practice, eliminating the need for derivatives related to such arguments. Comments?
 

rdk

unread,
Apr 17, 2013, 11:20:39 AM4/17/13
to cmc-ve...@googlegroups.com
Another question:

Can array ranges be passed to functions?

For example:

analog function real func3 
   input [0:3] x;
   real x[0:3];
   begin
      func3=x[0]+x[1]+x[2]+x[3];
   end
endfunction

real y,z[0:10];
y=func3(z[4:7]);

Geoffrey Coram

unread,
Apr 22, 2013, 2:39:38 PM4/22/13
to cmc-ve...@googlegroups.com, aard...@gmail.com
Hi, Richard -
I don't have all the answers, but I have a few.

> *Can an element of an array be passed as a scalar to an analog function?*

This should be OK; per A.8.4, a primary can be

| hierarchical_identifier [ { [ expression ] } [ range_expression ] ]

which is how you reference an element of an array.


> *What is the reasoning behind this statement in LRM 2.3.1, section 4.7.2.3?*
>
> inout arguments are not “pass by reference”, but more closely related to “copy in” and “copy out”.


The issue here, as I recall, has to do with passing the same variable twice:


analog function real myfunc(a, b);
inout a, b;
real a, b;

begin
a = 5;
myfunc = b;
end
endfunction


analog begin : body
real x, y;
x = 6;
y = myfunc(x, x);


What is the value of y? If you pass by reference, then when the function sets "a = 5"
it would set the value of x to 5, and then the reference passed as "b" would also have
a value of 5, and so the function would return 5. With copy in/copy out, a and b each
get a copy of x (which is 6) that is used in the function, and the function returns 6.


> *Are compilers expected to properly generate partial derivatives whose numerators and/or denominators pass through arrays? *

Compilers are expected to generate derivatives of variables whose values depend on
access references through function calls. (I think you got ahead of yourself,
because I don't know what numerators and denominators you are referring to.)

The way functions are defined -- specifically, that they are defined within the module
with restrictions on their contents -- they can be in-lined into the module code, so
that the compiler should be able to generate any necessary derivatives.

-Geoffrey




On 04/16/13 13:26, rdk wrote:
> I'm currently refining array support, see ambiguity in the LRM regarding various implementation issues, and am seeking clarification:
>
> *Can a whole array be assigned to another array? *
>
> For example, is the following valid:
>
>
> real ar1[0:10],ar2[0:10];
>
> analog begin
> ar1=ar2;
> end
>
> I think the answer is NO.
>
> *Can an element of an array be passed as a scalar to an analog function?*
>
> For example, is the following valid:
>
> analog function real func1
> input x;
> inout y;
> real x,y;
> begin
> y=y+x;
> func1=y;
> end
> endfunction
>
> real z,ar1[0:10];
> begin
> z=func1(2.4,ar1[3]);
> end
>
> I think the answer is YES.
>
>
> *Can the directionality of array arguments to analog functions be split according to element ranges?*
>
> Consider the following function:
>
> analog function real func3
> input [0:4] x;
> inout [5:8] x;
> output[9:10] x;
> real x[0:10];
> ...
> endfunction
>
> I always thought the the duplication of a range specification on the port specifications was redundant, unless it could mean that we can split up the directionality of the elements. I don't see this indicated anywhere, and I think the answer is NO.
>
>
> *What happens to results of a temporary array for an inout or output argument to an analog function?*
>
> Consider the following example:
>
> analog function real func2
> input x;
> output [0:2] ar;
> real x,ar[0:2];
> begin
> ar[0]=x+1;
> ar[1]=x+2;
> ar[3]=x+3;
> func2=0;
> end
> endfunction
>
> real result,z1,z2,z3;
> begin
> result=func2(9.7,`{z1,z2,z3});
> end
>
> After the call to func2 occurs, what is the value of z1, z2, z3? Are they still their original value? Another way of asking this is? Are temporary inline vectors constructed by value? I think the answer is YES, meaning the temporary accumulates the results of the function call, but then discards them.
>
>
> *What is the reasoning behind this statement in LRM 2.3.1, section 4.7.2.3?*
>
> inout arguments are not “pass by reference”, but more closely related to “copy in” and “copy out”.
>
>
> That is a somewhat vague statement. What exactly are the requirements being met here? By stating that we cannot pass by reference, and instead must copy, there is a big inefficiency introduced, in particular for large arrays. For this reason, my preference is to pass by reference. Why not?
>
>
> *Are compilers expected to properly generate partial derivatives whose numerators and/or denominators pass through arrays? *
> *
> *
>
> This task might be somewhat manageable for arrays in the analog block, but becomes rather tangled when we introduce the use of index variables and use analog functions to various depths. I would like to ban the practice, eliminating the need for derivatives related to such arguments. Comments?
>
>
> --
> You received this message because you are subscribed to the Google Groups "CMC Verilog-A" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cmc-verilog-...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


Reply all
Reply to author
Forward
0 new messages