diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-18 12:58:46 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-18 12:58:46 +0000 |
commit | 2314c1bf476dbef2bd5904d262410dff230e1661 (patch) | |
tree | 973f93f04da36aa796065dd1c2c47f5c17590e11 | |
parent | 4595d9a3c98bfc759f4c3361adb20a9213ec610c (diff) |
* bignum.c (bary_sq_fast): Specialize the last iteration of the
outer loop.
(bigfixize): A condition simplified.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | bignum.c | 25 |
2 files changed, 26 insertions, 5 deletions
@@ -1,3 +1,9 @@ +Thu Jul 18 21:30:50 2013 Tanaka Akira <[email protected]> + + * 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 <[email protected]> * array.c (rb_ary_equal): compare RARRAY_PTR() for performance @@ -1605,7 +1605,11 @@ bary_sq_fast(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn) 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, BDIGIT *xds, size_t xn) 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) 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]; |