From: Junio C Hamano Date: Fri, 25 May 2012 19:05:02 +0000 (-0700) Subject: Merge branch 'rs/xdiff-fast-hash-fix' X-Git-Tag: v1.7.11-rc0~9 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/0bc8bea2b4d73b20ce418b88300f498396d0a924?ds=inline;hp=-c Merge branch 'rs/xdiff-fast-hash-fix' Fixes compilation issue on 32-bit in an earlier series. --- 0bc8bea2b4d73b20ce418b88300f498396d0a924 diff --combined xdiff/xutils.c index ae6ce0d95c,179bc4fe04..9504eaecb8 --- a/xdiff/xutils.c +++ b/xdiff/xutils.c @@@ -122,6 -122,35 +122,6 @@@ void *xdl_cha_alloc(chastore_t *cha) return data; } - -void *xdl_cha_first(chastore_t *cha) { - chanode_t *sncur; - - if (!(cha->sncur = sncur = cha->head)) - return NULL; - - cha->scurr = 0; - - return (char *) sncur + sizeof(chanode_t) + cha->scurr; -} - - -void *xdl_cha_next(chastore_t *cha) { - chanode_t *sncur; - - if (!(sncur = cha->sncur)) - return NULL; - cha->scurr += cha->isize; - if (cha->scurr == sncur->icurr) { - if (!(sncur = cha->sncur = sncur->next)) - return NULL; - cha->scurr = 0; - } - - return (char *) sncur + sizeof(chanode_t) + cha->scurr; -} - - long xdl_guess_lines(mmfile_t *mf, long sample) { long nl = 0, size, tsize = 0; char const *data, *cur, *top; @@@ -251,9 -280,11 +251,11 @@@ static unsigned long xdl_hash_record_wi #ifdef XDL_FAST_HASH - #define ONEBYTES 0x0101010101010101ul - #define NEWLINEBYTES 0x0a0a0a0a0a0a0a0aul - #define HIGHBITS 0x8080808080808080ul + #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x)) + + #define ONEBYTES REPEAT_BYTE(0x01) + #define NEWLINEBYTES REPEAT_BYTE(0x0a) + #define HIGHBITS REPEAT_BYTE(0x80) /* Return the high bit set in the first byte that is a zero */ static inline unsigned long has_zero(unsigned long a) @@@ -270,21 -301,19 +272,19 @@@ static inline long count_masked_bytes(u * that works for the bytemasks without having to * mask them first. */ - return mask * 0x0001020304050608 >> 56; - } else { /* - * Modified Carl Chatfield G+ version for 32-bit * + * return mask * 0x0001020304050608 >> 56; * - * (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 + * Doing it like this avoids warnings on 32-bit machines. */ - long a = (mask - 256) >> 23; - long b = mask & 1; - return a + b + 1; + long a = (REPEAT_BYTE(0x01) / 0xff + 1); + return mask * a >> (sizeof(long) * 7); + } else { + /* Carl Chatfield / Jan Achrenius G+ version for 32-bit */ + /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */ + long a = (0x0ff0001 + mask) >> 23; + /* Fix the 1 for 00 case */ + return a & mask; } } @@@ -401,6 -430,20 +401,6 @@@ int xdl_num_out(char *out, long val) return str - out; } - -long xdl_atol(char const *str, char const **next) { - long val, base; - char const *top; - - for (top = str; XDL_ISDIGIT(*top); top++); - if (next) - *next = top; - for (val = 0, base = 1, top--; top >= str; top--, base *= 10) - val += base * (long)(*top - '0'); - return val; -} - - int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, const char *func, long funclen, xdemitcb_t *ecb) { int nb = 0;