Re: XDL_FAST_HASH breaks git on OS X 10.7.3

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: XDL_FAST_HASH breaks git on OS X 10.7.3

From: Thomas Rast <hidden>
Date: 2016-06-15 22:53:41

Hi Brian

I can reproduce this.  The problem is that __WORDSIZE is not defined,
either because it's Darwin or because the GCC is too old.  It winds up
compiling the 32-bit case, which of course doesn't work for 64-bit
builds.

Perhaps we can rewrite it in terms of sizeof(long) like this?
diff --git i/xdiff/xutils.c w/xdiff/xutils.c
index e05b5c9..1b3b471 100644
--- i/xdiff/xutils.c
+++ w/xdiff/xutils.c
@@ -290,39 +290,33 @@ static inline unsigned long has_zero(unsigned long a)
 	return ((a - ONEBYTES) & ~a) & HIGHBITS;
 }
 
-#if __WORDSIZE == 64
-
-/*
- * Jan Achrenius on G+: microoptimized version of
- * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
- * that works for the bytemasks without having to
- * mask them first.
- */
 static inline long count_masked_bytes(unsigned long mask)
 {
-	return mask * 0x0001020304050608 >> 56;
-}
-
-#else	/* 32-bit case */
-
-/* Modified Carl Chatfield G+ version for 32-bit */
-static inline long count_masked_bytes(long mask)
-{
-	/*
-	 * (a) gives us
-	 *   -1 (0, ff), 0 (ffff) or 1 (ffffff)
-	 * (b) gives us
-	 *   0 for 0, 1 for (ff ffff ffffff)
-	 * (a+b+1) gives us
-	 *   correct 0-3 bytemask count result
-	 */
-	long a = (mask - 256) >> 23;
-	long b = mask & 1;
-	return a + b + 1;
+	if (sizeof(long) == 8) {
+		/*
+		 * Jan Achrenius on G+: microoptimized version of
+		 * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
+		 * that works for the bytemasks without having to
+		 * mask them first.
+		 */
+		return mask * 0x0001020304050608 >> 56;
+	} else {
+		/*
+		 * Modified Carl Chatfield G+ version for 32-bit *
+		 *
+		 * (a) gives us
+		 *   -1 (0, ff), 0 (ffff) or 1 (ffffff)
+		 * (b) gives us
+		 *   0 for 0, 1 for (ff ffff ffffff)
+		 * (a+b+1) gives us
+		 *   correct 0-3 bytemask count result
+		 */
+		long a = (mask - 256) >> 23;
+		long b = mask & 1;
+		return a + b + 1;
+	}
 }
 
-#endif
-
 unsigned long xdl_hash_record(char const **data, char const *top, long flags)
 {
 	unsigned long hash = 5381;
-- 
Thomas Rast
trast@{inf,student}.ethz.ch

Re: XDL_FAST_HASH breaks git on OS X 10.7.3

From: Brian Gernhardt <hidden>
Date: 2016-06-15 22:53:42

On Apr 30, 2012, at 12:38 PM, Thomas Rast wrote:
I can reproduce this.  The problem is that __WORDSIZE is not defined,
either because it's Darwin or because the GCC is too old.  It winds up
compiling the 32-bit case, which of course doesn't work for 64-bit
builds.
Great.  I was worried about having to help you debug it via e-mail round-trips.  :-D
Perhaps we can rewrite it in terms of sizeof(long) like this?
It does work for me, and seems pretty valid to me since long is actually the type you're storing it in.

~~ Brian G.

Re: XDL_FAST_HASH breaks git on OS X 10.7.3

From: David Aguilar <hidden>
Date: 2016-06-15 22:53:42

On Mon, Apr 30, 2012 at 9:38 AM, Thomas Rast [off-list ref] wrote:
quoted hunk
Hi Brian

I can reproduce this.  The problem is that __WORDSIZE is not defined,
either because it's Darwin or because the GCC is too old.  It winds up
compiling the 32-bit case, which of course doesn't work for 64-bit
builds.

Perhaps we can rewrite it in terms of sizeof(long) like this?
diff --git i/xdiff/xutils.c w/xdiff/xutils.c
index e05b5c9..1b3b471 100644
--- i/xdiff/xutils.c
+++ w/xdiff/xutils.c
@@ -290,39 +290,33 @@ static inline unsigned long has_zero(unsigned long a)
       return ((a - ONEBYTES) & ~a) & HIGHBITS;
 }

-#if __WORDSIZE == 64
-
-/*
- * Jan Achrenius on G+: microoptimized version of
- * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
- * that works for the bytemasks without having to
- * mask them first.
- */
 static inline long count_masked_bytes(unsigned long mask)
 {
-       return mask * 0x0001020304050608 >> 56;
-}
-
-#else  /* 32-bit case */
-
-/* Modified Carl Chatfield G+ version for 32-bit */
-static inline long count_masked_bytes(long mask)
-{
-       /*
-        * (a) gives us
-        *   -1 (0, ff), 0 (ffff) or 1 (ffffff)
-        * (b) gives us
-        *   0 for 0, 1 for (ff ffff ffffff)
-        * (a+b+1) gives us
-        *   correct 0-3 bytemask count result
-        */
-       long a = (mask - 256) >> 23;
-       long b = mask & 1;
-       return a + b + 1;
+       if (sizeof(long) == 8) {

Isn't the whole point of this code to be fast?

This should be a compile-time check... conditionals hurt perf.
-- 
David
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help