From 768adc07743c4121216fdca0d8b4a0d7184ebd3c Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Tue, 21 Jan 2020 18:57:16 -0800 Subject: [PATCH 1/5] Fix timefn on android --- programs/timefn.c | 2 +- programs/timefn.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/timefn.c b/programs/timefn.c index 096e1910b..4025063eb 100644 --- a/programs/timefn.c +++ b/programs/timefn.c @@ -84,7 +84,7 @@ PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd) #elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \ - && defined(TIME_UTC) /* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance */ + && defined(TIME_UTC) && !defined(__ANDROID__) /* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance */ #include /* abort */ #include /* perror */ diff --git a/programs/timefn.h b/programs/timefn.h index b156a33b6..0f2b12ce8 100644 --- a/programs/timefn.h +++ b/programs/timefn.h @@ -52,7 +52,7 @@ extern "C" { #define UTIL_TIME_INITIALIZER 0 #elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \ - && defined(TIME_UTC) /* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance */ + && defined(TIME_UTC) && !defined(__ANDROID__) /* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance */ typedef struct timespec UTIL_time_t; #define UTIL_TIME_INITIALIZER { 0, 0 } From 7ec87cfb28d389b946452bd74dac884ace542f13 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Wed, 22 Jan 2020 11:17:30 -0800 Subject: [PATCH 2/5] Update comment in timefn --- programs/timefn.c | 5 +++-- programs/timefn.h | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/programs/timefn.c b/programs/timefn.c index 4025063eb..8d92b3a70 100644 --- a/programs/timefn.c +++ b/programs/timefn.c @@ -82,9 +82,10 @@ PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd) } - +/* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance. + Android also lacks it but does define TIME_UTC. */ #elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \ - && defined(TIME_UTC) && !defined(__ANDROID__) /* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance */ + && defined(TIME_UTC) && !defined(__ANDROID__) #include /* abort */ #include /* perror */ diff --git a/programs/timefn.h b/programs/timefn.h index 0f2b12ce8..7636f1f4d 100644 --- a/programs/timefn.h +++ b/programs/timefn.h @@ -51,8 +51,10 @@ extern "C" { typedef PTime UTIL_time_t; #define UTIL_TIME_INITIALIZER 0 +/* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance. + Android also lacks it but does define TIME_UTC. */ #elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \ - && defined(TIME_UTC) && !defined(__ANDROID__) /* C11 requires timespec_get, but FreeBSD 11 lacks it, while still claiming C11 compliance */ + && defined(TIME_UTC) && !defined(__ANDROID__) typedef struct timespec UTIL_time_t; #define UTIL_TIME_INITIALIZER { 0, 0 } From 6e3cd5b0243c51aaa4ce46ee6cf82bc7c576d832 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 23 Jan 2020 12:27:39 -0800 Subject: [PATCH 3/5] Move ZSTD_checkContinuity() to zstd_decompress_block.c --- lib/decompress/zstd_decompress.c | 11 ----------- lib/decompress/zstd_decompress_block.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index d92440ae8..8ca7c5e41 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -559,17 +559,6 @@ unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize) * Frame decoding ***************************************************************/ - -void ZSTD_checkContinuity(ZSTD_DCtx* dctx, const void* dst) -{ - if (dst != dctx->previousDstEnd) { /* not contiguous */ - dctx->dictEnd = dctx->previousDstEnd; - dctx->virtualStart = (const char*)dst - ((const char*)(dctx->previousDstEnd) - (const char*)(dctx->prefixStart)); - dctx->prefixStart = dst; - dctx->previousDstEnd = dst; - } -} - /** ZSTD_insertBlock() : * insert `src` block into `dctx` history. Useful to track uncompressed blocks. */ size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize) diff --git a/lib/decompress/zstd_decompress_block.c b/lib/decompress/zstd_decompress_block.c index ce43c5255..0b9e50f67 100644 --- a/lib/decompress/zstd_decompress_block.c +++ b/lib/decompress/zstd_decompress_block.c @@ -1285,6 +1285,17 @@ ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx, } +void ZSTD_checkContinuity(ZSTD_DCtx* dctx, const void* dst) +{ + if (dst != dctx->previousDstEnd) { /* not contiguous */ + dctx->dictEnd = dctx->previousDstEnd; + dctx->virtualStart = (const char*)dst - ((const char*)(dctx->previousDstEnd) - (const char*)(dctx->prefixStart)); + dctx->prefixStart = dst; + dctx->previousDstEnd = dst; + } +} + + size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize) From cb2abc3dbe010113d9e00ca3b612bf61983145a2 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 23 Jan 2020 16:18:52 -0800 Subject: [PATCH 4/5] Fix performance regression on aarch64 with clang --- lib/decompress/huf_decompress.c | 11 ++++++----- lib/decompress/zstd_decompress_block.c | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/decompress/huf_decompress.c b/lib/decompress/huf_decompress.c index 732e1c93b..e599070ae 100644 --- a/lib/decompress/huf_decompress.c +++ b/lib/decompress/huf_decompress.c @@ -817,7 +817,7 @@ HUF_decompress4X2_usingDTable_internal_body( /* 16-32 symbols per loop (4-8 symbols per stream) */ for ( ; (endSignal) & (op4 < olimit); ) { -#ifdef __clang__ +#if defined(__clang__) && (defined(__x86_64__) || defined(__i386__)) HUF_DECODE_SYMBOLX2_2(op1, &bitD1); HUF_DECODE_SYMBOLX2_1(op1, &bitD1); HUF_DECODE_SYMBOLX2_2(op1, &bitD1); @@ -855,10 +855,11 @@ HUF_decompress4X2_usingDTable_internal_body( HUF_DECODE_SYMBOLX2_0(op2, &bitD2); HUF_DECODE_SYMBOLX2_0(op3, &bitD3); HUF_DECODE_SYMBOLX2_0(op4, &bitD4); - endSignal &= BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished; - endSignal &= BIT_reloadDStreamFast(&bitD2) == BIT_DStream_unfinished; - endSignal &= BIT_reloadDStreamFast(&bitD3) == BIT_DStream_unfinished; - endSignal &= BIT_reloadDStreamFast(&bitD4) == BIT_DStream_unfinished; + endSignal = LIKELY( + (BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished) + & (BIT_reloadDStreamFast(&bitD2) == BIT_DStream_unfinished) + & (BIT_reloadDStreamFast(&bitD3) == BIT_DStream_unfinished) + & (BIT_reloadDStreamFast(&bitD4) == BIT_DStream_unfinished)); #endif } diff --git a/lib/decompress/zstd_decompress_block.c b/lib/decompress/zstd_decompress_block.c index ce43c5255..33c812d04 100644 --- a/lib/decompress/zstd_decompress_block.c +++ b/lib/decompress/zstd_decompress_block.c @@ -580,7 +580,7 @@ typedef struct { * Precondition: *ip <= *op * Postcondition: *op - *op >= 8 */ -static void ZSTD_overlapCopy8(BYTE** op, BYTE const** ip, size_t offset) { +HINT_INLINE void ZSTD_overlapCopy8(BYTE** op, BYTE const** ip, size_t offset) { assert(*ip <= *op); if (offset < 8) { /* close range match, overlap */ From fa6a772f38f4ac2bea1a428743f2bcdd41fa267a Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 23 Jan 2020 17:54:48 -0800 Subject: [PATCH 5/5] Initialize dctx->bType to silence valgrind false positive --- lib/decompress/zstd_decompress.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 8ca7c5e41..f87e26184 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -1159,6 +1159,7 @@ size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx) dctx->entropy.hufTable[0] = (HUF_DTable)((HufLog)*0x1000001); /* cover both little and big endian */ dctx->litEntropy = dctx->fseEntropy = 0; dctx->dictID = 0; + dctx->bType = bt_reserved; ZSTD_STATIC_ASSERT(sizeof(dctx->entropy.rep) == sizeof(repStartValue)); memcpy(dctx->entropy.rep, repStartValue, sizeof(repStartValue)); /* initial repcodes */ dctx->LLTptr = dctx->entropy.LLTable;