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

git at git.haskell.org git at git.haskell.org
Mon Nov 20 03:03:46 UTC 2017


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

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

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

commit 08a3042c190c1f47dd2edf8652a6c2e4b582fb18
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


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

08a3042c190c1f47dd2edf8652a6c2e4b582fb18
 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