[Git][ghc/ghc][master] Bignum: fix powMod for gmp backend (#18515)

Marge Bot gitlab at gitlab.haskell.org
Fri Jul 31 02:56:10 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
380638a3 by Sylvain Henry at 2020-07-30T22:56:03-04:00
Bignum: fix powMod for gmp backend (#18515)

Also reenable integerPowMod test which had never been reenabled by
mistake.

- - - - -


7 changed files:

- libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs
- testsuite/tests/lib/integer/all.T
- testsuite/tests/lib/integer/integerPowMod.hs
- testsuite/tests/lib/integer/integerPowMod.stdout
- + testsuite/tests/numeric/should_run/T18515.hs
- + testsuite/tests/numeric/should_run/T18515.stdout
- testsuite/tests/numeric/should_run/all.T


Changes:

=====================================
libraries/ghc-bignum/src/GHC/Num/BigNat/GMP.hs
=====================================
@@ -349,7 +349,8 @@ bignat_powmod
    -> State# RealWorld
    -> State# RealWorld
 bignat_powmod r b e m s =
-   ioVoid (integer_gmp_powm# r b (wordArraySize# b) e (wordArraySize# e) m (wordArraySize# m)) s
+   case ioInt# (integer_gmp_powm# r b (wordArraySize# b) e (wordArraySize# e) m (wordArraySize# m)) s of
+      (# s', n #) -> mwaSetSize# r (narrowGmpSize# n) s'
 
 
 ----------------------------------------------------------------------


=====================================
testsuite/tests/lib/integer/all.T
=====================================
@@ -5,11 +5,11 @@ test('integerConstantFolding', normal, makefile_test, ['integerConstantFolding']
 test('fromToInteger', [], makefile_test, ['fromToInteger'])
 test('IntegerConversionRules', [], makefile_test, ['IntegerConversionRules'])
 test('gcdInteger', normal, compile_and_run, [''])
+test('integerPowMod', [], compile_and_run, [''])
 
 # skip ghci as it doesn't support unboxed tuples
 test('integerImportExport', [omit_ways(['ghci'])], compile_and_run, [''])
 
 # Disable GMP only tests
 #test('integerGcdExt', [omit_ways(['ghci'])], compile_and_run, [''])
-#test('integerPowMod', [], compile_and_run, [''])
 #test('integerGmpInternals', [], compile_and_run, [''])


=====================================
testsuite/tests/lib/integer/integerPowMod.hs
=====================================
@@ -7,19 +7,12 @@ import Control.Monad
 
 import GHC.Word
 import GHC.Base
-import qualified GHC.Integer.GMP.Internals as I
-
-powModSecInteger :: Integer -> Integer -> Integer -> Integer
-powModSecInteger = I.powModSecInteger
-
-powModInteger :: Integer -> Integer -> Integer -> Integer
-powModInteger = I.powModInteger
+import GHC.Natural
 
 main :: IO ()
 main = do
-    print $ powModInteger b e m
-    print $ powModInteger b e (m-1)
-    print $ powModSecInteger b e (m-1)
+    print $ powModNatural b e m
+    print $ powModNatural b e (m-1)
 
   where
     b = 2988348162058574136915891421498819466320163312926952423791023078876139


=====================================
testsuite/tests/lib/integer/integerPowMod.stdout
=====================================
@@ -1,3 +1,2 @@
 1527229998585248450016808958343740453059
 682382427572745901624116300491295556924
-682382427572745901624116300491295556924


=====================================
testsuite/tests/numeric/should_run/T18515.hs
=====================================
@@ -0,0 +1,12 @@
+{-# LANGUAGE MagicHash #-}
+
+import GHC.Num.BigNat
+import GHC.Num.Integer
+
+main :: IO ()
+main =
+    let b = integerToBigNatClamp# 251943445928310882947152017889649234
+        e = integerToBigNatClamp# 503886891856621765894304035779298468
+        m = integerToBigNatClamp# 503886891856621765894304035779298469
+        r = integerFromBigNat# (bigNatPowMod b e m)
+     in print r


=====================================
testsuite/tests/numeric/should_run/T18515.stdout
=====================================
@@ -0,0 +1 @@
+1


=====================================
testsuite/tests/numeric/should_run/all.T
=====================================
@@ -72,3 +72,4 @@ test('T17303', normal, compile_and_run, [''])
 test('T18359', normal, compile_and_run, [''])
 test('T18499', normal, compile_and_run, [''])
 test('T18509', normal, compile_and_run, [''])
+test('T18515', normal, compile_and_run, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/380638a33691ba43fdcd2e18bca636750e5f66f1

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/380638a33691ba43fdcd2e18bca636750e5f66f1
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200730/37336611/attachment-0001.html>


More information about the ghc-commits mailing list