summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2013-04-23 09:18:37 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2013-04-23 09:18:37 +0000
commit4d78351d21f8a52c4b64313354f24dd534205256 (patch)
treef562e1ac1eb953e09a0acfccd275ba706e16521b /runtime
parent945e1e3c0e601f711ab83f65333f4c2b9e713c99 (diff)
Make ia32/ code more portable across systems.
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2214 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'runtime')
-rw-r--r--runtime/Makefile2
-rw-r--r--runtime/ia32/i64_dtos.S60
-rw-r--r--runtime/ia32/i64_dtos.s63
-rw-r--r--runtime/ia32/i64_dtou.S76
-rw-r--r--runtime/ia32/i64_dtou.s77
-rw-r--r--runtime/ia32/i64_sar.S60
-rw-r--r--runtime/ia32/i64_sar.s63
-rw-r--r--runtime/ia32/i64_scmp.S58
-rw-r--r--runtime/ia32/i64_scmp.s61
-rw-r--r--runtime/ia32/i64_sdiv.S74
-rw-r--r--runtime/ia32/i64_sdiv.s77
-rw-r--r--runtime/ia32/i64_shl.S59
-rw-r--r--runtime/ia32/i64_shl.s62
-rw-r--r--runtime/ia32/i64_shr.S59
-rw-r--r--runtime/ia32/i64_shr.s62
-rw-r--r--runtime/ia32/i64_smod.S70
-rw-r--r--runtime/ia32/i64_smod.s74
-rw-r--r--runtime/ia32/i64_stod.S45
-rw-r--r--runtime/ia32/i64_stod.s48
-rw-r--r--runtime/ia32/i64_ucmp.S52
-rw-r--r--runtime/ia32/i64_ucmp.s56
-rw-r--r--runtime/ia32/i64_udiv.S52
-rw-r--r--runtime/ia32/i64_udiv.s56
-rw-r--r--runtime/ia32/i64_udivmod.S104
-rw-r--r--runtime/ia32/i64_udivmod.s106
-rw-r--r--runtime/ia32/i64_umod.S51
-rw-r--r--runtime/ia32/i64_utod.S51
-rw-r--r--runtime/ia32/i64_utod.s54
-rw-r--r--runtime/ia32/sysdeps.h (renamed from runtime/ia32/i64_umod.s)59
29 files changed, 912 insertions, 879 deletions
diff --git a/runtime/Makefile b/runtime/Makefile
index 6f45850..3565fb1 100644
--- a/runtime/Makefile
+++ b/runtime/Makefile
@@ -17,7 +17,7 @@ $(LIB): $(OBJS)
$(CASMRUNTIME) $^
%.o: $(ARCH)/%.S
- $(CASMRUNTIME) -DVARIANT_$(VARIANT) $^
+ $(CASMRUNTIME) -DVARIANT_$(VARIANT) -DSYS_$(SYSTEM) $^
clean::
rm -f *.o $(LIB)
diff --git a/runtime/ia32/i64_dtos.S b/runtime/ia32/i64_dtos.S
new file mode 100644
index 0000000..3cc381b
--- /dev/null
+++ b/runtime/ia32/i64_dtos.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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Conversion float -> signed long
+
+FUNCTION(__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
+ENDFUNCTION(__i64_dtos)
+
diff --git a/runtime/ia32/i64_dtos.s b/runtime/ia32/i64_dtos.s
deleted file mode 100644
index 780cf35..0000000
--- a/runtime/ia32/i64_dtos.s
+++ /dev/null
@@ -1,63 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..cdd2381
--- /dev/null
+++ b/runtime/ia32/i64_dtou.S
@@ -0,0 +1,76 @@
+// *****************************************************************
+//
+// 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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Conversion float -> unsigned long
+
+FUNCTION(__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 8(%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
+
+ .p2align 2
+LC1: .long 0x5f000000 // 2^63 in single precision
+
+ENDFUNCTION(__i64_dtou)
+ \ No newline at end of file
diff --git a/runtime/ia32/i64_dtou.s b/runtime/ia32/i64_dtou.s
deleted file mode 100644
index d700d69..0000000
--- a/runtime/ia32/i64_dtou.s
+++ /dev/null
@@ -1,77 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..cf2233b
--- /dev/null
+++ b/runtime/ia32/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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Shift right signed
+
+// Note: IA32 shift instructions treat their amount (in %cl) modulo 32
+
+FUNCTION(__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
+ENDFUNCTION(__i64_sar)
+
diff --git a/runtime/ia32/i64_sar.s b/runtime/ia32/i64_sar.s
deleted file mode 100644
index fc11190..0000000
--- a/runtime/ia32/i64_sar.s
+++ /dev/null
@@ -1,63 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..93ef2c2
--- /dev/null
+++ b/runtime/ia32/i64_scmp.S
@@ -0,0 +1,58 @@
+// *****************************************************************
+//
+// 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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Signed comparison
+
+FUNCTION(__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
+ENDFUNCTION(__i64_scmp)
+
diff --git a/runtime/ia32/i64_scmp.s b/runtime/ia32/i64_scmp.s
deleted file mode 100644
index e008f8d..0000000
--- a/runtime/ia32/i64_scmp.s
+++ /dev/null
@@ -1,61 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..f6551c7
--- /dev/null
+++ b/runtime/ia32/i64_sdiv.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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Signed division
+
+FUNCTION(__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 GLOB(__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
+ENDFUNCTION(__i64_sdiv)
+
diff --git a/runtime/ia32/i64_sdiv.s b/runtime/ia32/i64_sdiv.s
deleted file mode 100644
index c2a2d5f..0000000
--- a/runtime/ia32/i64_sdiv.s
+++ /dev/null
@@ -1,77 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..1fabebc
--- /dev/null
+++ b/runtime/ia32/i64_shl.S
@@ -0,0 +1,59 @@
+// *****************************************************************
+//
+// 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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Shift left
+
+// Note: IA32 shift instructions treat their amount (in %cl) modulo 32
+
+FUNCTION(__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
+ENDFUNCTION(__i64_shl)
+
diff --git a/runtime/ia32/i64_shl.s b/runtime/ia32/i64_shl.s
deleted file mode 100644
index a69dbbd..0000000
--- a/runtime/ia32/i64_shl.s
+++ /dev/null
@@ -1,62 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..34196f0
--- /dev/null
+++ b/runtime/ia32/i64_shr.S
@@ -0,0 +1,59 @@
+// *****************************************************************
+//
+// 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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Shift right unsigned
+
+// Note: IA32 shift instructions treat their amount (in %cl) modulo 32
+
+FUNCTION(__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
+ENDFUNCTION(__i64_shr)
+
diff --git a/runtime/ia32/i64_shr.s b/runtime/ia32/i64_shr.s
deleted file mode 100644
index 691c4d0..0000000
--- a/runtime/ia32/i64_shr.s
+++ /dev/null
@@ -1,62 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..28f47ad
--- /dev/null
+++ b/runtime/ia32/i64_smod.S
@@ -0,0 +1,70 @@
+// *****************************************************************
+//
+// 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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Signed remainder
+
+FUNCTION(__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 GLOB(__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
+ENDFUNCTION(__i64_smod)
diff --git a/runtime/ia32/i64_smod.s b/runtime/ia32/i64_smod.s
deleted file mode 100644
index 66503cc..0000000
--- a/runtime/ia32/i64_smod.s
+++ /dev/null
@@ -1,74 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..50ac06d
--- /dev/null
+++ b/runtime/ia32/i64_stod.S
@@ -0,0 +1,45 @@
+// *****************************************************************
+//
+// 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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Conversion signed long -> float
+
+FUNCTION(__i64_stod)
+ fildll 4(%esp)
+ ret
+ENDFUNCTION(__i64_stod)
+
diff --git a/runtime/ia32/i64_stod.s b/runtime/ia32/i64_stod.s
deleted file mode 100644
index b85a099..0000000
--- a/runtime/ia32/i64_stod.s
+++ /dev/null
@@ -1,48 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..3415986
--- /dev/null
+++ b/runtime/ia32/i64_ucmp.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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Unsigned comparison
+
+FUNCTION(__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
+ENDFUNCTION(__i64_ucmp)
diff --git a/runtime/ia32/i64_ucmp.s b/runtime/ia32/i64_ucmp.s
deleted file mode 100644
index 39f1f38..0000000
--- a/runtime/ia32/i64_ucmp.s
+++ /dev/null
@@ -1,56 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..6de5d37
--- /dev/null
+++ b/runtime/ia32/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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Unsigned division
+
+FUNCTION(__i64_udiv)
+ pushl %ebp
+ pushl %esi
+ pushl %edi
+ call __i64_udivmod
+ movl %esi, %eax
+ movl %edi, %edx
+ popl %edi
+ popl %esi
+ popl %ebp
+ ret
+ENDFUNCTION(__i64_udiv)
diff --git a/runtime/ia32/i64_udiv.s b/runtime/ia32/i64_udiv.s
deleted file mode 100644
index acf1dbd..0000000
--- a/runtime/ia32/i64_udiv.s
+++ /dev/null
@@ -1,56 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..dccfc28
--- /dev/null
+++ b/runtime/ia32/i64_udivmod.S
@@ -0,0 +1,104 @@
+// *****************************************************************
+//
+// 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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// 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
+
+FUNCTION(__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
+
+ENDFUNCTION(__i64_udivmod)
diff --git a/runtime/ia32/i64_udivmod.s b/runtime/ia32/i64_udivmod.s
deleted file mode 100644
index 8f1e97d..0000000
--- a/runtime/ia32/i64_udivmod.s
+++ /dev/null
@@ -1,106 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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..a019df2
--- /dev/null
+++ b/runtime/ia32/i64_umod.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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Unsigned remainder
+
+FUNCTION(__i64_umod)
+ pushl %ebp
+ pushl %esi
+ pushl %edi
+ call GLOB(__i64_udivmod)
+ popl %edi
+ popl %esi
+ popl %ebp
+ ret
+ENDFUNCTION(__i64_umod)
+
diff --git a/runtime/ia32/i64_utod.S b/runtime/ia32/i64_utod.S
new file mode 100644
index 0000000..7754ef2
--- /dev/null
+++ b/runtime/ia32/i64_utod.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 <organization> 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 <COPYRIGHT
+// HOLDER> 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.
+
+#include "sysdeps.h"
+
+// Conversion unsigned long -> float
+
+FUNCTION(__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
+
+ .p2align 2
+LC1: .long 0x5f800000 // 2^64 in single precision
+
+ENDFUNCTION(__i64_utod)
diff --git a/runtime/ia32/i64_utod.s b/runtime/ia32/i64_utod.s
deleted file mode 100644
index 81673fd..0000000
--- a/runtime/ia32/i64_utod.s
+++ /dev/null
@@ -1,54 +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 <organization> 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 <COPYRIGHT
-# HOLDER> 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/i64_umod.s b/runtime/ia32/sysdeps.h
index 8fb1f52..1aa54d3 100644
--- a/runtime/ia32/i64_umod.s
+++ b/runtime/ia32/sysdeps.h
@@ -32,23 +32,44 @@
#
# *********************************************************************
-# 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
+# System dependencies
+#if defined(SYS_linux) || defined(SYS_bsd)
+
+#define GLOB(x) x
+#define FUNCTION(f) \
+ .text; \
+ .globl f; \
+ .align 16; \
+f:
+
+#define ENDFUNCTION(f) \
+ .type f, @function; .size f, . - f
+
+#endif
+
+#if defined(SYS_macosx)
+
+#define GLOB(x) _##x
+#define FUNCTION(f) \
+ .text; \
+ .globl _##f; \
+ .align 4; \
+_##f:
+
+#define ENDFUNCTION(f)
+
+#endif
+
+#if defined(SYS_cygwin)
+
+#define GLOB(x) _##x
+#define FUNCTION(f) \
+ .text; \
+ .globl _##f; \
+ .align 16; \
+_##f:
+
+#define ENDFUNCTION(f)
+
+#endif