[MLton-commit] r4581

Matthew Fluet MLton@mlton.org
Wed, 24 May 2006 15:10:32 -0700


A somewhat different solution to the issue discussed in r4578.  Rather
than include "basis-ffi.h" (and suffer incompatible extern
declarations for Basis Library values imported as _symbol), we
conditionally include either a declaration of WordS<N>_{quot,rem} or a
static inline definition.

Also fixed a bug whereby the inlined Real<N>_Math_* functions did not
have declarations for the underlying <math.h> functions; again, this
is a consequence of "c-chunk.h" not including "platform.h".

Both issues could be solved by including "platform.h" in "c-chunk.h",
but it isn't clear why this was never done before.  (Of course, the
extern/_symbol issue remains.)


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

U   mlton/branches/on-20050822-x86_64-branch/bytecode/interpret.c
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/Word/Word-ops.h

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

Modified: mlton/branches/on-20050822-x86_64-branch/bytecode/interpret.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/bytecode/interpret.c	2006-05-24 21:52:07 UTC (rev 4580)
+++ mlton/branches/on-20050822-x86_64-branch/bytecode/interpret.c	2006-05-24 22:10:31 UTC (rev 4581)
@@ -6,7 +6,22 @@
  */
 
 #define MLTON_GC_INTERNAL_TYPES
+#ifndef MLTON_CODEGEN_STATIC_INLINE
 #define MLTON_CODEGEN_STATIC_INLINE static inline
+#endif
+/* No need to declare inlined math functions, since <math.h> comes
+ * with "platform.h".
+ */
+#ifndef MLTON_CODEGEN_MATHFN
+#define MLTON_CODEGEN_MATHFN(decl) 
+#endif
+/* WordS<N>_quot and WordS<N>_rem can be inlined with the
+ * bytecode-codegen, since they will be used in a context where the
+ * arguments are variables.
+ */
+#ifndef MLTON_CODEGEN_WORDSQUOTREM
+#define MLTON_CODEGEN_WORDSQUOTREM(decl, func) func
+#endif
 #include "platform.h"
 
 #include "interpret.h"

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-24 21:52:07 UTC (rev 4580)
+++ mlton/branches/on-20050822-x86_64-branch/include/c-chunk.h	2006-05-24 22:10:31 UTC (rev 4581)
@@ -196,8 +196,20 @@
 #ifndef MLTON_CODEGEN_STATIC_INLINE
 #define MLTON_CODEGEN_STATIC_INLINE static inline
 #endif
-#define MLTON_CCODEGEN_HIDE(z) 
-#include "basis-ffi.h"
+/* Declare inlined math functions, since <math.h> isn't included.
+ */
+#ifndef MLTON_CODEGEN_MATHFN
+#define MLTON_CODEGEN_MATHFN(decl) decl
+#endif
+/* WordS<N>_quot and WordS<N>_rem can't be inlined with the C-codegen,
+ * because the gcc optimizer sometimes produces incorrect results when
+ * one of the arguments is a constant.  
+ * However, we need the declarations for Word-check.h
+ */
+#ifndef MLTON_CODEGEN_WORDSQUOTREM
+#define MLTON_CODEGEN_WORDSQUOTREM(decl, func) decl
+#endif
+// #include "basis-ffi.h"
 #include "basis/coerce.h"
 #include "basis/Real/Real-ops.h"
 #include "basis/Real/Math-fns.h"

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-24 21:52:07 UTC (rev 4580)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/Math-fns.h	2006-05-24 22:10:31 UTC (rev 4581)
@@ -1,9 +1,15 @@
 
+#ifndef MLTON_CODEGEN_MATHFN
+#define MLTON_CODEGEN_MATHFN(decl) 
+#endif
+
 #define unaryReal(g, h)                                         \
+  MLTON_CODEGEN_MATHFN(Real64_t h(Real64_t x);)                 \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real64_t Real64_##g (Real64_t x) {                            \
     return h (x);                                               \
   }                                                             \
+  MLTON_CODEGEN_MATHFN(Real32_t h##f(Real32_t x);)              \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real32_t Real32_##g (Real32_t x) {                            \
     return h##f (x);                                            \
@@ -13,10 +19,12 @@
 #undef unaryReal
   
 #define binaryReal(g, h)                                        \
+  MLTON_CODEGEN_MATHFN(Real64_t h(Real64_t x, Real64_t y);)     \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real64_t Real64_Math_##g (Real64_t x, Real64_t y) {           \
     return h (x, y);                                            \
   }                                                             \
+  MLTON_CODEGEN_MATHFN(Real32_t h##f(Real32_t x, Real32_t y);)  \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real32_t Real32_Math_##g (Real32_t x, Real32_t y) {           \
     return h##f (x, y);                                         \
@@ -26,10 +34,12 @@
 #undef binaryReal
 
 #define unaryReal(g, h)                                         \
+  MLTON_CODEGEN_MATHFN(Real64_t h(Real64_t x);)                 \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real64_t Real64_Math_##g (Real64_t x) {                       \
     return h (x);                                               \
   }                                                             \
+  MLTON_CODEGEN_MATHFN(Real32_t h##f(Real32_t x);)              \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real32_t Real32_Math_##g (Real32_t x) {                       \
     return h##f (x);                                            \
@@ -50,10 +60,12 @@
 #undef unaryReal
 
 #define binaryRealIntRef(g, h)                                  \
+  MLTON_CODEGEN_MATHFN(Real64_t h (Real64_t x, int* ip);)       \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real64_t Real64_##g (Real64_t x, Ref(C_Int_t) i) {            \
     return h (x, (int*)i);                                      \
   }                                                             \
+  MLTON_CODEGEN_MATHFN(Real32_t h##f (Real32_t x, int* ip);)    \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real32_t Real32_##g (Real32_t x, Ref(C_Int_t) i) {            \
     return h##f (x, (int*)i);                                   \
@@ -62,10 +74,12 @@
 #undef binaryRealIntRef
 
 #define binaryRealInt(g, h)                                     \
+  MLTON_CODEGEN_MATHFN(Real64_t h (Real64_t x, int i);)         \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real64_t Real64_##g (Real64_t x, C_Int_t i) {                 \
     return h (x, i);                                            \
   }                                                             \
+  MLTON_CODEGEN_MATHFN(Real32_t h##f (Real32_t x, int i);)      \
   MLTON_CODEGEN_STATIC_INLINE                                   \
   Real32_t Real32_##g (Real32_t x, C_Int_t i) {                 \
     return h##f (x, i);                                         \

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Word/Word-ops.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Word/Word-ops.h	2006-05-24 21:52:07 UTC (rev 4580)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Word/Word-ops.h	2006-05-24 22:10:31 UTC (rev 4581)
@@ -1,8 +1,11 @@
 
-#ifndef MLTON_CCODEGEN_HIDE
-#define MLTON_CCODEGEN_HIDE(z) z
+#ifndef MLTON_CODEGEN_WORDSQUOTREM
+#define MLTON_CODEGEN_WORDSQUOTREM(decl, func) func
 #endif
 
+#define binaryDecl(kind, name)                                          \
+  Word##kind Word##kind##_##name (Word##kind w1, Word##kind w2);
+
 #define binary(kind, name, op)                                          \
   MLTON_CODEGEN_STATIC_INLINE                                           \
   Word##kind Word##kind##_##name (Word##kind w1, Word##kind w2) {       \
@@ -61,10 +64,14 @@
 unary (size, notb, ~)                           \
 /* WordS<N>_quot and WordS<N>_rem can't be inlined with the C-codegen,   \ 
  * because the gcc optimizer sometimes produces incorrect results        \
- * when one of th arguments is a constant.                               \
+ * when one of the arguments is a constant.                              \
+ * However, we need the declarations for Word-check.h                    \
+ * WordS<N>_quot and WordS<N>_rem can be inlined with the                \
+ * bytecode-codegen, since they will be used in a context where the      \
+ * arguments are variables.                                              \
  */                                                                      \
-MLTON_CCODEGEN_HIDE(binary (S##size, quot, /))  \
-MLTON_CCODEGEN_HIDE(binary (S##size, rem, %))   \
+MLTON_CODEGEN_WORDSQUOTREM(binaryDecl (S##size, quot), binary (S##size, quot, /)) \
+MLTON_CODEGEN_WORDSQUOTREM(binaryDecl (S##size, rem), binary (S##size, rem, %))   \
 binary (U##size, quot, /)                       \
 binary (U##size, rem, %)                        \
 binary (size, orb, |)                           \