Commit fad7453b authored by Simon Marlow's avatar Simon Marlow
Browse files

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.
parent 08042a51
......@@ -13,7 +13,7 @@ module CmmMachOp
, mo_wordAnd, mo_wordOr, mo_wordXor, mo_wordNot, mo_wordShl, mo_wordSShr, mo_wordUShr
, mo_u_8To32, mo_s_8To32, mo_u_16To32, mo_s_16To32
, mo_u_8ToWord, mo_s_8ToWord, mo_u_16ToWord, mo_s_16ToWord, mo_u_32ToWord, mo_s_32ToWord
, mo_32To8, mo_32To16, mo_WordTo8, mo_WordTo16, mo_WordTo32
, mo_32To8, mo_32To16, mo_WordTo8, mo_WordTo16, mo_WordTo32, mo_WordTo64
-- CallishMachOp
, CallishMachOp(..)
......@@ -124,7 +124,7 @@ mo_wordAdd, mo_wordSub, mo_wordEq, mo_wordNe,mo_wordMul, mo_wordSQuot
, mo_wordAnd, mo_wordOr, mo_wordXor, mo_wordNot, mo_wordShl, mo_wordSShr, mo_wordUShr
, mo_u_8To32, mo_s_8To32, mo_u_16To32, mo_s_16To32
, mo_u_8ToWord, mo_s_8ToWord, mo_u_16ToWord, mo_s_16ToWord, mo_u_32ToWord, mo_s_32ToWord
, mo_32To8, mo_32To16, mo_WordTo8, mo_WordTo16, mo_WordTo32
, mo_32To8, mo_32To16, mo_WordTo8, mo_WordTo16, mo_WordTo32, mo_WordTo64
:: MachOp
mo_wordAdd = MO_Add wordWidth
......@@ -171,6 +171,7 @@ mo_u_32ToWord = MO_UU_Conv W32 wordWidth
mo_WordTo8 = MO_UU_Conv wordWidth W8
mo_WordTo16 = MO_UU_Conv wordWidth W16
mo_WordTo32 = MO_UU_Conv wordWidth W32
mo_WordTo64 = MO_UU_Conv wordWidth W64
mo_32To8 = MO_UU_Conv W32 W8
mo_32To16 = MO_UU_Conv W32 W16
......
......@@ -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] _
......
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