summaryrefslogtreecommitdiff
path: root/compiler/codeGen
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2012-08-29 14:50:14 +0100
committerSimon Marlow <marlowsd@gmail.com>2012-08-31 16:43:59 +0100
commitfad7453b64fd1783e688efaa534ffdc2fe6f1324 (patch)
tree8d91a4a0c326d1b8626a13133ade27e123d0ee33 /compiler/codeGen
parent08042a51b677b4f5c611e7fdacb8a1c18922fef7 (diff)
downloadhaskell-fad7453b64fd1783e688efaa534ffdc2fe6f1324.tar.gz
Narrow the arg of popCnt# to the correct width
Fixes cgrun071 on recent Mac OS X versions. This is the right fix at least until we have proper types for Word8#, Word16# etc.
Diffstat (limited to 'compiler/codeGen')
-rw-r--r--compiler/codeGen/CgPrimOp.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/compiler/codeGen/CgPrimOp.hs b/compiler/codeGen/CgPrimOp.hs
index 0c8fb1a89a..88d60b654d 100644
--- a/compiler/codeGen/CgPrimOp.hs
+++ b/compiler/codeGen/CgPrimOp.hs
@@ -424,12 +424,21 @@ emitPrimOp [] CopyMutableByteArrayOp [src,src_off,dst,dst_off,n] live =
emitPrimOp [] SetByteArrayOp [ba,off,len,c] live =
doSetByteArrayOp ba off len c live
--- Population count
-emitPrimOp [res] PopCnt8Op [w] live = emitPopCntCall res w W8 live
-emitPrimOp [res] PopCnt16Op [w] live = emitPopCntCall res w W16 live
-emitPrimOp [res] PopCnt32Op [w] live = emitPopCntCall res w W32 live
-emitPrimOp [res] PopCnt64Op [w] live = emitPopCntCall res w W64 live
-emitPrimOp [res] PopCntOp [w] live = emitPopCntCall res w wordWidth live
+-- Population count.
+-- The type of the primop takes a Word#, so we have to be careful to narrow
+-- to the correct width before calling the primop. Otherwise this can result
+-- in a crash e.g. when calling the helper hs_popcnt8() which assumes that the
+-- argument is <=0xff.
+emitPrimOp [res] PopCnt8Op [w] live =
+ emitPopCntCall res (CmmMachOp mo_WordTo8 [w]) W8 live
+emitPrimOp [res] PopCnt16Op [w] live =
+ emitPopCntCall res (CmmMachOp mo_WordTo16 [w]) W16 live
+emitPrimOp [res] PopCnt32Op [w] live =
+ emitPopCntCall res (CmmMachOp mo_WordTo32 [w]) W32 live
+emitPrimOp [res] PopCnt64Op [w] live =
+ emitPopCntCall res (CmmMachOp mo_WordTo64 [w]) W64 live
+emitPrimOp [res] PopCntOp [w] live =
+ emitPopCntCall res w wordWidth live
-- The rest just translate straightforwardly
emitPrimOp [res] op [arg] _