Subject: Re: [sv-cc] DirectC layer: C array indices mapping for unpacked arrays
From: Andrzej Litwiniuk (Andrzej.Litwiniuk@synopsys.com)
Date: Tue Feb 04 2003 - 07:25:09 PST
Francoise wrote:
> [...] I think that for Verilog arrays
> since they are compatible with C arrays, it is not natural or intuitive to
> take the smallest
> indice and to map it to C index 0.
> If I declare an array arr[1:3][2:9], then the indices map nicely to the C
> array because
> the ranges on the Verilog side are ascending but if they are descending or
> even mix, the
> user who declares his Verilog array needs to cross map the indices to C.
>
> arr[0:3] [4:2] -> in C the 0,0 indices will correspond to 0,2 of the
> original Verilog array
>
> Why not instead mapping the Verilog memory and arrays to a C array of
> integers where the indices follow the same indices of the Verilog declaration.
> For example if the Verilog array is declared as [27:0], the 0 index in C
> will contain bit 27
> contrarily if the Verilog array is declared as [0:27], C index 0 will
> correspond to bit 0.
Francoise,
For the packed arrays the left and right boundary are semantically meaningful,
since they refer to MSB and LSB. Therefore packed ranges are not symmetrical,
i.e. it matters whether a packed array is declared as [1:8] or [8:1].
For the unpacked arrays (aka memories in good ole Verilog) ascending or
descending order carries no semantical information, in the sense that there is
no was to tell by using Verilog code only what is the actual order of elements
in the representation used by the simulator. Therefore I believe that the same
layout (order of elements) may be used for both [1:8] and [8:1].
Actually, VCS behaves that way. I don't know about other simulators.
Hence the proposed and simple rule:
for the unpacked range [L:R], min(L,R) corresponds to 0 in C,
max(L,R) corresponds to abs(L-R) in C, and that ordring is symmetric,
in the sense that it doesn't matter whether L<R or not.
> [...] but I wanted to point out that
> it may not be intuitive to do the mapping you propose.
>
> Francoise
Well, all that is required by the proposed rule is to shift an index by
min(L,R), then, first go smaller indices, next go bigger indices.
"Intuitive" is a subjective term; the above rule is intuitive for me.
But really, this ain't that important. If others prefer a different ordering,
let it be. Just try to make it consistent with the layout used by the existing
simulators. (What, however, if they behave differently?)
Andrzej
This archive was generated by hypermail 2b28 : Tue Feb 04 2003 - 07:25:43 PST