Introduce new SIZEOF_MP_LIMB_T derived constant
authorHerbert Valerio Riedel <hvr@gnu.org>
Thu, 16 Jan 2014 20:39:06 +0000 (21:39 +0100)
committerHerbert Valerio Riedel <hvr@gnu.org>
Thu, 16 Jan 2014 20:39:06 +0000 (21:39 +0100)
This allows to simplify code in `float.c` and to encode the
"sizeof(mp_limb_t) != sizeof(W_)" assumption as a compile-time
assertion.

Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
cbits/float.c
cbits/gmp-wrappers.cmm
mkGmpDerivedConstants/mkGmpDerivedConstants.c

index ec2ec13..73a89f5 100644 (file)
@@ -11,6 +11,7 @@
 /* #include "PosixSource.h" */
 #include "Rts.h"
 #include "gmp.h"
+#include "GmpDerivedConstants.h"
 
 #include <math.h>
 
  * (lib/fltcode.c).
  */
 
-#ifdef _SHORT_LIMB
-#define SIZEOF_LIMB_T SIZEOF_UNSIGNED_INT
-#else
-#ifdef _LONG_LONG_LIMB
-#define SIZEOF_LIMB_T SIZEOF_UNSIGNED_LONG_LONG
-#else
-#define SIZEOF_LIMB_T SIZEOF_UNSIGNED_LONG
-#endif
-#endif
+#define SIZEOF_LIMB_T SIZEOF_MP_LIMB_T
 
 #if SIZEOF_LIMB_T == 4
 #define GMP_BASE 4294967296.0
index eb555fd..4c7df57 100644 (file)
@@ -80,6 +80,10 @@ import "rts" stg_INTLIKE_closure;
    the case for all the platforms that GHC supports, currently.
    -------------------------------------------------------------------------- */
 
+#if SIZEOF_MP_LIMB_T != SIZEOF_W
+#error "sizeof(mp_limb_t) != sizeof(W_)"
+#endif
+
 /* This is used when a dummy pointer is needed for a ByteArray# return value
 
    Ideally this would be a statically allocated 'ByteArray#'
index ed07111..fb7290f 100644 (file)
@@ -69,6 +69,7 @@ main(int argc, char *argv[])
     struct_field(MP_INT,_mp_alloc);
     struct_field(MP_INT,_mp_size);
     struct_field(MP_INT,_mp_d);
+    def_size("MP_LIMB_T", sizeof(mp_limb_t));
 
     return 0;
 }