A bug in div64.s

Paul Mackerras paulus at samba.org
Mon Sep 12 18:26:18 EST 2005

Liu Fred-a18596 writes:

> I found there was a bug in arch/ppc/lib/div64.s.
> The original div64_32() function would produce a zero divide
> exception in case of div64_32(0x100000000, 0xFFFFFFFF).

Thanks for pointing this out.

> Here is the bug-fixed new div64_32()function.

A patch would have been more helpful, so we could see immediately what
you have changed.  Also, notes (or outlook or whatever mail program
you are using) has completely munged all the spacing of the code you

Anyway, I have some comments on your proposed fix:

>                addc.      r9,r4,r10 # rounding up (so the estimate cannot

I understand that the add that I had here can overflow in the case you
pointed out, so we need to preserve the carry.  But why did you use
"addc." rather than "addc" ?

>                mfxer   r12                    #
>                rlwinm. r12, r12, 3, 31, 31    # XER[CA]
>                cmpwi   r12, 1                 # carry ?
>                bne     5f
>                ori     r9, r9, 0x1            # carry !

I think just "addze r9,r9" would do instead of these 5 instructions,
wouldn't it?


More information about the Linuxppc-dev mailing list