RE: DirectC: C layer revised


Subject: RE: DirectC: C layer revised
From: Warmke, Doug (doug_warmke@mentorg.com)
Date: Sat Jan 11 2003 - 19:31:40 PST


Andrzej,

I have embedded a few comments and suggestions for clarifications
and embellishments. Great job.

Regards,
Doug

> -----Original Message-----
> From: Andrzej Litwiniuk [mailto:Andrzej.Litwiniuk@synopsys.com]
> Sent: Friday, January 10, 2003 7:51 AM
> To: sv-cc@server.eda.org
> Subject: DirectC: C layer revised
>
>
> Team,
>
> Enclosed is the complete revised version of the C layer of SV
> DirectC Interface.
>
> Regards,
> Andrzej
>
> ------------------------ DirectC C Layer
> --------------------------------------
>
>
>
> Overview of C layer
> ===================
>

DOUG: This document discusses the C layer, but it only addresses
the case in which SV calls C functions. Most of the material
in here applies to C calling SV, however.

Would it be possible to extend the detailed presentation of
the intricate details such that C calling SV is addressed as well?
Some points I can think of that would need addressing:
  - delinearization and denormalization of C array ranges
  - Handling of char* args passed from the C side
  - Call-by-reference details
  - Opaque pointer details (and usefulness?)

The John/Joao proposal has some information on C-calling-SV,
but nothing equivalent to the details in your work here.
I would really like it if this document could be extended
to discuss these issues. A few paragraphs and examples is
probably all it would take.

>
> Representation of the data
> --------------------------
>
> The following is assumed about the representation of SV data:
>
> a) representation of packed types is implementation dependent
>
> b) basic integer and real data types are represented as
> defined in LRM 3.3,
> 3.4.2, see also "Data type mapping" below.
>
> c) layout of unpacked structures is same as used by C
> compiler (LRM 3.7)
>
> d) layout of sized unpacked arrays is same as used by C compiler;
> this includes arrays embedded in structures and the
> standalone arrays
> (i.e. not embedded in any structure)
>
> Note that this is a restriction imposed on the SV side of
> the interface!
> Depending on the implementation, a particular array may or
> may be not
> accepted as an actual argument for the formal argument
> which is a sized
> array (it will be always accepted for unsized array).
>
> e) layout of the unsized (aka open) standalone unpacked arrays
> is implementation dependent with the following restriction:
> an element of an array must have the same representation as
> individual a value of the same type, with the exception
> of scalars
> (bit or logic) and packed arrays as a type of an element.
> Hence array's elements other than scalars or packed
> arrays can be
> accessed via pointers similarly to individual values.
>
>
> Note that d) actually does not impose any restrictions on how
> unpacked arrays
> are implemented; it says only that an array that does not satisfy d)
> may not be passed as an actual argument for the formal
> argument which is
> a sized array; it may be passed, however, for unsized array.
> Therefore, the correctness of an actual argument may be
> implementation
> dependent. Nevertheless an open array provides implementation
> independent
> solution. This seems to be a reasonable trade-off.
>
> Data type mapping
> -----------------
>
> The basic SV data types are represented as follows:
>
> char -> char
> shortint -> shortint
> int -> int
> longint -> long
> byte -> char
> real -> double
> shortreal -> float
> 'opaque pointer'-> void*
> 'string' -> char*
>
> Representation of SV specific data types like packed bit and
> logic vectors is
> implementation dependent and generally transparent to the user.
> Nevertheless, for the sake of performance, applications may
> be tuned for a
> specific implementation and make use of the actual
> representation used by that
> implementation; such applications will not be binary
> compatible, however.
>
> Access to data
> --------------
>
> DirectC interface defines the canonical API representation of
> packed 2-state
> and 4-state arrays. (Actually based on PLI's avalue/bvalue
> for 4-state.)
>
> Library functions will provide the translation between the
> representation
> used in a simulator and the canonical API representation.
>
> Abstract access is provided only for the unsized (open)
> packed and unpacked
> arrays. All other objects are directlly accessible.
>
> C compatible data types are accessed either directly or
> through pointers.
>
> Packed arrays are accessible via canonical representation;
> interface provides
> functions for moving data between implementation
> representation and canonical
> representation, any necessary convertion is performed on the fly.
> There are also functions for bit selects and limited (up to
> 32 bits) partial bit
> selects.
>
> Array slices are not supported.

DOUG: The difference between "array slices" and "part selects" is
not perfectly clear. Perhaps a little elaboration here would
be a good clarification. For part selects, you probably
mean a slice of a packed array of bit or logic type, right?

>
> For unsized (open) arrays the original SV ranges are used in indexing.
>
> For sized arrays normalized ranges are assumed.
>
> For example, if 'logic [2:3][1:3][2:0] b [1:10]' is used in SV type,
> it will have to be defined in C as if it were declared in SV
> in the following
> normalized form: 'logic [17:0] b [0:9]'.
> That practically means that the packed part must be
> linearized and the ranges
> must be normalized.
>
>
> By and large the actual arguments will be passed by
> reference, with a few
> exceptions (e.g. small input arguments).
>
> There will be no copying of arguments (other than resulting
> from coercing)
> Please recall item 10 from "17 items"!
> [10a: "xf must not modify the values of its input args'
> 10b: "The initial values of formal output args are
> unspecified and may be
> implementation dependent."]
>
> The actual arguments passed by reference by and large will be
> passed as they are, without changing their representation
> from the one used by a simulator.
> (Again, there are some exceptions, mainly for the 'open'
> alias 'unsized' arrays.)
>
> Therefore there will be no overhead on argument passing
> because no copying or
> translation between different representations will be required.
>
> C data types will be directly accessible.
>
> SV specific types will be accessible both via the interface
> library functions,
> what grants the compatibility, and directly thru pointers,
> what allows for
> the simulator-specific tuning of the application.
>
> 'Open' alias 'unsized' arrays will be accessible through the
> abstract access
> mode, i.e. via the interface library functions.
>
> Depending on the data types used for the external (or
> exported) functions,
> either binary level or C source level compatibility is granted.
>
> The binary level compatibility is granted for all data types
> that do not mix
> C types with SV specific types, though either category
> separately is fine.
> For example, if a formal argument type is a C structure or a
> packed array
> of bit or logic, then binary level compatibility is granted.
> On the other hand, if a packed structure is embedded in an
> unpacked data
> type, then only a source level compatibility is granted.
> (Binary level compatibility means that an application
> compiled for a given
> platform shall work with every SV simulator on that platform.
> Source level compatibility means that an application will
> have to be re-compiled for each SV simulator and that the
> implementation specific definitions
> will be required for the compilation.)
>
>
>
> Argument passing
> =================
>

DOUG: This section is one area that would need to be updated to
address the C-calls-SV direction.

> Actual arguments generally are passed by reference or by
> value and will
> be directly accessible in C code.
>
> In some cases, defined separately, an argument will be passed
> by handle and will
> be accessible via library functions (abstract acess mode).
>
> For the arguments passed by reference, their original
> simulator-specific
> representation will be used and a reference to the original
> data object
> will be passed.
>
> If an argument of type 'T' is passed by reference, than the
> formal argument
> shall be of the type 'T *'.
>
> Output and inout arguments are passed by reference.
>
> Input arguments are passed by value or by reference,
> depending on the size.
> 'Small' values of formal input arguments are passed by value.
> The following data types are considered 'small':
>
> - char, byte, int, real, shortreal (have I omitted something?)
> - pointer, string
> - bit (i.e. 2-state) vectors up to 32-bit; canonical
> representation will
> be used, similarly for function result
>
> Input arguments of other types are passed by reference.
>
>
>
> Include files
> =================
>
> (All names are provisional and subject to discussion and improvment.)
>
> The C layer of SV DirectC interface defines two include files
> corresponding to
> the two levels of compatibility (binary level and source code level):
> - "svc_bin.h"
> - "svc_src.h"

DOUG: My suggestion for these file names is:
      - "svc.h" - SVC interface functions required by standard.
                        Provides for binary compatability.
      - "svc_impl.h" - Implementation-specific SVC functions.
                        Provides for source compatability.

The svc_bin.h and svc_src.h names are fine with me if my
suggestions are not popular.

>
> "svc_bin.h" is fully defined by the interface and is
> implementation independent.
> It defines the canonical API representation of 2-state (bit)
> and 4-state (logic)
> values, defines the types used for passing references to SV
> data objects,
> provides function headers and defines a number of helper
> macros and constants.
>
> "svc_src.h" provides implementation dependent definitions.
> The contens of this file, i.e. what symbols are defined
> (constants, macros,
> typedefs), is defined by the interface.
> The actual definitions of the symbols, however, are
> implementation specific and
> will be provided by the vendors.
>
> "svc_src.h" defines data structures for implementation
> specific representation
> of 2-state and 4-state vectors, as well as a number of helper
> macros and
> constants.
>
> User's applications that require "svc_src.h" file will be
> only source-level
> compatible, i.e. they will have to be compiled with the
> version of "svc_src.h"
> provided for a particular implementation of SV.
>
> The applications that use only "svc_bin.h" will be binary
> compatible with
> all SV simulators.
>
>
> The values of C-like types may be directly accessed via the
> corresponding
> C type definitions.
>
> The values of SV specific types, like packed arrays of bit or
> logic, may
> be accessed via interface functions using the canonical
> representation of
> 2-state and 4-state vectors.
> They also may be directly accessed using the implementation
> representation.
> The former mode will assure binary level compatibility, the later one
> will allow for tool-specific performance oriented tuning of
> an application.
>
> There will be no confusion whether passing a particular data type
> is binary compatible or only source level compatible.
> The rule is straightforward: if a correcponding type definition can be
> written in C without the need to include "svc_src.h" file,
> then the binary
> compatibility is granted. Everything that requires
> "svc_src.h" is not binary
> compatible and needs recompilation for each simulator of choice.
>
> Applications that pass solely C compatible data types or
> standalone packed
> arrays (both 2-st and 4-st) will require only "svc_bin.h" and
> therefore will be
> binary compatible will all simulators.
>
> Applications that pass complex data types that contain at the
> same time
> packed arrays and C-compatible types, will require also
> "svc_src.h" file and
> therefore will not be binary compatible will all simulators.
> The source level
> compatibility is, however, granted.
>
>
>
> "svc_bin.h"
> =================
>
> This file contains the following definitions:
>
> /* canonical API representation */
>
> #define sv_0 0
> #define sv_1 1
> #define sv_z 2 /* representation of 4-st scalar z */
> #define sv_x 3 /* representation of 4-st scalar x */
>
> /* common type for 'bit' and 'logic' scalars. */
> typedef unsigned char svScalar;
>
> typedef svScalar svBit; /* scalar */
> typedef svScalar svLogic; /* scalar */
>
> /* 2-state and 4-state vectors, modelled upon PLI's avalue/bvalue */
> #define VEC32_NEEDED(WIDTH) (((WIDTH)+31)>>5)
DOUG: This name should be more descriptive IMO:
          WORDS_NEEDED_FOR_VEC32(WIDTH)
-or-
          VEC32_WORDS_NEEDED(WIDTH)

>
> typedef unsigned int
> svBitVec32; /* (a chunk of) packed bit array */
>
> typedef struct { unsigned int c; unsigned int d;} /* as in VCS */
> svLogicVec32; /* (a chunk of) packed logic array */
>
> /* reference to a standalone packed array */
> typedef void* svBitPackedArr;
> typedef void* svLogicPackedArr;
>
> /* a handle to a generic object (actually, unsized array) */
> typedef void* svHandle;
>
> /* functions for translation between simulator's and
> canonical representations */
>
> /* s=source, d=destination, w=width */
>
> /* actual <-- canonical */
> void svPutBitVec32 (svBitPackedArr d, svBitVec32* s, int w);
> void svPutLogicVec32 (svLogicPackedArr d, svLogicVec32* s, int w);
>
> /* canonical <-- actual */
> void svGetBitVec32 (svBitVec32* d, svBitPackedArr s, int w);
> void svGetLogicVec32 (svLogicVec32* d, svLogicPackedArr s, int w);
>
> The above functions copy the whole array in either direction.
> User is responsible for providing the correct width and for
> allocating an array
> in the canonical representation.
>
> Although the put/get functionality provided for 'bit' and 'logic'
> packed arrays is sufficient yet basic, it requires
> unnecessary copying of
> the whole packed array when perhaps only some bits are needed.
>
> For the sake of the convenience and improved performance, the
> bit selects and
> limited (up to 32 bits) part-selects are also supported.
>
> Functions for part-select allow to access (read/write) only a
> narrow subranges
> of up to 32 bits. A canonical representation will be used for
> such narrow
> vectors.
>
> For the sake of symmetry a single chunk of an array in the canonical
> representation is used both for 'logic' and 'bit'.
> One may argue, however, that in the case of 'bit' such small vector
> is actually a single int, so perhaps a more intuitive
> signature could be
> used.
>
>
> /* functions for bit-select and limited width part-select */
>
> /* Packed arrays are assumed to be indexed n-1:0,
> where 0 is the index of least significant bit */
>
> /* functions for bit-select */
> /* s=source, d=destination, i=bit-index */
>
> svScalar svGetSelectBit(svBitPackedArr s, int i);
> svScalar svGetSelectLogic(svLogicPackedArr s, int i);
>
> void svPutSelectBit(svBitPackedArr d, int i, scalar s);
> void svPutSelectLogic(svLogicPackedArr d, int i, scalar s);
>
>
> /*
> * functions for part-select
> *
> * a narrow (<=32 bits) part select is copied between
> * the implementation representation and a single chunk of
> * canonical representation
> *
> * s=source, d=destination, i=starting bit index, w=width
> * like for variable part selects; limitations: w <= 32
> */
>
> Please note that for the sake of symmetry a canonical representation
> (i.e. an array) is used both for 'bit' and 'logic', though a simpler
> int could be used for 'bit' part selects <= 32-bit.
>
>
> void svGetPartSelectBit(svBitVec32* d, svBitPackedArr s,
> int i, int w);
> void svPartGetSelectLogic(svLogicVec32* d, svLogicPackedArr
> s, int i, int w);
DOUG: The "PartGet" portion of this function name is transposed.

>
> /*
> * for 'bit' type a part select <= 32-bit is really an int
> * so a function could be used:
> * int svGetPartSelectBit(svBitPackedArr s, int i, int w);
> */
>
>
> void svPutPartSelectBit(svBitPackedArr d, svBitPackedArr s,
> int i, int w);
> void svPutPartSelectLogic(svLogicPackedArr d,
> svLogicPackedArr s, int i, int w);
>
> /*
> * for 'bit' type a part select <= 32-bit is really an int
> * so simpler arg could be used:
> * svPutPartSelectBit(svBitPackedArr d, int up_to_32-bits,
> int i, int w);
> */
>
>
> More functions may be added, for example, for converting
> packed arrays into
> char* strings (for printing) or other way round (for
> reading), like in VCS
> (cf. VCS DirectC.h).
>
>
> "svc_src.h"
> ===========
>
> This file provides implementation specific definitions.
> In particular, it defines the macros for specifying variables
> representing
> SV packed arrays:
>
> #define BIT_PACKED_ARRAY(WIDTH,NAME) ...
> #define LOGIC_PACKED_ARRAY(WIDTH,NAME) ...
DOUG: Above your naming has "Bit" and "Logic" appended at the
end of your names (e.g. svPutPartSelectBit). Here those
substrings are at the start of the names. I suggest putting
them at the end for consistency with svc_bin.h.

>
> (For example, VCS might defined the later macro as follows:
> #define LOGIC_PACKED_ARRAY(WIDTH,NAME) vec32 NAME [
> VEC32_NEEDED(WIDTH) ]
> )
>
>
> Example 1 - binary compatible application
> =========================================
>
> SV:
> typedef struct {int a; int b;} pair;
> extern void foo(input int i1, pair i2, output logic [63:0] o3);
>
> C:
> #include "svc_bin.h"
>
> typedef struct {int a; int b;} pair;
> void foo(int i1, pair *i2, svLogicPackedArr o3)
> {
> svLogicVec32 arr[VEC32_NEEDED(64)]; /* 2 chunks needed */
>
> printf("%d\n", i1);
> arr[1].c = i2->a;
> arr[1].d = 0;
> arr[2].c = i2->b;
> arr[2].d = 0;
> svPutLogicVec32 (o3, arr, 64);
> }
>
>
> Example 2 - source level compatible application
> ===============================================
>
> SV:
> typedef struct {int a; bit [6:1][1:8] b [65:2]; int c;} triple;
> // troublesome mix od C types and packed arrays
> extern void foo(input triple i);
>
> C:
> #include "svc_bin.h"
> #include "svc_src.h"
>
> typedef struct {
> int a;
> BIT_PACKED_ARRAY(6*8, b) [64];
> int c;
> } triple;
>
> /* Note that 'b' is defined as for 'bit [6*8-1:0] b [63:0]' */
>
> void foo(triple *i)
> {
> int j;
> svBitVec32 arr[VEC32_NEEDED(6*8)]; /* 6*8 packed bits */
>
> printf("%d %d\n", i->a, i->c);
> for (j=0; j<64; j++) {
> svGetBitVec32(arr, (svBitPackedArr)&(i->b[j]), 6*8);
> ...
> }
> }
>
> Note that 'a', 'b', 'c' are directly accessed as fields in a
> structure.
> In the case of 'b', which represents unpacked array of packed arrays,
> individual element is accessed via library function svGetBitVec32(),
> by passing its address to the function.
>
>
>
> Open (Unsized) Arrays and Abstract Access - Overview
> ====================================================
>
> All open arrays, packed (i.e. vectors) and unpacked (i.e.
> arrays per se)
> will be passed by handle and accessed mainly via accessory
> functions (abstract
> access).
>
> Abstract access for open arrays will allow inquires about the
> dimensions
> and the original boundaries of SV actual argument and will
> allow to access
> the elements of an open array using the same range of indices
> as in SV.
>
> The programmer will always have a choice, whether to specify a formal
> argument as a sized array or as an open (unsized) array.
DOUG: It would be nice to cross-reference the pertinent part
of "17 items" that shows the syntactic differences on the SV side.

>
> In the former case all indices will be normalized on the C
> side (i.e. 0 and up)
> and the programmer is assumed to know the size of an array.
> Programmer is also assumed to be capable of figuring out how
> the ranges of
> the actual argument will map onto C-style ranges.
> Hint: programmers may decide to stick to [n:0]name[0:k] style
> ranges in SV.

DOUG: I would like to see this exposition part briefly discuss
array range direction topics:
  - When using the term "LSB" in this document, exactly what is
    it referring to? The LSB of the normalized C array?
    Or the LSB of the formal SV argument?
    When referring to the LSB of the actual argument it seems we
    are referring to the rightmost bit of the argument.
    When referring to the LSB of the formal argument it seems we
    are referring to the 0'th bit of the normalized C array.
    I'm thinking about the following kind of situations on the SV side:

       extern "C" void userSvFuncDesFormal(input logic[31:0] formalArg);
       extern "C" void userSvFuncAscFormal(input logic[0:31] formalArg);

       reg [31:0] descendingReg;
       reg [0:31] ascendingReg;
       reg someScalar;

       userSvFuncDesFormal(ascendingReg);
       userSvFuncDesFormal(descendingReg);
       userSvFuncDesFormal({descendingReg[30:0], someScalar});
       userSvFuncAscFormal(ascendingReg);
       userSvFuncAscFormal(descendingReg);
       userSvFuncAscForma({someScalar, ascendingReg[2:31], someScalar);
  - When using the word "ascending" (or "incrementing", as you have done)
    what exactly is it referring to? It must be referring to the
    actual SV argument side.

I hope these thoughts give you some ideas on how to clarify this topic.
I think clarifications will be necessary for unambiguous reading
of the spec. For the open array case, it does seem we need to
index based on the SV actual. What will happen if concatenation
cases such as above are used?

>
> In the later case, i.e. open array, the abstract access mode
> will be used,
> what would facilitate SV-style of indexing with the original
> boundaries of
> the actual argument, all this for the price of some overhead.
>
> Note that this provides some degree of flexibility and allows
> programmer
> to control the trade-off of performance vs. convenience.
> If a formal argument is specified as a sized array, then it
> will be passed by reference, with no overhead, and will be
> directly accessible as a normalized
> array.
> If a formal argument is specified as a open (unsized) array,
> then it will be
> passed by handle, with some overhead, and will be accessible
> mostly indirectly,
> again with some overhead, although with the original boundaries.
>
>
> Unsized formal arguments
> ========================
>
> For input, output and inout arguments that are declared as open array,
> the corresponding formal argument in C will be of type svHandle.
>
> Type svHandle denotes an opaque pointer to a descriptor
> generated by SV
> compiler for an actual argument. Descriptor will provide comprehensive
> information about an actual argument. The internal structure
> of a descriptor
> is implementation dependent and fully irrelevant to the user.
>
> Limitations
> ===========
>
> The unpacked part of an open array may be multidimensional.
> The packed part, however, is restricted to a single dimension.
>
> Note that any packed data type in SV is eventually equivalent to
> a one-dimensional packed array. Hence the above limitation is
> practically
> not restrictive.
>
> Open array querying functions
> =============================
>
> These functions are modelled upon SV array querying functions, with
> the same semantics (cf. LRM 16.3):
>
> /* h= handle to open array, d=dimension */
>
> /* For unpacked part */
> int svUnpackedLeft(svHandle h, int d);
> int svUnpackedRight(svHandle h, int d);
> int svUnpackedLow(svHandle h, int d);
> int svUnpackedHigh(svHandle h, int d);
> int svUnpackedIncrement(svHandle h, int d);
DOUG: The name of this function could be improved.
Instead of a 1 or -1 return, I think it makes more
sense to treat this as a boolean:

  int svUnpackedIsAscending(svHandle h, int d);

Return 1 if true, 0 if false.
Please consider the suggestion, which I think
will improve readability in the C code.
Same kind of suggestion applies to other
functions relating to Ascending/Incrementing ranges.

> int svUnpackedLength(svHandle h, int d);
DOUG: Suggest renaming to
  int svUnpackedDimensionLength(svHandle h, int dimension);
for clarity (a la Francoise commentary)

I also like the ideas Francoise came up with about
simplifying this area. My suggestions could be laid
in on top of your reformulation if you agree with them.

Thanks for all the work Andre.
It's detailed and thorough, and a good
solution to some tough problem constraints.

Regards,
Doug

> int svUnpackedDimensions(svHandle h);
>
> /* For 1-dimensional packed part */
> int svPackedLeft(svHandle h);
> int svPackedRight(svHandle h);
> int svPackedLow(svHandle h);
> int svPackedHigh(svHandle h);
> int svPackedIncrement(svHandle h);
> int svPackedLength(svHandle h);
>
>
>
> Open array access functions
> =============================
>
> Similarly to sized arrays, there are functions for copying
> data between
> the simulator representation and the canonical representation.
>
> It will be also possible to get the actual address of SV data object
> or of an individual element of an unpacked array.
> This may be useful for the simulator-specific tuning of the
> application.
>
> Depending on the type of an element of an unpacked array,
> different access
> methods are used:
> - packed arrays ('bit' or 'logic') are accessed via copying
> to or from
> the canonical representation
> - scalars (1-bit value of type 'bit' or 'logic') are accessed directly
> - other types of values (e.g. structures) are accessed via
> generic pointers;
> a library function calculates an address and the user should provide
> the appropriate casting
> - all types but scalars may be accessed via pointers, as
> described above
>
> SV allows arbitrary dimensions and hence an arbitrary number
> of indices.
> To facilitate this, a variable argument list functions will be used.
> For the sake of performance the specialized versions of all
> indexing functions
> are provided for 1, 2 and 3 indices.
>
>
> 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.
DOUG: This is clear, as I mentioned above.
However, what happens for fancy cases in the actual argument,
like concatenations, or some kinds of coercions.

>
>
> /* functions for translation between simulator's and canonical
> representations */
>
> /* s=source, d=destination */
>
> /* actual <-- canonical */
> void svPutBitArrElemVec32 (svHandle d, svBitVec32* s, int indx1, ...);
> void svPutBitArrElem1Vec32(svHandle d, svBitVec32* s, int indx1);
> void svPutBitArrElem2Vec32(svHandle d, svBitVec32* s, int
> indx1, int indx2);
> void svPutBitArrElem3Vec32(svHandle d, svBitVec32* s,
> U indx1, int
> indx2, int indx3);
>
> void svPutLogicArrElemVec32 (svHandle d, svLogicVec32* s, int
> indx1, ...);
> void svPutLogicArrElem1Vec32(svHandle d, svLogicVec32* s, int indx1);
> void svPutLogicArrElem2Vec32(svHandle d, svLogicVec32* s, int
> indx1, int indx2);
> void svPutLogicArrElem3Vec32(svHandle d, svLogicVec32* s,
> U indx1, int
> indx2, int indx3);
>
> /* canonical <-- actual */
> void svGetBitArrElemVec32 (svBitVec32* d, svHandle s, int indx1, ...);
> void svGetBitArrElem1Vec32(svBitVec32* d, svHandle s, int indx1);
> void svGetBitArrElem2Vec32(svBitVec32* d, svHandle s, int
> indx1, int indx2);
> void svGetBitArrElem3Vec32(svBitVec32* d, svHandle s,
> U indx1, int
> indx2, int indx3);
>
> void svGetLogicArrElemVec32 (svLogicVec32* d, svHandle s, int
> indx1, ...);
> void svGetLogicArrElem1Vec32(svLogicVec32* d, svHandle s, int indx1);
> void svGetLogicArrElem2Vec32(svLogicVec32* d, svHandle s, int
> indx1, int indx2);
> void svGetLogicArrElem3Vec32(svLogicVec32* d, svHandle s,
> U indx1,U
> indx2, int indx3);
>
> The above functions copy the whole packed array in either direction.
> User is responsible for providing the correct width and for
> allocating an array
> in the canonical representation.
>
>
> Access to scalars ('bit' and 'logic')
> -------------------------------------
>
> Another group of functions is needed for scalars (i.e. when an element
> of an array is a simple scalar, 'bit' or 'logic':
>
> svBit svGetBitArrElem (svHandle s, int indx1, ...);
> svBit svGetBitArrElem (svHandle s, int indx1);
> svBit svGetBitArrElem (svHandle s, int indx1, int indx2);
> svBit svGetBitArrElem (svHandle s, int indx1,U indx2, int indx3);
>
> svLogic svGetLogicArrElem(svHandle s, int indx1, ...);
> svLogic svGetLogicArrElem(svHandle s, int indx1);
> svLogic svGetLogicArrElem(svHandle s, int indx1, int indx2);
> svLogic svGetLogicArrElem(svHandle s, int indx1,U indx2, int indx3);
>
> void svPutLogicArrElem(svHandle d, svBit value, int indx1, ...);
> void svPutLogicArrElem(svHandle d, svBit value, int indx1);
> void svPutLogicArrElem(svHandle d, svBit value, int indx1,
> int indx2);
> void svPutLogicArrElem(svHandle d, svBit value, int indx1,U
> indx2, int indx3);
>
> void svPutBitArrElem (svHandle d, svLogic value, int indx1, ...);
> void svPutBitArrElem (svHandle d, svLogic value, int indx1);
> void svPutBitArrElem (svHandle d, svLogic value, int indx1,
> int indx2);
> void svPutBitArrElem (svHandle d, svLogic value, int indx1,U
> indx2, int indx3);
>
>
> 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.
>
> These functions will be also usefull for the vendors, because
> they provide access to the actual representation for all
> types of arrays.
>
> If the actual layout of the SV array passed as an argument
> for an open unpacked
> array is different than C layout, then it will not be
> posssible to access such
> array as a whole and therefore the address and size of such
> array will be
> undefined (zero, to be exact).
> Nonetheless the adresses of individual elements of an array
> will be always
> supported.
>
> Note that no specific representation of an array is assumed
> here, hence
> all functions use a generic pointer void *.
>
>
> /* a pointer to the actual representation of the whole array
> of any type */
> /* NULL if not in C layout */
> void *svGetArrayPtr(svHandle);
>
> int svSizeOfArray(svHandle); /* total size in bytes or 0 if
> not in C layout */
>
> /* Return a pointer to an element of the array
> or NULL if index outside the range or null pointer */
>
> void *svGetArrElemPtr(svHandle, int indx1, ...);
>
> /* specialized versions for 1-, 2- and 3-dimensional arrays: */
> void *svGetArrElemPtr1(svHandle, int indx1);
> void *svGetArrElemPtr2(svHandle, int indx1, int indx2);
> void *svGetArrElemPtr3(svHandle, int indx1, int indx2, int indx3);
>
>
> Access to array elements of other types
> ---------------------------------------
>
> If array's elements are of a type compatible with C, then
> there is no need
> to use the canonical representation. In such situations the
> elements will
> be accessed via pointers, i.e. the actual address of an
> element will be
> computed first and then used to access the desired element.
>
>
> Example 3 - open array
> ======================
>
> SV:
> typedef struct {int i; ... } MyType;
>
> extern void foo(input MyType i [][]);
> // 2-dimensional unsized unpacked array
> of MyType
>
> MyType a_10x5 [11:20][6:2];
> MyType a_64x8 [64:1][-1:-8];
>
> foo(a_10x5);
> foo(a_64x8);
>
>
> C:
> #include "svc_bin.h"
>
> typedef struct {int i; ... } MyType;
>
> void foo(svHandle h)
> {
> MyType my_value;
> int i, j;
> int lo1 = svUnpackedLow(h, 1);
> int hi1 = svUnpackedHigh(h, 1);
> int lo2 = svUnpackedLow(h, 2);
> int hi2 = svUnpackedHigh(h, 2);
>
> for (i = lo1; i <= hi1; i++) {
> for (j = lo2; j <= hi2; j++) {
>
> my_value = *(MyType *)svGetArrElemPtr2(h, i, j);
> ...
> *(MyType *)svGetArrElemPtr2(h, i, j) = my_value;
> ...
> }
> ...
> }
> }
>
>
>
> Example 4 - open array
> ======================
>
> SV:
> typedef struct { ... } MyType;
>
> extern void foo(input MyType i [], output MyType o []);
>
> MyType source [11:20];
> MyType target [11:20];
>
> foo(source, target);
>
>
> C:
> #include "svc_bin.h"
>
> typedef struct ... } MyType;
>
> void foo(svHandle hin, svHandle hout)
> {
> int count = svUnpackedLength(hin, 1);
> MyType *s = (MyType *)svGetArrayPtr(hin);
> MyType *d = (MyType *)svGetArrayPtr(hout);
>
> if (s && d) { /* both arrays have C layout */
>
> /* an efficient solution using poiter arithmetics */
> while (count--)
> *d++ = *s++;
>
> /* even more efficient:
> memcpy(d, s, svSizeOfArray(hin));
> */
>
> } else { /* less efficient yet implementation independent */
>
> int i = svUnpackedLow(hin, 1);
> int j = svUnpackedLow(hout, 1);
> while (i <= svUnpackedHigh(hin, 1)) {
> *(MyType *)svGetArrElemPtr1(hout, j++) =
> *(MyType *)svGetArrElemPtr1(hin, i++);
> }
>
> }
>
> }
>
>
> ------------------------ End Of C Layer
> --------------------------------------
>
>
> ==============================================================
> ================
> Andrzej I. Litwiniuk, PhD Principal Engineer
> VCS R&D
> Synopsys, Inc
> TEL: (508) 263-8056
> 154 Crane Meadow Road, Suite 300,
> FAX: (508) 263-8069
> Marlboro, MA 01752, USA
> ==============================================================
> ================
>



This archive was generated by hypermail 2b28 : Sat Jan 11 2003 - 19:32:45 PST