[commit: ghc] master: CmmParse: Expose popcnt operations (42e8528)

git at git.haskell.org git at git.haskell.org
Fri Oct 30 19:20:14 UTC 2015


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/42e85284b7be4aa298cff51119f33a72c0e3bd7a/ghc

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

commit 42e85284b7be4aa298cff51119f33a72c0e3bd7a
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Fri Oct 30 19:53:52 2015 +0100

    CmmParse: Expose popcnt operations
    
    Make various population count operations available via C-- syntax
    under the names %popcnt{8,16,32,64}. Fixes #11037.
    
    Reviewers: simonmar, austin, ekmett
    
    Reviewed By: austin, ekmett
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1402
    
    GHC Trac Issues: #11037


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

42e85284b7be4aa298cff51119f33a72c0e3bd7a
 compiler/cmm/CmmParse.y                                          | 7 ++++++-
 testsuite/tests/codeGen/should_run/{T5149.hs => PopCnt.hs}       | 5 +++--
 .../Capi_Ctype_001.stdout => codeGen/should_run/PopCnt.stdout}   | 2 +-
 testsuite/tests/codeGen/should_run/PopCnt_cmm.cmm                | 9 +++++++++
 testsuite/tests/codeGen/should_run/all.T                         | 2 ++
 5 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/compiler/cmm/CmmParse.y b/compiler/cmm/CmmParse.y
index 555aed2..11e68bd 100644
--- a/compiler/cmm/CmmParse.y
+++ b/compiler/cmm/CmmParse.y
@@ -981,7 +981,12 @@ callishMachOps = listToUFM $
         ("prefetch0", (,) $ MO_Prefetch_Data 0),
         ("prefetch1", (,) $ MO_Prefetch_Data 1),
         ("prefetch2", (,) $ MO_Prefetch_Data 2),
-        ("prefetch3", (,) $ MO_Prefetch_Data 3)
+        ("prefetch3", (,) $ MO_Prefetch_Data 3),
+
+        ( "popcnt8",  (,) $ MO_PopCnt W8  ),
+        ( "popcnt16", (,) $ MO_PopCnt W16 ),
+        ( "popcnt32", (,) $ MO_PopCnt W32 ),
+        ( "popcnt64", (,) $ MO_PopCnt W64 )
 
         -- ToDo: the rest, maybe
         -- edit: which rest?
diff --git a/testsuite/tests/codeGen/should_run/T5149.hs b/testsuite/tests/codeGen/should_run/PopCnt.hs
similarity index 51%
copy from testsuite/tests/codeGen/should_run/T5149.hs
copy to testsuite/tests/codeGen/should_run/PopCnt.hs
index c0c88e3..e6c99a4 100644
--- a/testsuite/tests/codeGen/should_run/T5149.hs
+++ b/testsuite/tests/codeGen/should_run/PopCnt.hs
@@ -3,6 +3,7 @@ module Main where
 
 import GHC.Exts
 
-foreign import prim "f5149" f :: Int# -> Int# -> Double# -> Int#
+foreign import prim "do_popcnt32" popcnt32 :: Int# -> Int#
+
+main = print (I# (popcnt32 0xffff#))
 
-main = print (I# (f 1# 2# 1.0##))
diff --git a/testsuite/tests/ffi/should_run/Capi_Ctype_001.stdout b/testsuite/tests/codeGen/should_run/PopCnt.stdout
similarity index 60%
copy from testsuite/tests/ffi/should_run/Capi_Ctype_001.stdout
copy to testsuite/tests/codeGen/should_run/PopCnt.stdout
index dc3ed24..b5794c5 100644
--- a/testsuite/tests/ffi/should_run/Capi_Ctype_001.stdout
+++ b/testsuite/tests/codeGen/should_run/PopCnt.stdout
@@ -1,2 +1,2 @@
-6
 16
+
diff --git a/testsuite/tests/codeGen/should_run/PopCnt_cmm.cmm b/testsuite/tests/codeGen/should_run/PopCnt_cmm.cmm
new file mode 100644
index 0000000..21e02fa
--- /dev/null
+++ b/testsuite/tests/codeGen/should_run/PopCnt_cmm.cmm
@@ -0,0 +1,9 @@
+#include "Cmm.h"
+
+do_popcnt32 (W_ x)
+{
+    W_ res;
+    (res) = prim %popcnt32(x);
+    R1 = res;
+    jump %ENTRY_CODE(Sp(0)) [R1];
+}
diff --git a/testsuite/tests/codeGen/should_run/all.T b/testsuite/tests/codeGen/should_run/all.T
index 13eda78..defd9b2 100644
--- a/testsuite/tests/codeGen/should_run/all.T
+++ b/testsuite/tests/codeGen/should_run/all.T
@@ -139,3 +139,5 @@ test('T10414', [only_ways(['threaded2']), extra_ways(['threaded2'])],
 test('T10521', normal, compile_and_run, [''])
 test('T10521b', normal, compile_and_run, [''])
 test('T10870', normal, compile_and_run, [''])
+test('PopCnt', omit_ways(['ghci']), multi_compile_and_run,
+                 ['PopCnt', [('PopCnt_cmm.cmm', '')], ''])
\ No newline at end of file



More information about the ghc-commits mailing list