fast fallback for the case where xxHash libraries are not available at
build time.
-based-on: 9dd99521381e022d81528696ca2457e17727200b
+based-on: d47a80c05ecb2d4e8356697e3f71c219a639fecc
diff --git a/Makefile.in b/Makefile.in
--- a/Makefile.in
+++ b/Makefile.in
diff --git a/checksum.c b/checksum.c
--- a/checksum.c
+++ b/checksum.c
-@@ -45,6 +45,7 @@ extern const char *checksum_choice;
- #define CSUM_MD4 4
- #define CSUM_MD5 5
- #define CSUM_XXH64 6
-+#define CSUM_MD5P8 7
-
- struct name_num_obj valid_checksums = {
- "checksum", NULL, NULL, 0, 0, {
-@@ -52,6 +53,7 @@ struct name_num_obj valid_checksums = {
+@@ -44,6 +44,7 @@ struct name_num_obj valid_checksums = {
{ CSUM_XXH64, "xxh64", NULL },
{ CSUM_XXH64, "xxhash", NULL },
#endif
{ CSUM_MD5, "md5", NULL },
{ CSUM_MD4, "md4", NULL },
{ CSUM_NONE, "none", NULL },
-@@ -139,6 +141,7 @@ int csum_len_for_type(int cst, BOOL flist_csum)
+@@ -131,6 +132,7 @@ int csum_len_for_type(int cst, BOOL flist_csum)
case CSUM_MD4_OLD:
case CSUM_MD4_BUSTED:
return MD4_DIGEST_LEN;
case CSUM_MD5:
return MD5_DIGEST_LEN;
#ifdef SUPPORT_XXHASH
-@@ -164,6 +167,7 @@ int canonical_checksum(int csum_type)
+@@ -156,6 +158,7 @@ int canonical_checksum(int csum_type)
case CSUM_MD4_BUSTED:
break;
case CSUM_MD4:
case CSUM_MD5:
return -1;
#ifdef SUPPORT_XXHASH
-@@ -197,9 +201,19 @@ uint32 get_checksum1(char *buf1, int32 len)
+@@ -168,7 +171,9 @@ int canonical_checksum(int csum_type)
+ return 0;
+ }
+
+-#ifndef HAVE_SIMD /* See simd-checksum-*.cpp. */
++#ifdef HAVE_SIMD /* See simd-checksum-*.cpp. */
++#define get_checksum2 get_checksum2_nosimd
++#else
+ /*
+ a simple 32 bit checksum that can be updated from either end
+ (inspired by Mark Adler's Adler-32 checksum)
+@@ -189,9 +194,18 @@ uint32 get_checksum1(char *buf1, int32 len)
}
return (s1 & 0xffff) + (s2 << 16);
}
+void checksum2_disable_prefetch()
+{
+}
-+
-+void get_checksum2(char *buf, int32 len, char *sum, UNUSED(OFF_T prefetch_offset))
-+#else
-+void get_checksum2_nosimd(char *buf, int32 len, char *sum, UNUSED(OFF_T prefetch_offset))
#endif
--
+
-void get_checksum2(char *buf, int32 len, char *sum)
++/* Renamed to get_checksum2_nosimd() with HAVE_SIMD */
++void get_checksum2(char *buf, int32 len, char *sum, UNUSED(OFF_T prefetch_offset))
{
switch (xfersum_type) {
#ifdef SUPPORT_XXHASH
-@@ -207,6 +221,7 @@ void get_checksum2(char *buf, int32 len, char *sum)
+@@ -199,6 +213,7 @@ void get_checksum2(char *buf, int32 len, char *sum)
SIVAL64(sum, 0, XXH64(buf, len, checksum_seed));
break;
#endif
case CSUM_MD5: {
MD5_CTX m5;
uchar seedbuf[4];
-@@ -322,6 +337,21 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
+@@ -314,6 +329,21 @@ void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
break;
}
#endif
case CSUM_MD5: {
MD5_CTX m5;
-@@ -397,6 +427,7 @@ static union {
+@@ -389,6 +419,7 @@ static union {
#ifdef SUPPORT_XXHASH
static XXH64_state_t* xxh64_state;
#endif
static int cursum_type;
void sum_init(int csum_type, int seed)
-@@ -415,6 +446,9 @@ void sum_init(int csum_type, int seed)
+@@ -407,6 +438,9 @@ void sum_init(int csum_type, int seed)
XXH64_reset(xxh64_state, 0);
break;
#endif
case CSUM_MD5:
MD5_Init(&ctx.m5);
break;
-@@ -457,6 +491,9 @@ void sum_update(const char *p, int32 len)
+@@ -449,6 +483,9 @@ void sum_update(const char *p, int32 len)
XXH64_update(xxh64_state, p, len);
break;
#endif
case CSUM_MD5:
MD5_Update(&ctx.m5, (uchar *)p, len);
break;
-@@ -511,6 +548,9 @@ int sum_end(char *sum)
+@@ -503,6 +540,9 @@ int sum_end(char *sum)
SIVAL64(sum, 0, XXH64_digest(xxh64_state));
break;
#endif
diff --git a/lib/mdigest.h b/lib/mdigest.h
--- a/lib/mdigest.h
+++ b/lib/mdigest.h
-@@ -32,3 +32,14 @@ void md5_begin(md_context *ctx);
+@@ -18,6 +18,7 @@
+ #define CSUM_MD4 4
+ #define CSUM_MD5 5
+ #define CSUM_XXH64 6
++#define CSUM_MD5P8 7
+
+ typedef struct {
+ uint32 A, B, C, D;
+@@ -40,3 +41,14 @@ void md5_begin(md_context *ctx);
void md5_update(md_context *ctx, const uchar *input, uint32 length);
void md5_result(md_context *ctx, uchar digest[MD5_DIGEST_LEN]);
#endif
*/
#ifdef __x86_64__
-@@ -423,6 +439,176 @@ uint32 get_checksum1(char *buf1, int32 len)
+@@ -423,6 +439,171 @@ uint32 get_checksum1(char *buf1, int32 len)
return (s1 & 0xffff) + (s2 << 16);
}
-+#define PREFETCH_ENABLE // debugging
++#define PREFETCH_ENABLE 1 // debugging
+
+#if 0 // debugging
+#define PREFETCH_PRINTF(f_, ...) printf((f_), ##__VA_ARGS__)
+
+#define PREFETCH_MIN_LEN 1024 // the overhead is unlikely to be worth the gain for small blocks
+#define PREFETCH_MAX_BLOCKS 8
-+#define CSUM_MD5 5
-+#define CSUM_MD5P8 7
+
+typedef struct {
+ int in_use;
+ }
+}
+
-+void checksum2_enable_prefetch(struct map_struct *map, OFF_T len, int32 blocklen)
++void checksum2_enable_prefetch(UNUSED(struct map_struct *map), UNUSED(OFF_T len), UNUSED(int32 blocklen))
+{
+#ifdef PREFETCH_ENABLE
+ checksum2_disable_prefetch();
+ int slots = md5_parallel_slots();
-+ if (((xfersum_type == CSUM_MD5) || (xfersum_type == CSUM_MD5P8)) && (slots > 1) && (len >= blocklen * PREFETCH_MAX_BLOCKS) && (blocklen >= PREFETCH_MIN_LEN)) {
++ if ((xfersum_type == CSUM_MD5 || xfersum_type == CSUM_MD5P8)
++ && slots > 1 && len >= blocklen * PREFETCH_MAX_BLOCKS && blocklen >= PREFETCH_MIN_LEN) {
+ prefetch = (prefetch_t*)malloc(sizeof(prefetch_t));
+ memset(prefetch, 0, sizeof(prefetch_t));
+ prefetch->map = map;
+ prefetch->blocks = MIN(PREFETCH_MAX_BLOCKS, slots);
+ PREFETCH_PRINTF("checksum2_enable_prefetch len:%ld blocklen:%d blocks:%d\n", prefetch->len, prefetch->blocklen, prefetch->blocks);
+ }
-+#else
-+ (void)map;
-+ (void)len;
-+ (void)blocklen;
+#endif
+}
+
+ int slots = md5_parallel_slots();
+ if ((streams < 1) || (streams > slots)) return 0;
+ if (pre4 && post4) return 0;
-+
++
+ if (slots == 1) {
+ MD5_CTX ctx;
+ MD5_Init(&ctx);