Skip to content

Commit 02b7d4c

Browse files
committed
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
1 parent 984759e commit 02b7d4c

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

bignum.c

+10-19
Original file line numberDiff line numberDiff line change
@@ -6992,40 +6992,31 @@ int_pow_tmp2(VALUE x, VALUE y, long mm, int nega_flg)
69926992
long tmp = 1L;
69936993
long yy;
69946994
#ifdef DLONG
6995-
DLONG const mmm = mm;
6995+
const DLONG m = mm;
6996+
long tmp2 = tmp;
69966997
long xx = FIX2LONG(x);
69976998
# define MUL_MODULO(a, b, c) (long)(((DLONG)(a) * (DLONG)(b)) % (c))
6998-
6999-
for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, idGTGT, 1, LONG2FIX(1L))) {
7000-
if (RTEST(rb_int_odd_p(y))) {
7001-
tmp = MUL_MODULO(tmp, xx, mmm);
7002-
}
7003-
xx = MUL_MODULO(xx, xx, mmm);
7004-
}
7005-
for (yy = FIX2LONG(y); yy; yy >>= 1L) {
7006-
if (yy & 1L) {
7007-
tmp = MUL_MODULO(tmp, xx, mmm);
7008-
}
7009-
xx = MUL_MODULO(xx, xx, mmm);
7010-
}
70116999
#else
7012-
VALUE const m = LONG2FIX(mm);
7000+
const VALUE m = LONG2FIX(mm);
70137001
VALUE tmp2 = LONG2FIX(tmp);
7002+
VALUE xx = x;
70147003
# define MUL_MODULO(a, b, c) rb_int_modulo(rb_fix_mul_fix((a), (b)), (c))
7004+
#endif
70157005

70167006
for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, idGTGT, 1, LONG2FIX(1L))) {
70177007
if (RTEST(rb_int_odd_p(y))) {
7018-
tmp2 = MUL_MODULO(tmp2, x, m);
7008+
tmp2 = MUL_MODULO(tmp2, xx, m);
70197009
}
7020-
x = MUL_MODULO(x, x, m);
7010+
xx = MUL_MODULO(xx, xx, m);
70217011
}
70227012
for (yy = FIX2LONG(y); yy; yy >>= 1L) {
70237013
if (yy & 1L) {
7024-
tmp2 = MUL_MODULO(tmp2, x, m);
7014+
tmp2 = MUL_MODULO(tmp2, xx, m);
70257015
}
7026-
x = MUL_MODULO(x, x, m);
7016+
xx = MUL_MODULO(xx, xx, m);
70277017
}
70287018

7019+
#ifndef DLONG
70297020
tmp = FIX2LONG(tmp2);
70307021
#endif
70317022
if (nega_flg && tmp) {

0 commit comments

Comments
 (0)