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

ruby-changes:29394

From: akr <ko1@a...>
Date: Thu, 20 Jun 2013 01:37:26 +0900 (JST)
Subject: [ruby-changes:29394] akr:r41446 (trunk): * bignum.c (bdigit_roomof): Use SIZEOF_BDIGITS.

akr	2013-06-20 01:37:14 +0900 (Thu, 20 Jun 2013)

  New Revision: 41446

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

  Log:
    * bignum.c (bdigit_roomof): Use SIZEOF_BDIGITS.
      (bigfixize): Refine an ifdef condition.
      (rb_absint_size): Use bdigit_roomof.
      (rb_absint_singlebit_p): Ditto.
      (rb_integer_pack): Ditto.
      (integer_pack_fill_dd): Use BITSPERDIG.
      (integer_unpack_push_bits): Use BITSPERDIG, BIGLO and BIGDN.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41445)
+++ ChangeLog	(revision 41446)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jun 20 01:34:15 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (bdigit_roomof): Use SIZEOF_BDIGITS.
+	  (bigfixize): Refine an ifdef condition.
+	  (rb_absint_size): Use bdigit_roomof.
+	  (rb_absint_singlebit_p): Ditto.
+	  (rb_integer_pack): Ditto.
+	  (integer_pack_fill_dd): Use BITSPERDIG.
+	  (integer_unpack_push_bits): Use BITSPERDIG, BIGLO and BIGDN.
+
 Thu Jun 20 01:07:39 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* gc.c (MARKED_IN_BITMAP, FL_TEST2): return boolean value since always
Index: bignum.c
===================================================================
--- bignum.c	(revision 41445)
+++ bignum.c	(revision 41446)
@@ -54,7 +54,7 @@ static VALUE big_three = Qnil; https://github.com/ruby/ruby/blob/trunk/bignum.c#L54
 
 #define BIGDIVREM_EXTRA_WORDS 2
 #define roomof(n, m) ((int)(((n)+(m)-1) / (m)))
-#define bdigit_roomof(n) roomof(n, sizeof(BDIGIT))
+#define bdigit_roomof(n) roomof(n, SIZEOF_BDIGITS)
 #define BARY_ARGS(ary) ary, numberof(ary)
 
 #define BARY_ADD(z, x, y) bary_add(BARY_ARGS(z), BARY_ARGS(x), BARY_ARGS(y))
@@ -295,7 +295,7 @@ bigfixize(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L295
     if (len == 0) return INT2FIX(0);
     if (rb_absint_size(x, NULL) <= sizeof(long)) {
 	long num = 0;
-#if 2*SIZEOF_BDIGITS > SIZEOF_LONG
+#if SIZEOF_BDIGITS >= SIZEOF_LONG
 	num = (long)ds[0];
 #else
 	while (len--) {
@@ -542,7 +542,7 @@ rb_absint_size(VALUE val, int *nlz_bits_ https://github.com/ruby/ruby/blob/trunk/bignum.c#L542
 {
     BDIGIT *dp;
     BDIGIT *de;
-    BDIGIT fixbuf[(sizeof(long) + SIZEOF_BDIGITS - 1) / SIZEOF_BDIGITS];
+    BDIGIT fixbuf[bdigit_roomof(sizeof(long))];
 
     int num_leading_zeros;
 
@@ -707,7 +707,7 @@ rb_absint_singlebit_p(VALUE val) https://github.com/ruby/ruby/blob/trunk/bignum.c#L707
 {
     BDIGIT *dp;
     BDIGIT *de;
-    BDIGIT fixbuf[(sizeof(long) + SIZEOF_BDIGITS - 1) / SIZEOF_BDIGITS];
+    BDIGIT fixbuf[bdigit_roomof(sizeof(long))];
     BDIGIT d;
 
     val = rb_to_int(val);
@@ -857,9 +857,9 @@ integer_pack_loop_setup( https://github.com/ruby/ruby/blob/trunk/bignum.c#L857
 static inline void
 integer_pack_fill_dd(BDIGIT **dpp, BDIGIT **dep, BDIGIT_DBL *ddp, int *numbits_in_dd_p)
 {
-    if (*dpp < *dep && SIZEOF_BDIGITS * CHAR_BIT <= (int)sizeof(*ddp) * CHAR_BIT - *numbits_in_dd_p) {
+    if (*dpp < *dep && BITSPERDIG <= (int)sizeof(*ddp) * CHAR_BIT - *numbits_in_dd_p) {
         *ddp |= (BDIGIT_DBL)(*(*dpp)++) << *numbits_in_dd_p;
-        *numbits_in_dd_p += SIZEOF_BDIGITS * CHAR_BIT;
+        *numbits_in_dd_p += BITSPERDIG;
     }
     else if (*dpp == *dep) {
         /* higher bits are infinity zeros */
@@ -1112,7 +1112,7 @@ rb_integer_pack(VALUE val, void *words, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1112
     int sign;
     BDIGIT *ds;
     size_t num_bdigits;
-    BDIGIT fixbuf[(sizeof(long) + SIZEOF_BDIGITS - 1) / SIZEOF_BDIGITS];
+    BDIGIT fixbuf[bdigit_roomof(sizeof(long))];
 
     RB_GC_GUARD(val) = rb_to_int(val);
 
@@ -1245,10 +1245,10 @@ integer_unpack_push_bits(int data, int n https://github.com/ruby/ruby/blob/trunk/bignum.c#L1245
 {
     (*ddp) |= ((BDIGIT_DBL)data) << (*numbits_in_dd_p);
     *numbits_in_dd_p += numbits;
-    while (SIZEOF_BDIGITS*CHAR_BIT <= *numbits_in_dd_p) {
-        *(*dpp)++ = (BDIGIT)((*ddp) & (((BDIGIT_DBL)1 << (SIZEOF_BDIGITS*CHAR_BIT))-1));
-        *ddp >>= SIZEOF_BDIGITS*CHAR_BIT;
-        *numbits_in_dd_p -= SIZEOF_BDIGITS*CHAR_BIT;
+    while (BITSPERDIG <= *numbits_in_dd_p) {
+        *(*dpp)++ = BIGLO(*ddp);
+        *ddp = BIGDN(*ddp);
+        *numbits_in_dd_p -= BITSPERDIG;
     }
 }
 

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

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