summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2004-07-19 08:17:25 +0000
committerdas <das@FreeBSD.org>2004-07-19 08:17:25 +0000
commit86c293bf54231dee13f45592a39a3f0d0cf19931 (patch)
treec9066d911af64f4a2b6d8c54df428e3e3cc5eb40
parent7aef999db62cfb1370a29fad2bbee5c489b660ec (diff)
downloadFreeBSD-src-86c293bf54231dee13f45592a39a3f0d0cf19931.zip
FreeBSD-src-86c293bf54231dee13f45592a39a3f0d0cf19931.tar.gz
Make FLT_ROUNDS correctly reflect the dynamic rounding mode.
-rw-r--r--lib/libc/amd64/gen/Makefile.inc2
-rw-r--r--lib/libc/amd64/gen/flt_rounds.c26
-rw-r--r--lib/libc/i386/gen/Makefile.inc2
-rw-r--r--lib/libc/i386/gen/flt_rounds.c25
-rw-r--r--lib/libc/ia64/gen/Makefile.inc3
-rw-r--r--lib/libc/ia64/gen/flt_rounds.c25
-rw-r--r--sys/amd64/include/float.h6
-rw-r--r--sys/arm/include/float.h4
-rw-r--r--sys/i386/include/float.h6
-rw-r--r--sys/ia64/include/float.h6
-rw-r--r--sys/powerpc/include/float.h6
11 files changed, 102 insertions, 9 deletions
diff --git a/lib/libc/amd64/gen/Makefile.inc b/lib/libc/amd64/gen/Makefile.inc
index 9f559e6..9cae7fa 100644
--- a/lib/libc/amd64/gen/Makefile.inc
+++ b/lib/libc/amd64/gen/Makefile.inc
@@ -4,5 +4,5 @@
SRCS+= _setjmp.S rfork_thread.S setjmp.S sigsetjmp.S \
fabs.S modf.S \
infinity.c ldexp.c makecontext.c signalcontext.c \
- fpgetmask.c fpsetmask.c fpgetprec.c fpsetprec.c \
+ flt_rounds.c fpgetmask.c fpsetmask.c fpgetprec.c fpsetprec.c \
fpgetround.c fpsetround.c fpgetsticky.c fpsetsticky.c
diff --git a/lib/libc/amd64/gen/flt_rounds.c b/lib/libc/amd64/gen/flt_rounds.c
new file mode 100644
index 0000000..c0ce81f
--- /dev/null
+++ b/lib/libc/amd64/gen/flt_rounds.c
@@ -0,0 +1,26 @@
+/*
+ * Written by J.T. Conklin, Apr 10, 1995
+ * Public domain.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+
+static const int map[] = {
+ 1, /* round to nearest */
+ 3, /* round to zero */
+ 2, /* round to negative infinity */
+ 0 /* round to positive infinity */
+};
+
+int
+__flt_rounds(void)
+{
+ int x;
+
+ /* Assume that the x87 and the SSE unit agree on the rounding mode. */
+ __asm("fnstcw %0" : "=m" (x));
+ return (map[(x >> 10) & 0x03]);
+}
diff --git a/lib/libc/i386/gen/Makefile.inc b/lib/libc/i386/gen/Makefile.inc
index fcfc9ec..7776387 100644
--- a/lib/libc/i386/gen/Makefile.inc
+++ b/lib/libc/i386/gen/Makefile.inc
@@ -2,5 +2,5 @@
# $FreeBSD$
SRCS+= _ctx_start.S _setjmp.S alloca.S fabs.S \
- infinity.c ldexp.c makecontext.c modf.S \
+ flt_rounds.c infinity.c ldexp.c makecontext.c modf.S \
rfork_thread.S setjmp.S signalcontext.c sigsetjmp.S
diff --git a/lib/libc/i386/gen/flt_rounds.c b/lib/libc/i386/gen/flt_rounds.c
new file mode 100644
index 0000000..16417ff
--- /dev/null
+++ b/lib/libc/i386/gen/flt_rounds.c
@@ -0,0 +1,25 @@
+/*
+ * Written by J.T. Conklin, Apr 10, 1995
+ * Public domain.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+
+static const int map[] = {
+ 1, /* round to nearest */
+ 3, /* round to zero */
+ 2, /* round to negative infinity */
+ 0 /* round to positive infinity */
+};
+
+int
+__flt_rounds(void)
+{
+ int x;
+
+ __asm("fnstcw %0" : "=m" (x));
+ return (map[(x >> 10) & 0x03]);
+}
diff --git a/lib/libc/ia64/gen/Makefile.inc b/lib/libc/ia64/gen/Makefile.inc
index 30bb45e..f7dcd6a 100644
--- a/lib/libc/ia64/gen/Makefile.inc
+++ b/lib/libc/ia64/gen/Makefile.inc
@@ -2,7 +2,8 @@
SRCS+= __divdf3.S __divdi3.S __divsf3.S __divsi3.S __moddi3.S __modsi3.S \
__udivdi3.S __udivsi3.S __umoddi3.S __umodsi3.S _setjmp.S fabs.S \
- fpgetmask.c fpgetround.c fpsetmask.c fpsetround.c infinity.c \
+ flt_rounds.c fpgetmask.c fpgetround.c fpsetmask.c \
+ fpsetround.c infinity.c \
ldexp.c makecontext.c modf.c setjmp.S signalcontext.c sigsetjmp.S
# The following may go away if function _Unwind_FindTableEntry()
diff --git a/lib/libc/ia64/gen/flt_rounds.c b/lib/libc/ia64/gen/flt_rounds.c
new file mode 100644
index 0000000..d650965
--- /dev/null
+++ b/lib/libc/ia64/gen/flt_rounds.c
@@ -0,0 +1,25 @@
+/*
+ * Written by J.T. Conklin, Apr 10, 1995
+ * Public domain.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+
+static const int map[] = {
+ 1, /* round to nearest */
+ 3, /* round to zero */
+ 2, /* round to negative infinity */
+ 0 /* round to positive infinity */
+};
+
+int
+__flt_rounds(void)
+{
+ int x;
+
+ __asm("mov %0=ar.fpsr" : "=r" (x));
+ return (map[(x >> 10) & 0x03]);
+}
diff --git a/sys/amd64/include/float.h b/sys/amd64/include/float.h
index 1608472..ea2df3c 100644
--- a/sys/amd64/include/float.h
+++ b/sys/amd64/include/float.h
@@ -35,8 +35,12 @@
#include <sys/cdefs.h>
+__BEGIN_DECLS
+extern int __flt_rounds(void);
+__END_DECLS
+
#define FLT_RADIX 2 /* b */
-#define FLT_ROUNDS 1 /* FP addition rounds to nearest */
+#define FLT_ROUNDS __flt_rounds()
#if __ISO_C_VISIBLE >= 1999
#define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */
#define DECIMAL_DIG 21 /* max precision in decimal digits */
diff --git a/sys/arm/include/float.h b/sys/arm/include/float.h
index 2cbdcaf..21761ec 100644
--- a/sys/arm/include/float.h
+++ b/sys/arm/include/float.h
@@ -38,8 +38,8 @@
#define _MACHINE_FLOAT_H_ 1
#define FLT_RADIX 2 /* b */
-#define FLT_ROUNDS 1 /* FP addition rounds to nearest */
-#define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */
+#define FLT_ROUNDS (-1) /* indeterminate */
+#define FLT_EVAL_METHOD (-1) /* XXX */
#define DECIMAL_DIG 21 /* max precision in decimal digits */
#define FLT_MANT_DIG 24 /* p */
diff --git a/sys/i386/include/float.h b/sys/i386/include/float.h
index 1608472..ea2df3c 100644
--- a/sys/i386/include/float.h
+++ b/sys/i386/include/float.h
@@ -35,8 +35,12 @@
#include <sys/cdefs.h>
+__BEGIN_DECLS
+extern int __flt_rounds(void);
+__END_DECLS
+
#define FLT_RADIX 2 /* b */
-#define FLT_ROUNDS 1 /* FP addition rounds to nearest */
+#define FLT_ROUNDS __flt_rounds()
#if __ISO_C_VISIBLE >= 1999
#define FLT_EVAL_METHOD (-1) /* i387 semantics are...interesting */
#define DECIMAL_DIG 21 /* max precision in decimal digits */
diff --git a/sys/ia64/include/float.h b/sys/ia64/include/float.h
index ffd430b..21f1608 100644
--- a/sys/ia64/include/float.h
+++ b/sys/ia64/include/float.h
@@ -35,8 +35,12 @@
#include <sys/cdefs.h>
+__BEGIN_DECLS
+extern int __flt_rounds(void);
+__END_DECLS
+
#define FLT_RADIX 2 /* b */
-#define FLT_ROUNDS 1 /* FP addition rounds to nearest */
+#define FLT_ROUNDS __flt_rounds()
#if __ISO_C_VISIBLE >= 1999
#define FLT_EVAL_METHOD 0 /* no promotions */
#define DECIMAL_DIG 35 /* max precision in decimal digits */
diff --git a/sys/powerpc/include/float.h b/sys/powerpc/include/float.h
index 1d683f6..fff14f4 100644
--- a/sys/powerpc/include/float.h
+++ b/sys/powerpc/include/float.h
@@ -36,8 +36,12 @@
#include <sys/cdefs.h>
+__BEGIN_DECLS
+extern int __flt_rounds(void);
+__END_DECLS
+
#define FLT_RADIX 2 /* b */
-#define FLT_ROUNDS 1 /* FP addition rounds to nearest */
+#define FLT_ROUNDS __flt_rounds()
#if __ISO_C_VISIBLE >= 1999
#define FLT_EVAL_METHOD 1 /* operands promoted to double */
#define DECIMAL_DIG 35 /* max precision in decimal digits */
OpenPOWER on IntegriCloud