I have a design were I'm writing/reading to/from a RAM and perform some computation on the read values. In some cases, I read values from RAM locations where I haven't written anything to yet. This is intentional because in the cases where this happens, the uninitialized values don't affect the computation: in these cases, the uninitialized values are multiplied with 0.
However, multiplying an unsigned
/signed
type which contains 'U'
bits results in a "don't care" output (i.e. all bits of the multiplication output are 'X'
) even if the other operand is 0. Therefore, I can't check the final computation output in my testbench because it becomes "don't care" (it seems like "don't care" outputs are interpreted as 0).
To avoid this problem, I wrote a function that resolves any 'U'
or 'X'
bits in a std_logic_vector
to '0'
. The functions looks as follows
function f(x : std_logic_vector) return std_logic_vector is
variable y : std_logic_vector (x'range);
begin
y := x;
-- pragma synthesis off
for i in 0 to x'length-1 loop
case x(i) is
when 'U' | 'X' => y(i) := '0';
when others => y(i) := x(i);
end case;
end loop; -- i
-- pragma synthesis on
return y;
end;
Now I'd like to expand the function by not only setting 'X'
and 'U'
bits to '0'
but to randomly set them to either '0'
or '1'
. I've tried using the uniform
function within f
. The problem is that when I define the two seeds within the function, that each time the function f
is called it returns the same std_logic_vector
(when it is given the same std_logic_vector
). As I take it from the uniform
function description, I should pass the two seeds from outside the function f
because they are modified by the uniform
function for the next call to uniform
.
Is there a possibility how this can be achieved using a function?