[前][次][番号順一覧][スレッド一覧]

ruby-changes:29027

From: akr <ko1@a...>
Date: Wed, 5 Jun 2013 08:15:42 +0900 (JST)
Subject: [ruby-changes:29027] akr:r41079 (trunk): * bignum.c (rb_big_pow): Don't need to multiply SIZEOF_BDIGITS.

akr	2013-06-05 08:15:30 +0900 (Wed, 05 Jun 2013)

  New Revision: 41079

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41079

  Log:
    * bignum.c (rb_big_pow): Don't need to multiply SIZEOF_BDIGITS.
      Use nlz instead of bitlength_bdigit.
      (bitlength_bdigit): Removed.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41078)
+++ ChangeLog	(revision 41079)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun  5 08:13:37 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (rb_big_pow): Don't need to multiply SIZEOF_BDIGITS.
+	  Use nlz instead of bitlength_bdigit.
+	  (bitlength_bdigit): Removed.
+
 Wed Jun  5 07:14:18 2013  Tadayoshi Funaba  <tadf@d...>
 
 	* ext/date/date_core.c (d_lite_cmp, d_lite_equal): simplified.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41078)
+++ bignum.c	(revision 41079)
@@ -3178,24 +3178,6 @@ bigsqr(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L3178
     return bigtrunc(bigmul0(x, x));
 }
 
-static int
-bitlength_bdigit(BDIGIT v)
-{
-    if (v == 0)
-        return 0;
-    v |= v >> 1;
-    v |= v >> 2;
-    v |= v >> 4;
-    v |= v >> 8;
-#if 2 < SIZEOF_BDIGITS
-    v |= v >> 16;
-#endif
-    v++;
-    if (v == 0)
-        return SIZEOF_BDIGITS*CHAR_BIT;
-    return ffs(v)-1; /* assumption: sizeof(BDIGIT) <= sizeof(int) */
-}
-
 /*
  *  call-seq:
  *     big ** exponent   -> numeric
@@ -3236,8 +3218,8 @@ rb_big_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L3218
 	else {
 	    VALUE z = 0;
 	    SIGNED_VALUE mask;
-	    const long xlen = RBIGNUM_LEN(x) - 1;
-	    const long xbits = bitlength_bdigit(RBIGNUM_DIGITS(x)[xlen]) + SIZEOF_BDIGITS*BITSPERDIG*xlen;
+	    const long xlen = RBIGNUM_LEN(x);
+            const long xbits = BITSPERDIG*xlen - nlz(RBIGNUM_DIGITS(x)[xlen-1]);
 	    const long BIGLEN_LIMIT = BITSPERDIG*1024*1024;
 
 	    if ((xbits > BIGLEN_LIMIT) || (xbits * yy > BIGLEN_LIMIT)) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]