Re: [sv-bc] packed array question

From: Brad Pierce <Brad.Pierce_at_.....>
Date: Sat Dec 17 2005 - 00:01:50 PST
Steven,

I think the proposed syntax would still fit naturally into SV.

The LRM doesn't exactly say that the 'signed' applies to the "rightmost
dimension".  Sure, this is true if there are any unpacked dimensions.
The LRM in 5.2 says

    "If an unpacked array is declared as signed, then this applies to
the individual elements of the array because the whole array cannot be
viewed as a single vector."

For example, in

    bit signed [3:0] [7:0] j [256] [32]

there are 256 arrays of 32-bit signed words, each composed of 4 unsigned
bytes.

But when there are no unpacked dimensions, the 'signed' applies not to
the rightmost *actual* dimension, but only to some phantom unpacked
dimension even further to the right.  The LRM in 5.2 says

     "If a packed array is declared as signed, then the array viewed as
a single vector shall be signed. The individual elements of the array
are unsigned unless they are of a named type declared as signed."

For example, in

    bit signed [7:0] k;

it's not the elements (bits) of the packed dimension that are signed,
but the vector k as a whole.  The 'signed' and the '[7:0]' are parallel
attributes of k.  The '[7:0]' says how long k is and how k is to be
indexed into, and the 'signed' says how to extend k when k is the
operand of a longer operation.  The tool must always be informed of the
values of *both* attributes, although the default value 'unsigned' makes
that fact easy to overlook.

Likewise, in

    bit signed [3:0] [7:0] m;

or as allowed in the proposed syntax

    bit signed [3:0] unsigned [7:0] m;

the entire vector is signed, not the individual bytes.  To make a signed
word of signed bytes in the suggested syntax you would write --

    bit signed [3:0] signed [7:0] n;

and to make an unsigned word of signed bytes you would write --

    bit [3:0] signed [7:0] o;    

or

    bit unsigned [3:0] signed [7:0] o;

-- Brad


-----Original Message-----
From: Steven Sharp [mailto:sharp@cadence.com] 
Sent: Friday, December 16, 2005 5:47 PM
To: sv-bc@eda.org; Brad.Pierce@synopsys.COM
Subject: Re: [sv-bc] packed array question


>From: "Brad Pierce" <Brad.Pierce@synopsys.com>

>But, according to the current BNF you can't do --
>
>   bit [4:0] signed [31:0] i;
>
>The BNF would make more sense as --
>
>  packed_dimension ::=
>      [ signing ] '[' constant_range ']'
>   |  [ signing ] unsized_dimension
>
>Signedness should be an attribute of a dimension.

The Cadence datatype proposal to 1364 had this capability.  Most
people found it confusing when they first saw the description.
For most people, it is only after playing with packed arrays for
a while that they run into the need to control signedness of
slices at each level, and then suddenly the description makes
sense (and they realize that SV lacks a useful capability).

I don't believe you can add this to SV now, because it has
already defined that the 'signed' keyword on the far left applies
to the rightmost dimension.  This prevents you from having the
'signed' keyword apply to the dimension immediately after it.

I believe it is possible in SV to use typedefs to get one of the
lower dimensions to be signed, but there is no way to get multiple
dimensions to be signed, even building it with multiple levels of
typedefs.  This could probably be fixed though.

Steven Sharp
sharp@cadence.com
Received on Sat Dec 17 00:02:21 2005

This archive was generated by hypermail 2.1.8 : Sat Dec 17 2005 - 00:04:49 PST