[commit: ghc] wip/angerman/llvmng: Add Pdep and Pext primops. (e7e781b)

git at git.haskell.org git at git.haskell.org
Sun Nov 19 08:31:00 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/angerman/llvmng
Link       : http://ghc.haskell.org/trac/ghc/changeset/e7e781b696c5e3f140d82041663e9f03c1373404/ghc

>---------------------------------------------------------------

commit e7e781b696c5e3f140d82041663e9f03c1373404
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date:   Sat Nov 18 17:45:26 2017 +0800

    Add Pdep and Pext primops.
    
    Were introduced in f5dc8ccc


>---------------------------------------------------------------

e7e781b696c5e3f140d82041663e9f03c1373404
 compiler/llvmGen-ng/Data/BitCode/LLVM/Gen.hs | 37 ++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/compiler/llvmGen-ng/Data/BitCode/LLVM/Gen.hs b/compiler/llvmGen-ng/Data/BitCode/LLVM/Gen.hs
index c1c9e8c..4222dbd 100644
--- a/compiler/llvmGen-ng/Data/BitCode/LLVM/Gen.hs
+++ b/compiler/llvmGen-ng/Data/BitCode/LLVM/Gen.hs
@@ -888,6 +888,43 @@ genCall blockMap regMap target dsts args = case target of
         ty <- EDSL.deptr (EDSL.ty slot)
         EDSL.store slot =<< cast ty ret
     | otherwise -> panic "genCall: PopCnt not implemented."
+  (PrimTarget (MO_Pdep w))
+    | ([dst], [src, mask]) <- (dsts, args) -> do
+        slot <- lookupLocalReg dst regMap
+
+        src'  <- bind2 cast (EDSL.i (widthInBits w)) (exprToVar blockMap regMap src)
+        mask' <- bind2 cast (EDSL.i (widthInBits w)) (exprToVar blockMap regMap mask)
+
+        arch <- platformArch . targetPlatform <$> getDynFlags
+        f <- let w' = widthInBits w
+                 fn = case arch of
+                   ArchX86_64 -> "llvm.x86.bmi.pdep."
+                   _ ->  "hs_pdep"
+             in EDSL.fun (fn ++ show w') =<< [ EDSL.i w', EDSL.i w' ] --> EDSL.i w'
+
+        Just ret <- EDSL.ccall f [ src', mask' ]
+        ty <- EDSL.deptr (EDSL.ty slot)
+        EDSL.store slot =<< cast ty ret
+    | otherwise -> panic "genCall: Pdep not implemented."
+  (PrimTarget (MO_Pext w))
+    | ([dst], [src, mask]) <- (dsts, args) -> do
+        slot <- lookupLocalReg dst regMap
+
+        src'  <- bind2 cast (EDSL.i (widthInBits w)) (exprToVar blockMap regMap src)
+        mask' <- bind2 cast (EDSL.i (widthInBits w)) (exprToVar blockMap regMap mask)
+
+        arch <- platformArch . targetPlatform <$> getDynFlags
+
+        f <- let w' = widthInBits w
+                 fn = case arch of
+                   ArchX86_64 -> "llvm.x86.bmi.pext."
+                   _ ->  "hs_pext"
+             in EDSL.fun (fn ++ show w') =<< [ EDSL.i w', EDSL.i w' ] --> EDSL.i w'
+
+        Just ret <- EDSL.ccall f [ src', mask' ]
+        ty <- EDSL.deptr (EDSL.ty slot)
+        EDSL.store slot =<< cast ty ret
+    | otherwise -> panic "genCall: Pext not implemented."
   (PrimTarget (MO_Clz w))
     | ([dst], [e]) <- (dsts, args) -> do
         slot <- lookupLocalReg dst regMap



More information about the ghc-commits mailing list