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

ruby-changes:35685

From: normal <ko1@a...>
Date: Fri, 3 Oct 2014 06:17:19 +0900 (JST)
Subject: [ruby-changes:35685] normal:r47767 (trunk): st.c (new_size): use next_pow2 function

normal	2014-10-03 06:17:13 +0900 (Fri, 03 Oct 2014)

  New Revision: 47767

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

  Log:
    st.c (new_size): use next_pow2 function
    
    Reduces object size slightly on x86-64:
    
       text	   data	    bss	    dec	    hex	filename
    2782359	  22400	  71880	2876639	 2be4df	ruby.orig
    2781831	  22400	  71880	2876111	 2be2cf	ruby.pow2
    
    And on 32-bit x86:
    
       text	   data	    bss	    dec	    hex	filename
    2814751	  12100	  30552	2857403	 2b99bb	ruby.orig
    2814051	  12100	  30552	2856703	 2b96ff	ruby.pow2
    
    This is not a performance-critical function, but the
    smaller icache footprint seems worth it.

  Modified files:
    trunk/ChangeLog
    trunk/st.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47766)
+++ ChangeLog	(revision 47767)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct  3 06:06:28 2014  Eric Wong  <e@8...>
+
+	* st.c (next_pow2): new function (from old bignum.c)
+	  (new_size): use next_pow2 function
+
 Fri Oct  3 05:58:58 2014  Eric Wong  <e@8...>
 
 	* vm_trace.c (rb_tp_t): pack 56 => 48 bytes on 64-bit
Index: st.c
===================================================================
--- st.c	(revision 47766)
+++ st.c	(revision 47767)
@@ -141,13 +141,30 @@ remove_safe_packed_entry(st_table *table https://github.com/ruby/ruby/blob/trunk/st.c#L141
 }
 
 static st_index_t
+next_pow2(st_index_t x)
+{
+    x |= x >> 1;
+    x |= x >> 2;
+    x |= x >> 4;
+    x |= x >> 8;
+    x |= x >> 16;
+#if SIZEOF_ST_INDEX_T == 8
+    x |= x >> 32;
+#endif
+    return x + 1;
+}
+
+static st_index_t
 new_size(st_index_t size)
 {
-    st_index_t i;
+    st_index_t n;
+
+    if (size && (size & ~(size - 1)) == size) /* already a power-of-two? */
+	return size;
 
-    for (i=3; i<31; i++) {
-	if ((st_index_t)(1<<i) > size) return 1<<i;
-    }
+    n = next_pow2(size);
+    if (n > size)
+	return n;
 #ifndef NOT_RUBY
     rb_raise(rb_eRuntimeError, "st_table too big");
 #endif

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

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