[Git][ghc/ghc][wip/T23645] Improve mulmayoflo
Jaro Reinders (@Noughtmare)
gitlab at gitlab.haskell.org
Wed Jul 19 10:00:58 UTC 2023
Jaro Reinders pushed to branch wip/T23645 at Glasgow Haskell Compiler / GHC
Commits:
9513973b by Jaro Reinders at 2023-07-19T12:00:48+02:00
Improve mulmayoflo
- - - - -
3 changed files:
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- testsuite/tests/codeGen/should_run/MulMayOflo.hs
- testsuite/tests/codeGen/should_run/all.T
Changes:
=====================================
compiler/GHC/CmmToAsm/X86/CodeGen.hs
=====================================
@@ -972,21 +972,20 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = -- dyadic MachOps
-- multiplication doesn't use two registers.
--
-- The plan is:
- -- 1. truncate and sign-extend a and b to 8bit width
- -- 2. multiply a' = a * b in 32bit width
- -- 3. copy and sign-extend 8bit from a' to c
- -- 4. compare a' and c: they are equal if there was no overflow
+ -- 1. multiply b1 = a * b where b1 has 16bit width
+ -- 2. subtract b2 = b1 - (-128)
+ -- (this has shorter machine code than b1 + 128)
+ -- 3. compare b2 > 255 unsigned
+ -- This is equivalent to checking b1 < -128 || 127 < b1
(a_reg, a_code) <- getNonClobberedReg a
- (b_reg, b_code) <- getNonClobberedReg b
+ b_code <- getAnyReg b
let
- code = a_code `appOL` b_code `appOL`
+ code = a_code `appOL` b_code eax `appOL`
toOL [
- MOVSxL II8 (OpReg a_reg) (OpReg a_reg),
- MOVSxL II8 (OpReg b_reg) (OpReg b_reg),
- IMUL II32 (OpReg b_reg) (OpReg a_reg),
- MOVSxL II8 (OpReg a_reg) (OpReg eax),
- CMP II16 (OpReg a_reg) (OpReg eax),
- SETCC NE (OpReg eax)
+ IMUL2 II8 (OpReg a_reg), -- result in %ax
+ SUB II16 (OpImm (ImmInt (-128))) (OpReg eax),
+ CMP II16 (OpImm (ImmInt 255)) (OpReg eax),
+ SETCC GU (OpReg eax)
]
return (Fixed II8 eax code)
imulMayOflo rep a b = do
=====================================
testsuite/tests/codeGen/should_run/MulMayOflo.hs
=====================================
@@ -23,4 +23,4 @@ import GHC.Exts
foreign import prim "runCmmzh" runCmmzh# :: Word# -> Word#
main :: IO ()
-main = print . show $ W# (runCmmzh# 42##)
+main = W# (runCmmzh# 42##) `seq` pure ()
=====================================
testsuite/tests/codeGen/should_run/all.T
=====================================
@@ -232,8 +232,6 @@ test('OrigThunkInfo', normal, compile_and_run, ['-forig-thunk-info'])
# Note [MO_S_MulMayOflo significant width]) and may require fixing/adjustment.
test('MulMayOflo_full',
[ extra_files(['MulMayOflo.hs']),
- when(unregisterised(), skip),
- unless(arch('x86_64') or arch('i386'), skip),
- ignore_stdout],
+ when(unregisterised(), skip) ],
multi_compile_and_run,
['MulMayOflo', [('MulMayOflo_full.cmm', '')], ''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9513973b37c0cce03b7a57f28be124cdd54efb69
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9513973b37c0cce03b7a57f28be124cdd54efb69
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/20230719/8077f22a/attachment-0001.html>
More information about the ghc-commits
mailing list