diff options
author | Cheng Shao <terrorjack@type.dance> | 2022-11-28 09:05:57 +0000 |
---|---|---|
committer | Cheng Shao <terrorjack@type.dance> | 2022-11-28 09:05:57 +0000 |
commit | 36b53a9db6d8e7537a8e956a703e3ec3c5081fc3 (patch) | |
tree | 31a4f27b16056af5db9d61422694e262e680ca98 | |
parent | 0eb1c3311aa01646fd19334f2541f96a701c1e20 (diff) | |
download | haskell-36b53a9db6d8e7537a8e956a703e3ec3c5081fc3.tar.gz |
compiler: generate ccalls for clz/ctz/popcnt in wasm NCG
We used to generate a single wasm clz/ctz/popcnt opcode, but it's
wrong when it comes to subwords, so might as well generate ccalls for
them. See #22470 for details.
-rw-r--r-- | compiler/GHC/CmmToAsm/Wasm/Asm.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/CmmToAsm/Wasm/FromCmm.hs | 25 | ||||
-rw-r--r-- | compiler/GHC/CmmToAsm/Wasm/Types.hs | 3 |
3 files changed, 21 insertions, 10 deletions
diff --git a/compiler/GHC/CmmToAsm/Wasm/Asm.hs b/compiler/GHC/CmmToAsm/Wasm/Asm.hs index 2cc08a58b3..7de170bbf0 100644 --- a/compiler/GHC/CmmToAsm/Wasm/Asm.hs +++ b/compiler/GHC/CmmToAsm/Wasm/Asm.hs @@ -308,9 +308,6 @@ asmTellWasmInstr ty_word instr = case instr of WasmConvert Unsigned t0 t1 -> asmTellLine $ asmFromWasmType t1 <> ".convert_" <> asmFromWasmType t0 <> "_u" - WasmClz ty -> asmTellLine $ asmFromWasmType ty <> ".clz" - WasmCtz ty -> asmTellLine $ asmFromWasmType ty <> ".ctz" - WasmPopcnt ty -> asmTellLine $ asmFromWasmType ty <> ".popcnt" WasmAdd ty -> asmTellLine $ asmFromWasmType ty <> ".add" WasmSub ty -> asmTellLine $ asmFromWasmType ty <> ".sub" WasmMul ty -> asmTellLine $ asmFromWasmType ty <> ".mul" diff --git a/compiler/GHC/CmmToAsm/Wasm/FromCmm.hs b/compiler/GHC/CmmToAsm/Wasm/FromCmm.hs index d41b95feba..4e138ba263 100644 --- a/compiler/GHC/CmmToAsm/Wasm/FromCmm.hs +++ b/compiler/GHC/CmmToAsm/Wasm/FromCmm.hs @@ -1238,8 +1238,13 @@ lower_CallishMachOp lbl (MO_Memcmp {}) rs xs = CmmMayReturn rs xs -lower_CallishMachOp lbl (MO_PopCnt {}) rs xs = - lower_CMO_Un_Prim lbl WasmPopcnt rs xs +lower_CallishMachOp lbl (MO_PopCnt w0) rs xs = + lower_CmmUnsafeForeignCall + lbl + (Left $ fromString $ "hs_popcnt" <> show (widthInBits w0)) + CmmMayReturn + rs + xs lower_CallishMachOp lbl (MO_Pdep w0) rs xs = lower_CmmUnsafeForeignCall lbl @@ -1254,8 +1259,20 @@ lower_CallishMachOp lbl (MO_Pext w0) rs xs = CmmMayReturn rs xs -lower_CallishMachOp lbl (MO_Clz {}) rs xs = lower_CMO_Un_Prim lbl WasmClz rs xs -lower_CallishMachOp lbl (MO_Ctz {}) rs xs = lower_CMO_Un_Prim lbl WasmCtz rs xs +lower_CallishMachOp lbl (MO_Clz w0) rs xs = + lower_CmmUnsafeForeignCall + lbl + (Left $ fromString $ "hs_clz" <> show (widthInBits w0)) + CmmMayReturn + rs + xs +lower_CallishMachOp lbl (MO_Ctz w0) rs xs = + lower_CmmUnsafeForeignCall + lbl + (Left $ fromString $ "hs_ctz" <> show (widthInBits w0)) + CmmMayReturn + rs + xs lower_CallishMachOp lbl (MO_BSwap w0) rs xs = lower_CmmUnsafeForeignCall lbl diff --git a/compiler/GHC/CmmToAsm/Wasm/Types.hs b/compiler/GHC/CmmToAsm/Wasm/Types.hs index ab052dc353..06d2c246e6 100644 --- a/compiler/GHC/CmmToAsm/Wasm/Types.hs +++ b/compiler/GHC/CmmToAsm/Wasm/Types.hs @@ -279,9 +279,6 @@ data WasmInstr :: WasmType -> [WasmType] -> [WasmType] -> Type where w (t0 : pre) (t1 : pre) - WasmClz :: WasmTypeTag t -> WasmInstr w (t : pre) (t : pre) - WasmCtz :: WasmTypeTag t -> WasmInstr w (t : pre) (t : pre) - WasmPopcnt :: WasmTypeTag t -> WasmInstr w (t : pre) (t : pre) WasmAdd :: WasmTypeTag t -> WasmInstr w (t : t : pre) (t : pre) WasmSub :: WasmTypeTag t -> WasmInstr w (t : t : pre) (t : pre) WasmMul :: WasmTypeTag t -> WasmInstr w (t : t : pre) (t : pre) |