summaryrefslogtreecommitdiff
path: root/testsuite/tests/primops
diff options
context:
space:
mode:
authorJan Stolarek <jan.stolarek@p.lodz.pl>2013-08-19 16:31:19 +0100
committerJan Stolarek <jan.stolarek@p.lodz.pl>2013-08-19 16:31:19 +0100
commit5314acb9c594558ff1a69cdb826313dda764ee7d (patch)
tree8f65b66343e3d84967e9d03e52250a2adbd7cb27 /testsuite/tests/primops
parentd157f5f248b2dc07ce1b65c279158bab4ba400c5 (diff)
downloadhaskell-5314acb9c594558ff1a69cdb826313dda764ee7d.tar.gz
Rellocate test for T7689 to different directory
This test is testing primops, so it should be in the primops/ directory and not numeric.
Diffstat (limited to 'testsuite/tests/primops')
-rw-r--r--testsuite/tests/primops/should_run/T7689.hs78
-rw-r--r--testsuite/tests/primops/should_run/T7689.stdout37
-rw-r--r--testsuite/tests/primops/should_run/all.T2
3 files changed, 117 insertions, 0 deletions
diff --git a/testsuite/tests/primops/should_run/T7689.hs b/testsuite/tests/primops/should_run/T7689.hs
new file mode 100644
index 0000000000..4f0d8e4394
--- /dev/null
+++ b/testsuite/tests/primops/should_run/T7689.hs
@@ -0,0 +1,78 @@
+{-# LANGUAGE BangPatterns, MagicHash #-}
+module Main where
+
+import Data.Bits (finiteBitSize)
+import GHC.Exts
+
+main :: IO ()
+main = do
+ -- 0 is the annihilator of andI#
+ print (I# (maxI# `andI#` 0#) == 0)
+ print (I# (minI# `andI#` 0#) == 0)
+ print (I# (0# `andI#` maxI#) == 0)
+ print (I# (0# `andI#` minI#) == 0)
+ print (I# (0# `andI#` 0#) == 0)
+ -- integer with all bits set to 1 is the neutral element of orI#,
+ -- in two's complement this is -1
+ print (I# (maxI# `andI#` -1#) == maxI)
+ print (I# (minI# `andI#` -1#) == minI)
+ print (I# (-1# `andI#` maxI#) == maxI)
+ print (I# (-1# `andI#` minI#) == minI)
+ print (I# (-1# `andI#` -1#) == -1)
+ -- these two numbers have every other bit set, they should give 0
+ print (I# (magicInt1# `andI#` magicInt2#) == 0)
+
+ -- integer with all bits set to 1 is the annihilator of orI#,
+ print (I# (maxI# `orI#` -1#) == -1)
+ print (I# (minI# `orI#` -1#) == -1)
+ print (I# (-1# `orI#` maxI#) == -1)
+ print (I# (-1# `orI#` minI#) == -1)
+ print (I# (-1# `orI#` -1#) == -1)
+ -- 0 is the neutral element of orI#
+ print (I# (maxI# `orI#` 0#) == maxI)
+ print (I# (minI# `orI#` 0#) == minI)
+ print (I# (0# `orI#` maxI#) == maxI)
+ print (I# (0# `orI#` minI#) == minI)
+ print (I# (0# `orI#` 0#) == 0)
+ -- this time we should get an integer with all bits set, that is -1
+ print (I# (magicInt1# `orI#` magicInt2#) == -1)
+
+ -- suprising as the first two tests may look, this is what we expect from
+ -- bitwise negation in two's complement enccoding
+ print (I# (notI# 0#) == -1)
+ print (I# (notI# -1#) == 0)
+ -- magic int numbers are bitwise complementary
+ print (I# (notI# magicInt1#) == magicInt2)
+ print (I# (notI# magicInt2#) == magicInt1)
+
+ -- 0 is the identity of xor
+ print (I# (minI# `xorI#` 0#) == minI)
+ print (I# (maxI# `xorI#` 0#) == maxI)
+ print (I# (0# `xorI#` minI#) == minI)
+ print (I# (0# `xorI#` maxI#) == maxI)
+ -- anything xored with itself is 0
+ print (I# (maxI# `xorI#` maxI#) == 0)
+ print (I# (minI# `xorI#` minI#) == 0)
+ -- xoring with -1 is like bitwise negation (becuse -1 has all bits set to 1)
+ print (I# (minI# `xorI#` -1#) == maxI)
+ print (I# (maxI# `xorI#` -1#) == minI)
+ print (I# (-1# `xorI#` minI#) == maxI)
+ print (I# (-1# `xorI#` maxI#) == minI)
+ -- since these two have exactly the opposite bits turned on they should
+ -- give an int with all bits set, and that is -1 as you probably already
+ -- remember by now
+ print (I# (magicInt1# `xorI#` magicInt2#) == -1)
+ where
+ intBitSize = finiteBitSize (undefined :: Int)
+ minI = minBound :: Int
+ maxI = maxBound :: Int
+ minI# = x
+ where !(I# x) = minBound
+ maxI# = x
+ where !(I# x) = maxBound
+ magicInt1 = sum $ map (2^) [0,2..intBitSize] :: Int
+ magicInt2 = sum $ map (2^) [1,3..intBitSize] :: Int
+ magicInt1# = x
+ where !(I# x) = magicInt1
+ magicInt2# = x
+ where !(I# x) = magicInt2
diff --git a/testsuite/tests/primops/should_run/T7689.stdout b/testsuite/tests/primops/should_run/T7689.stdout
new file mode 100644
index 0000000000..1a97da1700
--- /dev/null
+++ b/testsuite/tests/primops/should_run/T7689.stdout
@@ -0,0 +1,37 @@
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
+True
diff --git a/testsuite/tests/primops/should_run/all.T b/testsuite/tests/primops/should_run/all.T
index ddd6060611..a2c48fe19a 100644
--- a/testsuite/tests/primops/should_run/all.T
+++ b/testsuite/tests/primops/should_run/all.T
@@ -1 +1,3 @@
test('T6135', normal, compile_and_run, [''])
+
+test('T7689', normal, compile_and_run, [''])