Re: [myhdl-list] Wraparound addition?
Brought to you by:
jandecaluwe
From: Christopher L. F. <cf...@uc...> - 2008-08-26 13:26:45
|
>>> >> >> There had been a discussion about that feature back in June of last >> year >> on this mailing list. Here is a link to the achieve of that: >> >> http://sourceforge.net/mailarchive/forum.php?forum_name=myhdl-list&max_rows=25&style=ultimate&viewmonth=200706 >> >> Jan had written some background information about the intention of >> intbv >> there in connection with the wrap around functionality. >> >> This might be a good question to be answered on the FAQ page. > > Ok, what about this: > > http://myhdl.jandecaluwe.com/doku.php/faq#how_do_i_describe_wrap-around_behaviour > Ok more on the wrap functionality. I know this has come up a couple times and may have been answered. The page referenced above has an example for an unsigned counter. In the case for signed values I don't think the mod works? As previously discussed the 2's complement wrap is often exploited in DSP. The solution thus far has been to design within limits (no wrapping). There are some scenarios that the resources required tends to using the 2's comp wrap. Below is an example that illustrates the mod function to support the wrap in MyHDL. I am missing how this can be applied to a signed value and still be convertible. I haven't been able to think of any elegant solutions other than handling a bunch of different cases to handle negatives. Increment Wrap Start Zero 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 Decrement Wrap Start Positive 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 Increment Wrap Start Negative -8 -8 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 Decrement Wrap Start Negative -1 -1 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 from myhdl import * Q = 3 L = 2**Q x = intbv(0, min=-L, max=L) print '\n\nIncrement Wrap Start Zero' for i in range(1, 11*L): print '%4d ' % x, x[:] = (x + 1) % L if i%15 == 0: print '' print '\n\nDecrement Wrap Start Positive' for i in range(1, 11*L): print '%4d ' % x, x[:] = (x - 1) % L if i%15 == 0: print '' print '\n\nIncrement Wrap Start Negative -%d' % L x[:] = -L for i in range(1, 11*L): print '%4d ' % x, x[:] = (x + 1) % L if i%15 == 0: print '' print '\n\nDecrement Wrap Start Negative -1' x[:] = -1 for i in range(1, 11*L): print '%4d ' % x, x[:] = (x - 1) % L if i%15 == 0: print '' |