[Git][ghc/ghc][wip/T23576] Add more shifts

Jaro Reinders (@Noughtmare) gitlab at gitlab.haskell.org
Fri Jun 30 15:26:13 UTC 2023



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


Commits:
da6d9762 by Jaro Reinders at 2023-06-30T17:26:03+02:00
Add more shifts

- - - - -


3 changed files:

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


Changes:

=====================================
compiler/GHC/CmmToAsm/X86/CodeGen.hs
=====================================
@@ -643,6 +643,27 @@ iselExpr64 (CmmMachOp (MO_Mul _) [e1,e2]) = do
    return (RegCode64 code rhi rlo)
 
 iselExpr64 (CmmMachOp (MO_Shl _) [e1,e2]) = do
+   RegCode64 code1 r1hi r1lo <- iselExpr64 e1
+   (r2, code2) <- getSomeReg e2
+   Reg64 rhi rlo <- getNewReg64
+   b <- newBlockId
+   let
+        code =  code1 `appOL`
+                code2 `appOL`
+                toOL [ MOV II32 (OpReg r1lo) (OpReg rlo),
+                       MOV II32 (OpReg r1hi) (OpReg rhi),
+                       MOV II32 (OpReg r2) (OpReg ecx),
+                       SHLD II32 (OpReg ecx) (OpReg rlo) (OpReg rhi),
+                       SAL II32 (OpReg ecx) (OpReg rlo),
+                       TEST II32 (OpImm (ImmInt 32)) (OpReg ecx),
+                       JXX EQQ b,
+                       MOV II32 (OpReg rlo) (OpReg rhi),
+                       XOR II32 (OpReg rlo) (OpReg rlo),
+                       NEWBLOCK b
+                     ]
+   return (RegCode64 code rhi rlo)
+
+iselExpr64 (CmmMachOp (MO_S_Shr _) [e1,e2]) = do
    RegCode64 code1 r1hi r1lo <- iselExpr64 e1
    (r2, code2) <- getSomeReg e2
    Reg64 rhi rlo <- getNewReg64
@@ -663,6 +684,27 @@ iselExpr64 (CmmMachOp (MO_Shl _) [e1,e2]) = do
                      ]
    return (RegCode64 code rhi rlo)
 
+iselExpr64 (CmmMachOp (MO_U_Shr _) [e1,e2]) = do
+   RegCode64 code1 r1hi r1lo <- iselExpr64 e1
+   (r2, code2) <- getSomeReg e2
+   Reg64 rhi rlo <- getNewReg64
+   b <- newBlockId
+   let
+        code =  code1 `appOL`
+                code2 `appOL`
+                toOL [ MOV II32 (OpReg r1lo) (OpReg rlo),
+                       MOV II32 (OpReg r1hi) (OpReg rhi),
+                       MOV II32 (OpReg r2) (OpReg ecx),
+                       SHRD II32 (OpReg ecx) (OpReg rhi) (OpReg rlo),
+                       SHR II32 (OpReg ecx) (OpReg rhi),
+                       TEST II32 (OpImm (ImmInt 32)) (OpReg ecx),
+                       JXX EQQ b,
+                       MOV II32 (OpReg rhi) (OpReg rlo),
+                       XOR II32 (OpReg rhi) (OpReg rhi),
+                       NEWBLOCK b
+                     ]
+   return (RegCode64 code rhi rlo)
+
 iselExpr64 expr
    = do
       platform <- getPlatform


=====================================
compiler/GHC/CmmToAsm/X86/Instr.hs
=====================================
@@ -248,8 +248,10 @@ data Instr
         -- Shifts (amount may be immediate or %cl only)
         | SHL         Format Operand{-amount-} Operand
         | SAR         Format Operand{-amount-} Operand
+        | SAL         Format Operand{-amount-} Operand
         | SHR         Format Operand{-amount-} Operand
         | SHRD        Format Operand{-amount-} Operand Operand
+        | SHLD        Format Operand{-amount-} Operand Operand
 
         | BT          Format Imm Operand
         | NOP
@@ -398,8 +400,10 @@ regUsageOfInstr platform instr
     BSWAP  _ reg        -> mkRU [reg] [reg]
     NEGI   _ op         -> usageM op
     SHL    _ imm dst    -> usageRM imm dst
+    SAL    _ imm dst    -> usageRM imm dst
     SAR    _ imm dst    -> usageRM imm dst
     SHR    _ imm dst    -> usageRM imm dst
+    SHLD   _ imm dst1 dst2 -> usageRMM imm dst1 dst2
     SHRD   _ imm dst1 dst2 -> usageRMM imm dst1 dst2
     BT     _ _   src    -> mkRUR (use_R src [])
 
@@ -568,8 +572,10 @@ patchRegsOfInstr instr env
     BSWAP fmt reg        -> BSWAP fmt (env reg)
     NEGI fmt op          -> patch1 (NEGI fmt) op
     SHL  fmt imm dst     -> patch1 (SHL fmt imm) dst
+    SAL  fmt imm dst     -> patch1 (SAR fmt imm) dst
     SAR  fmt imm dst     -> patch1 (SAR fmt imm) dst
     SHR  fmt imm dst     -> patch1 (SHR fmt imm) dst
+    SHLD fmt imm dst1 dst2 -> patch2 (SHRD fmt imm) dst1 dst2
     SHRD fmt imm dst1 dst2 -> patch2 (SHRD fmt imm) dst1 dst2
     BT   fmt imm src     -> patch1 (BT  fmt imm) src
     TEST fmt src dst     -> patch2 (TEST fmt) src dst


=====================================
compiler/GHC/CmmToAsm/X86/Ppr.hs
=====================================
@@ -726,21 +726,20 @@ pprInstr platform i = case i of
    SHL format src dst
       -> pprShift (text "shl") format src dst
 
+   SAL format src dst
+      -> pprShift (text "sal") format src dst
+
    SAR format src dst
       -> pprShift (text "sar") format src dst
 
    SHR format src dst
       -> pprShift (text "shr") format src dst
    
+   SHLD format src dst1 dst2
+      -> pprShift2 (text "shld") format src dst1 dst2
+
    SHRD format src dst1 dst2
-      -> line $ hcat [
-           pprMnemonic (text "shrd") format,
-           pprOperand platform II8 src,  -- src is 8-bit sized
-           comma,
-           pprOperand platform format dst1,
-           comma,
-           pprOperand platform format dst2
-         ]
+      -> pprShift2 (text "shrd") format src dst1 dst2
 
    BT format imm src
       -> pprFormatImmOp (text "bt") format imm src
@@ -1080,6 +1079,17 @@ pprInstr platform i = case i of
            pprOperand platform format dest
        ]
 
+   pprShift2 :: Line doc -> Format -> Operand -> Operand -> Operand -> doc
+   pprShift2 name format src dest1 dest2
+     = line $ hcat [
+           pprMnemonic name format,
+           pprOperand platform II8 src,  -- src is 8-bit sized
+           comma,
+           pprOperand platform format dest1,
+           comma,
+           pprOperand platform format dest2
+       ]
+
 
    pprFormatOpOpCoerce :: Line doc -> Format -> Format -> Operand -> Operand -> doc
    pprFormatOpOpCoerce name format1 format2 op1 op2



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

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


More information about the ghc-commits mailing list