summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xconfigure6
-rw-r--r--otherlibs/num/.depend1
-rw-r--r--otherlibs/num/Makefile2
-rw-r--r--otherlibs/num/README1
-rw-r--r--otherlibs/num/bng.c2
-rw-r--r--otherlibs/num/bng_sparc.c77
6 files changed, 85 insertions, 4 deletions
diff --git a/configure b/configure
index 8cb221ffe2..93015a5bdb 100755
--- a/configure
+++ b/configure
@@ -658,9 +658,9 @@ esac
# Determine alignment constraints
case "$target" in
- hppa*-*-*|arm*-*-*|mips*-*-*)
+ sparc*-*-*|hppa*-*-*|arm*-*-*|mips*-*-*)
# On Sparc V9 with certain versions of gcc, determination of double
- # alignment is not reliable (PR#1521), hence we used to force it.
+ # alignment is not reliable (PR#1521), hence force it.
# Same goes for hppa.
# PR#5088 suggests same problem on ARM.
# PR#5280 reports same problem on MIPS.
@@ -696,7 +696,7 @@ esac
case "$target" in
# PR#5088: autodetection is unreliable on ARM. PR#5280: also on MIPS.
- hppa*-*-*|arm*-*-*|mips*-*-*)
+ sparc*-*-*|hppa*-*-*|arm*-*-*|mips*-*-*)
if test $2 = 8; then
inf "64-bit integers can be word-aligned."
echo "#undef ARCH_ALIGN_INT64" >> m.h
diff --git a/otherlibs/num/.depend b/otherlibs/num/.depend
index cfbb689dd9..4cbd79e4f1 100644
--- a/otherlibs/num/.depend
+++ b/otherlibs/num/.depend
@@ -6,6 +6,7 @@ bng_arm64.$(O): bng_arm64.c
bng_digit.$(O): bng_digit.c
bng_ia32.$(O): bng_ia32.c
bng_ppc.$(O): bng_ppc.c
+bng_sparc.$(O): bng_sparc.c
nat_stubs.$(O): nat_stubs.c ../../byterun/caml/alloc.h \
../../byterun/caml/compatibility.h ../../byterun/caml/misc.h \
../../byterun/caml/config.h ../../byterun/caml/../../config/m.h \
diff --git a/otherlibs/num/Makefile b/otherlibs/num/Makefile
index 9e23f8c09b..a43b58a004 100644
--- a/otherlibs/num/Makefile
+++ b/otherlibs/num/Makefile
@@ -28,7 +28,7 @@ clean::
rm -f *~
bng.$(O): bng.h bng_digit.c \
- bng_amd64.c bng_ia32.c bng_ppc.c
+ bng_amd64.c bng_ia32.c bng_ppc.c bng_sparc.c
.PHONY: depend
depend:
diff --git a/otherlibs/num/README b/otherlibs/num/README
index eef186e897..a979356d2b 100644
--- a/otherlibs/num/README
+++ b/otherlibs/num/README
@@ -51,4 +51,5 @@ Here are the processors for which such optimizations are available:
AMD64 (Opteron) (carry, dwmult, dwdiv)
PowerPC (carry, dwmult)
Alpha (dwmult)
+ SPARC (carry, dwmult, dwdiv)
MIPS (dwmult)
diff --git a/otherlibs/num/bng.c b/otherlibs/num/bng.c
index 659a7f2293..c4d0ea1a51 100644
--- a/otherlibs/num/bng.c
+++ b/otherlibs/num/bng.c
@@ -23,6 +23,8 @@
#include "bng_amd64.c"
#elif defined(BNG_ARCH_ppc)
#include "bng_ppc.c"
+#elif defined (BNG_ARCH_sparc)
+#include "bng_sparc.c"
#elif defined (BNG_ARCH_arm64)
#include "bng_arm64.c"
#endif
diff --git a/otherlibs/num/bng_sparc.c b/otherlibs/num/bng_sparc.c
new file mode 100644
index 0000000000..c007cb7742
--- /dev/null
+++ b/otherlibs/num/bng_sparc.c
@@ -0,0 +1,77 @@
+/**************************************************************************/
+/* */
+/* OCaml */
+/* */
+/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 2003 Institut National de Recherche en Informatique et */
+/* en Automatique. */
+/* */
+/* All rights reserved. This file is distributed under the terms of */
+/* the GNU Lesser General Public License version 2.1, with the */
+/* special exception on linking described in the file LICENSE. */
+/* */
+/**************************************************************************/
+
+/* Code specific to the SPARC (V8 and above) architecture. */
+
+#define BngAdd2(res,carryout,arg1,arg2) \
+ asm("addcc %2, %3, %0 \n\t" \
+ "addx %%g0, 0, %1" \
+ : "=r" (res), "=r" (carryout) \
+ : "r" (arg1), "r" (arg2) \
+ : "cc")
+
+#define BngAdd2Carry(res,carryout,arg1,arg2,carryin) \
+ asm("subcc %%g0, %4, %%g0 \n\t" \
+ "addxcc %2, %3, %0 \n\t" \
+ "addx %%g0, 0, %1" \
+ : "=r" (res), "=r" (carryout) \
+ : "r" (arg1), "r" (arg2), "r" (carryin) \
+ : "cc")
+
+#define BngAdd3(res,carryaccu,arg1,arg2,arg3) \
+ asm("addcc %2, %3, %0 \n\t" \
+ "addx %1, 0, %1 \n\t" \
+ "addcc %0, %4, %0 \n\t" \
+ "addx %1, 0, %1" \
+ : "=r" (res), "=r" (carryaccu) \
+ : "r" (arg1), "r" (arg2), "r" (arg3), "1" (carryaccu) \
+ : "cc")
+
+#define BngSub2(res,carryout,arg1,arg2) \
+ asm("subcc %2, %3, %0 \n\t" \
+ "addx %%g0, 0, %1" \
+ : "=r" (res), "=r" (carryout) \
+ : "r" (arg1), "r" (arg2) \
+ : "cc")
+
+#define BngSub2Carry(res,carryout,arg1,arg2,carryin) \
+ asm("subcc %%g0, %4, %%g0 \n\t" \
+ "subxcc %2, %3, %0 \n\t" \
+ "addx %%g0, 0, %1" \
+ : "=r" (res), "=r" (carryout) \
+ : "r" (arg1), "r" (arg2), "r" (carryin) \
+ : "cc")
+
+#define BngSub3(res,carryaccu,arg1,arg2,arg3) \
+ asm("subcc %2, %3, %0 \n\t" \
+ "addx %1, 0, %1 \n\t" \
+ "subcc %0, %4, %0 \n\t" \
+ "addx %1, 0, %1" \
+ : "=r" (res), "=r" (carryaccu) \
+ : "r" (arg1), "r" (arg2), "r" (arg3), "1" (carryaccu) \
+ : "cc")
+
+#define BngMult(resh,resl,arg1,arg2) \
+ asm("umul %2, %3, %0 \n\t" \
+ "rd %%y, %1" \
+ : "=r" (resl), "=r" (resh) \
+ : "r" (arg1), "r" (arg2))
+
+#define BngDiv(quo,rem,nh,nl,d) \
+ asm("wr %1, %%y \n\t" \
+ "udiv %2, %3, %0" \
+ : "=r" (quo) \
+ : "r" (nh), "r" (nl), "r" (d)); \
+ rem = nl - d * quo