[PATCH] Fix carry bug in 128-bit unsigned integer adding

Kumar Gala galak at kernel.crashing.org
Tue Jan 8 17:27:59 EST 2008


On Jan 6, 2008, at 8:26 AM, Liu Yu wrote:

> This bug exists in math emulation for powerpc.
> The macro define are mainly used by multiplication.
>
> When adding two unsigned operands ( r = x + y ),
> the carry bit can be counted by whether r is less than x.
> However, when adding three unsigned operands, this method does not  
> work.
>
> The original code below uses this method to count carry,
> it apparently overlook the case of three operands.
> Assume all the operands is 32-bit wide,
> ( r = x + y + last_carry , x = 0, y = 0xffffffff, last_carry = 1),
> then r is no less than x but it actually gets a carry.
>
> I tried to fix this bug, but this patch seems not that pretty.
> Are there any better ideas?
> Comments are always welcomed!

take a look at how include/math-emu/op-4.h implements __FP_FRAC_ADD_4  
& __FP_FRAC_SUB_4.  Will that fix the bug, if so we should make the  
code match how its done there.

- k




More information about the Linuxppc-dev mailing list