[前][次][番号順一覧][スレッド一覧]

ruby-changes:71902

From: Nobuyoshi <ko1@a...>
Date: Fri, 20 May 2022 19:07:14 +0900 (JST)
Subject: [ruby-changes:71902] a080651f46 (master): Disable GMP by -DUSE_GMP=0

https://git.ruby-lang.org/ruby.git/commit/?id=a080651f46

From a080651f4625207dc847962cff3a6fc6a7da4810 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 9 May 2022 15:57:09 +0900
Subject: Disable GMP by -DUSE_GMP=0

---
 bignum.c   | 34 ++++++++++++++++++++--------------
 rational.c | 12 +++++++++---
 2 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/bignum.c b/bignum.c
index 142059b8fd..8f351ee208 100644
--- a/bignum.c
+++ b/bignum.c
@@ -23,8 +23,14 @@ https://github.com/ruby/ruby/blob/trunk/bignum.c#L23
 # include <ieeefp.h>
 #endif
 
+#if !defined(USE_GMP)
 #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>
 #endif
 
@@ -145,7 +151,7 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGIT % SIZEOF_LONG == 0); https://github.com/ruby/ruby/blob/trunk/bignum.c#L151
 #define GMP_DIV_DIGITS 20
 #define GMP_BIG2STR_DIGITS 20
 #define GMP_STR2BIG_DIGITS 20
-#ifdef USE_GMP
+#if USE_GMP
 # define NAIVE_MUL_DIGITS GMP_MUL_DIGITS
 #else
 # define NAIVE_MUL_DIGITS KARATSUBA_MUL_DIGITS
@@ -2291,7 +2297,7 @@ rb_big_mul_toom3(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2297
     return z;
 }
 
-#ifdef USE_GMP
+#if USE_GMP
 static inline void
 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 https://github.com/ruby/ruby/blob/trunk/bignum.c#L2562
         }
     }
 
-#ifdef USE_GMP
+#if USE_GMP
     bary_mul_gmp(zds, zn, xds, xn, yds, yn);
 #else
     bary_mul_toom3_start(zds, zn, xds, xn, yds, yn, NULL, 0);
@@ -2776,7 +2782,7 @@ rb_big_divrem_normal(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2782
     return rb_assoc_new(q, r);
 }
 
-#ifdef USE_GMP
+#if USE_GMP
 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)
 {
@@ -2860,7 +2866,7 @@ rb_big_divrem_gmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2866
 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)
 {
-#ifdef USE_GMP
+#if USE_GMP
     if (GMP_DIV_DIGITS < xn) {
         bary_divmod_gmp(qds, qn, rds, rn, xds, xn, yds, yn);
         return;
@@ -3957,7 +3963,7 @@ str2big_karatsuba( https://github.com/ruby/ruby/blob/trunk/bignum.c#L3963
     return z;
 }
 
-#ifdef USE_GMP
+#if USE_GMP
 static VALUE
 str2big_gmp(
     int sign,
@@ -4222,7 +4228,7 @@ rb_int_parse_cstr(const char *str, ssize_t len, char **endp, size_t *ndigits, https://github.com/ruby/ruby/blob/trunk/bignum.c#L4228
         maxpow_in_bdigit_dbl(base, &digits_per_bdigits_dbl);
         num_bdigits = roomof(num_digits, digits_per_bdigits_dbl)*2;
 
-#ifdef USE_GMP
+#if USE_GMP
         if (GMP_STR2BIG_DIGITS < num_bdigits) {
             z = str2big_gmp(sign, digits_start, digits_end, num_digits,
                     num_bdigits, base);
@@ -4402,7 +4408,7 @@ rb_str2big_karatsuba(VALUE arg, int base, int badcheck) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4408
     return bignorm(z);
 }
 
-#ifdef USE_GMP
+#if USE_GMP
 VALUE
 rb_str2big_gmp(VALUE arg, int base, int badcheck)
 {
@@ -5012,7 +5018,7 @@ rb_big2str_generic(VALUE x, int base) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5018
     return big2str_generic(x, base);
 }
 
-#ifdef USE_GMP
+#if USE_GMP
 static VALUE
 big2str_gmp(VALUE x, int base)
 {
@@ -5083,7 +5089,7 @@ rb_big2str1(VALUE x, int base) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5089
         return big2str_base_poweroftwo(x, base);
     }
 
-#ifdef USE_GMP
+#if USE_GMP
     if (GMP_BIG2STR_DIGITS < xn) {
         return big2str_gmp(x, base);
     }
@@ -6940,7 +6946,7 @@ rb_big_isqrt(VALUE n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6946
     return x;
 }
 
-#ifdef USE_GMP
+#if USE_GMP
 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)
 {
@@ -6966,7 +6972,7 @@ bary_powm_gmp(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT https://github.com/ruby/ruby/blob/trunk/bignum.c#L6972
 static VALUE
 int_pow_tmp3(VALUE x, VALUE y, VALUE m, int nega_flg)
 {
-#ifdef USE_GMP
+#if USE_GMP
     VALUE z;
     size_t xn, yn, mn, zn;
 
@@ -7172,7 +7178,7 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L7178
 {
     rb_define_method(rb_cInteger, "coerce", rb_int_coerce, 1);
 
-#ifdef USE_GMP
+#if USE_GMP
     /* The version of loaded GMP. */
     rb_define_const(rb_cInteger, "GMP_VERSION", rb_sprintf("GMP %s", gmp_version));
 #endif
diff --git a/rational.c b/rational.c
index 16f45173c2..093de5fa5b 100644
--- a/rational.c
+++ b/rational.c
@@ -15,8 +15,14 @@ https://github.com/ruby/ruby/blob/trunk/rational.c#L15
 #include <ieeefp.h>
 #endif
 
+#if !defined(USE_GMP)
 #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>
 #endif
 
@@ -247,7 +253,7 @@ k_rational_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/rational.c#L253
 #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))
 
-#ifdef USE_GMP
+#if USE_GMP
 VALUE
 rb_gcd_gmp(VALUE x, VALUE y)
 {
@@ -364,7 +370,7 @@ rb_gcd_normal(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/rational.c#L370
 inline static VALUE
 f_gcd(VALUE x, VALUE y)
 {
-#ifdef USE_GMP
+#if USE_GMP
     if (RB_BIGNUM_TYPE_P(x) && RB_BIGNUM_TYPE_P(y)) {
         size_t xn = BIGNUM_LEN(x);
         size_t yn = BIGNUM_LEN(y);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]