ruby-changes:30309
From: akr <ko1@a...>
Date: Sun, 4 Aug 2013 00:26:15 +0900 (JST)
Subject: [ruby-changes:30309] akr:r42361 (trunk): * bignum.c (bary2bdigitdbl): New function.
akr 2013-08-04 00:26:04 +0900 (Sun, 04 Aug 2013) New Revision: 42361 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42361 Log: * bignum.c (bary2bdigitdbl): New function. (bdigitdbl2bary): Ditto. (bary_mul_single): Use bdigitdbl2bary. (power_cache_get_power): Ditto. (bary_divmod): Use bary2bdigitdbl. (big2str_orig): Ditto. (bigdivrem): Ditto. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42360) +++ ChangeLog (revision 42361) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Aug 4 00:22:34 2013 Tanaka Akira <akr@f...> + + * bignum.c (bary2bdigitdbl): New function. + (bdigitdbl2bary): Ditto. + (bary_mul_single): Use bdigitdbl2bary. + (power_cache_get_power): Ditto. + (bary_divmod): Use bary2bdigitdbl. + (big2str_orig): Ditto. + (bigdivrem): Ditto. + Sat Aug 3 22:47:11 2013 Tanaka Akira <akr@f...> * bignum.c: The branch condition of selecting multiplication Index: bignum.c =================================================================== --- bignum.c (revision 42360) +++ bignum.c (revision 42361) @@ -482,6 +482,27 @@ maxpow_in_bdigit(int base, int *exp_ret) https://github.com/ruby/ruby/blob/trunk/bignum.c#L482 return maxpow; } +static inline BDIGIT_DBL +bary2bdigitdbl(const BDIGIT *ds, size_t n) +{ + assert(n <= 2); + + if (n == 2) + return ds[0] | BIGUP(ds[1]); + if (n == 1) + return ds[0]; + return 0; +} + +static inline void +bdigitdbl2bary(BDIGIT *ds, size_t n, BDIGIT_DBL num) +{ + assert(n == 2); + + ds[0] = BIGLO(num); + ds[1] = (BDIGIT)BIGDN(num); +} + static int bary_cmp(const BDIGIT *xds, size_t xn, const BDIGIT *yds, size_t yn) { @@ -1551,9 +1572,7 @@ bary_mul_single(BDIGIT *zds, size_t zl, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1572 assert(2 <= zl); n = (BDIGIT_DBL)x * y; - zds[0] = BIGLO(n); - zds[1] = (BDIGIT)BIGDN(n); - + bdigitdbl2bary(zds, 2, n); BDIGITS_ZERO(zds + 2, zl - 2); } @@ -2724,8 +2743,8 @@ bary_divmod(BDIGIT *qds, size_t nq, BDIG https://github.com/ruby/ruby/blob/trunk/bignum.c#L2743 BDIGITS_ZERO(rds+1, nr-1); } else if (nx == 2 && ny == 2) { - BDIGIT_DBL x = xds[0] | BIGUP(xds[1]); - BDIGIT_DBL y = yds[0] | BIGUP(yds[1]); + BDIGIT_DBL x = bary2bdigitdbl(xds, 2); + BDIGIT_DBL y = bary2bdigitdbl(yds, 2); BDIGIT_DBL q = x / y; BDIGIT_DBL r = x % y; qds[0] = BIGLO(q); @@ -4151,8 +4170,7 @@ power_cache_get_power(int base, int powe https://github.com/ruby/ruby/blob/trunk/bignum.c#L4170 int numdigits0; BDIGIT_DBL dd = maxpow_in_bdigit_dbl(base, &numdigits0); power = bignew(2, 1); - BDIGITS(power)[0] = BIGLO(dd); - BDIGITS(power)[1] = (BDIGIT)BIGDN(dd); + bdigitdbl2bary(BDIGITS(power), 2, dd); numdigits = numdigits0; } else { @@ -4256,12 +4274,7 @@ big2str_orig(struct big2str_struct *b2s, https://github.com/ruby/ruby/blob/trunk/bignum.c#L4274 size_t len = 0; assert(xn <= 2); - - num = 0; - if (0 < xn) - num = xds[0]; - if (1 < xn) - num |= BIGUP(xds[1]); + num = bary2bdigitdbl(xds, xn); if (beginning) { if (num == 0) @@ -5575,8 +5588,8 @@ bigdivrem(VALUE x, VALUE y, volatile VAL https://github.com/ruby/ruby/blob/trunk/bignum.c#L5588 return Qnil; } if (nx == 2 && ny == 2) { - BDIGIT_DBL x0 = xds[0] | BIGUP(xds[1]); - BDIGIT_DBL y0 = yds[0] | BIGUP(yds[1]); + BDIGIT_DBL x0 = bary2bdigitdbl(xds, 2); + BDIGIT_DBL y0 = bary2bdigitdbl(yds, 2); BDIGIT_DBL q0 = x0 / y0; BDIGIT_DBL r0 = x0 % y0; if (divp) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/