Subject: [sv-cc] Re: Calling SV from C
From: Francoise Martinolle (fm@cadence.com)
Date: Wed Feb 05 2003 - 15:20:42 PST
My comments starting by Francoise:
At 01:35 PM 2/5/2003 -0500, Andrzej Litwiniuk wrote:
>Francoise wrote:
> >
> > I don't understand section 5.2 calling SV functions from C:
> >
> > "Note that the functions exported from SV may not have open arrays as
> > arguments.
> > Otherwise the same types of formal arguments may be declared in SV both for
> > the exported functions and for the external functions.
>
>Well, what I wanted to say was that generally the exported functions may have
>the same types of formal arguments as the external functions, with the
>exception
>of open arrays.
>
>I should have added also that similar restrictions are required for the
>function
>result type. This is definitely missing.
>
>
> > A function exported from SV will have the same function header as the
> external
> > function with the same function result type and same formal argument list."
> >
> >
> > My understanding was that there is an export declaration of the SV
> function
> > in the Verilog code.
>
>Right.
>I suppose that the export declaration will only provide the function name
>and the hierarchical path. The path will identify both the unique instance and
>the unique function declaration. There is no need to repeat the
>specification of formal arguments and function result.
Francoise:
I thought it would have been useful to include the prototype in the export
declaration if
SV compilers intend to generate automatically the extern C declaration. But
I don't think it is possible as the function declaration can involve
parameters which are defined by the
module definition.
> > There must also be an extern function declaration in C indicating that
> this
> > function is extern to the C file.
> > The formal arguments types, modes and argument passing of the C function
> > extern declaration must comply with the rules which were defined for a SV
> > function calling a directC function.
> > Therefore the user declare this function and determine the matching types
> > to the Verilog function
> > data types.
>
>Right.
>
>
> > Example:
> > typedef struct {int i; double r;} complex;
> > export logic [15:0] myfunc (input int address, output logic [31:0] r,
> input
> > T complex)
>
>Two modifications.
>
>First, function result types are restricted for the exported
>functions in the same way as for the external functions.
>Assume for the sake of this example, that function result type is "bit [15:0]"
>rather than "logic [15:0]".
>
>Second modification: 'myfunc' will be mentioned twice: in its primary
>declaration and in an export declaration.
Francoise: agreed
>So, SV portion may look like:
>
>typedef struct {int i; double r;} T; // "T" rather than "complex"?
>export a.b.c.myfunc; // whatever is the current syntax ...
> // a.b.c identifies a unique instance of a module where myfunc is defined
>...
>module M;
> ...
> function bit [15:0] myfunc (input int address, output logic [31:0] r,
> input T complex);
> begin ... end endfunction
> ...
>endmodule
>
>
> > The extern function declaration which will be used would be:
> > extern SVlogicVec32 myfunc (int address, SVlogicVec32 *r, T *complex)
> > address is passed by value, r is passed by reference, complex is passed by
> > reference, the function
> > return is a 32 bit logic struct.
> >
> > Correct?
>
>Almost correct. With the result type changed from 'logic' to 'bit'
>the extern function declaration which will be used would be:
>
>extern svBitVec32 myfunc (int address, svLogicPackedArrRef r, const T
>*complex);
>
> > the function return is a 32 bit logic struct.
>actually svBitVec32, because of the modification we had to make (logic-->bit)
>
> > address is passed by value
>Right.
>
> > r is passed by reference
>Right, svLogicPackedArrRef is a reference (actually typedefed to void *);
>note that the representation is implementation-dependent.
Francoise: Why can't I use svLogicVec32* for r?
> > complex is passed by reference
>Right, and qualified as 'const'.
>
>
>
> > If I am not understanding this correctly, please explain and or reword
> > section 5.2
>
>I believe you are understanding this correctly, by and large.
>
>
> > Another question I have is what would be the C matching type of a
> output SV
> > function
> > argument which is output logic r[31:0]; (unpacked array of 32 elements, 1
> > bit wide).
>
>svLogic *, I suppose. The actual size of an unpacked array is obviously
>absent.
Francoise: How do I know in my C code how big is the svLogic*? Do I have to
rely on the
SV declaration?
>Andrzej
This archive was generated by hypermail 2b28 : Wed Feb 05 2003 - 15:21:28 PST