[commit: packages/integer-gmp] master: Introduce new SIZEOF_MP_LIMB_T derived constant (dbb7e64)

git at git.haskell.org git at git.haskell.org
Thu Jan 16 23:20:07 UTC 2014


Repository : ssh://git@git.haskell.org/integer-gmp

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/dbb7e640d2856046dd82f134aa3eb6986472f698/integer-gmp

>---------------------------------------------------------------

commit dbb7e640d2856046dd82f134aa3eb6986472f698
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Thu Jan 16 21:39:06 2014 +0100

    Introduce new SIZEOF_MP_LIMB_T derived constant
    
    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 at gnu.org>


>---------------------------------------------------------------

dbb7e640d2856046dd82f134aa3eb6986472f698
 cbits/float.c                                 |   11 ++---------
 cbits/gmp-wrappers.cmm                        |    4 ++++
 mkGmpDerivedConstants/mkGmpDerivedConstants.c |    1 +
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/cbits/float.c b/cbits/float.c
index ec2ec13..73a89f5 100644
--- a/cbits/float.c
+++ b/cbits/float.c
@@ -11,6 +11,7 @@
 /* #include "PosixSource.h" */
 #include "Rts.h"
 #include "gmp.h"
+#include "GmpDerivedConstants.h"
 
 #include <math.h>
 
@@ -21,15 +22,7 @@
  * (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
diff --git a/cbits/gmp-wrappers.cmm b/cbits/gmp-wrappers.cmm
index eb555fd..4c7df57 100644
--- a/cbits/gmp-wrappers.cmm
+++ b/cbits/gmp-wrappers.cmm
@@ -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#'
diff --git a/mkGmpDerivedConstants/mkGmpDerivedConstants.c b/mkGmpDerivedConstants/mkGmpDerivedConstants.c
index ed07111..fb7290f 100644
--- a/mkGmpDerivedConstants/mkGmpDerivedConstants.c
+++ b/mkGmpDerivedConstants/mkGmpDerivedConstants.c
@@ -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;
 }



More information about the ghc-commits mailing list