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_scmp.s | 8 ++-- runtime/powerpc/i64_sdiv.s | 2 +- runtime/powerpc/i64_smod.s | 2 +- runtime/powerpc/i64_udiv.s | 2 +- runtime/powerpc/i64_udivmod.s | 95 +++++++++++++++++++++++++++++++++++++++++++ runtime/powerpc/i64_umod.s | 60 +++------------------------ 6 files changed, 108 insertions(+), 61 deletions(-) create mode 100644 runtime/powerpc/i64_udivmod.s (limited to 'runtime') diff --git a/runtime/powerpc/i64_scmp.s b/runtime/powerpc/i64_scmp.s index 8963006..87811e0 100644 --- a/runtime/powerpc/i64_scmp.s +++ b/runtime/powerpc/i64_scmp.s @@ -36,11 +36,11 @@ .text -### Unsigned comparison +### Signed comparison .balign 16 - .globl __i64_ucmp -__i64_ucmp: + .globl __i64_scmp +__i64_scmp: cmpw cr0, r3, r5 # compare high words (signed) cmplw cr1, r4, r6 # compare low words (unsigned) mfcr r0 @@ -67,6 +67,6 @@ __i64_ucmp: # = 0 if X = Y blr .type __i64_scmp, @function - .size __i64_scmp, .-__i64_ucmp + .size __i64_scmp, .-__i64_scmp \ No newline at end of file diff --git a/runtime/powerpc/i64_sdiv.s b/runtime/powerpc/i64_sdiv.s index 6f2547f..f522506 100644 --- a/runtime/powerpc/i64_sdiv.s +++ b/runtime/powerpc/i64_sdiv.s @@ -53,7 +53,7 @@ __i64_sdiv: xor r5, r5, r0 subfc r6, r0, r6 subfe r5, r0, r5 - bl __i64_umod # do unsigned division + bl __i64_udivmod # do unsigned division mtlr r11 # restore return address srawi r0, r12, 31 # apply expected sign to quotient xor r8, r8, r0 # RES = Q if r12 >= 0, -Q if r12 < 0 diff --git a/runtime/powerpc/i64_smod.s b/runtime/powerpc/i64_smod.s index 4787334..320571d 100644 --- a/runtime/powerpc/i64_smod.s +++ b/runtime/powerpc/i64_smod.s @@ -52,7 +52,7 @@ __i64_smod: xor r5, r5, r0 subfc r6, r0, r6 subfe r5, r0, r5 - bl __i64_umod # do unsigned division + bl __i64_udivmod # do unsigned division mtlr r11 # restore return address xor r4, r4, r12 # apply expected sign to remainder xor r3, r3, r12 # RES = R if r12 == 0, -R if r12 == -1 diff --git a/runtime/powerpc/i64_udiv.s b/runtime/powerpc/i64_udiv.s index d757c0f..7bca760 100644 --- a/runtime/powerpc/i64_udiv.s +++ b/runtime/powerpc/i64_udiv.s @@ -42,7 +42,7 @@ .globl __i64_udiv __i64_udiv: mflr r11 # save return address in r11 - bl __i64_umod # unsigned divide + bl __i64_udivmod # unsigned divide mtlr r11 # restore return address mr r3, r7 # R = quotient mr r4, r8 diff --git a/runtime/powerpc/i64_udivmod.s b/runtime/powerpc/i64_udivmod.s new file mode 100644 index 0000000..892e9a0 --- /dev/null +++ b/runtime/powerpc/i64_udivmod.s @@ -0,0 +1,95 @@ +# ***************************************************************** +# +# The Compcert verified compiler +# +# Xavier Leroy, INRIA Paris-Rocquencourt +# +# Copyright (c) 2013 Institut National de Recherche en Informatique et +# en Automatique. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# ********************************************************************* + +# Helper functions for 64-bit integer arithmetic. PowerPC version. + + .text + +# Unsigned division and modulus + +# This function computes both the quotient and the remainder of two +# unsigned 64-bit integers. + +# 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_udivmod + .balign 16 +__i64_udivmod: + # 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 + + .type __i64_udivmod, @function + .size __i64_udivmod, .-__i64_udivmod diff --git a/runtime/powerpc/i64_umod.s b/runtime/powerpc/i64_umod.s index 2f46712..a4f23c9 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 v1.2.3