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

ruby-changes:30493

From: akr <ko1@a...>
Date: Fri, 16 Aug 2013 01:47:16 +0900 (JST)
Subject: [ruby-changes:30493] akr:r42572 (trunk): * bignum.c (bigdivrem_single): Use shift when y is a power of two.

akr	2013-08-16 01:47:08 +0900 (Fri, 16 Aug 2013)

  New Revision: 42572

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

  Log:
    * bignum.c (bigdivrem_single): Use shift when y is a power of two.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42571)
+++ ChangeLog	(revision 42572)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug 16 01:37:43 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (bigdivrem_single): Use shift when y is a power of two.
+
 Fri Aug 16 01:09:33 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (bigdivrem_restoring): Use bigdivrem_single if non-topmost
Index: bignum.c
===================================================================
--- bignum.c	(revision 42571)
+++ bignum.c	(revision 42572)
@@ -2683,16 +2683,25 @@ bigdivrem_num_extra_words(size_t xn, siz https://github.com/ruby/ruby/blob/trunk/bignum.c#L2683
 static BDIGIT
 bigdivrem_single(BDIGIT *qds, const BDIGIT *xds, size_t xn, BDIGIT y)
 {
-    size_t i;
-    BDIGIT_DBL t2;
-    t2 = 0;
-    i = xn;
-    while (i--) {
-        t2 = BIGUP(t2) + xds[i];
-        qds[i] = (BDIGIT)(t2 / y);
-        t2 %= y;
+    assert(0 < xn);
+    if (POW2_P(y)) {
+        BDIGIT r;
+        r = xds[0] & (y-1);
+        bary_small_rshift(qds, xds, xn, bitsize(y)-1, 0);
+        return r;
+    }
+    else {
+        size_t i;
+        BDIGIT_DBL t2;
+        t2 = 0;
+        i = xn;
+        while (i--) {
+            t2 = BIGUP(t2) + xds[i];
+            qds[i] = (BDIGIT)(t2 / y);
+            t2 %= y;
+        }
+        return (BDIGIT)t2;
     }
-    return (BDIGIT)t2;
 }
 
 static void

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

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