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

ruby-changes:30497

From: akr <ko1@a...>
Date: Fri, 16 Aug 2013 10:11:24 +0900 (JST)
Subject: [ruby-changes:30497] akr:r42576 (trunk): * bignum.c (bigdivrem_single1): Renamed from bigdivrem_single. Add

akr	2013-08-16 10:11:18 +0900 (Fri, 16 Aug 2013)

  New Revision: 42576

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

  Log:
    * bignum.c (bigdivrem_single1): Renamed from bigdivrem_single.  Add
      x_higher_bdigit argument.
      (bigdivrem_single): Just call bigdivrem_single1.
      (bigdivrem_restoring): Use bigdivrem_single1 to avoid memmove.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42575)
+++ ChangeLog	(revision 42576)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug 16 10:07:59 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (bigdivrem_single1): Renamed from bigdivrem_single.  Add
+	  x_higher_bdigit argument.
+	  (bigdivrem_single): Just call bigdivrem_single1.
+	  (bigdivrem_restoring): Use bigdivrem_single1 to avoid memmove.
+
 Fri Aug 16 09:17:00 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (bary_small_rshift): Specify the higher BDIGIT instead of
Index: bignum.c
===================================================================
--- bignum.c	(revision 42575)
+++ bignum.c	(revision 42576)
@@ -2677,19 +2677,20 @@ bigdivrem_num_extra_words(size_t xn, siz https://github.com/ruby/ruby/blob/trunk/bignum.c#L2677
 }
 
 static BDIGIT
-bigdivrem_single(BDIGIT *qds, const BDIGIT *xds, size_t xn, BDIGIT y)
+bigdivrem_single1(BDIGIT *qds, const BDIGIT *xds, size_t xn, BDIGIT x_higher_bdigit, BDIGIT y)
 {
     assert(0 < xn);
+    assert(x_higher_bdigit < y);
     if (POW2_P(y)) {
         BDIGIT r;
         r = xds[0] & (y-1);
-        bary_small_rshift(qds, xds, xn, bitsize(y)-1, 0);
+        bary_small_rshift(qds, xds, xn, bitsize(y)-1, x_higher_bdigit);
         return r;
     }
     else {
         size_t i;
         BDIGIT_DBL t2;
-        t2 = 0;
+        t2 = x_higher_bdigit;
         i = xn;
         while (i--) {
             t2 = BIGUP(t2) + xds[i];
@@ -2700,6 +2701,12 @@ bigdivrem_single(BDIGIT *qds, const BDIG https://github.com/ruby/ruby/blob/trunk/bignum.c#L2701
     }
 }
 
+static BDIGIT
+bigdivrem_single(BDIGIT *qds, const BDIGIT *xds, size_t xn, BDIGIT y)
+{
+    return bigdivrem_single1(qds, xds, xn, 0, y);
+}
+
 static void
 bigdivrem_restoring(BDIGIT *zds, size_t zn, BDIGIT *yds, size_t yn)
 {
@@ -2707,15 +2714,14 @@ bigdivrem_restoring(BDIGIT *zds, size_t https://github.com/ruby/ruby/blob/trunk/bignum.c#L2714
     size_t ynzero;
 
     assert(BDIGIT_MSB(yds[yn-1]));
+    assert(zds[zn-1] < yds[yn-1]);
 
     for (ynzero = 0; !yds[ynzero]; ynzero++);
 
     if (ynzero+1 == yn) {
         BDIGIT r;
-        r = bigdivrem_single(zds+ynzero, zds+ynzero, zn-ynzero, yds[yn-1]);
-        assert(zds[zn-1] == 0);
-        MEMMOVE(zds+yn, zds+yn-1, BDIGIT, zn - yn);
-        zds[yn-1] = r;
+        r = bigdivrem_single1(zds+yn, zds+ynzero, zn-yn, zds[zn-1], yds[ynzero]);
+        zds[ynzero] = r;
         return;
     }
 

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

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