Hi, Lets say, I have a 6 bit rounded result (4 Int,2 Frac) from a signed multiplication. But i need a 4 bit output (2 int and 2 frac). So now I will have to check if the result overflows when i remove some integer bits. From this point could you check if i am doing the following logic correctly.
Assume 'x' is the 6 bit rounded result. and 'res' is the 4 bit output needed.
Code:
if x(5 downto 4) /= (x(3)&x(3)) then
if x(5) = '1' then
res <= (3=>'0', others=>'1');
else
res <= (3=>'1', others=>'0');
end if;
else
res <= x (3 downto 0);
end if;
If you tried out the fixed point packages, it would easy to do something like:
Code:
if x > to_sfixed(1.75, 4, -2) then
res <= to_sfixed(1.75, 1, -2);
elsif x < to_sfixed(-2.0, 4, -2) then
res <= to_sfixed(-2.0, 1, -2);
else
res <= x(1 downto -2);
end if;