From: Steven Sharp (sharp@cadence.com)
Date: Tue Nov 04 2003 - 13:11:04 PST
>$itos and $stoi would be very useful.
>We have often had need for such.
I assume that most of the need for $itos and $stoi can be met by the
Verilog-2001 system tasks $swrite and $sscanf with %d formats, though
they may not be as convenient as function versions in some situations.
I don't know if you were reading the details of the earlier discussion,
but there are some issues with function versions. All operands in
Verilog expressions must have known widths at compile time, including
system functions. This width can depend on things known at compile
time (such as the width of the arguments), but not on things that are
not known at compile time (such as the values of variables). So if you
want $itos to accept variable arguments and be able to produce the
correct string for the maximum possible value of the arguments, the
result must be as wide as that maximum possible value needs. And that
means that it will be that wide even for smaller values.
For example, a 32-bit signed integer requires 10 decimal digits to
represent the maximum value, 11 if you allow for a negative sign. That
means an 80 or 88 bit wide vector result. Even if the argument turns out
to be 1, the result would still be 88 bits wide. The lowest byte would
presumably be the ASCII character "1", but what should be used for the
upper bytes? The obvious candidates are:
- zero-extend the value with zero bits (creating NUL bytes). This is
what you would get if you assigned the shorter string "1" to the larger
80 or 88 bit wide vector.
- zero-pad the numeric field with "0" characters (e.g. "00000000001"
or maybe " 00000000001" or "+00000000001" if we had to leave space for
a negative sign). The first is how binary or hex values get printed
by $display. There is no example of the signed situations since binary
and hex formats print as unsigned and decimal format can print a sign
but doesn't print leading zeros. Some version of this might work for
Krishna's back-end tools, since they may be able to parse numbers with
leading zeros.
- pad with spaces (e.g. " 1"). This is how decimal values are
printed by $display.
Steven Sharp
sharp@cadence.com
This archive was generated by hypermail 2.1.4
: Tue Nov 04 2003 - 14:34:25 PST
and
sponsored by Boyd Technology, Inc.