[LLVMdev] Add/sub with carry; widening multiply

Domagoj Babic babic.domagoj at gmail.com
Wed Nov 21 11:55:18 PST 2007


On Nov 21, 2007 11:31 AM, Jonathan Brandmeyer <jbrandmeyer at earthlink.net> wrote:
> I've been playing around with llvm lately and I was wondering something about the bitcode instructions for basic arithmetic.  Is there any plan to provide instructions that perform widening multiply, or add with carry?  It might be written as:
> mulw i32 %lhs %rhs -> i64 ; widening multiply
> addw i32 %lhs %rhs -> i33 ; widening add
> addc i32 %lhs, i32 %rhs, i1 %c -> i33 ; add with carry

You would need 2 mulw instructions: signed and unsigned. Those
two functions would be useful.

addw can be easily split into several instructions that compute
the result and carry/overflow separately. Than you can add that
carry using plain add. For details, see:
Henry S. Warren: Hacker's Delight, A. Wesley 2002.


        Domagoj Babic


More information about the llvm-dev mailing list