From: Adam Krolnik (adamk@cyrix.com)
Date: Thu Apr 02 1998 - 20:41:02 PST
Behavioral Task Force - Enhancement Request
Assigned Enhancement Request Number: B15
Enhancement Name (Description): Built-in sizeof(x) function
Date Submitted: 970319
Requestor: adamk@cyrix.com (Adam Krolnik)
Status: RO
Is enhancement intended to be synthesizable?: yes
<p>7. Size of registers.
It would be nice to access the size of the registers without having to
define a macro, or a symbol to hold the value. If the width of constants can
be based on the lhs then this becomes less of a need and more of a
nice-to-have. E.g. instead of
`define SIZE_A 32
reg [SIZE_A-1:0] a;
if (a == `SIZE_A h 123)
From: mac@silicon-sorcery.com
Date: Wed, 19 Mar 97 14:22:50 PST
Another justification would be:
for (i = 0; i < sizeof(a); i = i + 1) begin
if (a[i]) $display($stime,,"a[%d] is set",i);
end
I could support adding this to the language.
<p>Karen's comment on this enhancement was to restrict it usage to run-time
statements. I.e. Declarations can't use this function.
If this needs to be defined within the BNF, these definitions will need to be
separated into declaration and run-time: "constant expression", "range".
Once this is done, one can extend the BNF as follows:
Add to the "constant_primary" definition,
"| sizeof '(' sizeof_identifier ')'"
Add to the "primary" definition,
"| sizeof '(' sizeof_identifier ')'"
Add the definition of "sizeof_identifier"
izeof_identifier ::=
reg_identifier
| net_identifier
<p>To section 4 "Expressions" add the following lines to the last unordered list:
" - Size of a net"
" - Size of a parameter, reg, integer, and time."
To section 4.2 "Operands" add the following lines to the third paragraph:
"The size of a vector net or register is also an operand."
Insert this section in between sections 4.2.2 "Memory addressing" and 4.2.3 "Strings":
"4.2.3 Size of an identifier"
"The size of an identifier may be obtained by the use of the sizeof function. The value returned is the number of bits that compose the given identifier. An identifier composed
of 1 bit has a size of 1. A vector has the size of the number of bits declared. This
function shall not be used when declaring identifiers.
Example:
reg [31:0] selection;
integer i;
always @(event)
for(i=0;i<sizeof(selection); i = i + 1)
begin
if (selection[i]) $display("Bit %0d set in selection.", i);
end
This example shows a code fragment that iterate through all the bits of 'selection'
regardless of its size in the declaration."
This archive was generated by hypermail 2.1.4
: Mon Jul 08 2002 - 12:52:47 PDT
and
sponsored by Boyd Technology, Inc.