summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-06-10 23:14:35 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2021-08-17 20:58:33 +0000
commitb784a51eb1cf084353e369d48643d64008b61b4a (patch)
tree7cb82ab868830b9a247f81565f78e3028ab4d991
parentacb188e0c02a114927d340dac78a68626c659cd3 (diff)
downloadhaskell-b784a51eb1cf084353e369d48643d64008b61b4a.tar.gz
Test non-native switch C-- with twos compliment
We don't want regressions like e8f7734d8a052f99b03e1123466dc9f47b48c311 to regress. Co-Authored-By: Sylvain Henry <hsyl20@gmail.com>
-rw-r--r--testsuite/tests/cmm/should_run/ByteSwitch.hs11
-rw-r--r--testsuite/tests/cmm/should_run/ByteSwitch.stdout9
-rw-r--r--testsuite/tests/cmm/should_run/ByteSwitch_cmm.cmm11
-rw-r--r--testsuite/tests/cmm/should_run/all.T10
4 files changed, 40 insertions, 1 deletions
diff --git a/testsuite/tests/cmm/should_run/ByteSwitch.hs b/testsuite/tests/cmm/should_run/ByteSwitch.hs
new file mode 100644
index 0000000000..40b1db7a2b
--- /dev/null
+++ b/testsuite/tests/cmm/should_run/ByteSwitch.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE UnliftedFFITypes #-}
+{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE GHCForeignImportPrim #-}
+
+import GHC.Int
+import GHC.Exts
+
+foreign import prim "byte_switch" byteSwitch:: Int8# -> Int8#
+
+main = traverse (\(I8# x#) -> print $ I8# (byteSwitch x#)) [-4..4]
diff --git a/testsuite/tests/cmm/should_run/ByteSwitch.stdout b/testsuite/tests/cmm/should_run/ByteSwitch.stdout
new file mode 100644
index 0000000000..ad436e9d57
--- /dev/null
+++ b/testsuite/tests/cmm/should_run/ByteSwitch.stdout
@@ -0,0 +1,9 @@
+-4
+-3
+15
+7
+5
+1
+2
+9
+4
diff --git a/testsuite/tests/cmm/should_run/ByteSwitch_cmm.cmm b/testsuite/tests/cmm/should_run/ByteSwitch_cmm.cmm
new file mode 100644
index 0000000000..f248b1e2a2
--- /dev/null
+++ b/testsuite/tests/cmm/should_run/ByteSwitch_cmm.cmm
@@ -0,0 +1,11 @@
+#include "Cmm.h"
+
+byte_switch (bits8 x) {
+ switch [0 .. 255] (x) {
+ case 255: { return (7); }
+ case 254: { return (15); }
+ case 0: { return (5); }
+ case 3: { return (9); }
+ default: { return (x); }
+ }
+}
diff --git a/testsuite/tests/cmm/should_run/all.T b/testsuite/tests/cmm/should_run/all.T
index bf1556e35c..cd7f5d094a 100644
--- a/testsuite/tests/cmm/should_run/all.T
+++ b/testsuite/tests/cmm/should_run/all.T
@@ -17,4 +17,12 @@ test('cmp64',
# extra_clean(['T17516A.hi', 'T17516A.o'])
# ],
# multimod_compile,
-# ['T17516', '-O -v0']) \ No newline at end of file
+# ['T17516', '-O -v0'])
+
+test('ByteSwitch',
+ [ extra_run_opts('"' + config.libdir + '"')
+ , omit_ways(['ghci'])
+ , extra_clean('ByteSwitch_cmm.o')
+ ],
+ multi_compile_and_run,
+ ['ByteSwitch', [('ByteSwitch_cmm.cmm', '')], ''])