summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib
diff options
context:
space:
mode:
authorAlan Mock <alan@alanmock.com>2016-06-03 22:16:27 +0200
committerBen Gamari <ben@smart-cactus.org>2016-06-04 09:35:49 +0200
commit02f893eb4fe3f75f0a9dc7e723568f4c75de5785 (patch)
tree37c8b38df14d99e8b9a625d3c1c2a95974bc0a33 /testsuite/tests/lib
parent079c1b8caed22db2be24f3304c56db56292670e1 (diff)
downloadhaskell-02f893eb4fe3f75f0a9dc7e723568f4c75de5785.tar.gz
integer-gmp: Make minusInteger more efficient
Give `minusInteger` its own implementation. Previously `minusInteger` used `plusInteger` and `negateInteger`, which meant it always allocated. Now it works more like `plusInteger`. Reviewers: goldfire, hvr, bgamari, austin Reviewed By: hvr, bgamari, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2278 GHC Trac Issues: #12129
Diffstat (limited to 'testsuite/tests/lib')
-rw-r--r--testsuite/tests/lib/integer/all.T2
-rw-r--r--testsuite/tests/lib/integer/plusMinusInteger.hs36
-rw-r--r--testsuite/tests/lib/integer/plusMinusInteger.stdout1
3 files changed, 38 insertions, 1 deletions
diff --git a/testsuite/tests/lib/integer/all.T b/testsuite/tests/lib/integer/all.T
index c0b39b01e4..327f5778f4 100644
--- a/testsuite/tests/lib/integer/all.T
+++ b/testsuite/tests/lib/integer/all.T
@@ -2,6 +2,7 @@ test('integerBits', normal, compile_and_run, [''])
test('integerConversions', normal, compile_and_run, [''])
# skip ghci as it doesn't support unboxed tuples
test('integerGmpInternals', [reqlib('integer-gmp'), omit_ways('ghci')], compile_and_run, [''])
+test('plusMinusInteger', [reqlib('integer-gmp'), omit_ways('ghci')], compile_and_run, [''])
test('integerConstantFolding',
[extra_clean(['integerConstantFolding.simpl']),
when(compiler_debugged(), expect_broken(11006))],
@@ -16,4 +17,3 @@ test('IntegerConversionRules',
run_command,
['$MAKE -s --no-print-directory IntegerConversionRules'])
test('gcdInteger', normal, compile_and_run, [''])
-
diff --git a/testsuite/tests/lib/integer/plusMinusInteger.hs b/testsuite/tests/lib/integer/plusMinusInteger.hs
new file mode 100644
index 0000000000..ec8d7e6ab4
--- /dev/null
+++ b/testsuite/tests/lib/integer/plusMinusInteger.hs
@@ -0,0 +1,36 @@
+module Main (main) where
+
+
+main :: IO ()
+main = do
+ print $ length vals
+
+ where
+ boundaries :: [Integer]
+ boundaries = [fromIntegral (maxBound :: Int) - 3,
+ fromIntegral (maxBound :: Int) - 2,
+ fromIntegral (maxBound :: Int) - 1,
+ fromIntegral (maxBound :: Int),
+ fromIntegral (maxBound :: Int) + 1,
+ fromIntegral (maxBound :: Int) + 2,
+ fromIntegral (maxBound :: Int) + 3,
+
+ fromIntegral (minBound :: Int) - 3,
+ fromIntegral (minBound :: Int) - 2,
+ fromIntegral (minBound :: Int) - 1,
+ fromIntegral (minBound :: Int),
+ fromIntegral (minBound :: Int) + 1,
+ fromIntegral (minBound :: Int) + 2,
+ fromIntegral (minBound :: Int) + 3,
+
+ fromIntegral (maxBound :: Word) - 3,
+ fromIntegral (maxBound :: Word) - 2,
+ fromIntegral (maxBound :: Word) - 1,
+ fromIntegral (maxBound :: Word),
+ fromIntegral (maxBound :: Word) + 1,
+ fromIntegral (maxBound :: Word) + 2,
+ fromIntegral (maxBound :: Word) + 3,
+
+ -3, -2, -1, 0, 1, 2, 3]
+ vals = filter (\(x, y) -> x /= y) [(x - y, x + negate y) |
+ x <- boundaries, y <- boundaries]
diff --git a/testsuite/tests/lib/integer/plusMinusInteger.stdout b/testsuite/tests/lib/integer/plusMinusInteger.stdout
new file mode 100644
index 0000000000..c227083464
--- /dev/null
+++ b/testsuite/tests/lib/integer/plusMinusInteger.stdout
@@ -0,0 +1 @@
+0 \ No newline at end of file