Date: 2001-04-03 15:43:03
I believe the fixed width integers I proposed do behave the way I want
them to. I apologize that I didn't explain clearly what it is they
were supposed to do. Let me try again.
Suppose I am developing a signal processing algorithm. Typically I
will start with a floating-point algorithm. This will often need to
be converted to fixed-point for hardware implementation. Here,
fixed-point really means integer.
In the final design each input and output of each step will have a
specific bit-width. To aid in the simulation I will often begin by
converting everything to integer. In the vast majority of cases, I
will never need more than sizeof(int)*8 bits. Therefore, I can just
use "int" or "long" everywhere.
Now I want to assign specific widths. I want to check for overflow at
specific points in the data path. I'd like to be able to choose at least
two actions on overflow: a) report an error or b) simulate the effect of
For intermediate results I will just use int. Assume it can be proven
by design that overflow could not occur at these points, so there is
no reason to check.
So the only thing this class does is perform the check. The example
you gave of multiplying Int<4> x Int<4> in a 4-bit domain doesn't
happen. The only operation you can do on Int<4> is convert it to int,
Then you could multiply the int's together, resulting in a correct int-size
result. This is then checked when it's assigned back to
Int<whatever>, if ever.
Note that the class is only designed for signed numbers - that's why
it's called sint. Handling unsigned also is something that should be
added. I'm not sure how much common factoring could be done between
I know this is all pretty trivial compared to the stuff that usually
is discussed on this list. I think it's important because other
attempts I have seen to solve this problem are far more complicated
and expensive - and I don't really think the added complication is
needed. The only thing that's important is to check for overflow on
assignment and perform a specific action.
Another improvement would be to correctly handle the case where an int
is not sufficient.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk