Altera_Forum
Honored Contributor
18 years agoBit extending when adding
Hello,
I'm trying to add an signed std_logic_vector(21 downto 0) with a std_logic (unsigned) using the vhdl operator "+". I'm using the "IEEE.std_logic_signed.all" library . I just assumed that the result would be a 23 bit number but the compiler complained and said that the result needed to be a 22 bit vector. Why is that? Does it interpret my std_logic as a signed? My first attempt looks like this:
signal p_value_truncated : std_logic_vector(21 downto 0);
signal p_value_rounded : std_logic_vector(22 downto 0);
signal p_value_carry : std_logic;
...
p_value_rounded <= p_value_truncated + p_value_carry;
This is going to be in a regulator so it is important that is does not overflow. To make sure, I've opted to sign extend p_value_truncated to 23 bits and extend p_value_carry with a zero. Does anyone understand how the compiler works in this case? Best Regards, Ola Bångdahl