[LLVMdev] Bignum development

Eli Friedman eli.friedman at gmail.com
Fri Jun 11 14:44:29 PDT 2010


On Fri, Jun 11, 2010 at 10:37 AM, Bill Hart <goodwillhart at googlemail.com> wrote:
> a) What plans are there to support addition, subtraction,
> multiplication, division, shifting, logical not and other logic ops
> for >= 64/128 bits (machine word size, whatever)? The documentation
> mentions integers of millions of bits....

Pretty much everything besides muliplication and division should work
at any width; the result is generally not especially efficient,
though.

> b) Would it be desirable to add primitives for retrieving both the low
> and high half of a multiplication and optimisations to combine where
> wide multiplications are available on the chip?

This should already work where applicable; for example, the following
C code gives an appropriately optimized result on x86-32:

int a(int x, int y) { return ((long long)x)*y >> 32; }

> c) I want to ask something about retrieving the carry or borrow from
> an addition or subtraction and using it in an ADC or SBB..... not sure
> what to ask.....

LLVM automatically expands wide addition/subtraction with ADC/SBB.
There's no other general way to write something which optimizes to an
ADC/SBB, at least at the moment.  What do you want here?

> d) Are you guys at all interested in supporting languages that provide
> multiprecision arithmetic? I have a vague notion that I'd like to sign
> on to help with that (and may be able to bring some other experienced
> devels with me if there was some interest).

By that, you mean languages that provide arbitrary-width integers?
You can already support that by lowering such operations to calls to a
multi-precision library instead of IR operations in your frontend.  It
would be an interesting experiment to write a pass which converts IR
operations which are too wide to calls to a multi-precision library,
though.

-Eli



More information about the llvm-dev mailing list