[LLVMdev] Optimizing math code

Michael Hamburg mike at shiftleft.org
Mon Feb 17 19:13:02 PST 2014


On Feb 17, 2014, at 6:38 PM, Stephen Checkoway <s at pahtak.org> wrote:

> 
> On Feb 17, 2014, at 8:10 PM, Michael Hamburg <mike at shiftleft.org> wrote:
> 
>> First, addition.  I have multiprecision integer objects, and I’d like to add them component-wise (likewise, subtract, negate, mask…).  For example:
>> 
>> struct mp {
>> 	int limb[8];
>> } __attribute__((aligned(32))) ;
>> 
>> void add(struct mp *a, const struct mp *b, const struct mp *c) {
>>   for (int i=0; i<8; i++) a->limb[i] = b->limb[i] + c->limb[i];
>> }
> 
> If the struct represents an integer, shouldn't the add take the carry into account?

Yes.  However, I’m using a redundant representation, with 56-bit digits in a 64-bit limb.  (The real code uses uint64_t’s instead of ints.)  That way up to 8 bits of carries can accumulate, and I can propagate them all at a more opportune time.

Cheers,
— Mike



More information about the llvm-dev mailing list