diff options
-rw-r--r-- | compiler/cmm/CmmMachOp.hs | 5 | ||||
-rw-r--r-- | compiler/codeGen/CgPrimOp.hs | 21 |
2 files changed, 18 insertions, 8 deletions
diff --git a/compiler/cmm/CmmMachOp.hs b/compiler/cmm/CmmMachOp.hs index f42626f638..d53f4855da 100644 --- a/compiler/cmm/CmmMachOp.hs +++ b/compiler/cmm/CmmMachOp.hs @@ -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 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] _ |