1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Disable GMP by -DUSE_GMP=0

This commit is contained in:
Nobuyoshi Nakada 2022-05-09 15:57:09 +09:00
parent b6649797ee
commit a080651f46
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 29 additions and 17 deletions

View file

@ -23,8 +23,14 @@
# include <ieeefp.h> # include <ieeefp.h>
#endif #endif
#if !defined(USE_GMP)
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H) #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
# define USE_GMP # define USE_GMP 1
#else
# define USE_GMP 0
#endif
#endif
#if USE_GMP
# include <gmp.h> # include <gmp.h>
#endif #endif
@ -145,7 +151,7 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGIT % SIZEOF_LONG == 0);
#define GMP_DIV_DIGITS 20 #define GMP_DIV_DIGITS 20
#define GMP_BIG2STR_DIGITS 20 #define GMP_BIG2STR_DIGITS 20
#define GMP_STR2BIG_DIGITS 20 #define GMP_STR2BIG_DIGITS 20
#ifdef USE_GMP #if USE_GMP
# define NAIVE_MUL_DIGITS GMP_MUL_DIGITS # define NAIVE_MUL_DIGITS GMP_MUL_DIGITS
#else #else
# define NAIVE_MUL_DIGITS KARATSUBA_MUL_DIGITS # define NAIVE_MUL_DIGITS KARATSUBA_MUL_DIGITS
@ -2291,7 +2297,7 @@ rb_big_mul_toom3(VALUE x, VALUE y)
return z; return z;
} }
#ifdef USE_GMP #if USE_GMP
static inline void static inline void
bdigits_to_mpz(mpz_t mp, const BDIGIT *digits, size_t len) bdigits_to_mpz(mpz_t mp, const BDIGIT *digits, size_t len)
{ {
@ -2556,7 +2562,7 @@ bary_mul(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds
} }
} }
#ifdef USE_GMP #if USE_GMP
bary_mul_gmp(zds, zn, xds, xn, yds, yn); bary_mul_gmp(zds, zn, xds, xn, yds, yn);
#else #else
bary_mul_toom3_start(zds, zn, xds, xn, yds, yn, NULL, 0); bary_mul_toom3_start(zds, zn, xds, xn, yds, yn, NULL, 0);
@ -2776,7 +2782,7 @@ rb_big_divrem_normal(VALUE x, VALUE y)
return rb_assoc_new(q, r); return rb_assoc_new(q, r);
} }
#ifdef USE_GMP #if USE_GMP
static void static void
bary_divmod_gmp(BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn) bary_divmod_gmp(BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
{ {
@ -2860,7 +2866,7 @@ rb_big_divrem_gmp(VALUE x, VALUE y)
static void static void
bary_divmod_branch(BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn) bary_divmod_branch(BDIGIT *qds, size_t qn, BDIGIT *rds, size_t rn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn)
{ {
#ifdef USE_GMP #if USE_GMP
if (GMP_DIV_DIGITS < xn) { if (GMP_DIV_DIGITS < xn) {
bary_divmod_gmp(qds, qn, rds, rn, xds, xn, yds, yn); bary_divmod_gmp(qds, qn, rds, rn, xds, xn, yds, yn);
return; return;
@ -3957,7 +3963,7 @@ str2big_karatsuba(
return z; return z;
} }
#ifdef USE_GMP #if USE_GMP
static VALUE static VALUE
str2big_gmp( str2big_gmp(
int sign, int sign,
@ -4222,7 +4228,7 @@ rb_int_parse_cstr(const char *str, ssize_t len, char **endp, size_t *ndigits,
maxpow_in_bdigit_dbl(base, &digits_per_bdigits_dbl); maxpow_in_bdigit_dbl(base, &digits_per_bdigits_dbl);
num_bdigits = roomof(num_digits, digits_per_bdigits_dbl)*2; num_bdigits = roomof(num_digits, digits_per_bdigits_dbl)*2;
#ifdef USE_GMP #if USE_GMP
if (GMP_STR2BIG_DIGITS < num_bdigits) { if (GMP_STR2BIG_DIGITS < num_bdigits) {
z = str2big_gmp(sign, digits_start, digits_end, num_digits, z = str2big_gmp(sign, digits_start, digits_end, num_digits,
num_bdigits, base); num_bdigits, base);
@ -4402,7 +4408,7 @@ rb_str2big_karatsuba(VALUE arg, int base, int badcheck)
return bignorm(z); return bignorm(z);
} }
#ifdef USE_GMP #if USE_GMP
VALUE VALUE
rb_str2big_gmp(VALUE arg, int base, int badcheck) rb_str2big_gmp(VALUE arg, int base, int badcheck)
{ {
@ -5012,7 +5018,7 @@ rb_big2str_generic(VALUE x, int base)
return big2str_generic(x, base); return big2str_generic(x, base);
} }
#ifdef USE_GMP #if USE_GMP
static VALUE static VALUE
big2str_gmp(VALUE x, int base) big2str_gmp(VALUE x, int base)
{ {
@ -5083,7 +5089,7 @@ rb_big2str1(VALUE x, int base)
return big2str_base_poweroftwo(x, base); return big2str_base_poweroftwo(x, base);
} }
#ifdef USE_GMP #if USE_GMP
if (GMP_BIG2STR_DIGITS < xn) { if (GMP_BIG2STR_DIGITS < xn) {
return big2str_gmp(x, base); return big2str_gmp(x, base);
} }
@ -6940,7 +6946,7 @@ rb_big_isqrt(VALUE n)
return x; return x;
} }
#ifdef USE_GMP #if USE_GMP
static void static void
bary_powm_gmp(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, const BDIGIT *mds, size_t mn) bary_powm_gmp(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, const BDIGIT *mds, size_t mn)
{ {
@ -6966,7 +6972,7 @@ bary_powm_gmp(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT
static VALUE static VALUE
int_pow_tmp3(VALUE x, VALUE y, VALUE m, int nega_flg) int_pow_tmp3(VALUE x, VALUE y, VALUE m, int nega_flg)
{ {
#ifdef USE_GMP #if USE_GMP
VALUE z; VALUE z;
size_t xn, yn, mn, zn; size_t xn, yn, mn, zn;
@ -7172,7 +7178,7 @@ Init_Bignum(void)
{ {
rb_define_method(rb_cInteger, "coerce", rb_int_coerce, 1); rb_define_method(rb_cInteger, "coerce", rb_int_coerce, 1);
#ifdef USE_GMP #if USE_GMP
/* The version of loaded GMP. */ /* The version of loaded GMP. */
rb_define_const(rb_cInteger, "GMP_VERSION", rb_sprintf("GMP %s", gmp_version)); rb_define_const(rb_cInteger, "GMP_VERSION", rb_sprintf("GMP %s", gmp_version));
#endif #endif

View file

@ -15,8 +15,14 @@
#include <ieeefp.h> #include <ieeefp.h>
#endif #endif
#if !defined(USE_GMP)
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H) #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
#define USE_GMP # define USE_GMP 1
#else
# define USE_GMP 0
#endif
#endif
#if USE_GMP
#include <gmp.h> #include <gmp.h>
#endif #endif
@ -247,7 +253,7 @@ k_rational_p(VALUE x)
#define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x)) #define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
#define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x)) #define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
#ifdef USE_GMP #if USE_GMP
VALUE VALUE
rb_gcd_gmp(VALUE x, VALUE y) rb_gcd_gmp(VALUE x, VALUE y)
{ {
@ -364,7 +370,7 @@ rb_gcd_normal(VALUE x, VALUE y)
inline static VALUE inline static VALUE
f_gcd(VALUE x, VALUE y) f_gcd(VALUE x, VALUE y)
{ {
#ifdef USE_GMP #if USE_GMP
if (RB_BIGNUM_TYPE_P(x) && RB_BIGNUM_TYPE_P(y)) { if (RB_BIGNUM_TYPE_P(x) && RB_BIGNUM_TYPE_P(y)) {
size_t xn = BIGNUM_LEN(x); size_t xn = BIGNUM_LEN(x);
size_t yn = BIGNUM_LEN(y); size_t yn = BIGNUM_LEN(y);