Commit ad9bf968 authored by rwbarton's avatar rwbarton Committed by tibbe
Browse files

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.
parent aea32bc5
......@@ -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)] +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment