[MLton-commit] r6673

Wesley Terpstra wesley at mlton.org
Sat Jul 26 16:50:28 PDT 2008


Add support for building with uclibc/linux (use fpu_control for feround).
Add also support for mips.


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

U   mlton/trunk/runtime/basis/Word/Word.c
U   mlton/trunk/runtime/platform/feround.c
U   mlton/trunk/runtime/platform/feround.h
U   mlton/trunk/runtime/platform/linux.c
U   mlton/trunk/runtime/platform/linux.h
U   mlton/trunk/runtime/platform/solaris.c

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

Modified: mlton/trunk/runtime/basis/Word/Word.c
===================================================================
--- mlton/trunk/runtime/basis/Word/Word.c	2008-07-16 18:46:51 UTC (rev 6672)
+++ mlton/trunk/runtime/basis/Word/Word.c	2008-07-26 23:50:01 UTC (rev 6673)
@@ -24,7 +24,7 @@
  * implements / and %.
  */
 
-#if ! (defined (__amd64__) || defined (__hppa__) || defined (__i386__) || defined(__ia64__)|| defined (__ppc__) || defined (__powerpc__) || defined (__sparc__))
+#if ! (defined (__amd64__) || defined (__hppa__) || defined (__i386__) || defined(__ia64__) || defined(__mips__) || defined (__ppc__) || defined (__powerpc__) || defined (__sparc__))
 #error check that C {/,%} correctly implement {quot,rem} from the basis library
 #endif
 

Modified: mlton/trunk/runtime/platform/feround.c
===================================================================
--- mlton/trunk/runtime/platform/feround.c	2008-07-16 18:46:51 UTC (rev 6672)
+++ mlton/trunk/runtime/platform/feround.c	2008-07-26 23:50:01 UTC (rev 6673)
@@ -1,9 +1,30 @@
-#if (defined __i386__)
+#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
 
@@ -14,13 +35,14 @@
         return (controlWord & ROUNDING_CONTROL_MASK) >> ROUNDING_CONTROL_SHIFT;
 }
 
-void fesetround (int mode) {
+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

Modified: mlton/trunk/runtime/platform/feround.h
===================================================================
--- mlton/trunk/runtime/platform/feround.h	2008-07-16 18:46:51 UTC (rev 6672)
+++ mlton/trunk/runtime/platform/feround.h	2008-07-26 23:50:01 UTC (rev 6673)
@@ -1,2 +1,2 @@
 int fegetround (void);
-void fesetround (int mode);
+int fesetround (int mode);

Modified: mlton/trunk/runtime/platform/linux.c
===================================================================
--- mlton/trunk/runtime/platform/linux.c	2008-07-16 18:46:51 UTC (rev 6672)
+++ mlton/trunk/runtime/platform/linux.c	2008-07-26 23:50:01 UTC (rev 6673)
@@ -10,6 +10,9 @@
 #include "nonwin.c"
 #include "sysconf.c"
 #include "use-mmap.c"
+#ifdef __UCLIBC__
+#include "feround.c"
+#endif
 
 #ifndef EIP
 #define EIP     14
@@ -19,7 +22,6 @@
  *  alpha: ucp->m_context.sc_pc
  *  arm: ucp->m_context.ctx.arm_pc
  *  ia64: ucp->m_context.sc_ip & ~0x3UL
- *  mips: ucp->m_context.sc_pc
  *  s390: ucp->m_context.sregs->regs.psw.addr
  */
 static void catcher (__attribute__ ((unused)) int sig, 
@@ -45,6 +47,13 @@
 #else
         GC_handleSigProf ((code_pointer) scp->si_regs.pc);
 #endif
+#elif (defined (__mips__))
+        ucontext_t* ucp = (ucontext_t*)mystery;
+#ifdef __UCLIBC__
+        GC_handleSigProf ((code_pointer) ucp->uc_mcontext.gpregs[CTX_EPC]);
+#else
+        GC_handleSigProf ((code_pointer) ucp->uc_mcontext.pc);
+#endif
 #elif (defined (__i386__))
         ucontext_t* ucp = (ucontext_t*)mystery;
         GC_handleSigProf ((code_pointer) ucp->uc_mcontext.gregs[EIP]);

Modified: mlton/trunk/runtime/platform/linux.h
===================================================================
--- mlton/trunk/runtime/platform/linux.h	2008-07-16 18:46:51 UTC (rev 6672)
+++ mlton/trunk/runtime/platform/linux.h	2008-07-26 23:50:01 UTC (rev 6673)
@@ -1,6 +1,8 @@
-#include <fenv.h>
 #include <inttypes.h>
 #include <stdint.h>
+#ifndef __UCLIBC__
+#include <fenv.h>
+#endif
 
 #include <unistd.h>
 
@@ -57,3 +59,13 @@
 #ifndef SO_ACCEPTCONN
 #define SO_ACCEPTCONN 30
 #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

Modified: mlton/trunk/runtime/platform/solaris.c
===================================================================
--- mlton/trunk/runtime/platform/solaris.c	2008-07-16 18:46:51 UTC (rev 6672)
+++ mlton/trunk/runtime/platform/solaris.c	2008-07-26 23:50:01 UTC (rev 6673)
@@ -26,7 +26,7 @@
         return mode;
 }
 
-void fesetround (int mode) {
+int fesetround (int mode) {
         switch (mode) {
         case 0: mode = FP_RN; break;
         case 1: mode = FP_RM; break;
@@ -34,6 +34,7 @@
         case 3: mode = FP_RZ; break;
         }
         fpsetround (mode);
+        return 0;
 }
 #endif /* __sparc__ */
 




More information about the MLton-commit mailing list