[commit: packages/ghc-prim] master: Make argument types in popcnt.c match declared primop types (ad9bf96)
git at git.haskell.org
git at git.haskell.org
Sat Mar 22 17:35:13 UTC 2014
Repository : ssh://git@git.haskell.org/ghc-prim
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/ad9bf96815cb5a9bb4acc51c99eff20be3e50da3/ghc-prim
>---------------------------------------------------------------
commit ad9bf96815cb5a9bb4acc51c99eff20be3e50da3
Author: Reid Barton <rwbarton at gmail.com>
Date: Fri Sep 6 19:22:38 2013 -0400
Make argument types in popcnt.c match declared primop types
On 64-bit Mac OS, gcc 4.2 (which comes with Xcode 4.6) generates code
that assumes that an argument that is smaller than the register
it is passed in has been sign- or zero-extended. But ghc thinks
the types of the PopCnt*Op primops are Word# -> Word#, so it passes
the entire argument word to the hs_popcnt* function as though it was
declared to have an argument of type StgWord. Segfaults ensue.
The easiest fix is to sidestep all this zero-extension business
by declaring the hs_popcnt* functions to take a whole StgWord (when their
argument would fit in a register), thereby matching the list of primops.
Fixes #7684.
>---------------------------------------------------------------
ad9bf96815cb5a9bb4acc51c99eff20be3e50da3
cbits/popcnt.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/cbits/popcnt.c b/cbits/popcnt.c
index b17b624..fc44ee7 100644
--- a/cbits/popcnt.c
+++ b/cbits/popcnt.c
@@ -12,24 +12,24 @@ static const unsigned char popcount_tab[] =
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
};
-extern StgWord hs_popcnt8(StgWord8 x);
+extern StgWord hs_popcnt8(StgWord x);
StgWord
-hs_popcnt8(StgWord8 x)
+hs_popcnt8(StgWord x)
{
return popcount_tab[(unsigned char)x];
}
-extern StgWord hs_popcnt16(StgWord16 x);
+extern StgWord hs_popcnt16(StgWord x);
StgWord
-hs_popcnt16(StgWord16 x)
+hs_popcnt16(StgWord x)
{
return popcount_tab[(unsigned char)x] +
popcount_tab[(unsigned char)(x >> 8)];
}
-extern StgWord hs_popcnt32(StgWord32 x);
+extern StgWord hs_popcnt32(StgWord x);
StgWord
-hs_popcnt32(StgWord32 x)
+hs_popcnt32(StgWord x)
{
return popcount_tab[(unsigned char)x] +
popcount_tab[(unsigned char)(x >> 8)] +
@@ -53,9 +53,9 @@ hs_popcnt64(StgWord64 x)
#ifdef i386_HOST_ARCH
-extern StgWord hs_popcnt(StgWord32 x);
+extern StgWord hs_popcnt(StgWord x);
StgWord
-hs_popcnt(StgWord32 x)
+hs_popcnt(StgWord x)
{
return popcount_tab[(unsigned char)x] +
popcount_tab[(unsigned char)(x >> 8)] +
@@ -65,9 +65,9 @@ hs_popcnt(StgWord32 x)
#else
-extern StgWord hs_popcnt(StgWord64 x);
+extern StgWord hs_popcnt(StgWord x);
StgWord
-hs_popcnt(StgWord64 x)
+hs_popcnt(StgWord x)
{
return popcount_tab[(unsigned char)x] +
popcount_tab[(unsigned char)(x >> 8)] +
More information about the ghc-commits
mailing list