[commit: testsuite] master: Add tests for new internal GMP primitives (31a12fc)
git at git.haskell.org
git
Tue Oct 1 10:08:02 UTC 2013
Repository : ssh://git at git.haskell.org/testsuite
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/31a12fce8983d200308a0f63944054b30f4c74f9/testsuite
>---------------------------------------------------------------
commit 31a12fce8983d200308a0f63944054b30f4c74f9
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Tue Oct 1 11:37:59 2013 +0200
Add tests for new internal GMP primitives
See [ce8ec963/integer-gmp] and [97c101b7/integer-gmp] for more details
>---------------------------------------------------------------
31a12fce8983d200308a0f63944054b30f4c74f9
.gitignore | 1 +
tests/lib/integer/all.T | 1 +
tests/lib/integer/integerGmpInternals.hs | 50 ++++++++++++++++++++++++++
tests/lib/integer/integerGmpInternals.stdout | 9 +++++
4 files changed, 61 insertions(+)
diff --git a/.gitignore b/.gitignore
index 41d92a0..81227dc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -853,6 +853,7 @@ tests/lib/integer/integerBits
tests/lib/integer/integerConstantFolding
tests/lib/integer/integerConstantFolding.simpl
tests/lib/integer/integerConversions
+tests/lib/integer/integerGmpInternals
tests/lib/libposix/po003.out
tests/lib/libposix/posix002
tests/lib/libposix/posix003
diff --git a/tests/lib/integer/all.T b/tests/lib/integer/all.T
index 61c061e..9364f41 100644
--- a/tests/lib/integer/all.T
+++ b/tests/lib/integer/all.T
@@ -1,5 +1,6 @@
test('integerBits', normal, compile_and_run, [''])
test('integerConversions', normal, compile_and_run, [''])
+test('integerGmpInternals', reqlib('integer-gmp'), compile_and_run, [''])
test('integerConstantFolding',
extra_clean(['integerConstantFolding.simpl']),
run_command,
diff --git a/tests/lib/integer/integerGmpInternals.hs b/tests/lib/integer/integerGmpInternals.hs
new file mode 100644
index 0000000..48bdc34
--- /dev/null
+++ b/tests/lib/integer/integerGmpInternals.hs
@@ -0,0 +1,50 @@
+{-# LANGUAGE MagicHash, UnboxedTuples #-}
+
+module Main (main) where
+
+import GHC.Base
+import GHC.Integer
+import GHC.Integer.GMP.Internals
+
+gcdExtInteger' :: Integer -> Integer -> (Integer, Integer)
+gcdExtInteger' a b = case gcdExtInteger a b of (# a, b #) -> (a,b)
+
+powInteger' :: Integer -> Word -> Integer
+powInteger' b (W# w#) = powInteger b w#
+
+{- Reference implementation for 'powModInteger'
+
+powModIntegerHs :: Integer -> Integer -> Integer -> Integer
+powModIntegerHs b0 e0 m
+ | e0 >= 0 = go b0 e0 1
+ | otherwise = error "non-neg exponent required"
+ where
+ go !b e !r
+ | odd e = go b' e' (r*b `mod` m)
+ | e == 0 = r
+ | otherwise = go b' e' r
+ where
+ b' = b*b `mod` m
+ e' = e `unsafeShiftR` 1 -- slightly faster than "e `div` 2"
+
+-}
+
+main :: IO ()
+main = do
+ print $ powModInteger b e m
+ print $ gcdExtInteger' b e
+ print $ gcdExtInteger' e b
+ print $ gcdExtInteger' x y
+ print $ gcdExtInteger' y x
+ print $ powInteger' 12345 0
+ print $ powInteger' 12345 1
+ print $ powInteger' 12345 30
+ print $ [ (x,i) | x <- [0..71], let i = recipModInteger x (2*3*11*11*17*17), i /= 0 ]
+ return ()
+ where
+ b = 2988348162058574136915891421498819466320163312926952423791023078876139
+ e = 2351399303373464486466122544523690094744975233415544072992656881240319
+ m = 10^(40::Int)
+
+ x = 5328841272400314897981163497728751426
+ y = 32052182750761975518649228050096851724
diff --git a/tests/lib/integer/integerGmpInternals.stdout b/tests/lib/integer/integerGmpInternals.stdout
new file mode 100644
index 0000000..5a490ba
--- /dev/null
+++ b/tests/lib/integer/integerGmpInternals.stdout
@@ -0,0 +1,9 @@
+1527229998585248450016808958343740453059
+(1,-238164827888328100873319793437342927637138278785737103723156342382925)
+(1,302679100340807588460107986194035692812415103244388831792688023418704)
+(92889294,115110207004456909698806038261)
+(92889294,-19137667681784054624628973533)
+1
+12345
+555562377826831043419246079513769804614412256811161773362797946971665712715296306339052301636736176350153982639312744140625
+[(1,1),(5,41963),(7,59947),(13,177535),(19,143557),(23,182447),(25,134281),(29,7235),(31,33841),(35,95915),(37,113413),(41,61409),(43,24397),(47,174101),(49,158431),(53,193979),(59,188477),(61,185737),(65,35507),(67,118999),(71,186173)]
More information about the ghc-commits
mailing list