ruby-changes:29992
From: akr <ko1@a...>
Date: Thu, 18 Jul 2013 21:58:59 +0900 (JST)
Subject: [ruby-changes:29992] akr:r42044 (trunk): * bignum.c (bary_sq_fast): Specialize the last iteration of the
akr 2013-07-18 21:58:46 +0900 (Thu, 18 Jul 2013) New Revision: 42044 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42044 Log: * bignum.c (bary_sq_fast): Specialize the last iteration of the outer loop. (bigfixize): A condition simplified. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 42043) +++ ChangeLog (revision 42044) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jul 18 21:30:50 2013 Tanaka Akira <akr@f...> + + * bignum.c (bary_sq_fast): Specialize the last iteration of the + outer loop. + (bigfixize): A condition simplified. + Thu Jul 18 21:15:41 2013 Masaki Matsushita <glass.saga@g...> * array.c (rb_ary_equal): compare RARRAY_PTR() for performance Index: bignum.c =================================================================== --- bignum.c (revision 42043) +++ bignum.c (revision 42044) @@ -1605,7 +1605,11 @@ bary_sq_fast(BDIGIT *zds, size_t zn, BDI https://github.com/ruby/ruby/blob/trunk/bignum.c#L1605 assert(xn * 2 <= zn); BDIGITS_ZERO(zds, zn); - for (i = 0; i < xn; i++) { + + if (xn == 0) + return; + + for (i = 0; i < xn-1; i++) { v = (BDIGIT_DBL)xds[i]; if (!v) continue; @@ -1625,11 +1629,22 @@ bary_sq_fast(BDIGIT *zds, size_t zn, BDI https://github.com/ruby/ruby/blob/trunk/bignum.c#L1629 c += (BDIGIT_DBL)zds[i + xn]; zds[i + xn] = BIGLO(c); c = BIGDN(c); - assert(c == 0 || i != xn-1); - if (c && i != xn-1) + if (c) zds[i + xn + 1] += (BDIGIT)c; } } + + /* i == xn-1 */ + v = (BDIGIT_DBL)xds[i]; + if (!v) + return; + c = (BDIGIT_DBL)zds[i + i] + v * v; + zds[i + i] = BIGLO(c); + c = BIGDN(c); + if (c) { + c += (BDIGIT_DBL)zds[i + xn]; + zds[i + xn] = BIGLO(c); + } } VALUE @@ -2336,11 +2351,11 @@ bigfixize(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2351 int i = (int)len; u = 0; while (i--) { - u = (long)(BIGUP(u) + ds[i]); + u = (unsigned long)(BIGUP(u) + ds[i]); } } #else /* SIZEOF_BDIGITS >= SIZEOF_LONG */ - if (1 < len || LONG_MAX < ds[0]) + if (1 < len) goto return_big; else u = ds[0]; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/