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

ruby-changes:29922

From: akr <ko1@a...>
Date: Mon, 15 Jul 2013 09:46:10 +0900 (JST)
Subject: [ruby-changes:29922] akr:r41974 (trunk): * bignum.c (power_cache_get_power): Use bitsize insteadof ceil_log2.

akr	2013-07-15 09:46:00 +0900 (Mon, 15 Jul 2013)

  New Revision: 41974

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

  Log:
    * bignum.c (power_cache_get_power): Use bitsize insteadof ceil_log2.
      (ones): Removed.
      (next_pow2): Removed.
      (floor_log2): Removed.
      (ceil_log2): Removed.
    
    * configure.in (__builtin_popcountl): Don't check.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/configure.in

Index: configure.in
===================================================================
--- configure.in	(revision 41973)
+++ configure.in	(revision 41974)
@@ -1847,7 +1847,6 @@ AC_CACHE_CHECK([for $1], AS_TR_SH(rb_cv_ https://github.com/ruby/ruby/blob/trunk/configure.in#L1847
 if test "${AS_TR_SH(rb_cv_builtin_$1)}" != no; then
   AC_DEFINE(AS_TR_CPP(HAVE_BUILTIN_$1))
 fi])
-RUBY_CHECK_BUILTIN_FUNC(__builtin_popcountl, [__builtin_popcountl(0)])
 RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap32, [__builtin_bswap32(0)])
 RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap64, [__builtin_bswap64(0)])
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41973)
+++ ChangeLog	(revision 41974)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul 15 09:39:07 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (power_cache_get_power): Use bitsize insteadof ceil_log2.
+	  (ones): Removed.
+	  (next_pow2): Removed.
+	  (floor_log2): Removed.
+	  (ceil_log2): Removed.
+
+	* configure.in (__builtin_popcountl): Don't check.
+
 Mon Jul 15 02:47:09 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* localeinit.c (rb_locale_charmap, Init_enc_set_filesystem_encoding):
Index: bignum.c
===================================================================
--- bignum.c	(revision 41973)
+++ bignum.c	(revision 41974)
@@ -3304,70 +3304,6 @@ big_rshift(VALUE x, unsigned long shift) https://github.com/ruby/ruby/blob/trunk/bignum.c#L3304
     return big_shift3(x, 0, s1, s2);
 }
 
-static inline int
-ones(register unsigned long x)
-{
-#ifdef HAVE_BUILTIN___BUILTIN_POPCOUNTL
-    return  __builtin_popcountl(x);
-#else
-#   if SIZEOF_LONG == 8
-#       define MASK_55 0x5555555555555555UL
-#       define MASK_33 0x3333333333333333UL
-#       define MASK_0f 0x0f0f0f0f0f0f0f0fUL
-#   else
-#       define MASK_55 0x55555555UL
-#       define MASK_33 0x33333333UL
-#       define MASK_0f 0x0f0f0f0fUL
-#   endif
-    x -= (x >> 1) & MASK_55;
-    x = ((x >> 2) & MASK_33) + (x & MASK_33);
-    x = ((x >> 4) + x) & MASK_0f;
-    x += (x >> 8);
-    x += (x >> 16);
-#   if SIZEOF_LONG == 8
-    x += (x >> 32);
-#   endif
-    return (int)(x & 0x7f);
-#   undef MASK_0f
-#   undef MASK_33
-#   undef MASK_55
-#endif
-}
-
-static inline unsigned long
-next_pow2(register unsigned long x)
-{
-    x |= x >> 1;
-    x |= x >> 2;
-    x |= x >> 4;
-    x |= x >> 8;
-    x |= x >> 16;
-#if SIZEOF_LONG == 8
-    x |= x >> 32;
-#endif
-    return x + 1;
-}
-
-static inline int
-floor_log2(register unsigned long x)
-{
-    x |= x >> 1;
-    x |= x >> 2;
-    x |= x >> 4;
-    x |= x >> 8;
-    x |= x >> 16;
-#if SIZEOF_LONG == 8
-    x |= x >> 32;
-#endif
-    return (int)ones(x) - 1;
-}
-
-static inline int
-ceil_log2(register unsigned long x)
-{
-    return floor_log2(x) + !POW2_P(x);
-}
-
 #define LOG2_KARATSUBA_DIGITS 7
 #define KARATSUBA_DIGITS (1L<<LOG2_KARATSUBA_DIGITS)
 #define MAX_BIG2STR_TABLE_ENTRIES 64
@@ -3407,7 +3343,7 @@ power_cache_get_power(int base, long n1, https://github.com/ruby/ruby/blob/trunk/bignum.c#L3343
     if (n1 <= KARATSUBA_DIGITS)
 	rb_bug("n1 > KARATSUBA_DIGITS");
 
-    m = ceil_log2(n1);
+    m = bitsize(n1-1); /* ceil(log2(n1)) */
     if (m1) *m1 = 1 << m;
     i = m - LOG2_KARATSUBA_DIGITS;
     if (i >= MAX_BIG2STR_TABLE_ENTRIES)

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

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