[Git][ghc/ghc][master] 2 commits: Move hs_mulIntMayOflo cbits to ghc-prim
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Tue Nov 29 04:47:59 UTC 2022
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
0eb1c331 by Cheng Shao at 2022-11-28T08:55:53+00:00
Move hs_mulIntMayOflo cbits to ghc-prim
It's only used by wasm NCG at the moment, but ghc-prim is a more
reasonable place for hosting out-of-line primops. Also, we only need a
single version of hs_mulIntMayOflo.
- - - - -
36b53a9d by Cheng Shao at 2022-11-28T09:05:57+00:00
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.
- - - - -
7 changed files:
- compiler/GHC/CmmToAsm/Wasm/Asm.hs
- compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
- compiler/GHC/CmmToAsm/Wasm/Types.hs
- + libraries/ghc-prim/cbits/mulIntMayOflo.c
- libraries/ghc-prim/ghc-prim.cabal
- rts/rts.cabal.in
- − rts/wasm/Ops.c
Changes:
=====================================
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"
=====================================
compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
=====================================
@@ -443,27 +443,22 @@ lower_MO_S_Shr lbl w0 [x, y] = case someWasmTypeFromCmmType (cmmBits w0) of
lower_MO_S_Shr _ _ _ = panic "lower_MO_S_Shr: unreachable"
-- | Lower a 'MO_MulMayOflo' operation. It's translated to a ccall to
--- one of the @hs_mulIntMayOflo@ functions in rts/wasm/Ops.c,
+-- @hs_mulIntMayOflo@ function in @ghc-prim/cbits/mulIntMayOflo@,
-- otherwise it's quite non-trivial to implement as inline assembly.
lower_MO_MulMayOflo ::
- CLabel ->
- Width ->
- [CmmExpr] ->
- WasmCodeGenM
- w
- (SomeWasmExpr w)
+ CLabel -> Width -> [CmmExpr] -> WasmCodeGenM w (SomeWasmExpr w)
lower_MO_MulMayOflo lbl w0 [x, y] = case someWasmTypeFromCmmType ty_cmm of
SomeWasmType ty -> do
WasmExpr x_instr <- lower_CmmExpr_Typed lbl ty x
WasmExpr y_instr <- lower_CmmExpr_Typed lbl ty y
- onFuncSym f [ty_cmm, ty_cmm] [ty_cmm]
+ onFuncSym "hs_mulIntMayOflo" [ty_cmm, ty_cmm] [ty_cmm]
pure $
SomeWasmExpr ty $
WasmExpr $
- x_instr `WasmConcat` y_instr `WasmConcat` WasmCCall f
+ x_instr
+ `WasmConcat` y_instr
+ `WasmConcat` WasmCCall "hs_mulIntMayOflo"
where
- f = fromString $ "hs_mulIntMayOflo" <> show (widthInBits w0)
-
ty_cmm = cmmBits w0
lower_MO_MulMayOflo _ _ _ = panic "lower_MO_MulMayOflo: unreachable"
@@ -1243,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
@@ -1259,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
=====================================
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)
=====================================
libraries/ghc-prim/cbits/mulIntMayOflo.c
=====================================
@@ -0,0 +1,3 @@
+#include "Rts.h"
+
+W_ hs_mulIntMayOflo(W_ a, W_ b) { return mulIntMayOflo(a, b); }
=====================================
libraries/ghc-prim/ghc-prim.cabal
=====================================
@@ -89,6 +89,7 @@ Library
cbits/ctz.c
cbits/debug.c
cbits/longlong.c
+ cbits/mulIntMayOflo.c
cbits/pdep.c
cbits/pext.c
cbits/popcnt.c
=====================================
rts/rts.cabal.in
=====================================
@@ -615,7 +615,6 @@ library
asm-sources: wasm/Wasm.S
c-sources: wasm/StgRun.c
wasm/GetTime.c
- wasm/Ops.c
wasm/OSMem.c
wasm/OSThreads.c
posix/Select.c
=====================================
rts/wasm/Ops.c deleted
=====================================
@@ -1,9 +0,0 @@
-#include "Stg.h"
-
-StgWord8 hs_mulIntMayOflo8(StgWord8 _0, StgWord8 _1) { return mulIntMayOflo(_0, _1); }
-
-StgWord16 hs_mulIntMayOflo16(StgWord16 _0, StgWord16 _1) { return mulIntMayOflo(_0, _1); }
-
-StgWord32 hs_mulIntMayOflo32(StgWord32 _0, StgWord32 _1) { return mulIntMayOflo(_0, _1); }
-
-StgWord64 hs_mulIntMayOflo64(StgWord64 _0, StgWord64 _1) { return mulIntMayOflo(_0, _1); }
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2da5c38a45fcfd9778d7d89d0946aa475ae96627...36b53a9db6d8e7537a8e956a703e3ec3c5081fc3
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2da5c38a45fcfd9778d7d89d0946aa475ae96627...36b53a9db6d8e7537a8e956a703e3ec3c5081fc3
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221128/69c01c8a/attachment-0001.html>
More information about the ghc-commits
mailing list