Go to the source code of this file.
Defines | |
#define | _TIFA_MACROS_H_ |
#define | MPN_NORMALIZE(dest, nlimbs) |
#define | SIZ(x) ((x)->_mp_size) |
#define | ABSIZ(x) (ABS(SIZ(x))) |
#define | MPZ_TO_ABS(x) (SIZ(x) = ABSIZ(x)) |
#define | PTR(x) ((x)->_mp_d) |
#define | ALLOC(x) ((x)->_mp_alloc) |
#define | MPZ_LIMB_VALUE(x, i) ( PTR(x)[(i)] & GMP_NUMB_MASK ) |
#define | MPZ_LAST_LIMB_VALUE(x) ( PTR(x)[SIZ(x) - 1] & GMP_NUMB_MASK ) |
#define | MAX(a, b) ( ((a) > (b)) ? (a) : (b) ) |
#define | MIN(a, b) ( ((a) < (b)) ? (a) : (b) ) |
#define | ABS(a) ( ((a) < 0) ? (-(a)) : (a) ) |
#define | IS_POWER_OF_2_UI(ui) ( ((ui) & ((ui) - 1)) == 0 ) |
#define | IS_EVEN(ui) (((ui) & 1) == 0) |
#define | IS_ODD(ui) (((ui) & 1) != 0) |
#define | ARE_EVEN(uia, uib) ((((uia) | (uib)) & 1) == 0) |
#define | ARE_ODD(uia, uib) ((((uia) | (uib)) & 1) != 0) |
#define | BIT(N, i) ( ((N) & (1<<(i))) ? 1 : 0 ) |
#define | DUFF_DEVICE(COUNT, STATEMENT,...) |
#define | MPZ_IS_SQUARE(X) (0 != mpz_perfect_square_p(X)) |
#define | NMILLER_RABIN 32 |
#define | MPZ_IS_PRIME(X) (0 != mpz_probab_prime_p((X), NMILLER_RABIN)) |
#define | MPN_ADD(A, B, C) |
#define | MPN_ADD_CS(A, B, C) |
#define | MPN_SUB(A, B, C) |
#define | MPN_SUB_N(A, B, C) |
#define | MPN_TDIV_QR(Q, R, N, D) |
#define | MPN_MUL(A, B, C) |
#define | MPN_MUL_N(A, B, C) |
#define | MPN_MUL_CS(A, B, C) |
#define | MPN_MUL_CS_S(A, B, C) |
#define | DECLARE_MPZ_SWAP_VARS |
#define | MPZ_SWAP(A, B) |
#define | TIFA_DEBUG_MSG(...) |
Definition in file macros.h.
#define ABS | ( | a | ) | ( ((a) < 0) ? (-(a)) : (a) ) |
#define ABSIZ | ( | x | ) | (ABS(SIZ(x))) |
#define ALLOC | ( | x | ) | ((x)->_mp_alloc) |
Macro from the GMP library: Returns the _mp_alloc
field of an mpz_t
integer.
Returns the _mp_alloc
field of an mpz_t
integer, that is to say the size (in units of mp_limb_t
) of the x->_mp_d
array.
#define ARE_EVEN | ( | uia, | |||
uib | ) | ((((uia) | (uib)) & 1) == 0) |
#define ARE_ODD | ( | uia, | |||
uib | ) | ((((uia) | (uib)) & 1) != 0) |
#define BIT | ( | N, | |||
i | ) | ( ((N) & (1<<(i))) ? 1 : 0 ) |
#define DECLARE_MPZ_SWAP_VARS |
Value:
mp_ptr __TMPPTR__MACROS_H__a9b3c01__; \ mp_size_t __TMPSIZ__MACROS_H__a9b3c01__;
MPZ_SWAP
macro. Should be called once prior to any use of the MPZ_SWAP
macro.
__TMPPTR__MACROS_H__a9b3c01__
and __TMPSIZ__MACROS_H__a9b3c01__
. Hopefully their names are fancy enough to avoid any local conflict. #define DUFF_DEVICE | ( | COUNT, | |||
STATEMENT, | |||||
... | ) |
Value:
do { \ long int __count__ = (COUNT); \ long int __niter__ = (__count__ + 7) >> 3; \ switch (__count__ & 7) { \ case 0: do { STATEMENT; __VA_ARGS__; \ case 7: STATEMENT; __VA_ARGS__; \ case 6: STATEMENT; __VA_ARGS__; \ case 5: STATEMENT; __VA_ARGS__; \ case 4: STATEMENT; __VA_ARGS__; \ case 3: STATEMENT; __VA_ARGS__; \ case 2: STATEMENT; __VA_ARGS__; \ case 1: STATEMENT; __VA_ARGS__; \ __niter__--; \ } while (__niter__ > 0); \ } \ } while (0)
COUNT
is the number of times to perform the operations given by STATEMENTS.
COUNT
should be strictly positive. Using COUNT
equals to zero will yield wrong results."A Reusable Duff Device", Ralf Holly, Dr. Dobb's Journal, August 2005. Available online at: http://www.drdobbs.com/high-performance-computing/184406208 (URL last accessed on Thu 17 Feb 2011)
#define IS_EVEN | ( | ui | ) | (((ui) & 1) == 0) |
#define IS_ODD | ( | ui | ) | (((ui) & 1) != 0) |
#define IS_POWER_OF_2_UI | ( | ui | ) | ( ((ui) & ((ui) - 1)) == 0 ) |
Macro returning a non-zero value if the unsigned integer ui
is a power of 2.
Definition at line 216 of file macros.h.
Referenced by ceil_log2().
#define MAX | ( | a, | |||
b | ) | ( ((a) > (b)) ? (a) : (b) ) |
#define MIN | ( | a, | |||
b | ) | ( ((a) < (b)) ? (a) : (b) ) |
#define MPN_ADD | ( | A, | |||
B, | |||||
C | ) |
Value:
do { \ if (mpn_add(PTR(A), PTR(B), SIZ(B), PTR(C), SIZ(C))) { \ SIZ(A) = SIZ(B); \ MPN_NORMALIZE(PTR(A), SIZ(A)); \ PTR(A)[SIZ(A)] = 1; \ SIZ(A)++; \ } else { \ SIZ(A) = SIZ(B); \ MPN_NORMALIZE(PTR(A), SIZ(A)); \ } \ } while (0)
mpn_add
. Performs size normalization on the result and takes care of the possible carry out. Does not perform any reallocation: the user should make sure the result has enough space to accomodate the possible carry out.
Takes as parameters three mpz_t
(and not arrays of mp_limb_t
). SIZ(B)
should be greater than or equal to SIZ(C)
.
B
and C
should be both positive or the result will be unpredictable.mpn_add
function. #define MPN_ADD_CS | ( | A, | |||
B, | |||||
C | ) |
Value:
Syntaxic sugar macro wrapping a call tompn_add
. Performs size normalization on the result, takes care of the possible carry out, and Checks the Sizes of the operands to call mpn_add
with the proper parameters' order. However, does not perform any reallocation: the user should make sure the result has enough space to accomodate the possible carry out.
Takes as parameters three mpz_t
(and not arrays of mp_limb_t
). B
and C
can be used interchangeably.
B
and C
should be both positive or the result will be unpredictable.mpn_add
function. #define MPN_MUL | ( | A, | |||
B, | |||||
C | ) |
Value:
do { \ mpn_mul(PTR(A), PTR(B), SIZ(B), PTR(C), SIZ(C)); \ SIZ(A) = SIZ(B) + SIZ(C); \ MPN_NORMALIZE(PTR(A), SIZ(A)); \ } while (0)
mpn_mul
. Performs size normalization on the result.
Takes as parameters three mpz_t
(and not arrays of mp_limb_t
). SIZ(B)
should be greater than or equal to SIZ(C)
.
B
and C
should be both positive or the result will be unpredictable.mpn_mul
function. #define MPN_MUL_CS | ( | A, | |||
B, | |||||
C | ) |
Value:
do { \ if (SIZ(B) > SIZ(C)) { \ mpn_mul(PTR(A), PTR(B), SIZ(B), PTR(C), SIZ(C)); \ } else { \ mpn_mul(PTR(A), PTR(C), SIZ(C), PTR(B), SIZ(B)); \ } \ SIZ(A) = SIZ(B) + SIZ(C); \ MPN_NORMALIZE(PTR(A), SIZ(A)); \ } while (0)
mpn_mul
. Performs size normalization on the result, and Checks the Sizes of the operands to call mpn_mul
with the proper parameters' order.
Takes as parameters three mpz_t
(and not arrays of mp_limb_t
). B
and C
can be used interchangeably.
B
and C
should be both positive or the result will be unpredictable.mpn_mul
function. #define MPN_MUL_CS_S | ( | A, | |||
B, | |||||
C | ) |
Value:
do { \ if (ABSIZ(B) > ABSIZ(C)) { \ mpn_mul(PTR(A), PTR(B), ABSIZ(B), PTR(C), ABSIZ(C)); \ } else { \ mpn_mul(PTR(A), PTR(C), ABSIZ(C), PTR(B), ABSIZ(B)); \ } \ SIZ(A) = ABSIZ(B) + ABSIZ(C); \ MPN_NORMALIZE(PTR(A), SIZ(A)); \ if ((SIZ(B) ^ SIZ(C)) < 0) { \ SIZ(A) = -SIZ(A); \ } \ } while (0)
mpn_mul
. Performs size normalization on the result, and Checks the Sizes and the Signs of the operands to call mpn_mul
with the proper parameters' order.
Takes as parameters three mpz_t
(and not arrays of mp_limb_t
). B
and C
can be used interchangeably.
B
and C
are allowed to be negative.mpn_mul
function. #define MPN_MUL_N | ( | A, | |||
B, | |||||
C | ) |
Value:
do { \ mpn_mul_n(PTR(A), PTR(B), PTR(C), SIZ(B)); \ SIZ(A) = SIZ(B) << 1; \ MPN_NORMALIZE(PTR(A), SIZ(A)); \ } while (0)
mpn_mul_n
. Performs size normalization on the result.
Takes as parameters three mpz_t
(and not arrays of mp_limb_t
). SIZ(B)
and SIZ(C)
should be the same.
B
and C
should be both positive or the result will be unpredictable.mpn_mul_n
function. #define MPN_NORMALIZE | ( | dest, | |||
nlimbs | ) |
Value:
do { \ while (((nlimbs) > 0) && ((dest)[(nlimbs) - 1] == 0)) { \ (nlimbs)--; \ } \ } while (0)
Given dest
, a pointer to an array of nlimbs
mp_limbs_t
integers giving the representation of a multi-precision integer n, computes the absolute value of the effective size of n, i.e the number of significant mp_size_t
integers needed to represent n and modifies the value of nlimbs
accordingly.
#define MPN_SUB | ( | A, | |||
B, | |||||
C | ) |
Value:
do { \ mpn_sub(PTR(A), PTR(B), SIZ(B), PTR(C), SIZ(C)); \ SIZ(A) = SIZ(B); \ MPN_NORMALIZE(PTR(A), SIZ(A)); \ } while (0)
mpn_sub
. Performs size normalization on the result but does not take care of the possible borrow out.
Takes as parameters three mpz_t
(and not arrays of mp_limb_t
). B
should be greater than or equal to C
.
B
and C
should be both positive or the result will be unpredictable.mpn_sub
function. #define MPN_SUB_N | ( | A, | |||
B, | |||||
C | ) |
Value:
do { \ mpn_sub_n(PTR(A), PTR(B), PTR(C), SIZ(B)); \ SIZ(A) = SIZ(B); \ MPN_NORMALIZE(PTR(A), SIZ(A)); \ } while (0)
mpn_sub_n
. Performs size normalization on the result but does not take care of the possible borrow out.
Takes as parameters three mpz_t
(and not arrays of mp_limb_t
). B
should be greater than or equal to C
.
B
and C
should be both positive or the result will be unpredictable.mpn_sub_n
function. #define MPN_TDIV_QR | ( | Q, | |||
R, | |||||
N, | |||||
D | ) |
Value:
do { \ if (SIZ(N) >= SIZ(D)) { \ mpn_tdiv_qr(PTR(Q), PTR(R), 0, PTR(N), SIZ(N), PTR(D), SIZ(D)); \ SIZ(Q) = SIZ(N) - SIZ(D) + 1; \ MPN_NORMALIZE(PTR(Q), SIZ(Q)); \ SIZ(R) = SIZ(D); \ MPN_NORMALIZE(PTR(R), SIZ(R)); \ } \ } while (0)
mpn_tdiv_qr
. Performs size normalization on both the quotient and remainder.
Takes as parameters four mpz_t
(and not arrays of mp_limb_t
).
N
and D
should be both positive or the result will be unpredictable.mpn_tdiv_qr
function. #define MPZ_IS_PRIME | ( | X | ) | (0 != mpz_probab_prime_p((X), NMILLER_RABIN)) |
#define MPZ_IS_SQUARE | ( | X | ) | (0 != mpz_perfect_square_p(X)) |
#define MPZ_LAST_LIMB_VALUE | ( | x | ) | ( PTR(x)[SIZ(x) - 1] & GMP_NUMB_MASK ) |
#define MPZ_LIMB_VALUE | ( | x, | |||
i | ) | ( PTR(x)[(i)] & GMP_NUMB_MASK ) |
#define MPZ_SWAP | ( | A, | |||
B | ) |
Value:
do { \ __TMPPTR__MACROS_H__a9b3c01__ = PTR(A); \ __TMPSIZ__MACROS_H__a9b3c01__ = SIZ(A); \ PTR(A) = PTR(B); \ SIZ(A) = SIZ(B); \ PTR(B) = __TMPPTR__MACROS_H__a9b3c01__; \ SIZ(B) = __TMPSIZ__MACROS_H__a9b3c01__; \ } while (0)
mpz_t
A
and B
.
DECLARE_MPZ_SWAP_VARS
should be called once before using MPZ_SWAP
. #define MPZ_TO_ABS | ( | x | ) | (SIZ(x) = ABSIZ(x)) |
#define NMILLER_RABIN 32 |
#define PTR | ( | x | ) | ((x)->_mp_d) |
Macro from the GMP library: Returns the _mp_d
field of an mpz_t
integer.
Returns the _mp_d
field of an mpz_t
integer, that is to say a pointer to an array of mp_limbs_t
integers giving the representation of the value of x
.
#define SIZ | ( | x | ) | ((x)->_mp_size) |
Macro from the GMP library: Returns the _mp_size
field of an mpz_t
integer.
Returns the _mp_size
field of the variable x
of type mpz_t
, that is to say the number of mp_limbs_t
integers needed to represent the value of x
. The sign of the returned value is given by the sign of x
's value.
#define TIFA_DEBUG_MSG | ( | ... | ) |