summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-05 00:09:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-05 00:09:58 +0000
commit02b7d4c5444fd64bde04b082672f61b880d77a70 (patch)
treef347a26081d50c64f312a8e778b75670ac8ab0f7 /bignum.c
parent984759ef98e7db295121d2cf19191acc6400891a (diff)
bignum.c: unified int_pow_tmp2
* bignum.c (int_pow_tmp2): unified DLONG and none DLONG code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/bignum.c b/bignum.c
index a87429aac6..94d0d50c8f 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6992,40 +6992,31 @@ int_pow_tmp2(VALUE x, VALUE y, long mm, int nega_flg)
long tmp = 1L;
long yy;
#ifdef DLONG
- DLONG const mmm = mm;
+ const DLONG m = mm;
+ long tmp2 = tmp;
long xx = FIX2LONG(x);
# define MUL_MODULO(a, b, c) (long)(((DLONG)(a) * (DLONG)(b)) % (c))
-
- for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, idGTGT, 1, LONG2FIX(1L))) {
- if (RTEST(rb_int_odd_p(y))) {
- tmp = MUL_MODULO(tmp, xx, mmm);
- }
- xx = MUL_MODULO(xx, xx, mmm);
- }
- for (yy = FIX2LONG(y); yy; yy >>= 1L) {
- if (yy & 1L) {
- tmp = MUL_MODULO(tmp, xx, mmm);
- }
- xx = MUL_MODULO(xx, xx, mmm);
- }
#else
- VALUE const m = LONG2FIX(mm);
+ const VALUE m = LONG2FIX(mm);
VALUE tmp2 = LONG2FIX(tmp);
+ VALUE xx = x;
# define MUL_MODULO(a, b, c) rb_int_modulo(rb_fix_mul_fix((a), (b)), (c))
+#endif
for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, idGTGT, 1, LONG2FIX(1L))) {
if (RTEST(rb_int_odd_p(y))) {
- tmp2 = MUL_MODULO(tmp2, x, m);
+ tmp2 = MUL_MODULO(tmp2, xx, m);
}
- x = MUL_MODULO(x, x, m);
+ xx = MUL_MODULO(xx, xx, m);
}
for (yy = FIX2LONG(y); yy; yy >>= 1L) {
if (yy & 1L) {
- tmp2 = MUL_MODULO(tmp2, x, m);
+ tmp2 = MUL_MODULO(tmp2, xx, m);
}
- x = MUL_MODULO(x, x, m);
+ xx = MUL_MODULO(xx, xx, m);
}
+#ifndef DLONG
tmp = FIX2LONG(tmp2);
#endif
if (nega_flg && tmp) {