RE: $sv-ec References in SystemVerilog (proposal)


Subject: RE: $sv-ec References in SystemVerilog (proposal)
From: David W. Smith (david.smith@synopsys.com)
Date: Thu Sep 19 2002 - 11:31:55 PDT


I think the first discussion that has to occur is how many of the
following three (and possibly more) items we are trying to provide:

1. support of opaque pointers that can be passed in from C calls and
passed to other C calls but have no other usefulness in SV.

2. support pass-by-reference semantics for passing composite data types
around. There is no pointer and no pointer arithmetic to deal with. This
has the advantage of allowing calls to be more effecient but the
possibility of unintended modifications of data. The type of data
structure would be manipulated in the called location the same as in the
calling (arrays are indexed, structures are refenced by field, etc).

3. support full pointer concepts where pointer arithmetic can be used
etc... The problem here is that it can be either a cost due to extensive
checking or stability problems.

So, what do we requirement do we have for reference and/or pointers in
System-Verilog?

Regards
David

David W. Smith
Synopsys Scientist

Synopsys, Inc.
Synopsys Technology Park
2025 NW Cornelius Pass Road
Hillsboro, OR 97124

Voice: 503.547.6467
Main: 503.547.6000
FAX: 503.547.6906
Email: david.smith@synopsys.com
http://www.synopsys.com

-----Original Message-----
From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of
Kevin Cameron
Sent: Wednesday, September 18, 2002 7:53 PM
To: sv-ec
Subject: $sv-ec References in SystemVerilog (proposal)

I'm not sure if there is an official donation for references or not,
'var' appeared in some of the Testbench discussion - but I had trouble
tracking down the text. SuperLog has some ref/deref stuff that was not
donated. Either of those approaches introduce new keywords and are a
little unwieldy. I'd like to propose something more along the lines of
C++'s & reference operator - using operators instead of keywords. E.g.:

    int table[15:0],
                   &pt; // pt is an integer reference
    ....
        pt &= table[5]; // pt becomes a reference to table entry 5
        ...
        pt = 12; // table[5] becomes 12

Since '&' is not valid as an identifier name and expressions are not
expected in that context, there is no clash with its other uses. The
assignment operator "&=" can be read as "refers to" and is similar to "
= & " in C. No dereference operator is required, new operators can be
added to manipulate the reference e.g.:

        pt &++; // increment reference to next element
        pt &--; // decrement

        pt &+= shift; // move reference by shift
        pt &-= shift; // ditto -shift

        pt &= null; // invalidate.

An out of range assignment would be the same as a null assignment,
comparison operators would allow for checking:

        if (pt &== null) begin...

        if (pt &!= table[3]) begin // skip special entry
         ....

Using a null reference would be a runtime error, and references would be
initially null. A reference can be used with "new" to create new objects
e.g.:

        int &pi[4:0]; // pi is a reference to 5 int array
        initial begin
            pi &= new; // create a 5 int array
            pi[0] = 1;
            ....

A "destroy" method is not required as the object will be reclaimed
automatically when no references exist.

The '&' can be used in task/function call argument lists to indicate
pass-by-reference.

        task foo (output int bar, input integer &data[1023:0]);
            ...

References can be written to channels (of the reference type), e.g.:

        typedef int pckt[0:255];
        channel pckt dut_data; // data channel to hardware
        typedef pckt &pp;
        channel pp ref_data; // channel to test-bench
        ...
        @(send_pkt) begin
            pp &= new;
            init_pckt(pp); // fix data
            dut_data <= pp; // send data to DUT
            ref_data <&= pp; // send reference to checker
        end

Note: each iteration of the loop above creates a new packet object which
exists until all references to it are destroyed, i.e. it will exist
until the reference written to the ref_data channel is read and
discarded.

-----------------------

If the text isn't in the right form for official consideration I'll
rewrite it. Feedback appreciated in the interim.

Regards,
Kev.



This archive was generated by hypermail 2b28 : Thu Sep 19 2002 - 11:35:05 PDT