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

ruby-changes:30167

From: akr <ko1@a...>
Date: Mon, 29 Jul 2013 00:14:35 +0900 (JST)
Subject: [ruby-changes:30167] akr:r42218 (trunk): * bignum.c (bigdivrem): Specialized implementation added for

akr	2013-07-29 00:14:20 +0900 (Mon, 29 Jul 2013)

  New Revision: 42218

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

  Log:
    * bignum.c (bigdivrem): Specialized implementation added for
      nx == 2 && ny == 2

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42217)
+++ ChangeLog	(revision 42218)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul 29 00:11:49 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (bigdivrem): Specialized implementation added for
+	  nx == 2 && ny == 2
+
 Sun Jul 28 20:28:41 2013  Masaki Matsushita  <glass.saga@g...>
 
 	* io.c (io_getpartial): use rb_str_locktmp_ensure().
Index: bignum.c
===================================================================
--- bignum.c	(revision 42217)
+++ bignum.c	(revision 42218)
@@ -5399,6 +5399,27 @@ bigdivrem(VALUE x, VALUE y, volatile VAL https://github.com/ruby/ruby/blob/trunk/bignum.c#L5399
 	if (divp) *divp = z;
 	return Qnil;
     }
+    if (nx == 2 && ny == 2) {
+        BDIGIT_DBL x0 = xds[0] | BIGUP(xds[1]);
+        BDIGIT_DBL y0 = yds[0] | BIGUP(yds[1]);
+        BDIGIT_DBL q0 = x0 / y0;
+        BDIGIT_DBL r0 = x0 % y0;
+        if (divp) {
+            z = bignew(bdigit_roomof(sizeof(BDIGIT_DBL)), RBIGNUM_SIGN(x)==RBIGNUM_SIGN(y));
+            zds = BDIGITS(z);
+            zds[0] = BIGLO(q0);
+            zds[1] = BIGLO(BIGDN(q0));
+            *divp = z;
+        }
+        if (modp) {
+            z = bignew(bdigit_roomof(sizeof(BDIGIT_DBL)), RBIGNUM_SIGN(x));
+            zds = BDIGITS(z);
+            zds[0] = BIGLO(r0);
+            zds[1] = BIGLO(BIGDN(r0));
+            *modp = z;
+        }
+        return Qnil;
+    }
 
     if (BDIGIT_MSB(yds[ny-1]) == 0) {
         /* Make yds modifiable. */

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

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