From 9b2190b382036354e4ff7026d2cd8f3f4fe8337d Mon Sep 17 00:00:00 2001 From: xleroy Date: Sun, 21 Apr 2013 16:13:55 +0000 Subject: Fixes in PowerPC port git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2209 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- runtime/powerpc/i64_umod.s | 60 +++++----------------------------------------- 1 file changed, 6 insertions(+), 54 deletions(-) (limited to 'runtime/powerpc/i64_umod.s') diff --git a/runtime/powerpc/i64_umod.s b/runtime/powerpc/i64_umod.s index 2f467127..a4f23c98 100644 --- a/runtime/powerpc/i64_umod.s +++ b/runtime/powerpc/i64_umod.s @@ -34,62 +34,14 @@ # Helper functions for 64-bit integer arithmetic. PowerPC version. - .text - -# Unsigned modulus + .text -# This function computes both the quotient and the remainder of two -# unsigned 64-bit integers. Called from C, it returns the remainder. +### Unsigned modulus -# Input: numerator N in (r3,r4), divisor D in (r5,r6) -# Output: quotient Q in (r7,r8), remainder R in (r3,r4) -# Locals: mask M in (r9,r10) - - .globl __i64_umod - .balign 16 + .balign 16 + .globl __i64_umod __i64_umod: - # Set up quotient and mask - li r8, 0 # Q = 0 - li r7, 0 - li r10, 1 # M = 1 - li r9, 0 - # Check for zero divisor - or. r0, r6, r5 - beqlr # return with unspecified quotient & remainder - # Scale divisor and mask -1: cmpwi r5, 0 # while top bit of D is zero... - blt 2f - subfc r0, r6, r4 # compute borrow out of N - D - subfe r0, r5, r3 - subfe. r0, r0, r0 # EQ iff no borrow iff N >= D - bne 2f # ... and while N >= D ... - addc r6, r6, r6 # scale divisor: D = D << 1 - adde r5, r5, r5 - addc r10, r10, r10 # scale mask: M = M << 1 - adde r9, r9, r9 - b 1b # end while - # Long division -2: subfc r4, r6, r4 # Q = Q | M, N = N - D, and compute borrow - or r8, r8, r10 - subfe r3, r5, r3 - or r7, r7, r9 - subfe. r0, r0, r0 # test borrow - beq 3f # no borrow: N >= D, continue - addc r4, r4, r6 # borrow: undo what we just did to N and Q - andc r8, r8, r10 - adde r3, r3, r5 - andc r7, r7, r9 -3: slwi r0, r9, 31 # unscale mask: M = M >> 1 - srwi r10, r10, 1 - or r10, r10, r0 - srwi r9, r9, 1 - slwi r0, r5, 31 # unscale divisor: D = D >> 1 - srwi r6, r6, 1 - or r6, r6, r0 - srwi r5, r5, 1 - or. r0, r10, r9 # iterate while M != 0 - bne 2b - blr - + b __i64_udivmod .type __i64_umod, @function .size __i64_umod, .-__i64_umod + -- cgit