J
Josh
Guest
Consider the following example, compiling with VHDL-2008 support.
library ieee;
use ieee.numeric_std.all;
....
if (to_unsigned(0, 3) <= 8) then
StatementsA
end if;
if (to_unsigned(1, 3) <= 8) then
StatementsB
end if;
In my experience, StatementsA get executed, but not StatementsB.
Logically I would expect that both statements get executed since 0 and
1 are both less than 8. My theory is that 8 is interpreted as a 3 bit
number, and the top bit is being lost, creating the value of 0.
Questions
1. Is this the intended behavior of VHDL?
2. What is the logic/reasoning behind this? Why wouldn't the size of
the comparison automatically be resized to the required size of the
integer?
3. What is a logical & safe practice to encourage in order to avoid
situations like this?
library ieee;
use ieee.numeric_std.all;
....
if (to_unsigned(0, 3) <= 8) then
StatementsA
end if;
if (to_unsigned(1, 3) <= 8) then
StatementsB
end if;
In my experience, StatementsA get executed, but not StatementsB.
Logically I would expect that both statements get executed since 0 and
1 are both less than 8. My theory is that 8 is interpreted as a 3 bit
number, and the top bit is being lost, creating the value of 0.
Questions
1. Is this the intended behavior of VHDL?
2. What is the logic/reasoning behind this? Why wouldn't the size of
the comparison automatically be resized to the required size of the
integer?
3. What is a logical & safe practice to encourage in order to avoid
situations like this?