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

ruby-changes:29532

From: akr <ko1@a...>
Date: Sun, 23 Jun 2013 08:20:34 +0900 (JST)
Subject: [ruby-changes:29532] akr:r41584 (trunk): * bignum.c (integer_unpack_single_bdigit): Extracted from

akr	2013-06-23 08:20:22 +0900 (Sun, 23 Jun 2013)

  New Revision: 41584

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

  Log:
    * bignum.c (integer_unpack_single_bdigit): Extracted from
      bary_unpack_internal.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41583)
+++ ChangeLog	(revision 41584)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jun 23 08:19:27 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (integer_unpack_single_bdigit): Extracted from
+	  bary_unpack_internal.
+
 Sun Jun 23 07:41:52 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (bary_unpack_internal): Suppress warnings (C4146) on Visual Studio.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41583)
+++ bignum.c	(revision 41584)
@@ -1343,6 +1343,23 @@ integer_unpack_push_bits(int data, int n https://github.com/ruby/ruby/blob/trunk/bignum.c#L1343
 }
 
 static int
+integer_unpack_single_bdigit(BDIGIT u, size_t size, int flags, BDIGIT *dp)
+{
+    int sign;
+    if (flags & INTEGER_PACK_2COMP) {
+        sign = (flags & INTEGER_PACK_NEGATIVE) ?
+            ((size == SIZEOF_BDIGITS && u == 0) ? -2 : -1) :
+            ((u >> (size * CHAR_BIT - 1)) ? -1 : 1);
+        if (sign < 0)
+            u = ((BDIGIT)0) - (u | LSHIFTX((~(BDIGIT)0), size * CHAR_BIT));
+    }
+    else
+        sign = (flags & INTEGER_PACK_NEGATIVE) ? -1 : 1;
+    *dp = u;
+    return sign;
+}
+
+static int
 bary_unpack_internal(BDIGIT *bdigits, size_t num_bdigits, const void *words, size_t numwords, size_t wordsize, size_t nails, int flags, int nlp_bits)
 {
     int sign;
@@ -1359,64 +1376,24 @@ bary_unpack_internal(BDIGIT *bdigits, si https://github.com/ruby/ruby/blob/trunk/bignum.c#L1376
                 (flags & INTEGER_PACK_BYTEORDER_MASK) != INTEGER_PACK_NATIVE_BYTE_ORDER &&
                 ((flags & INTEGER_PACK_MSBYTE_FIRST) ? !HOST_BIGENDIAN_P : HOST_BIGENDIAN_P);
             if (wordsize == 1) {
-                BDIGIT u = *(uint8_t *)buf;
-                if (flags & INTEGER_PACK_2COMP) {
-                    sign = (flags & INTEGER_PACK_NEGATIVE) ?
-                        ((sizeof(uint8_t) == SIZEOF_BDIGITS && u == 0) ? -2 : -1) :
-                        ((u >> (sizeof(uint8_t) * CHAR_BIT - 1)) ? -1 : 1);
-                    if (sign < 0) u = ((BDIGIT)0) - (u | LSHIFTX((~(BDIGIT)0), sizeof(uint8_t) * CHAR_BIT));
-                }
-                else
-                    sign = (flags & INTEGER_PACK_NEGATIVE) ? -1 : 1;
-                *dp = u;
-                return sign;
+                return integer_unpack_single_bdigit(*(uint8_t *)buf, sizeof(uint8_t), flags, dp);
             }
 #if defined(HAVE_UINT16_T) && 2 <= SIZEOF_BDIGITS
             if (wordsize == 2 && (uintptr_t)words % ALIGNOF(uint16_t) == 0) {
                 BDIGIT u = *(uint16_t *)buf;
-                if (need_swap) u = swap16(u);
-                if (flags & INTEGER_PACK_2COMP) {
-                    sign = (flags & INTEGER_PACK_NEGATIVE) ?
-                        ((sizeof(uint16_t) == SIZEOF_BDIGITS && u == 0) ? -2 : -1) :
-                        ((u >> (sizeof(uint16_t) * CHAR_BIT - 1)) ? -1 : 1);
-                    if (sign < 0) u = ((BDIGIT)0) - (u | LSHIFTX((~(BDIGIT)0), sizeof(uint16_t) * CHAR_BIT));
-                }
-                else
-                    sign = (flags & INTEGER_PACK_NEGATIVE) ? -1 : 1;
-                *dp = u;
-                return sign;
+                return integer_unpack_single_bdigit(need_swap ? swap16(u) : u, sizeof(uint16_t), flags, dp);
             }
 #endif
 #if defined(HAVE_UINT32_T) && 4 <= SIZEOF_BDIGITS
             if (wordsize == 4 && (uintptr_t)words % ALIGNOF(uint32_t) == 0) {
                 BDIGIT u = *(uint32_t *)buf;
-                if (need_swap) u = swap32(u);
-                if (flags & INTEGER_PACK_2COMP) {
-                    sign = (flags & INTEGER_PACK_NEGATIVE) ?
-                        ((sizeof(uint32_t) == SIZEOF_BDIGITS && u == 0) ? -2 : -1) :
-                        ((u >> (sizeof(uint32_t) * CHAR_BIT - 1)) ? -1 : 1);
-                    if (sign < 0) u = ((BDIGIT)0) - (u | LSHIFTX((~(BDIGIT)0), sizeof(uint32_t) * CHAR_BIT));
-                }
-                else
-                    sign = (flags & INTEGER_PACK_NEGATIVE) ? -1 : 1;
-                *dp = u;
-                return sign;
+                return integer_unpack_single_bdigit(need_swap ? swap32(u) : u, sizeof(uint32_t), flags, dp);
             }
 #endif
 #if defined(HAVE_UINT64_T) && 8 <= SIZEOF_BDIGITS
             if (wordsize == 8 && (uintptr_t)words % ALIGNOF(uint64_t) == 0) {
                 BDIGIT u = *(uint64_t *)buf;
-                if (need_swap) u = swap64(u);
-                if (flags & INTEGER_PACK_2COMP) {
-                    sign = (flags & INTEGER_PACK_NEGATIVE) ?
-                        ((sizeof(uint64_t) == SIZEOF_BDIGITS && u == 0) ? -2 : -1) :
-                        ((u >> (sizeof(uint64_t) * CHAR_BIT - 1)) ? -1 : 1);
-                    if (sign < 0) u = ((BDIGIT)0) - (u | LSHIFTX((~(BDIGIT)0), sizeof(uint64_t) * CHAR_BIT));
-                }
-                else
-                    sign = (flags & INTEGER_PACK_NEGATIVE) ? -1 : 1;
-                *dp = u;
-                return sign;
+                return integer_unpack_single_bdigit(need_swap ? swap64(u) : u, sizeof(uint64_t), flags, dp);
             }
 #endif
         }

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

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