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

* bignum.c (big_rshift): Use abs2twocomp and twocomp2abs_bang.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-06-29 16:58:58 +00:00
parent 3c9f0334a5
commit b1e052d080
2 changed files with 16 additions and 17 deletions

View file

@ -1,3 +1,7 @@
Sun Jun 30 01:57:08 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (big_rshift): Use abs2twocomp and twocomp2abs_bang.
Sun Jun 30 00:14:20 2013 Tanaka Akira <akr@fsij.org> Sun Jun 30 00:14:20 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (RBIGNUM_SET_NEGATIVE_SIGN): New macro. * bignum.c (RBIGNUM_SET_NEGATIVE_SIGN): New macro.

View file

@ -5163,33 +5163,28 @@ big_rshift(VALUE x, unsigned long shift)
long s1 = shift/BITSPERDIG; long s1 = shift/BITSPERDIG;
int s2 = (int)(shift%BITSPERDIG); int s2 = (int)(shift%BITSPERDIG);
VALUE z; VALUE z;
long i, j; long j;
volatile VALUE save_x; long xl;
BDIGIT hibitsx;
if (s1 > RBIGNUM_LEN(x)) { if (s1 > RBIGNUM_LEN(x)) {
if (RBIGNUM_SIGN(x)) if (RBIGNUM_POSITIVE_P(x) || bary_zero_p(BDIGITS(x), RBIGNUM_LEN(x)))
return INT2FIX(0); return INT2FIX(0);
else else
return INT2FIX(-1); return INT2FIX(-1);
} }
if (!RBIGNUM_SIGN(x)) { hibitsx = abs2twocomp(&x, &xl);
x = rb_big_clone(x);
get2comp(x);
}
save_x = x;
xds = BDIGITS(x); xds = BDIGITS(x);
i = RBIGNUM_LEN(x); j = i - s1; j = xl - s1;
if (j == 0) { if (j <= 0) {
if (RBIGNUM_SIGN(x)) return INT2FIX(0); if (!hibitsx) return INT2FIX(0);
else return INT2FIX(-1); else return INT2FIX(-1);
} }
z = bignew(j, RBIGNUM_SIGN(x)); z = bignew(j, 0);
zds = BDIGITS(z); zds = BDIGITS(z);
bary_small_rshift(zds, xds+s1, j, s2, !RBIGNUM_SIGN(x)); bary_small_rshift(zds, xds+s1, j, s2, hibitsx != 0);
if (!RBIGNUM_SIGN(x)) { twocomp2abs_bang(z, hibitsx != 0);
get2comp(z); RB_GC_GUARD(x);
}
RB_GC_GUARD(save_x);
return z; return z;
} }