- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 judged based on the first 3 MSB and they are ALL either zeros or ones, is there is no overflow? why? Does the overflow in the middle cares (e.g. I have more than 3 addition)?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the rule is :
For an N bit number N + N = N+1 bits required. So N + N + N requires N+2 bits. Which is what you have, hence it will never overflow.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the final result doesn't have an overflow, does an overflow in the middle of the calculation matters?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- If the final result doesn't have an overflow, does an overflow in the middle of the calculation matters? --- Quote End --- Yes it does. Normally you should not allow that by applying enough width for internal bit growth. If your application permits you may clip internally instead in the same way as my example but adjusted for relevant widths

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page