Types#
Descriptor Accessors#
A composed BigInt descriptor BI (for example
decltype(BitWidth<256>() + SM<800>() + Thread())) exposes the following compile-time
accessors and member types:
-
static constexpr unsigned int BI::num_limbs#
The number of 32-bit limbs in one instance:
bit_width / 32.
-
type BI::error_policy#
The configured on-error policy type—
OnErrorNone,OnErrorTrap, orOnErrorPrintTrap—used to report the failures listed under bigint_error. Defaults toOnErrorNonewhen the descriptor carries no policy operator. See Operators.
-
type BI::bigint_wide#
The double-width (
2 * bit_width-bit) big-integer type produced by wide multiplication and squaring, and consumed by Barrett reduction, Montgomery reduction, and double-width division. See bigint_wide below.
-
type BI::modulus#
montgomery_modulusspecialized for this descriptor’s limb count, error policy, andTPI. See montgomery_modulus below.
bigint#
-
class bigint#
The single-width, fixed-precision big-integer type. Not named directly in user code; obtained as
BI::bigintfrom a composed descriptorBI. All arithmetic, comparison, and modular operations described in Device functions are members of this type. Storage isnum_limbs32-bit limbs (little-endian, limb0least significant), distributed acrosstpicooperating warp lanes whentpi > 1.
bigint_wide#
-
class bigint_wide#
The double-width big-integer type holding
2 * num_limbslimbs, split into independentloandhihalves of typeBI::bigint. Produced bymul_wide,operator*, andsquare; consumed byreduce_barrett,reduce_montgomery, andbigint_wide::div_rem.
montgomery_modulus#
-
class montgomery_modulus : public bigint#
A modulus value with its Montgomery reduction constant
m' = -M^-1 mod 2^32precomputed once at construction, for reuse across repeatedto_montgomery/from_montgomery/mul_montgomery/reduce_montgomerycalls against the same modulus. Publicly derives from bigint, so the whole bigint interface is available on a modulus and one can be passed wherever a bigint is expected. Constructors are not inherited: the three below are the only ways to build one, so there is no scalar constructor as there is for bigint.The modulus must be odd. Montgomery reduction requires
gcd(R, m) = 1, whereR = 2^(num_limbs * 32); this holds only whenmis odd. Constructing amontgomery_modulusfrom an even value leavesm'without a valid inverse, so the precomputed constant is meaningless and every subsequentto_montgomery,mul_montgomery,from_montgomery, orreduce_montgomerycall against it silently produces incorrect results.-
__device__ montgomery_modulus(const bigint &modulus)#
Constructs from an already-loaded modulus value and precomputes
m'.modulusmust be odd.
-
__device__ explicit montgomery_modulus(const uint32_t *ptr)#
Loads the modulus from a limb pointer and precomputes
m'. The loaded value must be odd.
-
__device__ montgomery_modulus(const uint32_t *ptr, unsigned int index)#
Loads instance
indexof a batched modulus array and precomputesm'. The loaded value must be odd.
-
__device__ uint32_t m_prime() const#
Returns the precomputed Montgomery constant
m' = -M^-1 mod 2^32.
-
__device__ montgomery_modulus(const bigint &modulus)#
bigint_error#
-
enum class bigint_error#
Status returned by operations that can fail at run time, and passed to the configured on-error policy’s
handle()function (see Operators).-
enumerator success#
The operation completed successfully.
-
enumerator divide_by_zero#
div_rem(or a wrapper such asoperator/,operator%, ormod) was called with a zero divisor.
-
enumerator quotient_overflow#
The true quotient does not fit in the supplied quotient width.
-
enumerator barrett_divide_by_zero#
setup_barrettwas invoked with a zero denominator.
-
enumerator barrett_input_invariant_violated#
reduce_barrettwas invoked with a wide numeratornumwhose high half is not strictly less than the denominatorden(num.hi < dendoes not hold).denmust match the denominator most recently passed tosetup_barrett.
-
enumerator inv_mod_not_invertible#
The value and modulus passed to
inv_modare not coprime, so no inverse exists.
-
enumerator inv_mod_invalid_modulus#
The modulus passed to
inv_modis zero or one.
-
enumerator inv_mod_zero_input#
The input value passed to
inv_modis zero.
-
enumerator inv_mod_even_modulus#
Reserved for an internal odd-modulus-only inverse routine. Not returned by
inv_mod.
-
enumerator success#