CmmParse: Expose popcnt operations
authorBen Gamari <bgamari.foss@gmail.com>
Fri, 30 Oct 2015 18:53:52 +0000 (19:53 +0100)
committerBen Gamari <ben@smart-cactus.org>
Fri, 30 Oct 2015 18:54:00 +0000 (19:54 +0100)
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

compiler/cmm/CmmParse.y
testsuite/tests/codeGen/should_run/PopCnt.hs [new file with mode: 0644]
testsuite/tests/codeGen/should_run/PopCnt.stdout [new file with mode: 0644]
testsuite/tests/codeGen/should_run/PopCnt_cmm.cmm [new file with mode: 0644]
testsuite/tests/codeGen/should_run/all.T

index 555aed2..11e68bd 100644 (file)
@@ -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/PopCnt.hs b/testsuite/tests/codeGen/should_run/PopCnt.hs
new file mode 100644 (file)
index 0000000..e6c99a4
--- /dev/null
@@ -0,0 +1,9 @@
+{-# LANGUAGE MagicHash,GHCForeignImportPrim,UnliftedFFITypes #-}
+module Main where
+
+import GHC.Exts
+
+foreign import prim "do_popcnt32" popcnt32 :: Int# -> Int#
+
+main = print (I# (popcnt32 0xffff#))
+
diff --git a/testsuite/tests/codeGen/should_run/PopCnt.stdout b/testsuite/tests/codeGen/should_run/PopCnt.stdout
new file mode 100644 (file)
index 0000000..b5794c5
--- /dev/null
@@ -0,0 +1,2 @@
+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 (file)
index 0000000..21e02fa
--- /dev/null
@@ -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];
+}
index 13eda78..defd9b2 100644 (file)
@@ -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