Mantis 2269
Clarify static casting
In
Section 6.24.1
CHANGE
In a static
cast, the expression to be cast shall be enclosed in parentheses that are
prefixed with the casting type and an apostrophe. If the expression is
assignment compatible with the casting type, then the cast shall return the
value that a variable of the casting type would hold after being assigned the
expression. If the expression is not assignment compatible with the casting
type, then if the casting type is an enumerated type, the behavior shall be as
described as in 6.24.2, and if the casting type is a bit-stream type,
the behavior shall be as described in 6.24.3.
int’(2.0
* 3.0)
shortint'({8’hFA,8’hCE})
A positive
decimal number as a data type means a number of bits to change the size.
17’(x
- 2)
The signedness can also be changed.
signed’(x)
The expression inside the cast must be an
integral value when changing the size or signing. When changing the size, the
signing shall pass through unchanged and the result type shall be a one-dimensional
packed array with a right bound of zero. When changing the signing, the type of
the expression to be cast shall pass through unchanged, except for the signing.
TO
In a static
cast, the expression to be cast shall be enclosed in parentheses that are
prefixed with the casting type and an apostrophe. If the expression is
assignment compatible with the casting type, then the cast shall return the
value that a variable of the casting type would hold after being assigned the
expression. If the expression is not assignment compatible with the casting
type, then if the casting type is an enumerated type, the behavior shall be as
described as in 6.24.2, and if the casting type is a bit-stream type,
the behavior shall be as described in 6.24.3.
int’(2.0
* 3.0)
shortint'({8’hFA,8’hCE})
Thus, in the
following example, if expressions expr_1 and expr_2 are assignment compatible with data types cast_t1 and cast_t2,
respectively, then
A = cast_t1'(expr_1) + cast_t2'(expr_2);
is the same as
cast_t1 temp1;
cast_t2 temp2;
temp1 = expr_1;
temp2 = expr_2;
A = temp1 + temp2;
Thus,
an implicit cast (e.g., temp1 = expr1), if defined,
gives the same results as the corresponding explicit cast (cast_t1'(expr1)).
A positive
decimal number as a data type means a number of bits to change the size.
17’(x
- 2)
The signedness can also be changed.
signed’(x)
The expression inside the cast must be an
integral value when changing the size or signing. When changing the size, the signing shall pass through unchanged and the result type
shall be a one-dimensional packed array with a right bound of zero the cast shall
return the value that a packed array type with a single [n-1:0] dimension
would hold after being assigned the expression, where n is the cast
size. The signedness shall pass through unchanged,
i.e., the signedness
of the result shall be the self-determined signedness of the expression inside
the cast. The array elements shall be of type bit if the expression inside the cast is 2-state, otherwise they shall
be of type logic.
When changing the signing, the type of the expression to be cast shall pass through
unchanged, except for the signing. the cast shall
return the value that a packed array type with a single [n-1:0] dimension
would hold after being assigned the expression, where n is the number
of bits in the expression to be cast ($bits(expression)). The signedness of the result shall be the signedness
specified by the cast type. The array elements shall be of type bit if the expression inside the
cast is 2-state, otherwise they shall be of type logic.
NOTE – The $signed() and
$unsigned() system functions (see 11.7) return the same results as signed'() and unsigned'(),
respectively.
Examples:
logic [7:0]
regA;
logic signed [7:0]
regS;
regA = unsigned’(-4); // regA =
8'b11111100
regS =
signed’(4'b1100); // regS = -4
In Section
11.7,
CHANGE
The cast
operator can be used to change either the signedness
or type of an expression (see 6.24.1). In addition to the cast operator, the $signed
and $unsigned system functions are available
for casting the signedness (but not the type) of
expressions. These functions shall evaluate the input expression and return a
value with the same size and value of the input expression and the type defined
by the function.
TO
The cast
operator can be used to change either the signedness
or type of an expression (see 6.24.1). In addition to the cast operator, the $signed
and $unsigned system functions are available
for casting the signedness (but not the
type) of expressions. These functions shall evaluate the input
expression and return a value one-dimensional packed array with the
same size number of bits and value of the input expression and the type signedness defined by the function.