Subject: Re: DirectC C-Layer: open arrays and abstract access - revised
From: Andrzej Litwiniuk (Andrzej.Litwiniuk@synopsys.com)
Date: Fri Jan 10 2003 - 11:03:02 PST
My answers to Francoise's questions are interspersed with the relevant excerpts.
Regards,
Andrzej
========================================================================
> >Open array querying functions
> >=============================
> >
> >These functions are modelled upon SV array querying functions, with
> >the same semantics:
> >
> >/* h= handle to open array, d=dimension */
> >
> >/* For unpacked part */
> >int svcUnpackedLeft(svcHandle h, int d);
> >int svcUnpackedRight(svcHandle h, int d);
> >int svcUnpackedLow(svcHandle h, int d);
> >int svcUnpackedHigh(svcHandle h, int d);
> >int svcUnpackedIncrement(svcHandle h, int d);
Francoise: What does this function do?
#########
Pls. cf. LRM 16.3 "Array querying functions".
Generally, svNAME corresponds to $NAME.
So, vcsvcUnpackedIncrement(h,d) shall return 1 if vcUnpackedLeft(h,d) is greater
than or equal to vcUnpackedRight(h,d), and -1 otherwise.
> >int svcUnpackedLength(svcHandle h, int d);
Francoise: Does this function returns the width of a given dimension?
######### basically high - low +1?
Yes.
Francoise:
#########
> Did you think about have a single function doing the queries for the entire
> open array
> and returning the information in a single data structure rather than having
> distinct functions?
> The reason for this being that the C user code may need it all anyway.
>
> example:
> int svcOpenArrayData(svcHandle, svcDim_p dimdata);
> where svcDim_p is a pointer to list of structures svcDim describing the
> array dimensions
> from right most range to left most range. That way there is no limitation
> on the topology
> of the open array.
>
> struct svcDim{
> int high, low, left, right, length;
> svcDim_p next;
> }
Who will allocate and de-allocate that structure (list)?
I'm afraid that it will be simply asking for a trouble (memory leaks).
> >int svcUnpackedDimensions(svcHandle h);
> >
> >/* For 1-dimensional packed part */
> >int svcPackedLeft(svcHandle h);
> > ....
Francoise:
#########
> I don't see the need for both unpacked and packed queries functions, you
> could make it so that if the dimension is 0, then the query could be
> relative to the packed range.
This actually seems to be a good idea. The convention that dimension 0
referes to the packed part (which has been already assumed to be 1-dimensional)
and dimensions > 0 refer to the unpacked part would allow to unify those
functions and omit the qualifiers "Packed"/"Unpacked" from the names.
The functions unified that way would be as follows:
int svLeft(svHandle h, int d);
int svRight(svHandle h, int d);
int svLow(svHandle h, int d);
int svHigh(svHandle h, int d);
int svIncrement(svHandle h, int d);
int svLength(svHandle h, int d);
int svDimensions(svHandle h);
Thanks for this idea, Francoise!
> >Access via canonical representation
> >-----------------------------------
> >
> >This group of functions is meant for accessing elements which are packed
> >arrays ('bit' or 'logic').
> >
> >The following functions will copy a single vector from a canonical
> >representation to an element of an open array or other way round.
> >
> >Element of an array is identified by indices bound by the ranges of the
> >actual argument. In other words, original SV values are used for indexing.
Francoise:
#########
> The other alternative is to use a flat offset to the beginning of the array
> rather than the SV
> indices. The problem of the offset is that the user must calculate it; this
> may be easy
> in the case of array of bits and logic but more difficult in the general
> array case.
> I don't particular disagree with the multiple functions for 1, 2, 3, and
> var dimensions,
> but I wanted to bring the other alternative.
Actually, you have both ways, i.e. 'flat offset' and SV indices.
Function svGetArrayPtr() gives the address of the beginning of the array.
Then it's up to you whether you calculate the offset yourself or rather
go with SV indices and call a function.
> >/* functions for translation between simulator's and canonical
> > representations */
> >
> >/* actual <-- canonical */
> >void svcPutBitArrElemVec32 (svcHandle d, svcBitVec32* s, int indx1, ...);
> >
> >/* canonical <-- actual */
> >void svcGetBitArrElemVec32 (svcBitVec32* d, svcHandle s, int indx1, ...);
Francoise:
#########
> I don't see the width specified as a parameter! Is it missing?
No. It's been deliberately omitted. svcHandle carries enough information,
including the width.
> >Access to the actual representation
> >-----------------------------------
> >
> >The following functions provide an actual address of the whole array or
> >of its individual element. These functions will be used for accessing
> >elements of the arrays of types compatible with C.
> >
> >/* a pointer to the actual representation of the whole array of any type */
> >void *svcGetArrayPtr(svcHandle);
> >
> >Note that no specific representation of an array is assumed here, hence
> >a generic pointer void *.
Francoise:
#########
> How do you use the generic pointer void * which is returned. How do you
> traverse the actual representation?
> Let's assume that we have an open array of SV unpacked structures ? How do
> I retrieve the value of one element of that array?
User has to cast a generic pointer.
See Example 3. In short:
MyType my_value = *(MyType *)svGetArrElemPtr1(h, i);
I'm not sure I understand what you meant by "traversing the actual representation".
> >int svcSizeOfArray(svcHandle); /* total size in bytes */
Francoise:
#########
> How is the size function useful?
See Example 4. In short:
memcpy(svcGetArrayPtr(h1), svcGetArrayPtr(h2), svSizeOfArray(h1));
This archive was generated by hypermail 2b28 : Fri Jan 10 2003 - 11:08:20 PST