[LLVMdev] Checked arithmetic

Jonathan S. Shapiro shap at eros-os.com
Wed Mar 26 07:33:24 PDT 2008

On Wed, 2008-03-26 at 15:07 +0100, Duncan Sands wrote:

> 4. Do arithmetic in a type with one more bit.  For example, suppose you
> want to know if an i32 add "x+y" will overflow.  Extend x and y to 33
> bit integers, and do an i33 add.  Inspect the upper bit to see if it
> overflowed.  Truncate to 32 bits to get the result.  Probably codegen
> can be taught to implement this as a 32 bit add + inspection of the CC.

As a quick fix, that isn't a bad solution for bignum arithmetic, but it
doesn't deal with the upper bits from multiply, and it doesn't deal with
floating point condition codes at all.


More information about the llvm-dev mailing list