Hardware Reference
In-Depth Information
Table 7.1 Bit vector functions
Name Description
$countbits Count number of bits in a vector which match the argument values
$onehot0 Check that at most one bit in a vector is high
$onehot Check that exactly one bit in a vector is high
$countones Count number of bits in a vector with value high
$isunknown Check whether a vector has a bit with value x or z
7.1.1
Count Bits with Specific Values
$countbits returns the number of bits of its argument bit vector having the value
of one of the control bits. Bit vector function
$countbits(e, list_of_control_bits) has the following arguments:
￿ e — a bit vector, i.e., a packed or unpacked integral expression. 1
￿ list_of_control_bits — a comma separated list of control bit arguments
carrying the values 1'b1 , 1'b0 , 1'bx or 1'bz .
At least one control bit must be specified. A repetition of a control bit is ignored.
Also, when the width of a control bit argument is bigger than one, its LSB is taken
as the control bit.
Example 7.1.
No bus driver should be in high impedance state when signal en is
true.
Solution:
t
dr_t: assert final (en -> ($countbits(bus_in, 1'bz) == 0));
$countbits is a generalized bit vector function of all other bit vector functions
described in the following sections. The equivalent forms of the other bit vector
functions are shown below. Assume that e is a bit vector expression.
￿ $countones(e) is same as $countbits(e, 1'b1)
￿ $onehot(e) is same as $countbits(e, 1'b1)== 1
￿ $onehot0(e) is same as $countbits(e, 1'b1)<= 1
￿ $isunknown(e) is same as $countbits(e, 1'bx, 1'bz)!= 0
Note that using functions $countones , $onehot and $onehot0 is not always
safe in the presence of unknown values x or z . In this case using $countbits may
be a better choice.
1 It is treated as a vector of equal size assigned from >>{e} ,where >>{} is a streaming operator.
See [ 8 ].
 
Search WWH ::




Custom Search