summaryrefslogtreecommitdiff
path: root/libraries/ghc-prim/cbits
diff options
context:
space:
mode:
authorReid Barton <rwbarton@gmail.com>2013-09-06 19:22:38 -0400
committerJohan Tibell <johan.tibell@gmail.com>2014-03-22 17:13:30 +0100
commit1921238b70548fdad4528508a248b0acdf3233b0 (patch)
treeb55092902b818a54f6735fb3dc3dc08442ec7d55 /libraries/ghc-prim/cbits
parent99869efc79460f946ddaaf166d2a6dcbc8033a43 (diff)
downloadhaskell-1921238b70548fdad4528508a248b0acdf3233b0.tar.gz
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.
Diffstat (limited to 'libraries/ghc-prim/cbits')
-rw-r--r--libraries/ghc-prim/cbits/popcnt.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/libraries/ghc-prim/cbits/popcnt.c b/libraries/ghc-prim/cbits/popcnt.c
index b17b624186..fc44ee75a2 100644
--- a/libraries/ghc-prim/cbits/popcnt.c
+++ b/libraries/ghc-prim/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)] +