Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 6f1af02

Browse files
trastgitster
authored andcommitted
xdiff: choose XDL_FAST_HASH code on sizeof(long) instead of __WORDSIZE
Darwin does not define __WORDSIZE, and compiles the 32-bit code path on 64-bit systems, resulting in a totally broken git. I could not find an alternative -- other than the platform symbols (__x86_64__ etc.) -- that does the test in the preprocessor. However, we can also just test for the size of a 'long', which is what really matters here. Any compiler worth its salt will leave only the branch relevant for its platform, and indeed on Linux/GCC the numbers don't change: Test tr/darwin-xdl-fast-hash origin/next origin/master ------------------------------------------------------------------------------------------------------------------ 4000.1: log -3000 (baseline) 0.09(0.07+0.01) 0.09(0.07+0.01) -5.5%* 0.09(0.07+0.01) -4.1% 4000.2: log --raw -3000 (tree-only) 0.47(0.41+0.05) 0.47(0.40+0.05) -0.5% 0.45(0.38+0.06) -3.5%. 4000.3: log -p -3000 (Myers) 1.81(1.67+0.12) 1.81(1.67+0.13) +0.3% 1.99(1.84+0.12) +10.2%*** 4000.4: log -p -3000 --histogram 1.79(1.66+0.11) 1.80(1.67+0.11) +0.4% 1.96(1.82+0.10) +9.2%*** 4000.5: log -p -3000 --patience 2.17(2.02+0.13) 2.20(2.04+0.13) +1.3%. 2.33(2.18+0.13) +7.4%*** ------------------------------------------------------------------------------------------------------------------ Significance hints: '.' 0.1 '*' 0.05 '**' 0.01 '***' 0.001 Noticed-by: Brian Gernhardt <[email protected]> Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6942efc commit 6f1af02

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

xdiff/xutils.c

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -290,39 +290,33 @@ static inline unsigned long has_zero(unsigned long a)
290290
return ((a - ONEBYTES) & ~a) & HIGHBITS;
291291
}
292292

293-
#if __WORDSIZE == 64
294-
295-
/*
296-
* Jan Achrenius on G+: microoptimized version of
297-
* the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
298-
* that works for the bytemasks without having to
299-
* mask them first.
300-
*/
301293
static inline long count_masked_bytes(unsigned long mask)
302294
{
303-
return mask * 0x0001020304050608 >> 56;
304-
}
305-
306-
#else /* 32-bit case */
307-
308-
/* Modified Carl Chatfield G+ version for 32-bit */
309-
static inline long count_masked_bytes(long mask)
310-
{
311-
/*
312-
* (a) gives us
313-
* -1 (0, ff), 0 (ffff) or 1 (ffffff)
314-
* (b) gives us
315-
* 0 for 0, 1 for (ff ffff ffffff)
316-
* (a+b+1) gives us
317-
* correct 0-3 bytemask count result
318-
*/
319-
long a = (mask - 256) >> 23;
320-
long b = mask & 1;
321-
return a + b + 1;
295+
if (sizeof(long) == 8) {
296+
/*
297+
* Jan Achrenius on G+: microoptimized version of
298+
* the simpler "(mask & ONEBYTES) * ONEBYTES >> 56"
299+
* that works for the bytemasks without having to
300+
* mask them first.
301+
*/
302+
return mask * 0x0001020304050608 >> 56;
303+
} else {
304+
/*
305+
* Modified Carl Chatfield G+ version for 32-bit *
306+
*
307+
* (a) gives us
308+
* -1 (0, ff), 0 (ffff) or 1 (ffffff)
309+
* (b) gives us
310+
* 0 for 0, 1 for (ff ffff ffffff)
311+
* (a+b+1) gives us
312+
* correct 0-3 bytemask count result
313+
*/
314+
long a = (mask - 256) >> 23;
315+
long b = mask & 1;
316+
return a + b + 1;
317+
}
322318
}
323319

324-
#endif
325-
326320
unsigned long xdl_hash_record(char const **data, char const *top, long flags)
327321
{
328322
unsigned long hash = 5381;

0 commit comments

Comments
 (0)