ruby-changes:29790
From: akr <ko1@a...>
Date: Tue, 9 Jul 2013 01:50:16 +0900 (JST)
Subject: [ruby-changes:29790] akr:r41842 (trunk): * bignum.c (biglsh_bang): Don't shift a BDIGIT with BITSPERDIG bits.
akr 2013-07-09 01:50:04 +0900 (Tue, 09 Jul 2013) New Revision: 41842 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41842 Log: * bignum.c (biglsh_bang): Don't shift a BDIGIT with BITSPERDIG bits. (bigrsh_bang): Ditto. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41841) +++ ChangeLog (revision 41842) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jul 9 01:47:16 2013 Tanaka Akira <akr@f...> + + * bignum.c (biglsh_bang): Don't shift a BDIGIT with BITSPERDIG bits. + (bigrsh_bang): Ditto. + Tue Jul 9 01:17:57 2013 Tanaka Akira <akr@f...> * bignum.c (bigrsh_bang): Fix bignum digits overrun. Index: bignum.c =================================================================== --- bignum.c (revision 41841) +++ bignum.c (revision 41842) @@ -4417,22 +4417,25 @@ biglsh_bang(BDIGIT *xds, long xn, unsign https://github.com/ruby/ruby/blob/trunk/bignum.c#L4417 int const s3 = BITSPERDIG-s2; BDIGIT* zds; BDIGIT num; - long i; if (s1 >= xn) { MEMZERO(xds, BDIGIT, xn); return; } - zds = xds + xn - 1; - xn -= s1 + 1; - num = BIGLO(xds[xn]<<s2); - while (0 < xn) { - *zds-- = num | xds[--xn]>>s3; - num = BIGLO(xds[xn]<<s2); - } - assert(xds <= zds); - *zds = num; - for (i = s1; i > 0; --i) - *zds-- = 0; + if (s2 == 0) { + MEMMOVE(xds + s1, xds, BDIGIT, xn - s1); + } + else { + zds = xds + xn - 1; + xn -= s1 + 1; + num = BIGLO(xds[xn]<<s2); + while (0 < xn) { + *zds-- = num | xds[--xn]>>s3; + num = BIGLO(xds[xn]<<s2); + } + assert(xds <= zds); + *zds = num; + } + MEMZERO(xds, BDIGIT, s1); } static void @@ -4448,16 +4451,20 @@ bigrsh_bang(BDIGIT* xds, long xn, unsign https://github.com/ruby/ruby/blob/trunk/bignum.c#L4451 MEMZERO(xds, BDIGIT, xn); return; } - - i = 0; - zds = xds + s1; - num = *zds++>>s2; - while (i < xn - s1 - 1) { - xds[i++] = BIGLO(*zds<<s3) | num; - num = *zds++>>s2; + if (s2 == 0) { + MEMMOVE(xds, xds + s1, BDIGIT, xn - s1); + } + else { + i = 0; + zds = xds + s1; + num = *zds++>>s2; + while (i < xn - s1 - 1) { + xds[i++] = BIGLO(*zds<<s3) | num; + num = *zds++>>s2; + } + assert(i < xn); + xds[i] = num; } - assert(i < xn); - xds[i] = num; MEMZERO(xds + xn - s1, BDIGIT, s1); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/