Forum Discussion
Altera_Forum
Honored Contributor
13 years agojudgement on whether or not there is an overflow
I have 3 numbers x, y, z to be added together, each with the format of s1.14. Then the sum will be in the format of s3.14. How to make judgement on whether or not there is an overflow? If it is judg...
Altera_Forum
Honored Contributor
13 years ago --- Quote Start --- Sum is just an intermediate variable for the calculation, and the final output has the same number of bits as input. Besides, there is also an output (a flag) indicating whether there is an overflow in the final result. Then, how to make a judgement on whether or not there is an overflow, and why? --- Quote End --- in general if your internal bitwidth is say 20 bits and you want only 16 LSBs out then you check bit(18:15) if it is different from sign bit then you clip output to either +32767 or -32767 and raise the flag, otherwise you pass the 16 bits direct out.
if data_int(19 downto 15) = "00000" or data_int(19 downto 15) = "11111" then
dout <= data_int(15 downto 0);
clip <= '0';
elsif if data_int(19) = '0' then
dout <= 32767;
clip <= '1';
else
dout <= -32767;
clip <= '1';
end if;