From 6feeda594e010d1917393562863b972d5fc30503 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 23 Feb 2017 06:55:42 +0000 Subject: bignum.c: NAIVE_MUL_DIGITS * bignum.c (NAIVE_MUL_DIGITS): share threshold for bary_sq_fast between bary_mul and bigsq. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57696 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index 872610d1b9..638fec4610 100644 --- a/bignum.c +++ b/bignum.c @@ -138,6 +138,11 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGIT % SIZEOF_LONG == 0); #define GMP_DIV_DIGITS 20 #define GMP_BIG2STR_DIGITS 20 #define GMP_STR2BIG_DIGITS 20 +#ifdef USE_GMP +# define NAIVE_MUL_DIGITS GMP_MUL_DIGITS +#else +# define NAIVE_MUL_DIGITS KARATSUBA_MUL_DIGITS +#endif typedef void (mulfunc_t)(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn, BDIGIT *wds, size_t wn); @@ -2487,13 +2492,8 @@ bary_mul_toom3_start(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const static void bary_mul(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn) { -#ifdef USE_GMP - const size_t naive_threshold = GMP_MUL_DIGITS; -#else - const size_t naive_threshold = KARATSUBA_MUL_DIGITS; -#endif if (xn <= yn) { - if (xn < naive_threshold) { + if (xn < NAIVE_MUL_DIGITS) { if (xds == yds && xn == yn) bary_sq_fast(zds, zn, xds, xn); else @@ -2502,7 +2502,7 @@ bary_mul(BDIGIT *zds, size_t zn, const BDIGIT *xds, size_t xn, const BDIGIT *yds } } else { - if (yn < naive_threshold) { + if (yn < NAIVE_MUL_DIGITS) { bary_short_mul(zds, zn, yds, yn, xds, xn); return; } @@ -5820,17 +5820,10 @@ bigsq(VALUE x) xds = BDIGITS(x); zds = BDIGITS(z); -#ifdef USE_GMP - if (xn < GMP_MUL_DIGITS) - bary_sq_fast(zds, zn, xds, xn); - else - bary_mul(zds, zn, xds, xn, xds, xn); -#else - if (xn < KARATSUBA_MUL_DIGITS) + if (xn < NAIVE_MUL_DIGITS) bary_sq_fast(zds, zn, xds, xn); else bary_mul(zds, zn, xds, xn, xds, xn); -#endif RB_GC_GUARD(x); return z; -- cgit v1.2.3