Browse Source

powerpc: Fix a corner case in __div64_32

The code was incorrectly doing a division by 0 in the case where
the denominator was 0x100000000 and the divisor was 0xffffffff.
Thanks to Fred Liu of Motorola for pointing this out.

Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras 19 years ago
parent
commit
344480b997
1 changed files with 2 additions and 1 deletions
  1. 2 1
      arch/powerpc/lib/div64.S

+ 2 - 1
arch/powerpc/lib/div64.S

@@ -33,9 +33,10 @@ _GLOBAL(__div64_32)
 	cntlzw	r0,r5		# we are shifting the dividend right
 	cntlzw	r0,r5		# we are shifting the dividend right
 	li	r10,-1		# to make it < 2^32, and shifting
 	li	r10,-1		# to make it < 2^32, and shifting
 	srw	r10,r10,r0	# the divisor right the same amount,
 	srw	r10,r10,r0	# the divisor right the same amount,
-	add	r9,r4,r10	# rounding up (so the estimate cannot
+	addc	r9,r4,r10	# rounding up (so the estimate cannot
 	andc	r11,r6,r10	# ever be too large, only too small)
 	andc	r11,r6,r10	# ever be too large, only too small)
 	andc	r9,r9,r10
 	andc	r9,r9,r10
+	addze	r9,r9
 	or	r11,r5,r11
 	or	r11,r5,r11
 	rotlw	r9,r9,r0
 	rotlw	r9,r9,r0
 	rotlw	r11,r11,r0
 	rotlw	r11,r11,r0