summaryrefslogtreecommitdiff
path: root/libraries/integer-gmp2/src/GHC/Integer/Type.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/integer-gmp2/src/GHC/Integer/Type.hs')
-rw-r--r--libraries/integer-gmp2/src/GHC/Integer/Type.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/libraries/integer-gmp2/src/GHC/Integer/Type.hs b/libraries/integer-gmp2/src/GHC/Integer/Type.hs
index 48c5ed85bc..d771de1cda 100644
--- a/libraries/integer-gmp2/src/GHC/Integer/Type.hs
+++ b/libraries/integer-gmp2/src/GHC/Integer/Type.hs
@@ -1684,6 +1684,23 @@ isValidBigNat# (BN# ba#)
(# szq#, szr# #) = quotRemInt# sz# GMP_LIMB_BYTES#
+-- | Version of 'nextPrimeInteger' operating on 'BigNat's
+--
+-- /Since: 1.0.0.0/
+nextPrimeBigNat :: BigNat -> BigNat
+nextPrimeBigNat bn@(BN# ba#) = runS $ do
+ mbn@(MBN# mba#) <- newBigNat# n#
+ (W# c#) <- liftIO (nextPrime# mba# ba# n#)
+ case c# of
+ 0## -> unsafeFreezeBigNat# mbn
+ _ -> unsafeSnocFreezeBigNat# mbn c#
+ where
+ n# = sizeofBigNat# bn
+
+foreign import ccall unsafe "integer_gmp_next_prime"
+ nextPrime# :: MutableByteArray# RealWorld -> ByteArray# -> GmpSize#
+ -> IO GmpLimb
+
----------------------------------------------------------------------------
-- monadic combinators for low-level state threading