Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libm/arch/i387 Modify the i387 code so that it can be sh...



details:   https://anonhg.NetBSD.org/src/rev/9224f8df40c2
branches:  trunk
changeset: 511387:9224f8df40c2
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Tue Jun 19 00:26:29 2001 +0000

description:
Modify the i387 code so that it can be shared between the i386 port
and the x86_64 port. XXX some files should be distinct.

diffstat:

 lib/libm/arch/i387/abi.h            |  60 +++++++++++++++++++++++++++++++++++++
 lib/libm/arch/i387/e_acos.S         |   8 +++-
 lib/libm/arch/i387/e_asin.S         |   8 +++-
 lib/libm/arch/i387/e_atan2.S        |  10 ++++-
 lib/libm/arch/i387/e_atan2f.S       |  10 ++++-
 lib/libm/arch/i387/e_exp.S          |  27 +++++++++++++---
 lib/libm/arch/i387/e_expf.S         |  13 +++++--
 lib/libm/arch/i387/e_fmod.S         |  17 ++++++---
 lib/libm/arch/i387/e_log.S          |   8 +++-
 lib/libm/arch/i387/e_log10.S        |   8 +++-
 lib/libm/arch/i387/e_log10f.S       |   8 +++-
 lib/libm/arch/i387/e_logf.S         |   8 +++-
 lib/libm/arch/i387/e_remainder.S    |  16 ++++++---
 lib/libm/arch/i387/e_remainderf.S   |  16 ++++++---
 lib/libm/arch/i387/e_scalb.S        |  10 ++++-
 lib/libm/arch/i387/e_scalbf.S       |  10 ++++-
 lib/libm/arch/i387/e_sqrt.S         |   6 +++-
 lib/libm/arch/i387/e_sqrtf.S        |   6 +++-
 lib/libm/arch/i387/s_atan.S         |   8 +++-
 lib/libm/arch/i387/s_atanf.S        |   8 +++-
 lib/libm/arch/i387/s_ceil.S         |  19 +++++++++++-
 lib/libm/arch/i387/s_ceilf.S        |  17 +++++++++-
 lib/libm/arch/i387/s_copysign.S     |  37 ++++++++++++++++++++++-
 lib/libm/arch/i387/s_copysignf.S    |  37 ++++++++++++++++++++++-
 lib/libm/arch/i387/s_cos.S          |   9 ++++-
 lib/libm/arch/i387/s_cosf.S         |   8 +++-
 lib/libm/arch/i387/s_finite.S       |  12 ++++++-
 lib/libm/arch/i387/s_finitef.S      |  11 ++++++-
 lib/libm/arch/i387/s_floor.S        |  17 +++++++++-
 lib/libm/arch/i387/s_floorf.S       |  17 +++++++++-
 lib/libm/arch/i387/s_ilogb.S        |  13 ++++++-
 lib/libm/arch/i387/s_ilogbf.S       |  13 ++++++-
 lib/libm/arch/i387/s_log1p.S        |   8 +++-
 lib/libm/arch/i387/s_log1pf.S       |   8 +++-
 lib/libm/arch/i387/s_logb.S         |  10 ++++-
 lib/libm/arch/i387/s_logbf.S        |  10 ++++-
 lib/libm/arch/i387/s_rint.S         |   8 +++-
 lib/libm/arch/i387/s_rintf.S        |   8 +++-
 lib/libm/arch/i387/s_scalbn.S       |  10 ++++-
 lib/libm/arch/i387/s_scalbnf.S      |  10 ++++-
 lib/libm/arch/i387/s_significand.S  |  10 ++++-
 lib/libm/arch/i387/s_significandf.S |  10 ++++-
 lib/libm/arch/i387/s_sin.S          |   9 ++++-
 lib/libm/arch/i387/s_sinf.S         |   8 +++-
 lib/libm/arch/i387/s_tan.S          |   9 ++++-
 lib/libm/arch/i387/s_tanf.S         |   8 +++-
 46 files changed, 494 insertions(+), 107 deletions(-)

diffs (truncated from 1273 to 300 lines):

diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/abi.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/arch/i387/abi.h  Tue Jun 19 00:26:29 2001 +0000
@@ -0,0 +1,60 @@
+/*     $NetBSD: abi.h,v 1.1 2001/06/19 00:26:29 fvdl Exp $     */
+
+/*
+ * Written by Frank van der Linden (fvdl%wasabisystems.com@localhost)
+ */
+
+/*
+ * The x86-64 ABI specifies that float, double and long double
+ * arguments are passed in SSE2 (xmm) registers. Unfortunately,
+ * there is no way to push those on to the FP stack, which is
+ * where he fancier instructions get their arguments from.
+ *
+ * Define some prologues and epilogues to store and retrieve
+ * xmm regs to local variables.
+ */
+
+#ifdef __x86_64__
+
+#define ARG_DOUBLE_ONE         -8(%rsp)
+#define ARG_DOUBLE_TWO         -16(%rsp)
+#define ARG_FLOAT_ONE          -4(%rsp)
+#define ARG_FLOAT_TWO          -8(%rsp)
+
+#define XMM_ONE_ARG_DOUBLE_PROLOGUE \
+       movsd   %xmm0, ARG_DOUBLE_ONE
+       
+#define XMM_TWO_ARG_DOUBLE_PROLOGUE \
+       movsd   %xmm0, ARG_DOUBLE_ONE ; \
+       movsd   %xmm1, ARG_DOUBLE_TWO
+
+#define XMM_ONE_ARG_FLOAT_PROLOGUE \
+       movss   %xmm0, ARG_FLOAT_ONE
+
+#define XMM_TWO_ARG_FLOAT_PROLOGUE \
+       movss   %xmm0, ARG_FLOAT_ONE ; \
+       movss   %xmm1, ARG_FLOAT_TWO
+
+#define XMM_DOUBLE_EPILOGUE \
+       fstpl ARG_DOUBLE_ONE ; \
+       movsd ARG_DOUBLE_ONE, %xmm0
+
+#define XMM_FLOAT_EPILOGUE \
+       fstps ARG_FLOAT_ONE ; \
+       movss ARG_FLOAT_ONE, %xmm0
+#else
+
+#define ARG_DOUBLE_ONE         4(%esp)
+#define ARG_DOUBLE_TWO         12(%esp)
+#define ARG_FLOAT_ONE          4(%esp)
+#define ARG_FLOAT_TWO          8(%esp)
+
+#define XMM_ONE_ARG_DOUBLE_PROLOGUE
+#define XMM_TWO_ARG_DOUBLE_PROLOGUE
+#define XMM_ONE_ARG_FLOAT_PROLOGUE
+#define XMM_TWO_ARG_FLOAT_PROLOGUE
+
+#define XMM_DOUBLE_EPILOGUE
+#define XMM_FLOAT_EPILOGUE
+
+#endif
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_acos.S
--- a/lib/libm/arch/i387/e_acos.S       Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_acos.S       Tue Jun 19 00:26:29 2001 +0000
@@ -5,11 +5,14 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: e_acos.S,v 1.6 2000/09/26 07:28:23 kleink Exp $")
+#include "abi.h"
+
+RCSID("$NetBSD: e_acos.S,v 1.7 2001/06/19 00:26:29 fvdl Exp $")
 
 /* acos = atan (sqrt(1 - x^2) / x) */
 ENTRY(__ieee754_acos)
-       fldl    4(%esp)                 /* x */
+       XMM_ONE_ARG_DOUBLE_PROLOGUE
+       fldl    ARG_DOUBLE_ONE          /* x */
        fld     %st(0)
        fmul    %st(0)                  /* x^2 */
        fld1
@@ -17,4 +20,5 @@
        fsqrt                           /* sqrt (1 - x^2) */
        fxch    %st(1)
        fpatan
+       XMM_DOUBLE_EPILOGUE
        ret
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_asin.S
--- a/lib/libm/arch/i387/e_asin.S       Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_asin.S       Tue Jun 19 00:26:29 2001 +0000
@@ -5,15 +5,19 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: e_asin.S,v 1.5 2000/09/26 07:28:24 kleink Exp $")
+#include "abi.h"
+
+RCSID("$NetBSD: e_asin.S,v 1.6 2001/06/19 00:26:29 fvdl Exp $")
 
 /* asin = atan (x / sqrt(1 - x^2)) */
 ENTRY(__ieee754_asin)
-       fldl    4(%esp)                 /* x */
+       XMM_ONE_ARG_DOUBLE_PROLOGUE
+       fldl    ARG_DOUBLE_ONE          /* x */
        fld     %st(0)
        fmul    %st(0)                  /* x^2 */
        fld1
        fsubp                           /* 1 - x^2 */
        fsqrt                           /* sqrt (1 - x^2) */
        fpatan
+       XMM_DOUBLE_EPILOGUE
        ret
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_atan2.S
--- a/lib/libm/arch/i387/e_atan2.S      Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_atan2.S      Tue Jun 19 00:26:29 2001 +0000
@@ -5,10 +5,14 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: e_atan2.S,v 1.4 1995/05/08 23:46:28 jtc Exp $")
+#include "abi.h"
+
+RCSID("$NetBSD: e_atan2.S,v 1.5 2001/06/19 00:26:29 fvdl Exp $")
 
 ENTRY(__ieee754_atan2)
-       fldl     4(%esp)
-       fldl    12(%esp)
+       XMM_TWO_ARG_DOUBLE_PROLOGUE
+       fldl    ARG_DOUBLE_ONE
+       fldl    ARG_DOUBLE_TWO
        fpatan
+       XMM_DOUBLE_EPILOGUE
        ret
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_atan2f.S
--- a/lib/libm/arch/i387/e_atan2f.S     Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_atan2f.S     Tue Jun 19 00:26:29 2001 +0000
@@ -5,10 +5,14 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: e_atan2f.S,v 1.1 1995/05/08 23:35:10 jtc Exp $")
+#include "abi.h"
+
+RCSID("$NetBSD: e_atan2f.S,v 1.2 2001/06/19 00:26:30 fvdl Exp $")
 
 ENTRY(__ieee754_atan2f)
-       flds    4(%esp)
-       flds    8(%esp)
+       XMM_TWO_ARG_FLOAT_PROLOGUE
+       flds    ARG_FLOAT_ONE
+       flds    ARG_FLOAT_TWO
        fpatan
+       XMM_FLOAT_EPILOGUE
        ret
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_exp.S
--- a/lib/libm/arch/i387/e_exp.S        Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_exp.S        Tue Jun 19 00:26:29 2001 +0000
@@ -5,10 +5,13 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: e_exp.S,v 1.9 2000/09/26 07:28:24 kleink Exp $")
+#include "abi.h"
+
+RCSID("$NetBSD: e_exp.S,v 1.10 2001/06/19 00:26:30 fvdl Exp $")
 
 /* e^x = 2^(x * log2(e)) */
 ENTRY(__ieee754_exp)
+#ifdef __i386__
        pushl   %ebp
        movl    %esp,%ebp
        subl    $8,%esp
@@ -18,11 +21,20 @@
        orw     $0x0180,%dx
        movw    %dx,-16(%ebp)
        fldcw   -16(%ebp)               /* load modfied control word */
+       fldl    8(%ebp)
+#else
+       fstcw   -12(%rsp)
+       movw    -12(%rsp),%dx
+       orw     $0x0180,%dx
+       movw    %dx,-16(%rsp)
+       fldcw   -16(%rsp)
+       movsd   %xmm0,-8(%rsp)
+       fldl    -8(%rsp)
+#endif
 
-       fldl    8(%ebp)
        fldl2e
        fmulp                           /* x * log2(e) */
-       fldl    %st(0)
+       fld     %st(0)
        frndint                         /* int(x * log2(e)) */
        fxch    %st(1)
        fsub    %st(1),%st              /* fract(x * log2(e)) */
@@ -30,9 +42,14 @@
        fld1
        faddp                           /* 2^(fract(x * log2(e))) */
        fscale                          /* e^x */
-       fstpl   %st(1)
+       fstp    %st(1)
 
+#ifdef __i386__
        fldcw   -12(%ebp)               /* restore original control word */
-
        leave
+#else
+       fstpl   -8(%rsp)
+       movsd   -8(%rsp),%xmm0
+       fldcw   -12(%rbp)
+#endif
        ret
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_expf.S
--- a/lib/libm/arch/i387/e_expf.S       Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_expf.S       Tue Jun 19 00:26:29 2001 +0000
@@ -5,14 +5,18 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: e_expf.S,v 1.3 2000/09/26 07:28:24 kleink Exp $")
+#include "abi.h"
+
+
+RCSID("$NetBSD: e_expf.S,v 1.4 2001/06/19 00:26:30 fvdl Exp $")
 
 /* e^x = 2^(x * log2(e)) */
 ENTRY(__ieee754_expf)
-       flds    4(%esp)
+       XMM_ONE_ARG_FLOAT_PROLOGUE
+       flds    ARG_FLOAT_ONE
        fldl2e
        fmulp                           /* x * log2(e) */
-       fldl    %st(0)
+       fld     %st(0)
        frndint                         /* int(x * log2(e)) */
        fsubr   %st(0),%st(1)           /* fract(x * log2(e)) */
        fxch
@@ -20,5 +24,6 @@
        fld1
        faddp                           /* 2^(fract(x * log2(e))) */
        fscale                          /* e^x */
-       fstpl   %st(1)
+       fstp    %st(1)
+       XMM_FLOAT_EPILOGUE
        ret
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_fmod.S
--- a/lib/libm/arch/i387/e_fmod.S       Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_fmod.S       Tue Jun 19 00:26:29 2001 +0000
@@ -5,14 +5,19 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: e_fmod.S,v 1.4 1995/05/08 23:47:56 jtc Exp $")
+#include "abi.h"
+
+
+RCSID("$NetBSD: e_fmod.S,v 1.5 2001/06/19 00:26:30 fvdl Exp $")
 
 ENTRY(__ieee754_fmod)
-       fldl    12(%esp)
-       fldl    4(%esp)
+       XMM_TWO_ARG_DOUBLE_PROLOGUE
+       fldl    ARG_DOUBLE_TWO
+       fldl    ARG_DOUBLE_ONE
 1:     fprem
        fstsw   %ax
-       sahf
-       jp      1b
-       fstpl   %st(1)
+       btw     $2,%ax
+       jc      1b
+       fstp    %st(1)
+       XMM_DOUBLE_EPILOGUE
        ret
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_log.S
--- a/lib/libm/arch/i387/e_log.S        Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_log.S        Tue Jun 19 00:26:29 2001 +0000
@@ -5,10 +5,14 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: e_log.S,v 1.4 1995/05/08 23:48:39 jtc Exp $")
+#include "abi.h"
+
+RCSID("$NetBSD: e_log.S,v 1.5 2001/06/19 00:26:30 fvdl Exp $")
 
 ENTRY(__ieee754_log)
+       XMM_ONE_ARG_DOUBLE_PROLOGUE
        fldln2
-       fldl    4(%esp)
+       fldl    ARG_DOUBLE_ONE
        fyl2x
+       XMM_DOUBLE_EPILOGUE
        ret
diff -r 4832dbf81a29 -r 9224f8df40c2 lib/libm/arch/i387/e_log10.S
--- a/lib/libm/arch/i387/e_log10.S      Tue Jun 19 00:25:36 2001 +0000
+++ b/lib/libm/arch/i387/e_log10.S      Tue Jun 19 00:26:29 2001 +0000



Home | Main Index | Thread Index | Old Index