[MLton-commit] r4620

Matthew Fluet MLton@mlton.org
Sun, 28 May 2006 19:21:55 -0700


Move Real64_{fetch,move,store} from c-chunk.h to
Real<N>_{fetch,move,store} in Real-ops.h.

Move Real<N>_modf from modf.c to Math-fns.h.  (Real<N>_modf is now
inlined in the C-codegen.)

Implement Real64_modf using Real64_store on sparc and hppa; this
should fix the legitimate 'cast increases required alignment of target
type' warning.


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

U   mlton/branches/on-20050822-x86_64-branch/include/c-chunk.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Math-fns.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Real-ops.h
D   mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/modf.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def

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

Modified: mlton/branches/on-20050822-x86_64-branch/include/c-chunk.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/include/c-chunk.h	2006-05-28 12:25:24 UTC (rev 4619)
+++ mlton/branches/on-20050822-x86_64-branch/include/c-chunk.h	2006-05-29 02:21:54 UTC (rev 4620)
@@ -217,47 +217,6 @@
 #include "basis/Word/Word-check.h"
 
 /* ------------------------------------------------- */
-/*                        Real                       */
-/* ------------------------------------------------- */
-
-typedef volatile union {
-        Word32 tab[2];
-        Real64 d;
-} Real64Or2Word32s;
-
-static inline Real64 Real64_fetch (Real64 *dp) {
-        Real64Or2Word32s u;
-        Word32 *p;
-
-        p = (Word32*)dp;
-        u.tab[0] = p[0];
-        u.tab[1] = p[1];
-        return u.d;
-}
-
-static inline void Real64_move (Real64 *dst, Real64 *src) {
-        Word32 *pd;
-        Word32 *ps;
-        Word32 t;
-
-        pd = (Word32*)dst;
-        ps = (Word32*)src;
-        t = ps[1];
-        pd[0] = ps[0];
-        pd[1] = t;              
-}
-
-static inline void Real64_store (Real64 *dp, Real64 d) {
-        Real64Or2Word32s u;
-        Word32 *p;
-
-        p = (Word32*)dp;
-        u.d = d;
-        p[0] = u.tab[0];
-        p[1] = u.tab[1];
-}
-
-/* ------------------------------------------------- */
 /*                        Word                       */
 /* ------------------------------------------------- */
 

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Math-fns.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Math-fns.h	2006-05-28 12:25:24 UTC (rev 4619)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Math-fns.h	2006-05-29 02:21:54 UTC (rev 4620)
@@ -86,3 +86,40 @@
   }
 binaryRealInt(ldexp, ldexp)
 #undef binaryRealInt
+
+#if (defined (__hppa__) || defined (__sparc__))
+#define binaryRealRealRef(g, h)                                         \
+  MLTON_CODEGEN_MATHFN(Real32_t h##f (Real32_t x, Real32_t *yp);)       \
+    MLTON_CODEGEN_STATIC_INLINE                                         \
+  Real32_t Real32_##g (Real32_t x, Ref(Real32_t) yp) {                  \
+    /* Real32_t r, res; */                                              \
+    /* r = Real32_fetch (yp); */                                        \
+    /* res = h##f (x, &r); */                                           \
+    /* Real32_store (yp, r); */                                         \
+    /* return res; */                                                   \
+    return h##f (x, (Real32_t*)yp);                                     \
+  }                                                                     \
+  MLTON_CODEGEN_MATHFN(Real64_t h (Real64_t x, Real64_t *yp);)          \
+  MLTON_CODEGEN_STATIC_INLINE                                           \
+  Real64_t Real64_##g (Real64_t x, Ref(Real64_t) yp) {                  \
+    Real64_t r, res;                                                    \
+    /* r = Real64_fetch (yp); */                                        \
+    res = h (x, &r);                                                    \
+    Real64_store (yp, r);                                               \
+    return res;                                                         \
+  }
+#else
+#define binaryRealRealRef(g, h)                                         \
+  MLTON_CODEGEN_MATHFN(Real32_t h##f (Real32_t x, Real32_t *yp);)       \
+    MLTON_CODEGEN_STATIC_INLINE                                         \
+  Real32_t Real32_##g (Real32_t x, Ref(Real32_t) yp) {                  \
+    return h##f (x, (Real32_t*)yp);                                     \
+  }                                                                     \
+  MLTON_CODEGEN_MATHFN(Real64_t h (Real64_t x, Real64_t *yp);)          \
+  MLTON_CODEGEN_STATIC_INLINE                                           \
+  Real64_t Real64_##g (Real64_t x, Ref(Real64_t) yp) {                  \
+    return h (x, (Real64_t*)yp);                                        \
+  }
+#endif
+binaryRealRealRef(modf, modf)
+#undef binaryRealRealRef

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Real-ops.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Real-ops.h	2006-05-28 12:25:24 UTC (rev 4619)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Real-ops.h	2006-05-29 02:21:54 UTC (rev 4620)
@@ -23,6 +23,40 @@
     return op r1;                                                       \
   }
 
+#define misaligned(size)                                                \
+  typedef volatile union {                                              \
+    Real##size##_t r;                                                   \
+    Word32_t ws[sizeof(Real##size##_t) / sizeof(Word32_t)];             \
+  } Real##size##OrWord32s;                                              \
+  MLTON_CODEGEN_STATIC_INLINE                                           \
+  Real##size##_t Real##size##_fetch (Ref(Real##size##_t) rp) {          \
+    Real##size##OrWord32s u;                                            \
+    Word32_t *wp;                                                       \
+    wp = (Word32_t*)rp;                                                 \
+    u.ws[0] = wp[0];                                                    \
+    if ((sizeof(Real##size##_t) / sizeof(Word32_t)) > 1)                \
+      u.ws[1] = wp[1];                                                  \
+    return u.r;                                                         \
+  }                                                                     \
+  MLTON_CODEGEN_STATIC_INLINE                                           \
+  void Real##size##_store (Ref(Real##size##_t) rp, Real##size##_t r) {  \
+    Real##size##OrWord32s u;                                            \
+    Word32_t *wp;                                                       \
+    wp = (Word32_t*)rp;                                                 \
+    u.r = r;                                                            \
+    wp[0] = u.ws[0];                                                    \
+    if ((sizeof(Real##size##_t) / sizeof(Word32_t)) > 1)                \
+      wp[1] = u.ws[1];                                                  \
+    return;                                                             \
+  }                                                                     \
+  MLTON_CODEGEN_STATIC_INLINE                                           \
+  void Real##size##_move (Ref(Real##size##_t) dst, Ref(Real##size##_t) src) { \
+    Real##size##_t r;                                                   \
+    r = Real##size##_fetch (src);                                       \
+    Real##size##_store (dst, r);                                        \
+    return;                                                             \
+  }
+
 #define all(size)                               \
 binary(size, add, +)                            \
 binary(size, div, /)                            \
@@ -33,12 +67,14 @@
 compare(size, lt, <)                            \
 ternary(size, add, +)                           \
 ternary(size, sub, -)                           \
-unary(size, neg, -)
+unary(size, neg, -)                             \
+misaligned(size)
 
 all(32)
 all(64)
 
 #undef all
+#undef misaligned
 #undef unary
 #undef ternary
 #undef compare

Deleted: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/modf.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/modf.c	2006-05-28 12:25:24 UTC (rev 4619)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/modf.c	2006-05-29 02:21:54 UTC (rev 4620)
@@ -1,11 +0,0 @@
-#include "platform.h"
-
-#define binaryRealRealRef(g, h)                                 \
-Real64_t Real64_##g (Real64_t x, Ref(Real64_t) yp) {            \
-  return h (x, (Real64_t*)yp);                                  \
-}                                                               \
-Real32_t Real32_##g (Real32_t x, Ref(Real32_t) yp) {            \
-  return h##f (x, (Real32_t*)yp);                               \
-}
-binaryRealRealRef(modf, modf)
-#undef binaryRealRealRef

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def	2006-05-28 12:25:24 UTC (rev 4619)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def	2006-05-29 02:21:54 UTC (rev 4620)
@@ -875,6 +875,7 @@
 Real32.class = _import : Real32.t -> C_Int.t
 Real32.div = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t -> Real32.t
 Real32.equal = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t -> Bool.t
+Real32.fetch = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t ref -> Real32.t
 Real32.frexp = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * C_Int.t ref -> Real32.t
 Real32.gdtoa = _import : Real32.t * C_Int.t * C_Int.t * C_Int.t ref -> C_String.t
 Real32.ldexp = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * C_Int.t -> Real32.t
@@ -883,7 +884,8 @@
 Real32.maxFinite = _symbol : Real32.t
 Real32.minNormalPos = _symbol : Real32.t
 Real32.minPos = _symbol : Real32.t
-Real32.modf = _import : Real32.t * Real32.t ref -> Real32.t
+Real32.modf = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t ref -> Real32.t
+Real32.move = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t ref * Real32.t ref -> unit
 Real32.mul = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t -> Real32.t
 Real32.muladd = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t * Real32.t -> Real32.t
 Real32.mulsub = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t * Real32.t -> Real32.t
@@ -891,6 +893,7 @@
 Real32.nextAfter = _import : Real32.t * Real32.t -> Real32.t
 Real32.round = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t -> Real32.t
 Real32.signBit = _import : Real32.t -> C_Int.t
+Real32.store = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t ref * Real32.t -> unit
 Real32.strto = _import : NullString8.t -> Real32.t
 Real32.sub = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t -> Real32.t
 Real32.toReal32 = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t -> Real32.t
@@ -925,6 +928,7 @@
 Real64.class = _import : Real64.t -> C_Int.t
 Real64.div = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t -> Real64.t
 Real64.equal = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t -> Bool.t
+Real64.fetch = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t ref -> Real64.t
 Real64.frexp = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * C_Int.t ref -> Real64.t
 Real64.gdtoa = _import : Real64.t * C_Int.t * C_Int.t * C_Int.t ref -> C_String.t
 Real64.ldexp = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * C_Int.t -> Real64.t
@@ -933,7 +937,8 @@
 Real64.maxFinite = _symbol : Real64.t
 Real64.minNormalPos = _symbol : Real64.t
 Real64.minPos = _symbol : Real64.t
-Real64.modf = _import : Real64.t * Real64.t ref -> Real64.t
+Real64.modf = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t ref -> Real64.t
+Real64.move = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t ref * Real64.t ref -> unit
 Real64.mul = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t -> Real64.t
 Real64.muladd = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t * Real64.t -> Real64.t
 Real64.mulsub = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t * Real64.t -> Real64.t
@@ -941,6 +946,7 @@
 Real64.nextAfter = _import : Real64.t * Real64.t -> Real64.t
 Real64.round = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t -> Real64.t
 Real64.signBit = _import : Real64.t -> C_Int.t
+Real64.store = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t ref * Real64.t -> unit
 Real64.strto = _import : NullString8.t -> Real64.t
 Real64.sub = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t -> Real64.t
 Real64.toReal32 = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t -> Real32.t