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

ruby-changes:29255

From: akr <ko1@a...>
Date: Sat, 15 Jun 2013 10:03:48 +0900 (JST)
Subject: [ruby-changes:29255] akr:r41307 (trunk): * bignum.c (bdigs_small_rshift): Extracted from big_rshift.

akr	2013-06-15 10:03:37 +0900 (Sat, 15 Jun 2013)

  New Revision: 41307

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

  Log:
    * bignum.c (bdigs_small_rshift): Extracted from big_rshift.
      (bigdivrem): Use bdigs_small_rshift.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41306)
+++ ChangeLog	(revision 41307)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 15 10:02:26 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (bdigs_small_rshift): Extracted from big_rshift.
+	  (bigdivrem): Use bdigs_small_rshift.
+
 Sat Jun 15 08:37:28 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_eval.c (eval_string_with_cref): propagate absolute path from the
Index: bignum.c
===================================================================
--- bignum.c	(revision 41306)
+++ bignum.c	(revision 41307)
@@ -52,6 +52,7 @@ static VALUE big_three = Qnil; https://github.com/ruby/ruby/blob/trunk/bignum.c#L52
 
 static int nlz(BDIGIT x);
 static BDIGIT bdigs_small_lshift(BDIGIT *zds, BDIGIT *xds, long n, int shift);
+static void bdigs_small_rshift(BDIGIT *zds, BDIGIT *xds, long n, int shift, int sign_bit);
 
 #define BIGNUM_DEBUG 0
 #if BIGNUM_DEBUG
@@ -3845,13 +3846,7 @@ bigdivrem(VALUE x, VALUE y, volatile VAL https://github.com/ruby/ruby/blob/trunk/bignum.c#L3846
     if (modp) {			/* normalize remainder */
 	while (ny > 1 && !zds[ny-1]) --ny;
 	if (dd) {
-	    t2 = 0; i = ny;
-	    while (i--) {
-		t2 = (t2 | zds[i]) >> dd;
-		q = zds[i];
-		zds[i] = BIGLO(t2);
-		t2 = BIGUP(q);
-	    }
+            bdigs_small_rshift(zds, zds, ny, dd, 0);
 	}
 	if (!zds[ny-1]) ny--;
 	*modp = zz = bignew(ny, RBIGNUM_SIGN(x));
@@ -4621,6 +4616,22 @@ rb_big_rshift(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4616
     return bignorm(x);
 }
 
+static void
+bdigs_small_rshift(BDIGIT *zds, BDIGIT *xds, long n, int shift, int sign_bit)
+{
+    BDIGIT_DBL num = 0;
+    BDIGIT x;
+    if (sign_bit) {
+	num = (~(BDIGIT_DBL)0) << BITSPERDIG;
+    }
+    while (n--) {
+	num = (num | xds[n]) >> shift;
+        x = xds[n];
+	zds[n] = BIGLO(num);
+	num = BIGUP(x);
+    }
+}
+
 static VALUE
 big_rshift(VALUE x, unsigned long shift)
 {
@@ -4628,7 +4639,6 @@ big_rshift(VALUE x, unsigned long shift) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4639
     long s1 = shift/BITSPERDIG;
     int s2 = (int)(shift%BITSPERDIG);
     VALUE z;
-    BDIGIT_DBL num = 0;
     long i, j;
     volatile VALUE save_x;
 
@@ -4650,15 +4660,8 @@ big_rshift(VALUE x, unsigned long shift) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4660
 	else return INT2FIX(-1);
     }
     z = bignew(j, RBIGNUM_SIGN(x));
-    if (!RBIGNUM_SIGN(x)) {
-	num = ((BDIGIT_DBL)~0) << BITSPERDIG;
-    }
     zds = BDIGITS(z);
-    while (i--, j--) {
-	num = (num | xds[i]) >> s2;
-	zds[j] = BIGLO(num);
-	num = BIGUP(xds[i]);
-    }
+    bdigs_small_rshift(zds, xds+s1, j, s2, !RBIGNUM_SIGN(x));
     if (!RBIGNUM_SIGN(x)) {
 	get2comp(z);
     }

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

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