From e5362a794d813e0c4fb7a8a680a915eb57deaa7f Mon Sep 17 00:00:00 2001 From: xleroy Date: Sat, 20 Apr 2013 15:07:00 +0000 Subject: Split arch/int64.s into one file per function. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2206 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- runtime/Makefile | 7 +- runtime/arm/i64_dtos.S | 91 ++++++++++ runtime/arm/i64_dtou.S | 75 ++++++++ runtime/arm/i64_sar.s | 57 ++++++ runtime/arm/i64_scmp.s | 56 ++++++ runtime/arm/i64_sdiv.s | 66 +++++++ runtime/arm/i64_shl.s | 60 ++++++ runtime/arm/i64_shr.s | 57 ++++++ runtime/arm/i64_smod.s | 64 +++++++ runtime/arm/i64_stod.S | 55 ++++++ runtime/arm/i64_ucmp.s | 51 ++++++ runtime/arm/i64_udiv.s | 51 ++++++ runtime/arm/i64_udivmod.s | 80 ++++++++ runtime/arm/i64_umod.s | 49 +++++ runtime/arm/i64_utod.S | 56 ++++++ runtime/arm/int64.s | 381 -------------------------------------- runtime/ia32/i64_dtos.s | 63 +++++++ runtime/ia32/i64_dtou.s | 77 ++++++++ runtime/ia32/i64_sar.s | 63 +++++++ runtime/ia32/i64_scmp.s | 61 +++++++ runtime/ia32/i64_sdiv.s | 77 ++++++++ runtime/ia32/i64_shl.s | 62 +++++++ runtime/ia32/i64_shr.s | 62 +++++++ runtime/ia32/i64_smod.s | 74 ++++++++ runtime/ia32/i64_stod.s | 48 +++++ runtime/ia32/i64_ucmp.s | 56 ++++++ runtime/ia32/i64_udiv.s | 56 ++++++ runtime/ia32/i64_udivmod.s | 106 +++++++++++ runtime/ia32/i64_umod.s | 54 ++++++ runtime/ia32/i64_utod.s | 54 ++++++ runtime/ia32/int64.s | 414 ------------------------------------------ runtime/powerpc/i64_dtos.s | 89 +++++++++ runtime/powerpc/i64_dtou.s | 77 ++++++++ runtime/powerpc/i64_sar.s | 60 ++++++ runtime/powerpc/i64_scmp.s | 72 ++++++++ runtime/powerpc/i64_sdiv.s | 67 +++++++ runtime/powerpc/i64_shl.s | 64 +++++++ runtime/powerpc/i64_shr.s | 65 +++++++ runtime/powerpc/i64_smod.s | 65 +++++++ runtime/powerpc/i64_stod.s | 67 +++++++ runtime/powerpc/i64_ucmp.s | 72 ++++++++ runtime/powerpc/i64_udiv.s | 52 ++++++ runtime/powerpc/i64_umod.s | 95 ++++++++++ runtime/powerpc/i64_utod.s | 66 +++++++ runtime/powerpc/int64.s | 442 --------------------------------------------- 45 files changed, 2698 insertions(+), 1238 deletions(-) create mode 100644 runtime/arm/i64_dtos.S create mode 100644 runtime/arm/i64_dtou.S create mode 100644 runtime/arm/i64_sar.s create mode 100644 runtime/arm/i64_scmp.s create mode 100644 runtime/arm/i64_sdiv.s create mode 100644 runtime/arm/i64_shl.s create mode 100644 runtime/arm/i64_shr.s create mode 100644 runtime/arm/i64_smod.s create mode 100644 runtime/arm/i64_stod.S create mode 100644 runtime/arm/i64_ucmp.s create mode 100644 runtime/arm/i64_udiv.s create mode 100644 runtime/arm/i64_udivmod.s create mode 100644 runtime/arm/i64_umod.s create mode 100644 runtime/arm/i64_utod.S delete mode 100644 runtime/arm/int64.s create mode 100644 runtime/ia32/i64_dtos.s create mode 100644 runtime/ia32/i64_dtou.s create mode 100644 runtime/ia32/i64_sar.s create mode 100644 runtime/ia32/i64_scmp.s create mode 100644 runtime/ia32/i64_sdiv.s create mode 100644 runtime/ia32/i64_shl.s create mode 100644 runtime/ia32/i64_shr.s create mode 100644 runtime/ia32/i64_smod.s create mode 100644 runtime/ia32/i64_stod.s create mode 100644 runtime/ia32/i64_ucmp.s create mode 100644 runtime/ia32/i64_udiv.s create mode 100644 runtime/ia32/i64_udivmod.s create mode 100644 runtime/ia32/i64_umod.s create mode 100644 runtime/ia32/i64_utod.s delete mode 100644 runtime/ia32/int64.s create mode 100644 runtime/powerpc/i64_dtos.s create mode 100644 runtime/powerpc/i64_dtou.s create mode 100644 runtime/powerpc/i64_sar.s create mode 100644 runtime/powerpc/i64_scmp.s create mode 100644 runtime/powerpc/i64_sdiv.s create mode 100644 runtime/powerpc/i64_shl.s create mode 100644 runtime/powerpc/i64_shr.s create mode 100644 runtime/powerpc/i64_smod.s create mode 100644 runtime/powerpc/i64_stod.s create mode 100644 runtime/powerpc/i64_ucmp.s create mode 100644 runtime/powerpc/i64_udiv.s create mode 100644 runtime/powerpc/i64_umod.s create mode 100644 runtime/powerpc/i64_utod.s delete mode 100644 runtime/powerpc/int64.s (limited to 'runtime') diff --git a/runtime/Makefile b/runtime/Makefile index 5ed24af..6f45850 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -2,7 +2,9 @@ include ../Makefile.config CFLAGS=-O1 -g -Wall INCLUDES= -OBJS=int64.o +OBJS=i64_dtos.o i64_dtou.o i64_sar.o i64_scmp.o i64_sdiv.o i64_shl.o \ + i64_shr.o i64_smod.o i64_stod.o i64_ucmp.o i64_udivmod.o i64_udiv.o \ + i64_umod.o i64_utod.o LIB=libcompcert.a all: $(LIB) $(INCLUDES) @@ -14,6 +16,9 @@ $(LIB): $(OBJS) %.o: $(ARCH)/%.s $(CASMRUNTIME) $^ +%.o: $(ARCH)/%.S + $(CASMRUNTIME) -DVARIANT_$(VARIANT) $^ + clean:: rm -f *.o $(LIB) diff --git a/runtime/arm/i64_dtos.S b/runtime/arm/i64_dtos.S new file mode 100644 index 0000000..d0ef037 --- /dev/null +++ b/runtime/arm/i64_dtos.S @@ -0,0 +1,91 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Conversion from double float to signed 64-bit integer + + .global __i64_dtos +__i64_dtos: + push {r4, lr} + mov r4, r1, asr #31 @ save sign in r4 + @ extract unbiased exponent ((HI & 0x7FF00000) >> 20) - (1023 + 52) in r2 + @ note: 1023 + 52 = 1075 = 1024 + 51 + @ note: (HI & 0x7FF00000) >> 20 = (HI << 1) >> 21 + mov r2, r1, lsl #1 + mov r2, r2, lsr #21 + sub r2, r2, #51 + sub r2, r2, #1024 + @ check range of exponent + cmn r2, #52 @ if EXP < -52, |double| is < 1.0 + blt 1f + cmp r2, #11 @ if EXP >= 63 - 52, |double| is >= 2^63 + bge 2f + @ extract true mantissa + bic r1, r1, #0xFF000000 + bic r1, r1, #0x00F00000 @ HI &= ~0xFFF00000 + orr r1, r1, #0x00100000 @ HI |= 0x00100000 + @ shift it appropriately + cmp r2, #0 + blt 3f + bl __i64_shl @ if EXP >= 0, shift left by EXP + b 4f +3: rsb r2, r2, #0 + bl __i64_shr @ otherwise, shift right by -EXP + @ apply sign to result +4: eor r0, r0, r4 + eor r1, r1, r4 + subs r0, r0, r4 + sbc r1, r1, r4 + pop {r4, lr} + bx lr + @ special cases +1: mov r0, #0 @ result is 0 + mov r1, #0 + pop {r4, lr} + bx lr +2: cmp r4, #0 + blt 6f + mvn r0, #0 @ result is 0x7F....FF (MAX_SINT) + mov r1, r0, lsr #1 + pop {r4, lr} + bx lr +6: mov r0, #0 @ result is 0x80....00 (MIN_SINT) + mov r1, #0x80000000 + pop {r4, lr} + bx lr + .type __i64_dtos, %function + .size __i64_dtos, . - __i64_dtos diff --git a/runtime/arm/i64_dtou.S b/runtime/arm/i64_dtou.S new file mode 100644 index 0000000..7f6152e --- /dev/null +++ b/runtime/arm/i64_dtou.S @@ -0,0 +1,75 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Conversion from double float to unsigned 64-bit integer + + .global __i64_dtou +__i64_dtou: + cmp r1, #0 @ is double < 0 ? + blt 1f @ then it converts to 0 + @ extract unbiased exponent ((HI & 0x7FF00000) >> 20) - (1023 + 52) in r2 + @ note: 1023 + 52 = 1075 = 1024 + 51 + @ note: (HI & 0x7FF00000) >> 20 = (HI << 1) >> 21 + mov r2, r1, lsl #1 + mov r2, r2, lsr #21 + sub r2, r2, #51 + sub r2, r2, #1024 + @ check range of exponent + cmn r2, #52 @ if EXP < -52, double is < 1.0 + blt 1f + cmp r2, #12 @ if EXP >= 64 - 52, double is >= 2^64 + bge 2f + @ extract true mantissa + bic r1, r1, #0xFF000000 + bic r1, r1, #0x00F00000 @ HI &= ~0xFFF00000 + orr r1, r1, #0x00100000 @ HI |= 0x00100000 + @ shift it appropriately + cmp r2, #0 + bge __i64_shl @ if EXP >= 0, shift left by EXP + rsb r2, r2, #0 + b __i64_shr @ otherwise, shift right by -EXP + @ special cases +1: mov r0, #0 @ result is 0 + mov r1, #0 + bx lr +2: mvn r0, #0 @ result is 0xFF....FF (MAX_UINT) + mvn r1, #0 + bx lr + .type __i64_dtou, %function + .size __i64_dtou, . - __i64_dtou + diff --git a/runtime/arm/i64_sar.s b/runtime/arm/i64_sar.s new file mode 100644 index 0000000..a96d092 --- /dev/null +++ b/runtime/arm/i64_sar.s @@ -0,0 +1,57 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Shift right signed + + .global __i64_sar +__i64_sar: + and r2, r2, #63 @ normalize amount to 0...63 + rsbs r3, r2, #32 @ r3 = 32 - amount + ble 1f @ branch if <= 0, namely if amount >= 32 + mov r0, r0, lsr r2 + orr r0, r1, lsl r3 + mov r1, r1, asr r2 + bx lr +1: + sub r2, r2, #32 + mov r0, r1, asr r2 + mov r1, r1, asr #31 + bx lr + .type __i64_sar, %function + .size __i64_sar, . - __i64_sar + diff --git a/runtime/arm/i64_scmp.s b/runtime/arm/i64_scmp.s new file mode 100644 index 0000000..144a13c --- /dev/null +++ b/runtime/arm/i64_scmp.s @@ -0,0 +1,56 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Signed comparison + + .global __i64_scmp +__i64_scmp: + cmp r0, r2 @ compare low words (unsigned) + moveq r0, #0 @ res = 0 if eq + movhi r0, #1 @ res = 1 if unsigned higher + mvnlo r0, #0 @ res = -1 if unsigned lower + cmp r1, r3 @ compare high words (signed) + addgt r0, r0, #2 @ res += 2 if signed greater + sublt r0, r0, #2 @ res -= 2 if signed less + @ here, r0 = 0 if X == Y + @ r0 = -3, -2, -1 if X < Y + @ r0 = 1, 2, 3 if X > Y + bx lr + .type __i64_scmp, %function + .size __i64_scmp, . - __i64_scmp + diff --git a/runtime/arm/i64_sdiv.s b/runtime/arm/i64_sdiv.s new file mode 100644 index 0000000..e96008d --- /dev/null +++ b/runtime/arm/i64_sdiv.s @@ -0,0 +1,66 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Signed division + + .global __i64_sdiv +__i64_sdiv: + push {r4, r5, r6, r7, r8, r10, lr} + eor r10, r1, r3 @ r10 = sign of result + mov r4, r1, asr #31 @ take absolute value of N + eor r0, r0, r4 @ N = (N ^ (N >>s 31)) - (N >>s 31) + eor r1, r1, r4 + subs r0, r0, r4 + sbc r1, r1, r4 + mov r4, r3, asr #31 @ take absolute value of D + eor r2, r2, r4 + eor r3, r3, r4 + subs r2, r2, r4 + sbc r3, r3, r4 + bl __i64_udivmod @ do unsigned division + mov r0, r4 + mov r1, r5 + eor r0, r0, r10, asr#31 @ apply expected sign + eor r1, r1, r10, asr#31 + subs r0, r0, r10, asr#31 + sbc r1, r1, r10, asr#31 + pop {r4, r5, r6, r7, r8, r10, lr} + bx lr + .type __i64_sdiv, %function + .size __i64_sdiv, . - __i64_sdiv + diff --git a/runtime/arm/i64_shl.s b/runtime/arm/i64_shl.s new file mode 100644 index 0000000..8014f88 --- /dev/null +++ b/runtime/arm/i64_shl.s @@ -0,0 +1,60 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Shift left + +@ Note on ARM shifts: the shift amount is taken modulo 256. +@ Therefore, unsigned shifts by 32 bits or more produce 0. + + .global __i64_shl +__i64_shl: + and r2, r2, #63 @ normalize amount to 0...63 + rsbs r3, r2, #32 @ r3 = 32 - amount + ble 1f @ branch if <= 0, namely if amount >= 32 + mov r1, r1, lsl r2 + orr r1, r0, lsr r3 + mov r0, r0, lsl r2 + bx lr +1: + sub r2, r2, #32 + mov r1, r0, lsl r2 + mov r0, #0 + bx lr + .type __i64_shl, %function + .size __i64_shl, . - __i64_shl + diff --git a/runtime/arm/i64_shr.s b/runtime/arm/i64_shr.s new file mode 100644 index 0000000..f10b770 --- /dev/null +++ b/runtime/arm/i64_shr.s @@ -0,0 +1,57 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Shift right unsigned + + .global __i64_shr +__i64_shr: + and r2, r2, #63 @ normalize amount to 0...63 + rsbs r3, r2, #32 @ r3 = 32 - amount + ble 1f @ branch if <= 0, namely if amount >= 32 + mov r0, r0, lsr r2 + orr r0, r1, lsl r3 + mov r1, r1, lsr r2 + bx lr +1: + sub r2, r2, #32 + mov r0, r1, lsr r2 + mov r1, #0 + bx lr + .type __i64_shr, %function + .size __i64_shr, . - __i64_shr + diff --git a/runtime/arm/i64_smod.s b/runtime/arm/i64_smod.s new file mode 100644 index 0000000..8e766a0 --- /dev/null +++ b/runtime/arm/i64_smod.s @@ -0,0 +1,64 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Signed modulus + + .global __i64_smod +__i64_smod: + push {r4, r5, r6, r7, r8, r10, lr} + mov r10, r1 @ r10 = sign of result + mov r4, r1, asr#31 @ take absolute value of N + eor r0, r0, r4 @ N = (N ^ (N >>s 31)) - (N >>s 31) + eor r1, r1, r4 + subs r0, r0, r4 + sbc r1, r1, r4 + mov r4, r3, asr #31 @ take absolute value of D + eor r2, r2, r4 + eor r3, r3, r4 + subs r2, r2, r4 + sbc r3, r3, r4 + bl __i64_udivmod @ do unsigned division + eor r0, r0, r10, asr#31 @ apply expected sign + eor r1, r1, r10, asr#31 + subs r0, r0, r10, asr#31 + sbc r1, r1, r10, asr#31 + pop {r4, r5, r6, r7, r8, r10, lr} + bx lr + .type __i64_smod, %function + .size __i64_smod, . - __i64_smod + diff --git a/runtime/arm/i64_stod.S b/runtime/arm/i64_stod.S new file mode 100644 index 0000000..828d8b3 --- /dev/null +++ b/runtime/arm/i64_stod.S @@ -0,0 +1,55 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Conversion from signed 64-bit integer to double float + + .global __i64_stod +__i64_stod: + fmsr s0, r0 + fuitod d0, s0 @ convert low half to double (unsigned) + fmsr s2, r1 + fsitod d1, s2 @ convert high half to double (signed) + fldd d2, .LC1 @ d2 = 2^32 + fmacd d0, d1, d2 @ d0 = d0 + d1 * d2 = double value of int64 + fmrrd r0, r1, d0 @ return result in r0, r1 + bx lr + .type __i64_stod, %function + .size __i64_stod, . - __i64_stod + + .balign 8 +.LC1: .quad 0x41f0000000000000 @ 2^32 in double precision diff --git a/runtime/arm/i64_ucmp.s b/runtime/arm/i64_ucmp.s new file mode 100644 index 0000000..51a5fdb --- /dev/null +++ b/runtime/arm/i64_ucmp.s @@ -0,0 +1,51 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Unsigned comparison + + .global __i64_ucmp +__i64_ucmp: + cmp r1, r3 @ compare high words + cmpeq r0, r2 @ if equal, compare low words instead + moveq r0, #0 @ res = 0 if eq + movhi r0, #1 @ res = 1 if unsigned higher + mvnlo r0, #0 @ res = -1 if unsigned lower + bx lr + .type __i64_ucmp, %function + .size __i64_ucmp, . - __i64_ucmp + diff --git a/runtime/arm/i64_udiv.s b/runtime/arm/i64_udiv.s new file mode 100644 index 0000000..de41e00 --- /dev/null +++ b/runtime/arm/i64_udiv.s @@ -0,0 +1,51 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Unsigned division + + .global __i64_udiv +__i64_udiv: + push {r4, r5, r6, r7, r8, lr} + bl __i64_udivmod + mov r0, r4 + mov r1, r5 + pop {r4, r5, r6, r7, r8, lr} + bx lr + .type __i64_udiv, %function + .size __i64_udiv, . - __i64_udiv + diff --git a/runtime/arm/i64_udivmod.s b/runtime/arm/i64_udivmod.s new file mode 100644 index 0000000..e3d9c87 --- /dev/null +++ b/runtime/arm/i64_udivmod.s @@ -0,0 +1,80 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Auxiliary function for division and modulus. Don't call from C + +@ On entry: N = (r0, r1) numerator D = (r2, r3) divisor +@ On exit: Q = (r4, r5) quotient R = (r0, r1) remainder +@ Locals: M = (r6, r7) mask TMP = r8 temporary + + .global __i64_udivmod +__i64_udivmod: + orrs r8, r2, r3 @ is D == 0? + bxeq lr @ if so, return with unspecified results + mov r4, #0 @ Q = 0 + mov r5, #0 + mov r6, #1 @ M = 1 + mov r7, #0 +1: cmp r3, #0 @ while ((signed) D >= 0) ... + blt 2f + subs r8, r0, r2 @ ... and N >= D ... + sbcs r8, r1, r3 + blo 2f + adds r2, r2, r2 @ D = D << 1 + adc r3, r3, r3 + adds r6, r6, r6 @ M = M << 1 + adc r7, r7, r7 + b 1b +2: subs r0, r0, r2 @ N = N - D + sbcs r1, r1, r3 + orr r4, r4, r6 @ Q = Q | M + orr r5, r5, r7 + bhs 3f @ if N was >= D, continue + adds r0, r0, r2 @ otherwise, undo what we just did + adc r1, r1, r3 @ N = N + D + bic r4, r4, r6 @ Q = Q & ~M + bic r5, r5, r7 +3: movs r7, r7, lsr #1 @ M = M >> 1 + mov r6, r6, rrx + movs r3, r3, lsr #1 @ D = D >> 1 + mov r2, r2, rrx + orrs r8, r6, r7 @ repeat while (M != 0) ... + bne 2b + bx lr + .type __i64_udivmod, %function + .size __i64_udivmod, . - __i64_udivmod diff --git a/runtime/arm/i64_umod.s b/runtime/arm/i64_umod.s new file mode 100644 index 0000000..80af56e --- /dev/null +++ b/runtime/arm/i64_umod.s @@ -0,0 +1,49 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Unsigned modulus + + .global __i64_umod +__i64_umod: + push {r4, r5, r6, r7, r8, lr} + bl __i64_udivmod @ remainder is already in r0,r1 + pop {r4, r5, r6, r7, r8, lr} + bx lr + .type __i64_umod, %function + .size __i64_umod, . - __i64_umod + diff --git a/runtime/arm/i64_utod.S b/runtime/arm/i64_utod.S new file mode 100644 index 0000000..e98e46c --- /dev/null +++ b/runtime/arm/i64_utod.S @@ -0,0 +1,56 @@ +@ ***************************************************************** +@ +@ 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. ARM version. + + .text + +@@@ Conversion from unsigned 64-bit integer to double float + + .global __i64_utod +__i64_utod: + fmsr s0, r0 + fuitod d0, s0 @ convert low half to double (unsigned) + fmsr s2, r1 + fuitod d1, s2 @ convert high half to double (unsigned) + fldd d2, .LC1 @ d2 = 2^32 + fmacd d0, d1, d2 @ d0 = d0 + d1 * d2 = double value of int64 + fmrrd r0, r1, d0 @ return result in r0, r1 + bx lr + .type __i64_utod, %function + .size __i64_utod, . - __i64_utod + + .balign 8 +.LC1: .quad 0x41f0000000000000 @ 2^32 in double precision + diff --git a/runtime/arm/int64.s b/runtime/arm/int64.s deleted file mode 100644 index 5f01679..0000000 --- a/runtime/arm/int64.s +++ /dev/null @@ -1,381 +0,0 @@ -@ ***************************************************************** -@ -@ 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. ARM version. - -@ Calling conventions for R = F(X) or R = F(X,Y): -@ one or two long arguments: XL in r0, XH in r1, YL in r2, YH in r3 -@ one long argument, one int: XL in r0, XH in r1, Y in r2 -@ one float argument: X in r0, r1 -@ one long result: RL in r0, RH in r1 -@ one float result: R in r0, r1 -@ This is a little-endian convention: the low word is in the -@ low-numbered register. -@ Can use r0...r3 and f0...f7 as temporary registers (caller-save) - - .text - -@@@ Unsigned comparison - - .global __i64_ucmp -__i64_ucmp: - cmp r1, r3 @ compare high words - cmpeq r0, r2 @ if equal, compare low words instead - moveq r0, #0 @ res = 0 if eq - movhi r0, #1 @ res = 1 if unsigned higher - mvnlo r0, #0 @ res = -1 if unsigned lower - bx lr - .type __i64_ucmp, %function - .size __i64_ucmp, . - __i64_ucmp - -@@@ Signed comparison - - .global __i64_scmp -__i64_scmp: - cmp r0, r2 @ compare low words (unsigned) - moveq r0, #0 @ res = 0 if eq - movhi r0, #1 @ res = 1 if unsigned higher - mvnlo r0, #0 @ res = -1 if unsigned lower - cmp r1, r3 @ compare high words (signed) - addgt r0, r0, #2 @ res += 2 if signed greater - sublt r0, r0, #2 @ res -= 2 if signed less - @ here, r0 = 0 if X == Y - @ r0 = -3, -2, -1 if X < Y - @ r0 = 1, 2, 3 if X > Y - bx lr - .type __i64_scmp, %function - .size __i64_scmp, . - __i64_scmp - -@ Note on ARM shifts: the shift amount is taken modulo 256. -@ Therefore, unsigned shifts by 32 bits or more produce 0. - -@@@ Shift left - - .global __i64_shl -__i64_shl: - and r2, r2, #63 @ normalize amount to 0...63 - rsbs r3, r2, #32 @ r3 = 32 - amount - ble 1f @ branch if <= 0, namely if amount >= 32 - mov r1, r1, lsl r2 - orr r1, r0, lsr r3 - mov r0, r0, lsl r2 - bx lr -1: - sub r2, r2, #32 - mov r1, r0, lsl r2 - mov r0, #0 - bx lr - .type __i64_shl, %function - .size __i64_shl, . - __i64_shl - -@@@ Shift right unsigned - - .global __i64_shr -__i64_shr: - and r2, r2, #63 @ normalize amount to 0...63 - rsbs r3, r2, #32 @ r3 = 32 - amount - ble 1f @ branch if <= 0, namely if amount >= 32 - mov r0, r0, lsr r2 - orr r0, r1, lsl r3 - mov r1, r1, lsr r2 - bx lr -1: - sub r2, r2, #32 - mov r0, r1, lsr r2 - mov r1, #0 - bx lr - .type __i64_shr, %function - .size __i64_shr, . - __i64_shr - -@@@ Shift right signed - - .global __i64_sar -__i64_sar: - and r2, r2, #63 @ normalize amount to 0...63 - rsbs r3, r2, #32 @ r3 = 32 - amount - ble 1f @ branch if <= 0, namely if amount >= 32 - mov r0, r0, lsr r2 - orr r0, r1, lsl r3 - mov r1, r1, asr r2 - bx lr -1: - sub r2, r2, #32 - mov r0, r1, asr r2 - mov r1, r1, asr #31 - bx lr - .type __i64_sar, %function - .size __i64_sar, . - __i64_sar - -@@@ Auxiliary function for division and modulus. Not exported. - -@ On entry: N = (r0, r1) numerator D = (r2, r3) divisor -@ On exit: Q = (r4, r5) quotient R = (r0, r1) remainder -@ Locals: M = (r6, r7) mask TMP = r8 temporary - -__i64_udivmod: - orrs r8, r2, r3 @ is D == 0? - bxeq lr @ if so, return with unspecified results - mov r4, #0 @ Q = 0 - mov r5, #0 - mov r6, #1 @ M = 1 - mov r7, #0 -1: cmp r3, #0 @ while ((signed) D >= 0) ... - blt 2f - subs r8, r0, r2 @ ... and N >= D ... - sbcs r8, r1, r3 - blo 2f - adds r2, r2, r2 @ D = D << 1 - adc r3, r3, r3 - adds r6, r6, r6 @ M = M << 1 - adc r7, r7, r7 - b 1b -2: subs r0, r0, r2 @ N = N - D - sbcs r1, r1, r3 - orr r4, r4, r6 @ Q = Q | M - orr r5, r5, r7 - bhs 3f @ if N was >= D, continue - adds r0, r0, r2 @ otherwise, undo what we just did - adc r1, r1, r3 @ N = N + D - bic r4, r4, r6 @ Q = Q & ~M - bic r5, r5, r7 -3: movs r7, r7, lsr #1 @ M = M >> 1 - mov r6, r6, rrx - movs r3, r3, lsr #1 @ D = D >> 1 - mov r2, r2, rrx - orrs r8, r6, r7 @ repeat while (M != 0) ... - bne 2b - bx lr - -@@@ Unsigned division - - .global __i64_udiv -__i64_udiv: - push {r4, r5, r6, r7, r8, lr} - bl __i64_udivmod - mov r0, r4 - mov r1, r5 - pop {r4, r5, r6, r7, r8, lr} - bx lr - .type __i64_udiv, %function - .size __i64_udiv, . - __i64_udiv - -@@@ Unsigned modulus - - .global __i64_umod -__i64_umod: - push {r4, r5, r6, r7, r8, lr} - bl __i64_udivmod @ remainder is already in r0,r1 - pop {r4, r5, r6, r7, r8, lr} - bx lr - .type __i64_umod, %function - .size __i64_umod, . - __i64_umod - -@@@ Signed division - - .global __i64_sdiv -__i64_sdiv: - push {r4, r5, r6, r7, r8, r10, lr} - eor r10, r1, r3 @ r10 = sign of result - mov r4, r1, asr #31 @ take absolute value of N - eor r0, r0, r4 @ N = (N ^ (N >>s 31)) - (N >>s 31) - eor r1, r1, r4 - subs r0, r0, r4 - sbc r1, r1, r4 - mov r4, r3, asr #31 @ take absolute value of D - eor r2, r2, r4 - eor r3, r3, r4 - subs r2, r2, r4 - sbc r3, r3, r4 - bl __i64_udivmod @ do unsigned division - mov r0, r4 - mov r1, r5 - eor r0, r0, r10, asr#31 @ apply expected sign - eor r1, r1, r10, asr#31 - subs r0, r0, r10, asr#31 - sbc r1, r1, r10, asr#31 - pop {r4, r5, r6, r7, r8, r10, lr} - bx lr - .type __i64_sdiv, %function - .size __i64_sdiv, . - __i64_sdiv - -@@@ Signed modulus - - .global __i64_smod -__i64_smod: - push {r4, r5, r6, r7, r8, r10, lr} - mov r10, r1 @ r10 = sign of result - mov r4, r1, asr#31 @ take absolute value of N - eor r0, r0, r4 @ N = (N ^ (N >>s 31)) - (N >>s 31) - eor r1, r1, r4 - subs r0, r0, r4 - sbc r1, r1, r4 - mov r4, r3, asr #31 @ take absolute value of D - eor r2, r2, r4 - eor r3, r3, r4 - subs r2, r2, r4 - sbc r3, r3, r4 - bl __i64_udivmod @ do unsigned division - eor r0, r0, r10, asr#31 @ apply expected sign - eor r1, r1, r10, asr#31 - subs r0, r0, r10, asr#31 - sbc r1, r1, r10, asr#31 - pop {r4, r5, r6, r7, r8, r10, lr} - bx lr - .type __i64_smod, %function - .size __i64_smod, . - __i64_smod - -@@@ Conversion from unsigned 64-bit integer to double float - - .global __i64_utod -__i64_utod: - fmsr s0, r0 - fuitod d0, s0 @ convert low half to double (unsigned) - fmsr s2, r1 - fuitod d1, s2 @ convert high half to double (unsigned) - fldd d2, .LC1 @ d2 = 2^32 - fmacd d0, d1, d2 @ d0 = d0 + d1 * d2 = double value of int64 - fmrrd r0, r1, d0 @ return result in r0, r1 - bx lr - .type __i64_utod, %function - .size __i64_utod, . - __i64_utod - - .balign 8 -.LC1: .quad 0x41f0000000000000 @ 2^32 in double precision - -@@@ Conversion from signed 64-bit integer to double float - - .global __i64_stod -__i64_stod: - fmsr s0, r0 - fuitod d0, s0 @ convert low half to double (unsigned) - fmsr s2, r1 - fsitod d1, s2 @ convert high half to double (signed) - fldd d2, .LC1 @ d2 = 2^32 - fmacd d0, d1, d2 @ d0 = d0 + d1 * d2 = double value of int64 - fmrrd r0, r1, d0 @ return result in r0, r1 - bx lr - .type __i64_stod, %function - .size __i64_stod, . - __i64_stod - -@@@ Conversion from double float to unsigned 64-bit integer - - .global __i64_dtou -__i64_dtou: - cmp r1, #0 @ is double < 0 ? - blt 1f @ then it converts to 0 - @ extract unbiased exponent ((HI & 0x7FF00000) >> 20) - (1023 + 52) in r2 - @ note: 1023 + 52 = 1075 = 1024 + 51 - @ note: (HI & 0x7FF00000) >> 20 = (HI << 1) >> 21 - mov r2, r1, lsl #1 - mov r2, r2, lsr #21 - sub r2, r2, #51 - sub r2, r2, #1024 - @ check range of exponent - cmn r2, #52 @ if EXP < -52, double is < 1.0 - blt 1f - cmp r2, #12 @ if EXP >= 64 - 52, double is >= 2^64 - bge 2f - @ extract true mantissa - bic r1, r1, #0xFF000000 - bic r1, r1, #0x00F00000 @ HI &= ~0xFFF00000 - orr r1, r1, #0x00100000 @ HI |= 0x00100000 - @ shift it appropriately - cmp r2, #0 - bge __i64_shl @ if EXP >= 0, shift left by EXP - rsb r2, r2, #0 - b __i64_shr @ otherwise, shift right by -EXP - @ special cases -1: mov r0, #0 @ result is 0 - mov r1, #0 - bx lr -2: mvn r0, #0 @ result is 0xFF....FF (MAX_UINT) - mvn r1, #0 - bx lr - .type __i64_dtou, %function - .size __i64_dtou, . - __i64_dtou - -@@@ Conversion from double float to signed 64-bit integer - - .global __i64_dtos -__i64_dtos: - push {r4, lr} - mov r4, r1, asr #31 @ save sign in r4 - @ extract unbiased exponent ((HI & 0x7FF00000) >> 20) - (1023 + 52) in r2 - @ note: 1023 + 52 = 1075 = 1024 + 51 - @ note: (HI & 0x7FF00000) >> 20 = (HI << 1) >> 21 - mov r2, r1, lsl #1 - mov r2, r2, lsr #21 - sub r2, r2, #51 - sub r2, r2, #1024 - @ check range of exponent - cmn r2, #52 @ if EXP < -52, |double| is < 1.0 - blt 1f - cmp r2, #11 @ if EXP >= 63 - 52, |double| is >= 2^63 - bge 2f - @ extract true mantissa - bic r1, r1, #0xFF000000 - bic r1, r1, #0x00F00000 @ HI &= ~0xFFF00000 - orr r1, r1, #0x00100000 @ HI |= 0x00100000 - @ shift it appropriately - cmp r2, #0 - blt 3f - bl __i64_shl @ if EXP >= 0, shift left by EXP - b 4f -3: rsb r2, r2, #0 - bl __i64_shr @ otherwise, shift right by -EXP - @ apply sign to result -4: eor r0, r0, r4 - eor r1, r1, r4 - subs r0, r0, r4 - sbc r1, r1, r4 - pop {r4, lr} - bx lr - @ special cases -1: mov r0, #0 @ result is 0 - mov r1, #0 - pop {r4, lr} - bx lr -2: cmp r4, #0 - blt 6f - mvn r0, #0 @ result is 0x7F....FF (MAX_SINT) - mov r1, r0, lsr #1 - pop {r4, lr} - bx lr -6: mov r0, #0 @ result is 0x80....00 (MIN_SINT) - mov r1, #0x80000000 - pop {r4, lr} - bx lr - .type __i64_dtos, %function - .size __i64_dtos, . - __i64_dtos - diff --git a/runtime/ia32/i64_dtos.s b/runtime/ia32/i64_dtos.s new file mode 100644 index 0000000..780cf35 --- /dev/null +++ b/runtime/ia32/i64_dtos.s @@ -0,0 +1,63 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Conversion float -> signed long + + .globl __i64_dtos + .balign 16 +__i64_dtos: + subl $4, %esp + # Change rounding mode to "round towards zero" + fnstcw 0(%esp) + movw 0(%esp), %ax + movb $12, %ah + movw %ax, 2(%esp) + fldcw 2(%esp) + # Convert + fldl 8(%esp) + fistpll 8(%esp) + # Restore rounding mode + fldcw 0(%esp) + # Load result in edx:eax + movl 8(%esp), %eax + movl 12(%esp), %edx + addl $4, %esp + ret + .type __i64_dtos, @function + .size __i64_dtos, . - __i64_dtos + diff --git a/runtime/ia32/i64_dtou.s b/runtime/ia32/i64_dtou.s new file mode 100644 index 0000000..d700d69 --- /dev/null +++ b/runtime/ia32/i64_dtou.s @@ -0,0 +1,77 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Conversion float -> unsigned long + + .globl __i64_dtou + .balign 16 +__i64_dtou: + subl $4, %esp + # Change rounding mode to "round towards zero" + fnstcw 0(%esp) + movw 0(%esp), %ax + movb $12, %ah + movw %ax, 2(%esp) + fldcw 2(%esp) + # Compare argument with 2^63 + fldl (4+4)(%esp) + flds LC1 + fucomp + fnstsw %ax + sahf + jbe 1f # branch if not (ARG < 2^63) + # Argument < 2^63: convert as is + fistpll 8(%esp) + movl 8(%esp), %eax + movl 12(%esp), %edx + jmp 2f + # Argument > 2^63: offset ARG by -2^63, then convert, then offset RES by 2^63 +1: fsubs LC1 + fistpll 8(%esp) + movl 8(%esp), %eax + movl 12(%esp), %edx + addl $0x80000000, %edx + # Restore rounding mode +2: fldcw 0(%esp) + addl $4, %esp + ret + .type __i64_dtou, @function + .size __i64_dtou, . - __i64_dtou + + .balign 4 +LC1: .long 0x5f000000 # 2^63 in single precision diff --git a/runtime/ia32/i64_sar.s b/runtime/ia32/i64_sar.s new file mode 100644 index 0000000..fc11190 --- /dev/null +++ b/runtime/ia32/i64_sar.s @@ -0,0 +1,63 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Shift right signed + +# Note: IA32 shift instructions treat their amount (in %cl) modulo 32 + + .globl __i64_sar + .balign 16 +__i64_sar: + movl 12(%esp), %ecx # ecx = shift amount, treated mod 64 + testb $32, %cl + jne 1f + # shift amount < 32 + movl 4(%esp), %eax + movl 8(%esp), %edx + shrdl %cl, %edx, %eax # eax = low(XH:XL >> amount) + sarl %cl, %edx # edx = XH >> amount (signed) + ret + # shift amount >= 32 +1: movl 8(%esp), %eax + movl %eax, %edx + sarl %cl, %eax # eax = XH >> (amount - 32) + sarl $31, %edx # edx = sign of X + ret + .type __i64_sar, @function + .size __i64_sar, . - __i64_sar + diff --git a/runtime/ia32/i64_scmp.s b/runtime/ia32/i64_scmp.s new file mode 100644 index 0000000..e008f8d --- /dev/null +++ b/runtime/ia32/i64_scmp.s @@ -0,0 +1,61 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Signed comparison + + .globl __i64_scmp + .balign 16 +__i64_scmp: + movl 8(%esp), %eax # compare high words (signed) + cmpl 16(%esp), %eax + je 1f # if different, + setg %al # extract result + setl %dl + subb %dl, %al + movsbl %al, %eax + ret +1: movl 4(%esp), %eax # if high words equal, + cmpl 12(%esp), %eax # compare low words (unsigned) + seta %al # and extract result + setb %dl + subb %dl, %al + movsbl %al, %eax + ret + .type __i64_scmp, @function + .size __i64_scmp, . - __i64_scmp + diff --git a/runtime/ia32/i64_sdiv.s b/runtime/ia32/i64_sdiv.s new file mode 100644 index 0000000..c2a2d5f --- /dev/null +++ b/runtime/ia32/i64_sdiv.s @@ -0,0 +1,77 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Signed division + + .globl __i64_sdiv + .balign 16 +__i64_sdiv: + pushl %ebp + pushl %esi + pushl %edi + movl 20(%esp), %esi # esi = NH + movl %esi, %ebp # save sign of N in ebp + testl %esi, %esi + jge 1f # if N < 0, + negl 16(%esp) # N = -N + adcl $0, %esi + negl %esi + movl %esi, 20(%esp) +1: movl 28(%esp), %esi # esi = DH + xorl %esi, %ebp # sign of result in ebp + testl %esi, %esi + jge 2f # if D < 0, + negl 24(%esp) # D = -D + adcl $0, %esi + negl %esi + movl %esi, 28(%esp) +2: call __i64_udivmod + testl %ebp, %ebp # apply sign to result + jge 3f + negl %esi + adcl $0, %edi + negl %edi +3: movl %esi, %eax + movl %edi, %edx + popl %edi + popl %esi + popl %ebp + ret + .type __i64_sdiv, @function + .size __i64_sdiv, . - __i64_sdiv + diff --git a/runtime/ia32/i64_shl.s b/runtime/ia32/i64_shl.s new file mode 100644 index 0000000..a69dbbd --- /dev/null +++ b/runtime/ia32/i64_shl.s @@ -0,0 +1,62 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Shift left + +# Note: IA32 shift instructions treat their amount (in %cl) modulo 32 + + .globl __i64_shl + .balign 16 +__i64_shl: + movl 12(%esp), %ecx # ecx = shift amount, treated mod 64 + testb $32, %cl + jne 1f + # shift amount < 32 + movl 4(%esp), %eax + movl 8(%esp), %edx + shldl %cl, %eax, %edx # edx = high(XH:XL << amount) + shll %cl, %eax # eax = XL << amount + ret + # shift amount >= 32 +1: movl 4(%esp), %edx + shll %cl, %edx # edx = XL << (amount - 32) + xorl %eax, %eax # eax = 0 + ret + .type __i64_shl, @function + .size __i64_shl, . - __i64_shl + diff --git a/runtime/ia32/i64_shr.s b/runtime/ia32/i64_shr.s new file mode 100644 index 0000000..691c4d0 --- /dev/null +++ b/runtime/ia32/i64_shr.s @@ -0,0 +1,62 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Shift right unsigned + +# Note: IA32 shift instructions treat their amount (in %cl) modulo 32 + + .globl __i64_shr + .balign 16 +__i64_shr: + movl 12(%esp), %ecx # ecx = shift amount, treated mod 64 + testb $32, %cl + jne 1f + # shift amount < 32 + movl 4(%esp), %eax + movl 8(%esp), %edx + shrdl %cl, %edx, %eax # eax = low(XH:XL >> amount) + shrl %cl, %edx # edx = XH >> amount + ret + # shift amount >= 32 +1: movl 8(%esp), %eax + shrl %cl, %eax # eax = XH >> (amount - 32) + xorl %edx, %edx # edx = 0 + ret + .type __i64_shr, @function + .size __i64_shr, . - __i64_shr + diff --git a/runtime/ia32/i64_smod.s b/runtime/ia32/i64_smod.s new file mode 100644 index 0000000..66503cc --- /dev/null +++ b/runtime/ia32/i64_smod.s @@ -0,0 +1,74 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Signed remainder + + .globl __i64_smod + .balign 16 +__i64_smod: + pushl %ebp + pushl %esi + pushl %edi + movl 20(%esp), %esi # esi = NH + movl %esi, %ebp # save sign of result in ebp + testl %esi, %esi + jge 1f # if N < 0, + negl 16(%esp) # N = -N + adcl $0, %esi + negl %esi + movl %esi, 20(%esp) +1: movl 28(%esp), %esi # esi = DH + testl %esi, %esi + jge 2f # if D < 0, + negl 24(%esp) # D = -D + adcl $0, %esi + negl %esi + movl %esi, 28(%esp) +2: call __i64_udivmod + testl %ebp, %ebp # apply sign to result + jge 3f + negl %eax + adcl $0, %edx + negl %edx +3: popl %edi + popl %esi + popl %ebp + ret + .type __i64_smod, @function + .size __i64_smod, . - __i64_smod + diff --git a/runtime/ia32/i64_stod.s b/runtime/ia32/i64_stod.s new file mode 100644 index 0000000..b85a099 --- /dev/null +++ b/runtime/ia32/i64_stod.s @@ -0,0 +1,48 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Conversion signed long -> float + + .globl __i64_stod + .balign 16 +__i64_stod: + fildll 4(%esp) + ret + .type __i64_stod, @function + .size __i64_stod, . - __i64_stod + diff --git a/runtime/ia32/i64_ucmp.s b/runtime/ia32/i64_ucmp.s new file mode 100644 index 0000000..39f1f38 --- /dev/null +++ b/runtime/ia32/i64_ucmp.s @@ -0,0 +1,56 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Unsigned comparison + + .globl __i64_ucmp + .balign 16 +__i64_ucmp: + movl 8(%esp), %eax # compare high words + cmpl 16(%esp), %eax + jne 1f # if high words equal, + movl 4(%esp), %eax # compare low words + cmpl 12(%esp), %eax +1: seta %al # AL = 1 if >, 0 if <= + setb %dl # DL = 1 if <, 0 if >= + subb %dl, %al # AL = 0 if same, 1 if >, -1 if < + movsbl %al, %eax + ret + .type __i64_ucmp, @function + .size __i64_ucmp, . - __i64_ucmp + diff --git a/runtime/ia32/i64_udiv.s b/runtime/ia32/i64_udiv.s new file mode 100644 index 0000000..acf1dbd --- /dev/null +++ b/runtime/ia32/i64_udiv.s @@ -0,0 +1,56 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Unsigned division + + .globl __i64_udiv + .balign 16 +__i64_udiv: + pushl %ebp + pushl %esi + pushl %edi + call __i64_udivmod + movl %esi, %eax + movl %edi, %edx + popl %edi + popl %esi + popl %ebp + ret + .type __i64_udiv, @function + .size __i64_udiv, . - __i64_udiv + diff --git a/runtime/ia32/i64_udivmod.s b/runtime/ia32/i64_udivmod.s new file mode 100644 index 0000000..8f1e97d --- /dev/null +++ b/runtime/ia32/i64_udivmod.s @@ -0,0 +1,106 @@ +# ***************************************************************** +# +# 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. IA32 version. + +# Division and remainder + +# Auxiliary function, never called directly from C code +# Input: 20(esp), 24(esp) is dividend N +# 28(esp), 32(esp) is divisor D +# Output: esi:edi is quotient Q +# eax:edx is remainder R +# ebp is preserved + + .text + .globl __i64_udivmod + .balign 16 +__i64_udivmod: + cmpl $0, 32(%esp) # single-word divisor? (DH = 0) + jne 1f + # Special case 64 bits divided by 32 bits + movl 28(%esp), %ecx # divide NH by DL + movl 24(%esp), %eax # (will trap if D = 0) + xorl %edx, %edx + divl %ecx # eax = quotient, edx = remainder + movl %eax, %edi # high word of quotient in edi + movl 20(%esp), %eax # divide rem : NL by DL + divl %ecx # eax = quotient, edx = remainder + movl %eax, %esi # low word of quotient in esi */ + movl %edx, %eax # low word of remainder in eax + xorl %edx, %edx # high word of remainder is 0, in edx + ret + # The general case +1: movl 28(%esp), %ecx # esi:ecx = D + movl 32(%esp), %esi + movl 20(%esp), %eax # edx:eax = N + movl 24(%esp), %edx + # Scale D and N down, giving D' and N', until D' fits in 32 bits +2: shrl $1, %esi # shift D' right by one + rcrl $1, %ecx + shrl $1, %edx # shift N' right by one + rcrl $1, %eax + testl %esi, %esi # repeat until D'H = 0 + jnz 2b + # Divide N' by D' to get an approximate quotient + divl %ecx # eax = quotient, edx = remainder + movl %eax, %esi # save tentative quotient Q in esi + # Check for off by one quotient + # Compute Q * D +3: movl 32(%esp), %ecx + imull %esi, %ecx # ecx = Q * DH + movl 28(%esp), %eax + mull %esi # edx:eax = Q * DL + add %ecx, %edx # edx:eax = Q * D + jc 5f # overflow in addition means Q is too high + # Compare Q * D with N, computing the remainder in the process + movl %eax, %ecx + movl 20(%esp), %eax + subl %ecx, %eax + movl %edx, %ecx + movl 24(%esp), %edx + sbbl %ecx, %edx # edx:eax = N - Q * D + jnc 4f # no carry: N >= Q * D, we are fine + decl %esi # carry: N < Q * D, adjust Q down by 1 + addl 28(%esp), %eax # and remainder up by D + adcl 32(%esp), %edx + # Finished +4: xorl %edi, %edi # high half of quotient is 0 + ret + # Special case when Q * D overflows +5: decl %esi # adjust Q down by 1 + jmp 3b # and redo check & computation of remainder + + .type __i64_udivmod, @function + .size __i64_udivmod, . - __i64_udivmod diff --git a/runtime/ia32/i64_umod.s b/runtime/ia32/i64_umod.s new file mode 100644 index 0000000..8fb1f52 --- /dev/null +++ b/runtime/ia32/i64_umod.s @@ -0,0 +1,54 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Unsigned remainder + + .globl __i64_umod + .balign 16 +__i64_umod: + pushl %ebp + pushl %esi + pushl %edi + call __i64_udivmod + popl %edi + popl %esi + popl %ebp + ret + .type __i64_umod, @function + .size __i64_umod, . - __i64_umod + diff --git a/runtime/ia32/i64_utod.s b/runtime/ia32/i64_utod.s new file mode 100644 index 0000000..81673fd --- /dev/null +++ b/runtime/ia32/i64_utod.s @@ -0,0 +1,54 @@ +# ***************************************************************** +# +# 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. IA32 version. + + .text + +# Conversion unsigned long -> float + + .globl __i64_utod + .balign 16 +__i64_utod: + fildll 4(%esp) # convert as if signed + cmpl $0, 8(%esp) # is argument >= 2^63? + jns 1f + fadds LC1 # adjust by 2^64 +1: ret + .type __i64_utod, @function + .size __i64_utod, . - __i64_utod + + .balign 4 +LC1: .long 0x5f800000 # 2^64 in single precision + diff --git a/runtime/ia32/int64.s b/runtime/ia32/int64.s deleted file mode 100644 index 06a3b49..0000000 --- a/runtime/ia32/int64.s +++ /dev/null @@ -1,414 +0,0 @@ -# ***************************************************************** -# -# 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. IA32 version. - - .text - -# Division and remainder - -# Auxiliary function, not exported. -# Input: 20(esp), 24(esp) is dividend N -# 28(esp), 32(esp) is divisor D -# Output: esi:edi is quotient Q -# eax:edx is remainder R -# ebp is preserved - - .balign 16 -__i64_udivmod: - cmpl $0, 32(%esp) # single-word divisor? (DH = 0) - jne 1f - # Special case 64 bits divided by 32 bits - movl 28(%esp), %ecx # divide NH by DL - movl 24(%esp), %eax # (will trap if D = 0) - xorl %edx, %edx - divl %ecx # eax = quotient, edx = remainder - movl %eax, %edi # high word of quotient in edi - movl 20(%esp), %eax # divide rem : NL by DL - divl %ecx # eax = quotient, edx = remainder - movl %eax, %esi # low word of quotient in esi */ - movl %edx, %eax # low word of remainder in eax - xorl %edx, %edx # high word of remainder is 0, in edx - ret - # The general case -1: movl 28(%esp), %ecx # esi:ecx = D - movl 32(%esp), %esi - movl 20(%esp), %eax # edx:eax = N - movl 24(%esp), %edx - # Scale D and N down, giving D' and N', until D' fits in 32 bits -2: shrl $1, %esi # shift D' right by one - rcrl $1, %ecx - shrl $1, %edx # shift N' right by one - rcrl $1, %eax - testl %esi, %esi # repeat until D'H = 0 - jnz 2b - # Divide N' by D' to get an approximate quotient - divl %ecx # eax = quotient, edx = remainder - movl %eax, %esi # save tentative quotient Q in esi - # Check for off by one quotient - # Compute Q * D -3: movl 32(%esp), %ecx - imull %esi, %ecx # ecx = Q * DH - movl 28(%esp), %eax - mull %esi # edx:eax = Q * DL - add %ecx, %edx # edx:eax = Q * D - jc 5f # overflow in addition means Q is too high - # Compare Q * D with N, computing the remainder in the process - movl %eax, %ecx - movl 20(%esp), %eax - subl %ecx, %eax - movl %edx, %ecx - movl 24(%esp), %edx - sbbl %ecx, %edx # edx:eax = N - Q * D - jnc 4f # no carry: N >= Q * D, we are fine - decl %esi # carry: N < Q * D, adjust Q down by 1 - addl 28(%esp), %eax # and remainder up by D - adcl 32(%esp), %edx - # Finished -4: xorl %edi, %edi # high half of quotient is 0 - ret - # Special case when Q * D overflows -5: decl %esi # adjust Q down by 1 - jmp 3b # and redo check & computation of remainder - -# Unsigned division - - .globl __i64_udiv - .balign 16 -__i64_udiv: - pushl %ebp - pushl %esi - pushl %edi - call __i64_udivmod - movl %esi, %eax - movl %edi, %edx - popl %edi - popl %esi - popl %ebp - ret - .type __i64_udiv, @function - .size __i64_udiv, . - __i64_udiv - -# Unsigned remainder - - .globl __i64_umod - .balign 16 -__i64_umod: - pushl %ebp - pushl %esi - pushl %edi - call __i64_udivmod - popl %edi - popl %esi - popl %ebp - ret - .type __i64_umod, @function - .size __i64_umod, . - __i64_umod - -# Signed division - - .globl __i64_sdiv - .balign 16 -__i64_sdiv: - pushl %ebp - pushl %esi - pushl %edi - movl 20(%esp), %esi # esi = NH - movl %esi, %ebp # save sign of N in ebp - testl %esi, %esi - jge 1f # if N < 0, - negl 16(%esp) # N = -N - adcl $0, %esi - negl %esi - movl %esi, 20(%esp) -1: movl 28(%esp), %esi # esi = DH - xorl %esi, %ebp # sign of result in ebp - testl %esi, %esi - jge 2f # if D < 0, - negl 24(%esp) # D = -D - adcl $0, %esi - negl %esi - movl %esi, 28(%esp) -2: call __i64_udivmod - testl %ebp, %ebp # apply sign to result - jge 3f - negl %esi - adcl $0, %edi - negl %edi -3: movl %esi, %eax - movl %edi, %edx - popl %edi - popl %esi - popl %ebp - ret - .type __i64_sdiv, @function - .size __i64_sdiv, . - __i64_sdiv - -# Signed remainder - - .globl __i64_smod - .balign 16 -__i64_smod: - pushl %ebp - pushl %esi - pushl %edi - movl 20(%esp), %esi # esi = NH - movl %esi, %ebp # save sign of result in ebp - testl %esi, %esi - jge 1f # if N < 0, - negl 16(%esp) # N = -N - adcl $0, %esi - negl %esi - movl %esi, 20(%esp) -1: movl 28(%esp), %esi # esi = DH - testl %esi, %esi - jge 2f # if D < 0, - negl 24(%esp) # D = -D - adcl $0, %esi - negl %esi - movl %esi, 28(%esp) -2: call __i64_udivmod - testl %ebp, %ebp # apply sign to result - jge 3f - negl %eax - adcl $0, %edx - negl %edx -3: popl %edi - popl %esi - popl %ebp - ret - .type __i64_sdiv, @function - .size __i64_sdiv, . - __i64_sdiv - -# Note on shifts: -# IA32 shift instructions treat their amount (in %cl) modulo 32 - -# Shift left - - .globl __i64_shl - .balign 16 -__i64_shl: - movl 12(%esp), %ecx # ecx = shift amount, treated mod 64 - testb $32, %cl - jne 1f - # shift amount < 32 - movl 4(%esp), %eax - movl 8(%esp), %edx - shldl %cl, %eax, %edx # edx = high(XH:XL << amount) - shll %cl, %eax # eax = XL << amount - ret - # shift amount >= 32 -1: movl 4(%esp), %edx - shll %cl, %edx # edx = XL << (amount - 32) - xorl %eax, %eax # eax = 0 - ret - .type __i64_shl, @function - .size __i64_shl, . - __i64_shl - -# Shift right unsigned - - .globl __i64_shr - .balign 16 -__i64_shr: - movl 12(%esp), %ecx # ecx = shift amount, treated mod 64 - testb $32, %cl - jne 1f - # shift amount < 32 - movl 4(%esp), %eax - movl 8(%esp), %edx - shrdl %cl, %edx, %eax # eax = low(XH:XL >> amount) - shrl %cl, %edx # edx = XH >> amount - ret - # shift amount >= 32 -1: movl 8(%esp), %eax - shrl %cl, %eax # eax = XH >> (amount - 32) - xorl %edx, %edx # edx = 0 - ret - .type __i64_shr, @function - .size __i64_shr, . - __i64_shr - -# Shift right signed - - .globl __i64_sar - .balign 16 -__i64_sar: - movl 12(%esp), %ecx # ecx = shift amount, treated mod 64 - testb $32, %cl - jne 1f - # shift amount < 32 - movl 4(%esp), %eax - movl 8(%esp), %edx - shrdl %cl, %edx, %eax # eax = low(XH:XL >> amount) - sarl %cl, %edx # edx = XH >> amount (signed) - ret - # shift amount >= 32 -1: movl 8(%esp), %eax - movl %eax, %edx - sarl %cl, %eax # eax = XH >> (amount - 32) - sarl $31, %edx # edx = sign of X - ret - .type __i64_sar, @function - .size __i64_sar, . - __i64_sar - -# Unsigned comparison - - .globl __i64_ucmp - .balign 16 -__i64_ucmp: - movl 8(%esp), %eax # compare high words - cmpl 16(%esp), %eax - jne 1f # if high words equal, - movl 4(%esp), %eax # compare low words - cmpl 12(%esp), %eax -1: seta %al # AL = 1 if >, 0 if <= - setb %dl # DL = 1 if <, 0 if >= - subb %dl, %al # AL = 0 if same, 1 if >, -1 if < - movsbl %al, %eax - ret - .type __i64_ucmp, @function - .size __i64_ucmp, . - __i64_ucmp - -# Signed comparison - - .globl __i64_scmp - .balign 16 -__i64_scmp: - movl 8(%esp), %eax # compare high words (signed) - cmpl 16(%esp), %eax - je 1f # if different, - setg %al # extract result - setl %dl - subb %dl, %al - movsbl %al, %eax - ret -1: movl 4(%esp), %eax # if high words equal, - cmpl 12(%esp), %eax # compare low words (unsigned) - seta %al # and extract result - setb %dl - subb %dl, %al - movsbl %al, %eax - ret - .type __i64_scmp, @function - .size __i64_scmp, . - __i64_scmp - -# Conversion signed long -> float - - .globl __i64_stod - .balign 16 -__i64_stod: - fildll 4(%esp) - ret - .type __i64_stod, @function - .size __i64_stod, . - __i64_stod - -# Conversion unsigned long -> float - - .globl __i64_utod - .balign 16 -__i64_utod: - fildll 4(%esp) # convert as if signed - cmpl $0, 8(%esp) # is argument >= 2^63? - jns 1f - fadds LC1 # adjust by 2^64 -1: ret - .type __i64_stod, @function - .size __i64_stod, . - __i64_stod - - .balign 4 -LC1: .long 0x5f800000 # 2^64 in single precision - -# Conversion float -> signed long - - .globl __i64_dtos - .balign 16 -__i64_dtos: - subl $4, %esp - # Change rounding mode to "round towards zero" - fnstcw 0(%esp) - movw 0(%esp), %ax - movb $12, %ah - movw %ax, 2(%esp) - fldcw 2(%esp) - # Convert - fldl 8(%esp) - fistpll 8(%esp) - # Restore rounding mode - fldcw 0(%esp) - # Load result in edx:eax - movl 8(%esp), %eax - movl 12(%esp), %edx - addl $4, %esp - ret - .type __i64_dtos, @function - .size __i64_dtos, . - __i64_dtos - -# Conversion float -> unsigned long - - .globl __i64_dtou - .balign 16 -__i64_dtou: - subl $4, %esp - # Change rounding mode to "round towards zero" - fnstcw 0(%esp) - movw 0(%esp), %ax - movb $12, %ah - movw %ax, 2(%esp) - fldcw 2(%esp) - # Compare argument with 2^63 - fldl (4+4)(%esp) - flds LC2 - fucomp - fnstsw %ax - sahf - jbe 1f # branch if not (ARG < 2^63) - # Argument < 2^63: convert as is - fistpll 8(%esp) - movl 8(%esp), %eax - movl 12(%esp), %edx - jmp 2f - # Argument > 2^63: offset ARG by -2^63, then convert, then offset RES by 2^63 -1: fsubs LC2 - fistpll 8(%esp) - movl 8(%esp), %eax - movl 12(%esp), %edx - addl $0x80000000, %edx - # Restore rounding mode -2: fldcw 0(%esp) - addl $4, %esp - ret - .type __i64_dtou, @function - .size __i64_dtou, . - __i64_dtou - - .balign 4 -LC2: .long 0x5f000000 # 2^63 in single precision diff --git a/runtime/powerpc/i64_dtos.s b/runtime/powerpc/i64_dtos.s new file mode 100644 index 0000000..56c6e4b --- /dev/null +++ b/runtime/powerpc/i64_dtos.s @@ -0,0 +1,89 @@ +# ***************************************************************** +# +# 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 + +### Conversion from double float to signed long + + .balign 16 + .globl __i64_dtos +__i64_dtos: + stfdu f1, -16(r1) # extract LO (r4) and HI (r3) halves of double + lwz r3, 0(r1) + lwz r4, 4(r1) + addi r1, r1, 16 + srawi r10, r3, 31 # save sign of double in r10 + # extract unbiased exponent ((HI & 0x7FF00000) >> 20) - (1023 + 52) + rlwinm r5, r3, 12, 21, 31 + addi r5, r5, -1075 + # check range of exponent + cmpwi r5, -52 # if EXP < -52, abs(double) is < 1.0 + blt 1f + cmpwi r5, 11 # if EXP >= 63 - 52, abs(double) is >= 2^63 + bge 2f + # extract true mantissa + rlwinm r3, r3, 0, 12, 31 # HI &= ~0xFFF00000 + oris r3, r3, 0x10 # HI |= 0x00100000 + # shift it appropriately + mflr r9 # save retaddr in r9 + cmpwi r5, 0 + blt 3f + bl __i64_shl # if EXP >= 0, shift left by EXP + b 4f +3: subfic r5, r5, 0 + bl __i64_shr # if EXP < 0, shift right by -EXP + # apply sign to result +4: mtlr r9 + xor r4, r4, r10 + xor r3, r3, r10 + subfc r4, r10, r4 + subfe r3, r10, r3 + blr + # Special cases +1: li r3, 0 # result is 0 + li r4, 0 + blr +2: cmpwi r10, 0 # result is MAX_SINT or MIN_SINT + bge 5f # depending on sign + li r4, -1 # result is MAX_SINT = 0x7FFF_FFFF + srwi r3, r4, 1 + blr +5: lis r3, 0x8000 # result is MIN_SINT = 0x8000_0000 + li r4, 0 + blr + .type __i64_dtos, @function + .size __i64_dtos, .-__i64_dtos + \ No newline at end of file diff --git a/runtime/powerpc/i64_dtou.s b/runtime/powerpc/i64_dtou.s new file mode 100644 index 0000000..d9638e6 --- /dev/null +++ b/runtime/powerpc/i64_dtou.s @@ -0,0 +1,77 @@ +# ***************************************************************** +# +# 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 + +### Conversion from double float to unsigned long + + .balign 16 + .globl __i64_dtou +__i64_dtou: + stfdu f1, -16(r1) # extract LO (r4) and HI (r3) halves of double + lwz r3, 0(r1) + lwz r4, 4(r1) + addi r1, r1, 16 + cmpwi r3, 0 # is double < 0? + blt 1f # then it converts to 0 + # extract unbiased exponent ((HI & 0x7FF00000) >> 20) - (1023 + 52) + rlwinm r5, r3, 12, 21, 31 + addi r5, r5, -1075 + # check range of exponent + cmpwi r5, -52 # if EXP < -52, double is < 1.0 + blt 1f + cmpwi r5, 12 # if EXP >= 64 - 52, double is >= 2^64 + bge 2f + # extract true mantissa + rlwinm r3, r3, 0, 12, 31 # HI &= ~0xFFF00000 + oris r3, r3, 0x10 # HI |= 0x00100000 + # shift it appropriately + cmpwi r5, 0 + blt 3f + b __i64_shl # if EXP >= 0, shift left by EXP +3: subfic r5, r5, 0 + b __i64_shr # if EXP < 0, shift right by -EXP + # Special cases +1: li r3, 0 # result is 0 + li r4, 0 + blr +2: li r3, -1 # result is MAX_UINT + li r4, -1 + blr + .type __i64_dtou, @function + .size __i64_dtou, .-__i64_dtou + + \ No newline at end of file diff --git a/runtime/powerpc/i64_sar.s b/runtime/powerpc/i64_sar.s new file mode 100644 index 0000000..0fd410d --- /dev/null +++ b/runtime/powerpc/i64_sar.s @@ -0,0 +1,60 @@ +# ***************************************************************** +# +# 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 + +# Shift right signed + + .balign 16 + .globl __i64_sar +__i64_sar: + andi. r5, r5, 63 # take amount modulo 64 + cmpwi r5, 32 + bge 1f # amount < 32? + subfic r6, r5, 32 # r6 = 32 - amount + srw r4, r4, r5 # RH = XH >>s amount + slw r0, r3, r6 # RL = XL >>u amount | XH << (32 - amount) + or r4, r4, r0 + sraw r3, r3, r5 + blr +1: addi r6, r5, -32 # amount >= 32 + sraw r4, r3, r6 # RL = XH >>s (amount - 32) + srawi r3, r3, 31 # RL = sign extension of XH + blr + .type __i64_sar, @function + .size __i64_sar, .-__i64_sar + + \ No newline at end of file diff --git a/runtime/powerpc/i64_scmp.s b/runtime/powerpc/i64_scmp.s new file mode 100644 index 0000000..8963006 --- /dev/null +++ b/runtime/powerpc/i64_scmp.s @@ -0,0 +1,72 @@ +# ***************************************************************** +# +# 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 comparison + + .balign 16 + .globl __i64_ucmp +__i64_ucmp: + cmpw cr0, r3, r5 # compare high words (signed) + cmplw cr1, r4, r6 # compare low words (unsigned) + mfcr r0 +# At this point, the bits of r0 are as follow: +# bit 31: XH < YH +# bit 30: XH > YH +# bit 27: XL > YL +# bit 26: XL < YL + rlwinm r3, r0, 0, 0, 1 # r3 = r0 & 0xC000_0000 + srawi r3, r3, 24 # r4 = r4 >>s 28 +# r3 = -0x80 if XH < YH +# = 0x40 if XH > YH +# = 0 if XH = YH + rlwinm r4, r0, 4, 0, 1 # r4 = (r0 << 4) & 0xC000_0000 + srawi r4, r4, 28 # r4 = r4 >>s 28 +# r4 = -8 if XL < YL +# = 4 if XL > YL +# = 0 if XL = YL + add r3, r3, r4 +# r3 = -0x80 or -0x80 - 8 or -0x80 + 4 or -8 if X < Y +# (in all cases, r3 < 0 if X < Y) +# = 0x40 or 0x40 - 8 or 0x40 + 4 or 4 if X > Y +# (in all cases, r3 > 0 if X > Y) +# = 0 if X = Y + blr + .type __i64_scmp, @function + .size __i64_scmp, .-__i64_ucmp + + \ No newline at end of file diff --git a/runtime/powerpc/i64_sdiv.s b/runtime/powerpc/i64_sdiv.s new file mode 100644 index 0000000..6f2547f --- /dev/null +++ b/runtime/powerpc/i64_sdiv.s @@ -0,0 +1,67 @@ +# ***************************************************************** +# +# 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 + +### Signed division + + .balign 16 + .globl __i64_sdiv +__i64_sdiv: + mflr r11 # save return address + xor r12, r3, r5 # save sign of result in r12 (top bit) + srawi r0, r3, 31 # take absolute value of N + xor r4, r4, r0 # (i.e. N = N ^ r0 - r0, + xor r3, r3, r0 # where r0 = 0 if N >= 0 and r0 = -1 if N < 0) + subfc r4, r0, r4 + subfe r3, r0, r3 + srawi r0, r5, 31 # take absolute value of D + xor r6, r6, r0 # (same trick) + xor r5, r5, r0 + subfc r6, r0, r6 + subfe r5, r0, r5 + bl __i64_umod # 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 + xor r7, r7, r0 + subfc r4, r0, r8 + subfe r3, r0, r7 + blr + .type __i64_sdiv, @function + .size __i64_sdiv, .-__i64_sdiv + + \ No newline at end of file diff --git a/runtime/powerpc/i64_shl.s b/runtime/powerpc/i64_shl.s new file mode 100644 index 0000000..d122068 --- /dev/null +++ b/runtime/powerpc/i64_shl.s @@ -0,0 +1,64 @@ +# ***************************************************************** +# +# 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 + +# Shift left + + .balign 16 + .globl __i64_shl +__i64_shl: +# On PowerPC, shift instructions with amount mod 64 >= 32 return 0 +# hi = (hi << amount) | (lo >> (32 - amount)) | (lo << (amount - 32)) +# lo = lo << amount +# if 0 <= amount < 32: +# (amount - 32) mod 64 >= 32, hence lo << (amount - 32) == 0 +# if 32 <= amount < 64: +# lo << amount == 0 +# (32 - amount) mod 64 >= 32, hence lo >> (32 - amount) == 0 + andi. r5, r5, 63 # take amount modulo 64 + subfic r6, r5, 32 # r6 = 32 - amount + addi r7, r5, -32 # r7 = amount - 32 + slw r3, r3, r5 + srw r0, r4, r6 + or r3, r3, r0 + slw r0, r4, r7 + or r3, r3, r0 + slw r4, r4, r5 + blr + .type __i64_shl, @function + .size __i64_shl, .-__i64_shl + \ No newline at end of file diff --git a/runtime/powerpc/i64_shr.s b/runtime/powerpc/i64_shr.s new file mode 100644 index 0000000..fb7dc5c --- /dev/null +++ b/runtime/powerpc/i64_shr.s @@ -0,0 +1,65 @@ +# ***************************************************************** +# +# 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 + +# Shift right unsigned + + .balign 16 + .globl __i64_shr +__i64_shr: +# On PowerPC, shift instructions with amount mod 64 >= 32 return 0 +# lo = (lo >> amount) | (hi << (32 - amount)) | (hi >> (amount - 32)) +# hi = hi >> amount +# if 0 <= amount < 32: +# (amount - 32) mod 64 >= 32, hence hi >> (amount - 32) == 0 +# if 32 <= amount < 64: +# hi >> amount == 0 +# (32 - amount) mod 64 >= 32, hence hi << (32 - amount) == 0 + andi. r5, r5, 63 # take amount modulo 64 + subfic r6, r5, 32 # r6 = 32 - amount + addi r7, r5, -32 # r7 = amount - 32 + srw r4, r4, r5 + slw r0, r3, r6 + or r4, r4, r0 + srw r0, r3, r7 + or r4, r4, r0 + srw r3, r3, r5 + blr + .type __i64_shr, @function + .size __i64_shr, .-__i64_shr + + \ No newline at end of file diff --git a/runtime/powerpc/i64_smod.s b/runtime/powerpc/i64_smod.s new file mode 100644 index 0000000..4787334 --- /dev/null +++ b/runtime/powerpc/i64_smod.s @@ -0,0 +1,65 @@ +# ***************************************************************** +# +# 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 + +## Signed remainder + + .balign 16 + .globl __i64_smod +__i64_smod: + mflr r11 # save return address + srawi r12, r3, 31 # save sign of result in r12 (sign of N) + xor r4, r4, r12 # and take absolute value of N + xor r3, r3, r12 + subfc r4, r12, r4 + subfe r3, r12, r3 + srawi r0, r5, 31 # take absolute value of D + xor r6, r6, r0 + xor r5, r5, r0 + subfc r6, r0, r6 + subfe r5, r0, r5 + bl __i64_umod # 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 + subfc r4, r12, r4 + subfe r3, r12, r3 + blr + .type __i64_smod, @function + .size __i64_smod, .-__i64_smod + + \ No newline at end of file diff --git a/runtime/powerpc/i64_stod.s b/runtime/powerpc/i64_stod.s new file mode 100644 index 0000000..236d375 --- /dev/null +++ b/runtime/powerpc/i64_stod.s @@ -0,0 +1,67 @@ +# ***************************************************************** +# +# 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. + +### Conversion from signed long to double float + + .balign 16 + .globl __i64_stod +__i64_stod: + addi r1, r1, -16 + lis r5, 0x4330 + li r6, 0 + stw r5, 0(r1) + stw r4, 4(r1) # 0(r1) = 2^52 + (double) XL + stw r5, 8(r1) + stw r6, 12(r1) # 8(r1) = 2^52 + lfd f1, 0(r1) + lfd f2, 8(r1) + fsub f1, f1, f2 # f1 is XL (unsigned) as a double + lis r5, 0x4530 + lis r6, 0x8000 + stw r5, 0(r1) # 0(r1) = 2^84 + ((double)XL - 2^31) * 2^32 + add r3, r3, r6 + stw r3, 4(r1) + stw r5, 8(r1) # 8(r1) = 2^84 + 2^31 * 2^32 + stw r6, 12(r1) + lfd f2, 0(r1) + lfd f3, 8(r1) + fsub f2, f2, f3 # f2 is XH (signed) * 2^32 as a double + fadd f1, f1, f2 # add both to get result + addi r1, r1, 16 + blr + .type __i64_stod, @function + .size __i64_stod, .-__i64_stod + diff --git a/runtime/powerpc/i64_ucmp.s b/runtime/powerpc/i64_ucmp.s new file mode 100644 index 0000000..708bc74 --- /dev/null +++ b/runtime/powerpc/i64_ucmp.s @@ -0,0 +1,72 @@ +# ***************************************************************** +# +# 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 comparison + + .balign 16 + .globl __i64_ucmp +__i64_ucmp: + cmplw cr0, r3, r5 # compare high words (unsigned) + cmplw cr1, r4, r6 # compare low words (unsigned) + mfcr r0 +# At this point, the bits of r0 are as follow: +# bit 31: XH < YH +# bit 30: XH > YH +# bit 27: XL > YL +# bit 26: XL < YL + rlwinm r3, r0, 0, 0, 1 # r3 = r0 & 0xC000_0000 + srawi r3, r3, 24 # r4 = r4 >>s 28 +# r3 = -0x80 if XH < YH +# = 0x40 if XH > YH +# = 0 if XH = YH + rlwinm r4, r0, 4, 0, 1 # r4 = (r0 << 4) & 0xC000_0000 + srawi r4, r4, 28 # r4 = r4 >>s 28 +# r4 = -8 if XL < YL +# = 4 if XL > YL +# = 0 if XL = YL + add r3, r3, r4 +# r3 = -0x80 or -0x80 - 8 or -0x80 + 4 or -8 if X < Y +# (in all cases, r3 < 0 if X < Y) +# = 0x40 or 0x40 - 8 or 0x40 + 4 or 4 if X > Y +# (in all cases, r3 > 0 if X > Y) +# = 0 if X = Y + blr + .type __i64_ucmp, @function + .size __i64_ucmp, .-__i64_ucmp + + \ No newline at end of file diff --git a/runtime/powerpc/i64_udiv.s b/runtime/powerpc/i64_udiv.s new file mode 100644 index 0000000..d757c0f --- /dev/null +++ b/runtime/powerpc/i64_udiv.s @@ -0,0 +1,52 @@ +# ***************************************************************** +# +# 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 + + .balign 16 + .globl __i64_udiv +__i64_udiv: + mflr r11 # save return address in r11 + bl __i64_umod # unsigned divide + mtlr r11 # restore return address + mr r3, r7 # R = quotient + mr r4, r8 + blr + .type __i64_udiv, @function + .size __i64_udiv, .-__i64_udiv + diff --git a/runtime/powerpc/i64_umod.s b/runtime/powerpc/i64_umod.s new file mode 100644 index 0000000..2f46712 --- /dev/null +++ b/runtime/powerpc/i64_umod.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 modulus + +# This function computes both the quotient and the remainder of two +# unsigned 64-bit integers. Called from C, it returns the remainder. + +# 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 +__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 + + .type __i64_umod, @function + .size __i64_umod, .-__i64_umod diff --git a/runtime/powerpc/i64_utod.s b/runtime/powerpc/i64_utod.s new file mode 100644 index 0000000..e40eb5c --- /dev/null +++ b/runtime/powerpc/i64_utod.s @@ -0,0 +1,66 @@ +# ***************************************************************** +# +# 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 + +### Conversion from unsigned long to double float + + .balign 16 + .globl __i64_utod +__i64_utod: + addi r1, r1, -16 + lis r5, 0x4330 + li r6, 0 + stw r5, 0(r1) + stw r4, 4(r1) # 0(r1) = 2^52 + (double) XL + stw r5, 8(r1) + stw r6, 12(r1) # 8(r1) = 2^52 + lfd f1, 0(r1) + lfd f2, 8(r1) + fsub f1, f1, f2 # f1 is (double) XL + lis r5, 0x4530 + stw r5, 0(r1) # 0(r1) = 2^84 + (double) XL * 2^32 + stw r3, 4(r1) + stw r5, 8(r1) # 1(r1) = 2^84 + lfd f2, 0(r1) + lfd f3, 8(r1) + fsub f2, f2, f3 # f2 is XH * 2^32 as a double + fadd f1, f1, f2 # add both to get result + addi r1, r1, 16 + blr + .type __i64_utod, @function + .size __i64_utod, .-__i64_utod + diff --git a/runtime/powerpc/int64.s b/runtime/powerpc/int64.s deleted file mode 100644 index 247e3cd..0000000 --- a/runtime/powerpc/int64.s +++ /dev/null @@ -1,442 +0,0 @@ -# ***************************************************************** -# -# 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. - -# Calling conventions for R = F(X) or R = F(X,Y): -# one or two long arguments: XH in r3, XL in r4, YH in r5, YL in r6 -# one long argument, one int: XH in r3, XL in r4, Y in r5 -# one float argument: X in f1 -# one long result: RH in r3, RL in r4 -# one float result: R in f1 -# This is a big-endian convention: the high word is in the low-numbered register -# Can use r3...r12 and f0...r13 as temporary registers (caller-save) - - .text - -### Helper function for division and modulus. Not exported. -# Input: numerator N in (r3,r4), divisor D in (r5,r6) -# Output: quotient Q in (r7,r8), remainder R in (r3,r4) - .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 - -### Unsigned division - - .balign 16 - .globl __i64_udiv -__i64_udiv: - mflr r11 # save return address in r11 - bl __i64_udivmod # unsigned divide - mtlr r11 # restore return address - mr r3, r7 # R = quotient - mr r4, r8 - blr - .type __i64_udiv, @function - .size __i64_udiv, .-__i64_udiv - -### Unsigned remainder - - .balign 16 - .globl __i64_umod -__i64_umod: - mflr r11 - bl __i64_udivmod - mtlr r11 - blr # remainder is already in R - .type __i64_umod, @function - .size __i64_umod, .-__i64_umod - -### Signed division - - .balign 16 - .globl __i64_sdiv -__i64_sdiv: - mflr r11 # save return address - xor r12, r3, r5 # save sign of result in r12 (top bit) - srawi r0, r3, 31 # take absolute value of N - xor r4, r4, r0 # (i.e. N = N ^ r0 - r0, - xor r3, r3, r0 # where r0 = 0 if N >= 0 and r0 = -1 if N < 0) - subfc r4, r0, r4 - subfe r3, r0, r3 - srawi r0, r5, 31 # take absolute value of D - xor r6, r6, r0 # (same trick) - xor r5, r5, r0 - subfc r6, r0, r6 - subfe r5, r0, r5 - 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 - xor r7, r7, r0 - subfc r4, r0, r8 - subfe r3, r0, r7 - blr - .type __i64_sdiv, @function - .size __i64_sdiv, .-__i64_sdiv - -## Signed remainder - - .balign 16 - .globl __i64_smod -__i64_smod: - mflr r11 # save return address - srawi r12, r3, 31 # save sign of result in r12 (sign of N) - xor r4, r4, r12 # and take absolute value of N - xor r3, r3, r12 - subfc r4, r12, r4 - subfe r3, r12, r3 - srawi r0, r5, 31 # take absolute value of D - xor r6, r6, r0 - xor r5, r5, r0 - subfc r6, r0, r6 - subfe r5, r0, r5 - 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 - subfc r4, r12, r4 - subfe r3, r12, r3 - blr - .type __i64_smod, @function - .size __i64_smod, .-__i64_smod - -### Unsigned comparison - - .balign 16 - .globl __i64_ucmp -__i64_ucmp: - cmplw cr0, r3, r5 # compare high words (unsigned) - cmplw cr1, r4, r6 # compare low words (unsigned) - mfcr r0 -# At this point, the bits of r0 are as follow: -# bit 31: XH < YH -# bit 30: XH > YH -# bit 27: XL > YL -# bit 26: XL < YL - rlwinm r3, r0, 0, 0, 1 # r3 = r0 & 0xC000_0000 - srawi r3, r3, 24 # r4 = r4 >>s 28 -# r3 = -0x80 if XH < YH -# = 0x40 if XH > YH -# = 0 if XH = YH - rlwinm r4, r0, 4, 0, 1 # r4 = (r0 << 4) & 0xC000_0000 - srawi r4, r4, 28 # r4 = r4 >>s 28 -# r4 = -8 if XL < YL -# = 4 if XL > YL -# = 0 if XL = YL - add r3, r3, r4 -# r3 = -0x80 or -0x80 - 8 or -0x80 + 4 or -8 if X < Y -# (in all cases, r3 < 0 if X < Y) -# = 0x40 or 0x40 - 8 or 0x40 + 4 or 4 if X > Y -# (in all cases, r3 > 0 if X > Y) -# = 0 if X = Y - blr - .type __i64_ucmp, @function - .size __i64_ucmp, .-__i64_ucmp - -### Signed comparison - - .balign 16 - .globl __i64_scmp -__i64_scmp: - cmpw cr0, r3, r5 # compare high words (signed) - cmplw cr1, r4, r6 # compare low words (unsigned) - mfcr r0 -# Same trick as in __i64_ucmp - rlwinm r3, r0, 0, 0, 1 - srawi r3, r3, 24 - rlwinm r4, r0, 4, 0, 1 - srawi r4, r4, 28 - add r3, r3, r4 - blr - .type __i64_scmp, @function - .size __i64_scmp, .-__i64_scmp - -### Shifts - -# On PowerPC, shift instructions with amount mod 64 >= 32 return 0 - - .balign 16 - .globl __i64_shl -__i64_shl: -# hi = (hi << amount) | (lo >> (32 - amount)) | (lo << (amount - 32)) -# lo = lo << amount -# if 0 <= amount < 32: -# (amount - 32) mod 64 >= 32, hence lo << (amount - 32) == 0 -# if 32 <= amount < 64: -# lo << amount == 0 -# (32 - amount) mod 64 >= 32, hence lo >> (32 - amount) == 0 - andi. r5, r5, 63 # take amount modulo 64 - subfic r6, r5, 32 # r6 = 32 - amount - addi r7, r5, -32 # r7 = amount - 32 - slw r3, r3, r5 - srw r0, r4, r6 - or r3, r3, r0 - slw r0, r4, r7 - or r3, r3, r0 - slw r4, r4, r5 - blr - .type __i64_shl, @function - .size __i64_shl, .-__i64_shl - - .balign 16 - .globl __i64_shr -__i64_shr: -# lo = (lo >> amount) | (hi << (32 - amount)) | (hi >> (amount - 32)) -# hi = hi >> amount -# if 0 <= amount < 32: -# (amount - 32) mod 64 >= 32, hence hi >> (amount - 32) == 0 -# if 32 <= amount < 64: -# hi >> amount == 0 -# (32 - amount) mod 64 >= 32, hence hi << (32 - amount) == 0 - andi. r5, r5, 63 # take amount modulo 64 - subfic r6, r5, 32 # r6 = 32 - amount - addi r7, r5, -32 # r7 = amount - 32 - srw r4, r4, r5 - slw r0, r3, r6 - or r4, r4, r0 - srw r0, r3, r7 - or r4, r4, r0 - srw r3, r3, r5 - blr - .type __i64_shr, @function - .size __i64_shr, .-__i64_shr - - .balign 16 - .globl __i64_sar -__i64_sar: - andi. r5, r5, 63 # take amount modulo 64 - cmpwi r5, 32 - bge 1f # amount < 32? - subfic r6, r5, 32 # r6 = 32 - amount - srw r4, r4, r5 # RH = XH >>s amount - slw r0, r3, r6 # RL = XL >>u amount | XH << (32 - amount) - or r4, r4, r0 - sraw r3, r3, r5 - blr -1: addi r6, r5, -32 # amount >= 32 - sraw r4, r3, r6 # RL = XH >>s (amount - 32) - srawi r3, r3, 31 # RL = sign extension of XH - blr - .type __i64_sar, @function - .size __i64_sar, .-__i64_sar - -### Conversion from unsigned long to double float - - .balign 16 - .globl __i64_utod -__i64_utod: - addi r1, r1, -16 - lis r5, 0x4330 - li r6, 0 - stw r5, 0(r1) - stw r4, 4(r1) - stw r5, 8(r1) - stw r6, 12(r1) - lfd f1, 0(r1) - lfd f2, 8(r1) - fsub f1, f1, f2 # f1 is XL as a double - lis r5, 0x4530 - stw r5, 0(r1) - stw r3, 4(r1) - stw r5, 8(r1) - lfd f2, 0(r1) - lfd f3, 8(r1) - fsub f2, f2, f3 # f2 is XH * 2^32 as a double - fadd f1, f1, f2 # add both to get result - addi r1, r1, 16 - blr - .type __i64_utod, @function - .size __i64_utod, .-__i64_utod - -### Conversion from signed long to double float - - .balign 16 - .globl __i64_stod -__i64_stod: - addi r1, r1, -16 - lis r5, 0x4330 - li r6, 0 - stw r5, 0(r1) - stw r4, 4(r1) - stw r5, 8(r1) - stw r6, 12(r1) - lfd f1, 0(r1) - lfd f2, 8(r1) - fsub f1, f1, f2 # f1 is XL (unsigned) as a double - lis r5, 0x4530 - lis r6, 0x8000 - stw r5, 0(r1) - add r3, r3, r6 - stw r3, 4(r1) - stw r5, 8(r1) - stw r6, 12(r1) - lfd f2, 0(r1) - lfd f3, 8(r1) - fsub f2, f2, f3 # f2 is XH (signed) * 2^32 as a double - fadd f1, f1, f2 # add both to get result - addi r1, r1, 16 - blr - .type __i64_stod, @function - .size __i64_stod, .-__i64_stod - -### Conversion from double float to unsigned long - - .balign 16 - .globl __i64_dtou -__i64_dtou: - stfdu f1, -16(r1) # extract LO (r4) and HI (r3) halves of double - lwz r3, 0(r1) - lwz r4, 4(r1) - addi r1, r1, 16 - cmpwi r3, 0 # is double < 0? - blt 1f # then it converts to 0 - # extract unbiased exponent ((HI & 0x7FF00000) >> 20) - (1023 + 52) - rlwinm r5, r3, 12, 21, 31 - addi r5, r5, -1075 - # check range of exponent - cmpwi r5, -52 # if EXP < -52, double is < 1.0 - blt 1f - cmpwi r5, 12 # if EXP >= 64 - 52, double is >= 2^64 - bge 2f - # extract true mantissa - rlwinm r3, r3, 0, 12, 31 # HI &= ~0xFFF00000 - oris r3, r3, 0x10 # HI |= 0x00100000 - # shift it appropriately - cmpwi r5, 0 - blt 3f - b __i64_shl # if EXP >= 0, shift left by EXP -3: subfic r5, r5, 0 - b __i64_shr # if EXP < 0, shift right by -EXP - # Special cases -1: li r3, 0 # result is 0 - li r4, 0 - blr -2: li r3, -1 # result is MAX_UINT - li r4, -1 - blr - .type __i64_dtou, @function - .size __i64_dtou, .-__i64_dtou - -### Conversion from double float to signed long - - .balign 16 - .globl __i64_dtos -__i64_dtos: - stfdu f1, -16(r1) # extract LO (r4) and HI (r3) halves of double - lwz r3, 0(r1) - lwz r4, 4(r1) - addi r1, r1, 16 - srawi r10, r3, 31 # save sign of double in r10 - # extract unbiased exponent ((HI & 0x7FF00000) >> 20) - (1023 + 52) - rlwinm r5, r3, 12, 21, 31 - addi r5, r5, -1075 - # check range of exponent - cmpwi r5, -52 # if EXP < -52, abs(double) is < 1.0 - blt 1f - cmpwi r5, 11 # if EXP >= 63 - 52, abs(double) is >= 2^63 - bge 2f - # extract true mantissa - rlwinm r3, r3, 0, 12, 31 # HI &= ~0xFFF00000 - oris r3, r3, 0x10 # HI |= 0x00100000 - # shift it appropriately - mflr r9 # save retaddr in r9 - cmpwi r5, 0 - blt 3f - bl __i64_shl # if EXP >= 0, shift left by EXP - b 4f -3: subfic r5, r5, 0 - bl __i64_shr # if EXP < 0, shift right by -EXP - # apply sign to result -4: mtlr r9 - xor r4, r4, r10 - xor r3, r3, r10 - subfc r4, r10, r4 - subfe r3, r10, r3 - blr - # Special cases -1: li r3, 0 # result is 0 - li r4, 0 - blr -2: cmpwi r10, 0 # result is MAX_SINT or MIN_SINT - bge 5f # depending on sign - li r4, -1 # result is MAX_SINT = 0x7FFF_FFFF - srwi r3, r4, 1 - blr -5: lis r3, 0x8000 # result is MIN_SINT = 0x8000_0000 - li r4, 0 - blr - .type __i64_dtos, @function - .size __i64_dtos, .-__i64_dtos -- cgit v1.2.3