[LLVMdev] Checked arithmetic

Duncan Sands baldrick at free.fr
Wed Mar 26 07:47:59 PDT 2008


Hi Shap,

> > 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.

can you really use condition codes for multiply and floating point?  You
can handle integer multiply by doing it in an integer twice as wide as the
one you are interested in, so an i64 on a 32 bit machine.  Is there hardware
that supports checking for multiply overflow in a more efficient fashion,
and if so how does it work/get used?

Thanks,

Duncan.



More information about the llvm-dev mailing list