ruby-changes:29524
From: akr <ko1@a...>
Date: Sun, 23 Jun 2013 00:21:38 +0900 (JST)
Subject: [ruby-changes:29524] akr:r41576 (trunk): * bignum.c (MSB): New macro.
akr 2013-06-23 00:21:27 +0900 (Sun, 23 Jun 2013) New Revision: 41576 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41576 Log: * bignum.c (MSB): New macro. (bary_unpack_internal): Use MSB. (bary_divmod): Ditto. (bigdivrem): Ditto. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41575) +++ ChangeLog (revision 41576) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Jun 23 00:16:57 2013 Tanaka Akira <akr@f...> + + * bignum.c (MSB): New macro. + (bary_unpack_internal): Use MSB. + (bary_divmod): Ditto. + (bigdivrem): Ditto. + Sat Jun 22 23:45:22 2013 Tanaka Akira <akr@f...> * bignum.c (bary_swap): New function. Index: bignum.c =================================================================== --- bignum.c (revision 41575) +++ bignum.c (revision 41576) @@ -43,6 +43,8 @@ static VALUE big_three = Qnil; https://github.com/ruby/ruby/blob/trunk/bignum.c#L43 #define CLEAR_LOWBITS(d, numbits) ((d) & LSHIFTX(~((d)*0), (numbits))) #define FILL_LOWBITS(d, numbits) ((d) | (LSHIFTX(((d)*0+1), (numbits))-1)) +#define MSB(d) (RSHIFT((d), sizeof(d) * CHAR_BIT - 1) & 1) + #define BDIGITS(x) (RBIGNUM_DIGITS(x)) #define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT) #define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG) @@ -1482,7 +1484,7 @@ bary_unpack_internal(BDIGIT *bdigits, si https://github.com/ruby/ruby/blob/trunk/bignum.c#L1484 int zero_p = bary_2comp(dp, num_bdigits); sign = zero_p ? -2 : -1; } - else if (de[-1] >> (BITSPERDIG-1)) { + else if (MSB(de[-1])) { bary_2comp(dp, num_bdigits); sign = -1; } @@ -1569,8 +1571,7 @@ bary_unpack_internal(BDIGIT *bdigits, si https://github.com/ruby/ruby/blob/trunk/bignum.c#L1571 sign = bary_zero_p(bdigits, num_bdigits) ? -2 : -1; } else { - if (num_bdigits != 0 && - (bdigits[num_bdigits-1] >> (BITSPERDIG - 1))) + if (num_bdigits != 0 && MSB(bdigits[num_bdigits-1])) sign = -1; else sign = 1; @@ -1716,7 +1717,7 @@ rb_integer_unpack(const void *words, siz https://github.com/ruby/ruby/blob/trunk/bignum.c#L1717 return LONG2FIX(0); if (0 < sign && POSFIXABLE(u)) return LONG2FIX(u); - if (sign < 0 && (fixbuf[1] >> (BITSPERDIG-1)) == 0 && + if (sign < 0 && MSB(fixbuf[1]) == 0 && NEGFIXABLE(-(BDIGIT_DBL_SIGNED)u)) return LONG2FIX(-(BDIGIT_DBL_SIGNED)u); val = bignew((long)num_bdigits, 0 <= sign); @@ -4136,7 +4137,7 @@ bary_divmod(BDIGIT *qds, size_t nq, BDIG https://github.com/ruby/ruby/blob/trunk/bignum.c#L4137 MEMCPY(zds, xds, BDIGIT, nx); MEMZERO(zds+nx, BDIGIT, nz-nx); - if ((yds[ny-1] >> (BITSPERDIG-1)) & 1) { + if (MSB(yds[ny-1])) { /* bigdivrem_normal will not modify y. * So use yds directly. */ tds = yds; @@ -4200,7 +4201,7 @@ bigdivrem(VALUE x, VALUE y, volatile VAL https://github.com/ruby/ruby/blob/trunk/bignum.c#L4201 return Qnil; } - if (((yds[ny-1] >> (BITSPERDIG-1)) & 1) == 0) { + if (MSB(yds[ny-1]) == 0) { /* Make yds modifiable. */ tds = ALLOCV_N(BDIGIT, tmpy, ny); MEMCPY(tds, yds, BDIGIT, ny); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/