[Git][ghc/ghc][wip/T23645] Add special imulMayOflo case for W8

Jaro Reinders (@Noughtmare) gitlab at gitlab.haskell.org
Thu Jul 13 08:43:40 UTC 2023



Jaro Reinders pushed to branch wip/T23645 at Glasgow Haskell Compiler / GHC


Commits:
a2b083e5 by Jaro Reinders at 2023-07-13T10:43:32+02:00
Add special imulMayOflo case for W8

- - - - -


1 changed file:

- compiler/GHC/CmmToAsm/X86/CodeGen.hs


Changes:

=====================================
compiler/GHC/CmmToAsm/X86/CodeGen.hs
=====================================
@@ -968,12 +968,29 @@ getRegister' _ is32Bit (CmmMachOp mop [x, y]) = -- dyadic MachOps
 
 
     imulMayOflo :: Width -> CmmExpr -> CmmExpr -> NatM Register
+
+    -- Special case for W8. Given X, Y we compute:
+    -- Z := X * Y
+    -- Z + 128 > 255 (unsigned)
+    -- This is equivalent to checking: Z < -128 || 127 < Z
+    imulMayOflo W8 a b = do
+         (a_reg, a_code) <- getNonClobberedReg a
+         b_code <- getAnyReg b
+         let
+             code = a_code `appOL` b_code eax `appOL`
+                        toOL [
+                           IMUL2 II8 (OpReg a_reg),   -- result in %ax
+                           ADD 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
          (a_reg, a_code) <- getNonClobberedReg a
          b_code <- getAnyReg b
          let
              shift_amt  = case rep of
-                           W8 -> 7
                            W16 -> 15
                            W32 -> 31
                            W64 -> 63



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a2b083e548683f6da9ff58a9c763f25d4e99ac35

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a2b083e548683f6da9ff58a9c763f25d4e99ac35
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/20230713/531858d5/attachment-0001.html>


More information about the ghc-commits mailing list