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

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



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


Commits:
baebaebe by Jaro Reinders at 2023-07-13T10:48:43+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
+                           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
          (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/baebaebec91c97a6d0559ef95032ee69a4f2ebaf

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/baebaebec91c97a6d0559ef95032ee69a4f2ebaf
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/468e9e30/attachment-0001.html>


More information about the ghc-commits mailing list