{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedFFITypes #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GHCForeignImportPrim #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE NoImplicitPrelude #-}
#include "MachDeps.h"
module GHC.Integer.GMP.Internals
(
Integer(..)
, isValidInteger#
, module GHC.Integer
, gcdInteger
, gcdExtInteger
, lcmInteger
, sqrInteger
, powModInteger
, powModSecInteger
, recipModInteger
, wordToNegInteger
, bigNatToInteger
, bigNatToNegInteger
, BigNat(..)
, GmpLimb, GmpLimb#
, GmpSize, GmpSize#
, isValidBigNat#
, sizeofBigNat#
, zeroBigNat
, oneBigNat
, nullBigNat
, byteArrayToBigNat#
, wordToBigNat
, wordToBigNat2
, bigNatToInt
, bigNatToWord
, indexBigNat#
, plusBigNat
, plusBigNatWord
, minusBigNat
, minusBigNatWord
, timesBigNat
, timesBigNatWord
, sqrBigNat
, quotRemBigNat
, quotRemBigNatWord
, quotBigNatWord
, quotBigNat
, remBigNat
, remBigNatWord
, gcdBigNat
, gcdBigNatWord
, powModBigNat
, powModBigNatWord
, recipModBigNat
, shiftRBigNat
, shiftLBigNat
, testBitBigNat
, clearBitBigNat
, complementBitBigNat
, setBitBigNat
, andBigNat
, xorBigNat
, popCountBigNat
, orBigNat
, bitBigNat
, isZeroBigNat
, isNullBigNat#
, compareBigNatWord
, compareBigNat
, eqBigNatWord
, eqBigNatWord#
, eqBigNat
, eqBigNat#
, gtBigNatWord#
, gcdInt
, gcdWord
, powModWord
, recipModWord
, testPrimeInteger
, testPrimeBigNat
, testPrimeWord#
, nextPrimeInteger
, nextPrimeBigNat
, nextPrimeWord#
, sizeInBaseBigNat
, sizeInBaseInteger
, sizeInBaseWord#
, exportBigNatToAddr
, exportIntegerToAddr
, exportWordToAddr
, exportBigNatToMutableByteArray
, exportIntegerToMutableByteArray
, exportWordToMutableByteArray
, importBigNatFromAddr
, importIntegerFromAddr
, importBigNatFromByteArray
, importIntegerFromByteArray
) where
import GHC.Integer.Type
import GHC.Integer
import GHC.Prim
import GHC.Types
default ()
sizeInBaseInteger :: Integer -> Int# -> Word#
sizeInBaseInteger :: Integer -> Int# -> Word#
sizeInBaseInteger (S# Int#
i#) = Word# -> Int# -> Word#
sizeInBaseWord# (Int# -> Word#
int2Word# (Int# -> Int#
absI# Int#
i#))
sizeInBaseInteger (Jp# BigNat
bn) = BigNat -> Int# -> Word#
sizeInBaseBigNat BigNat
bn
sizeInBaseInteger (Jn# BigNat
bn) = BigNat -> Int# -> Word#
sizeInBaseBigNat BigNat
bn
sizeInBaseBigNat :: BigNat -> Int# -> Word#
sizeInBaseBigNat :: BigNat -> Int# -> Word#
sizeInBaseBigNat bn :: BigNat
bn@(BN# ByteArray#
ba#) = ByteArray# -> Int# -> Int# -> Word#
c_mpn_sizeinbase# ByteArray#
ba# (BigNat -> Int#
sizeofBigNat# BigNat
bn)
foreign import ccall unsafe "integer_gmp_mpn_sizeinbase"
c_mpn_sizeinbase# :: ByteArray# -> GmpSize# -> Int# -> Word#
foreign import ccall unsafe "integer_gmp_mpn_sizeinbase1"
sizeInBaseWord# :: Word# -> Int# -> Word#
exportIntegerToAddr :: Integer -> Addr# -> Int# -> IO Word
exportIntegerToAddr :: Integer -> Addr# -> Int# -> IO Word
exportIntegerToAddr (S# Int#
i#) = Word -> Addr# -> Int# -> IO Word
exportWordToAddr (Word# -> Word
W# (Int# -> Word#
int2Word# (Int# -> Int#
absI# Int#
i#)))
exportIntegerToAddr (Jp# BigNat
bn) = BigNat -> Addr# -> Int# -> IO Word
exportBigNatToAddr BigNat
bn
exportIntegerToAddr (Jn# BigNat
bn) = BigNat -> Addr# -> Int# -> IO Word
exportBigNatToAddr BigNat
bn
exportBigNatToAddr :: BigNat -> Addr# -> Int# -> IO Word
exportBigNatToAddr :: BigNat -> Addr# -> Int# -> IO Word
exportBigNatToAddr bn :: BigNat
bn@(BN# ByteArray#
ba#) Addr#
addr Int#
e
= ByteArray# -> Int# -> Addr# -> Int# -> Int# -> IO Word
c_mpn_exportToAddr# ByteArray#
ba# (BigNat -> Int#
sizeofBigNat# BigNat
bn) Addr#
addr Int#
0# Int#
e
foreign import ccall unsafe "integer_gmp_mpn_export"
c_mpn_exportToAddr# :: ByteArray# -> GmpSize# -> Addr# -> Int# -> Int#
-> IO Word
exportWordToAddr :: Word -> Addr# -> Int# -> IO Word
exportWordToAddr :: Word -> Addr# -> Int# -> IO Word
exportWordToAddr (W# Word#
w#) Addr#
addr
= Word# -> Addr# -> Int# -> Int# -> IO Word
c_mpn_export1ToAddr# Word#
w# Addr#
addr Int#
0#
foreign import ccall unsafe "integer_gmp_mpn_export1"
c_mpn_export1ToAddr# :: GmpLimb# -> Addr# -> Int# -> Int#
-> IO Word
exportIntegerToMutableByteArray :: Integer -> MutableByteArray# RealWorld
-> Word# -> Int# -> IO Word
exportIntegerToMutableByteArray :: Integer -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportIntegerToMutableByteArray (S# Int#
i#)
= Word -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportWordToMutableByteArray (Word# -> Word
W# (Int# -> Word#
int2Word# (Int# -> Int#
absI# Int#
i#)))
exportIntegerToMutableByteArray (Jp# BigNat
bn) = BigNat -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportBigNatToMutableByteArray BigNat
bn
exportIntegerToMutableByteArray (Jn# BigNat
bn) = BigNat -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportBigNatToMutableByteArray BigNat
bn
exportBigNatToMutableByteArray :: BigNat -> MutableByteArray# RealWorld -> Word#
-> Int# -> IO Word
exportBigNatToMutableByteArray :: BigNat -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportBigNatToMutableByteArray bn :: BigNat
bn@(BN# ByteArray#
ba#)
= ByteArray#
-> Int# -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
c_mpn_exportToMutableByteArray# ByteArray#
ba# (BigNat -> Int#
sizeofBigNat# BigNat
bn)
foreign import ccall unsafe "integer_gmp_mpn_export"
c_mpn_exportToMutableByteArray# :: ByteArray# -> GmpSize#
-> MutableByteArray# RealWorld -> Word#
-> Int# -> IO Word
exportWordToMutableByteArray :: Word -> MutableByteArray# RealWorld -> Word#
-> Int# -> IO Word
exportWordToMutableByteArray :: Word -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
exportWordToMutableByteArray (W# Word#
w#) = Word# -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
c_mpn_export1ToMutableByteArray# Word#
w#
foreign import ccall unsafe "integer_gmp_mpn_export1"
c_mpn_export1ToMutableByteArray# :: GmpLimb# -> MutableByteArray# RealWorld
-> Word# -> Int# -> IO Word
{-# NOINLINE testPrimeInteger #-}
testPrimeInteger :: Integer -> Int# -> Int#
testPrimeInteger :: Integer -> Int# -> Int#
testPrimeInteger (S# Int#
i#) = Word# -> Int# -> Int#
testPrimeWord# (Int# -> Word#
int2Word# (Int# -> Int#
absI# Int#
i#))
testPrimeInteger (Jp# BigNat
n) = BigNat -> Int# -> Int#
testPrimeBigNat BigNat
n
testPrimeInteger (Jn# BigNat
n) = BigNat -> Int# -> Int#
testPrimeBigNat BigNat
n
testPrimeBigNat :: BigNat -> Int# -> Int#
testPrimeBigNat :: BigNat -> Int# -> Int#
testPrimeBigNat bn :: BigNat
bn@(BN# ByteArray#
ba#) = ByteArray# -> Int# -> Int# -> Int#
c_integer_gmp_test_prime# ByteArray#
ba# (BigNat -> Int#
sizeofBigNat# BigNat
bn)
foreign import ccall unsafe "integer_gmp_test_prime"
c_integer_gmp_test_prime# :: ByteArray# -> GmpSize# -> Int# -> Int#
foreign import ccall unsafe "integer_gmp_test_prime1"
testPrimeWord# :: GmpLimb# -> Int# -> Int#
{-# NOINLINE nextPrimeInteger #-}
nextPrimeInteger :: Integer -> Integer
nextPrimeInteger :: Integer -> Integer
nextPrimeInteger (S# Int#
i#)
| Int# -> Bool
isTrue# (Int#
i# Int# -> Int# -> Int#
># Int#
1#) = Word# -> Integer
wordToInteger (Word# -> Word#
nextPrimeWord# (Int# -> Word#
int2Word# Int#
i#))
| Bool
True = Int# -> Integer
S# Int#
2#
nextPrimeInteger (Jp# BigNat
bn) = BigNat -> Integer
Jp# (BigNat -> BigNat
nextPrimeBigNat BigNat
bn)
nextPrimeInteger (Jn# BigNat
_) = Int# -> Integer
S# Int#
2#
foreign import ccall unsafe "integer_gmp_next_prime1"
nextPrimeWord# :: GmpLimb# -> GmpLimb#