[MLton-commit] r6887

Wesley Terpstra wesley at mlton.org
Tue Sep 23 19:05:28 PDT 2008


feround.c and IEEEReal.c carried duplicated fesetround code.
The IEEEReal i386 version also works on x86_64.
The feround.c version works on uclibc.

This patch combines the implementations into one place, eliminating the 
obsolete i386-specific code from feround.c.


----------------------------------------------------------------------

U   mlton/trunk/runtime/basis/Real/IEEEReal.c
D   mlton/trunk/runtime/platform/feround.c
D   mlton/trunk/runtime/platform/feround.h
U   mlton/trunk/runtime/platform/linux.c
U   mlton/trunk/runtime/platform/linux.h

----------------------------------------------------------------------

Modified: mlton/trunk/runtime/basis/Real/IEEEReal.c
===================================================================
--- mlton/trunk/runtime/basis/Real/IEEEReal.c	2008-09-23 15:06:38 UTC (rev 6886)
+++ mlton/trunk/runtime/basis/Real/IEEEReal.c	2008-09-24 02:05:27 UTC (rev 6887)
@@ -42,13 +42,34 @@
 #endif
 }
 
+#elif (defined __UCLIBC__)
+
+/* Use whatever we got from fpu_control.h for this CPU model */
+#define FE_MASK (FE_DOWNWARD|FE_TONEAREST|FE_TOWARDZERO|FE_UPWARD)
+
+static inline int fegetround () {
+        fpu_control_t controlWord;
+        _FPU_GETCW(controlWord);
+        return controlWord & FE_MASK;
+}
+
+static inline int fesetround (int mode) {
+        fpu_control_t controlWord;
+
+        _FPU_GETCW (controlWord);
+        controlWord = (controlWord & ~FE_MASK) | mode;
+        _FPU_SETCW (controlWord);
+        return 0;
+}
+
+
 #else
 
 #error fe{get,set}round not implemented
 
 #endif
 
-#endif
+#endif /* !HAS_FEROUND */
 
 C_Int_t IEEEReal_getRoundingMode (void) {
   return fegetround ();

Deleted: mlton/trunk/runtime/platform/feround.c
===================================================================
--- mlton/trunk/runtime/platform/feround.c	2008-09-23 15:06:38 UTC (rev 6886)
+++ mlton/trunk/runtime/platform/feround.c	2008-09-24 02:05:27 UTC (rev 6887)
@@ -1,52 +0,0 @@
-#if (defined(__UCLIBC__))
-
-/* Use whatever we got from fpu_control.h for this CPU model */
-#define FE_MASK (FE_DOWNWARD|FE_TONEAREST|FE_TOWARDZERO|FE_UPWARD)
-
-int fegetround () {
-        fpu_control_t controlWord;
-        _FPU_GETCW(controlWord);
-        return controlWord & FE_MASK;
-}
-
-int fesetround (int mode) {
-        fpu_control_t controlWord;
-
-        _FPU_GETCW (controlWord);
-        controlWord = (controlWord & ~FE_MASK) | mode;
-        _FPU_SETCW (controlWord);
-        return 0;
-}
-
-#elif (defined __i386__)
-
-/* Macros for accessing the hardware control word. */
-#define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))
-#define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))
-
-/* This assumes the FE_* macros are 0-3 as set by platform.h defaults */
-#define ROUNDING_CONTROL_MASK 0x0C00
-#define ROUNDING_CONTROL_SHIFT 10
-
-int fegetround () {
-        unsigned short controlWord;
-
-        _FPU_GETCW (controlWord);
-        return (controlWord & ROUNDING_CONTROL_MASK) >> ROUNDING_CONTROL_SHIFT;
-}
-
-int fesetround (int mode) {
-        unsigned short controlWord;
-
-        _FPU_GETCW (controlWord);
-        controlWord &= ~ROUNDING_CONTROL_MASK;
-        controlWord |= mode << ROUNDING_CONTROL_SHIFT;
-        _FPU_SETCW (controlWord);
-        return 0;
-}
-
-#else
-
-#error fe{get,set}round not implemented
-
-#endif

Deleted: mlton/trunk/runtime/platform/feround.h
===================================================================
--- mlton/trunk/runtime/platform/feround.h	2008-09-23 15:06:38 UTC (rev 6886)
+++ mlton/trunk/runtime/platform/feround.h	2008-09-24 02:05:27 UTC (rev 6887)
@@ -1,2 +0,0 @@
-int fegetround (void);
-int fesetround (int mode);

Modified: mlton/trunk/runtime/platform/linux.c
===================================================================
--- mlton/trunk/runtime/platform/linux.c	2008-09-23 15:06:38 UTC (rev 6886)
+++ mlton/trunk/runtime/platform/linux.c	2008-09-24 02:05:27 UTC (rev 6887)
@@ -9,9 +9,6 @@
 #include "nonwin.c"
 #include "sysconf.c"
 #include "use-mmap.c"
-#ifdef __UCLIBC__
-#include "feround.c"
-#endif
 
 #ifndef EIP
 #define EIP     14

Modified: mlton/trunk/runtime/platform/linux.h
===================================================================
--- mlton/trunk/runtime/platform/linux.h	2008-09-23 15:06:38 UTC (rev 6886)
+++ mlton/trunk/runtime/platform/linux.h	2008-09-24 02:05:27 UTC (rev 6887)
@@ -1,6 +1,8 @@
 #include <inttypes.h>
 #include <stdint.h>
-#ifndef __UCLIBC__
+#ifdef __UCLIBC__
+#include <fpu_control.h>
+#else
 #include <fenv.h>
 #endif
 
@@ -28,7 +30,11 @@
 #include <termios.h>
 #include <utime.h>
 
+#ifdef __UCLIBC__
+#define HAS_FEROUND FALSE
+#else
 #define HAS_FEROUND TRUE
+#endif
 #define HAS_FPCLASSIFY TRUE
 #define HAS_MSG_DONTWAIT TRUE
 #define HAS_REMAP TRUE
@@ -61,11 +67,8 @@
 #endif
 
 #ifdef __UCLIBC__
-#include <fpu_control.h>
-
 #define FE_DOWNWARD     _FPU_RC_DOWN
 #define FE_TONEAREST    _FPU_RC_NEAREST
 #define FE_TOWARDZERO   _FPU_RC_ZERO
 #define FE_UPWARD       _FPU_RC_UP
-#include "feround.h"
 #endif




More information about the MLton-commit mailing list