[#15707] Schedule for the 1.8.7 release — "Akinori MUSHA" <knu@...>

Hi, developers,

21 messages 2008/03/01

[#15740] Copy-on-write friendly garbage collector — Hongli Lai <hongli@...99.net>

Hi.

31 messages 2008/03/03
[#15742] Re: Copy-on-write friendly garbage collector — Yukihiro Matsumoto <matz@...> 2008/03/03

Hi,

[#15829] Re: Copy-on-write friendly garbage collector — Daniel DeLorme <dan-ml@...42.com> 2008/03/08

Yukihiro Matsumoto wrote:

[#15756] embedding Ruby 1.9.0 inside pthread — "Suraj Kurapati" <sunaku@...>

Hello,

18 messages 2008/03/03
[#15759] Re: embedding Ruby 1.9.0 inside pthread — Nobuyoshi Nakada <nobu@...> 2008/03/04

Hi,

[#15760] Re: embedding Ruby 1.9.0 inside pthread — Yukihiro Matsumoto <matz@...> 2008/03/04

Hi,

[#15762] Re: embedding Ruby 1.9.0 inside pthread — "Suraj N. Kurapati" <sunaku@...> 2008/03/04

Yukihiro Matsumoto wrote:

[#15783] Adding startup and shutdown to Test::Unit — Daniel Berger <Daniel.Berger@...>

Hi all,

15 messages 2008/03/04

[#15835] TimeoutError in core, timeouts for ConditionVariable#wait — MenTaLguY <mental@...>

I've been reworking JRuby's stdlib to improve performance and fix

10 messages 2008/03/09

[#15990] Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...>

Hi,

35 messages 2008/03/23
[#15991] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/23

[#15993] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/23

Hi Dave,

[#15997] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/23

[#16024] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/26

Hi Dave,

[#16025] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16026] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16027] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16029] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16030] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16031] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16032] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/26

On Wed, Mar 26, 2008 at 7:01 PM, Dave Thomas <dave@pragprog.com> wrote:

[#16033] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16041] Re: Recent changes in Range#step behavior — David Flanagan <david@...> 2008/03/26

Dave Thomas wrote:

Re: Copy-on-write friendly garbage collector

From: Hongli Lai <hongli@...99.net>
Date: 2008-03-15 16:15:10 UTC
List: ruby-core #15913
Hongli Lai wrote:
> Great work Daniel. I don't measure the same amount of speedup that you 
> claim in your email, but there is definitely a small speedup.
> 
> I've added some further further optimizations. 
> find_position_in_bitfield() now uses bit operators instead of division 
> and modulo operators. This should speed things up a little more.
> 
> The attached patch is created against Ruby 1.8, but it shows what I've 
> exactly changed.

I've been such a fool. The patch I sent uses platform-specific macros to 
figure out the base 2 log of sizeof(int)*8.

Here is a new patch, which uses straight C code to figure out that 
value. There is no performance overhead because the code is easily 
optimizable by the compiler, and is a lot more portable.

Attachments (1)

diff --git a/marktable.c b/marktable.c
index 84f88fe..5890835 100644
--- a/marktable.c
+++ b/marktable.c
@@ -51,20 +51,30 @@ find_position_in_bitfield(struct heaps_slot *hs, RVALUE *object,
 	 * We use bit operators to calculate the position in the bit field, whenever possible.
 	 * This only works if sizeof(int) is a multiple of 2, but I don't know of any platform
 	 * on which that is not true.
-	 *
-	 * The INT_BITS_LOG macro's value must be equal to the base 2 logarithm of sizeof(int).
 	 */
-	#ifdef __i386__
-		#define INT_BITS_LOG 5
-	#endif
-	
-	#ifdef INT_BITS_LOG
-		*bitfield_index = index >> INT_BITS_LOG;
-		*bitfield_offset = index & ((1 << INT_BITS_LOG) - 1);
-	#else
+	if (sizeof(int) == 4 || sizeof(int) == 8 || sizeof(int) == 16) {
+		int int_bits_log; /* Must be equal to the base 2 logarithm of sizeof(int) * 8 */
+		
+		switch (sizeof(int)) {
+		case 4:
+			int_bits_log = 5;
+			break;
+		case 8:
+			int_bits_log = 6;
+			break;
+		case 16:
+			int_bits_log = 7;
+			break;
+		default:
+			int_bits_log = 0; /* Shut up compiler warning. */
+			abort();
+		}
+		*bitfield_index = index >> int_bits_log;
+		*bitfield_offset = index & ((sizeof(int) * 8) - 1);
+	} else {
 		*bitfield_index = index / (sizeof(int) * 8);
 		*bitfield_offset = index % (sizeof(int) * 8);
-	#endif
+	}
 }
 
 

In This Thread