@@ -251,9 +251,11 @@ static unsigned long xdl_hash_record_with_whitespace(char const **data,
251251
252252#ifdef XDL_FAST_HASH
253253
254- #define ONEBYTES 0x0101010101010101ul
255- #define NEWLINEBYTES 0x0a0a0a0a0a0a0a0aul
256- #define HIGHBITS 0x8080808080808080ul
254+ #define REPEAT_BYTE (x ) ((~0ul / 0xff) * (x))
255+
256+ #define ONEBYTES REPEAT_BYTE(0x01)
257+ #define NEWLINEBYTES REPEAT_BYTE(0x0a)
258+ #define HIGHBITS REPEAT_BYTE(0x80)
257259
258260/* Return the high bit set in the first byte that is a zero */
259261static inline unsigned long has_zero (unsigned long a )
@@ -270,21 +272,19 @@ static inline long count_masked_bytes(unsigned long mask)
270272 * that works for the bytemasks without having to
271273 * mask them first.
272274 */
273- return mask * 0x0001020304050608 >> 56 ;
274- } else {
275275 /*
276- * Modified Carl Chatfield G+ version for 32-bit *
276+ * return mask * 0x0001020304050608 >> 56;
277277 *
278- * (a) gives us
279- * -1 (0, ff), 0 (ffff) or 1 (ffffff)
280- * (b) gives us
281- * 0 for 0, 1 for (ff ffff ffffff)
282- * (a+b+1) gives us
283- * correct 0-3 bytemask count result
278+ * Doing it like this avoids warnings on 32-bit machines.
284279 */
285- long a = (mask - 256 ) >> 23 ;
286- long b = mask & 1 ;
287- return a + b + 1 ;
280+ long a = (REPEAT_BYTE (0x01 ) / 0xff + 1 );
281+ return mask * a >> (sizeof (long ) * 7 );
282+ } else {
283+ /* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
284+ /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
285+ long a = (0x0ff0001 + mask ) >> 23 ;
286+ /* Fix the 1 for 00 case */
287+ return a & mask ;
288288 }
289289}
290290
0 commit comments