]> git.ipfire.org Git - thirdparty/zstd.git/commit
Remove clang-only branch hints from ZSTD_decodeSequence 3576/head
authorHan Zhu <zhuhan7737@gmail.com>
Tue, 28 Mar 2023 21:33:50 +0000 (14:33 -0700)
committerHan Zhu <zhuhan7737@gmail.com>
Tue, 28 Mar 2023 22:36:22 +0000 (15:36 -0700)
commitb558190ac76fe6b0f2c42ae5fb9d2f90652d21b0
tree450befe80f058ee91c8e33f2faa0431a77a72e88
parente6dccbf48246f4e2844251972fcc0946a5de5154
Remove clang-only branch hints from ZSTD_decodeSequence

Looking at the __builtin_expect in ZSTD_decodeSequence:

{   size_t offset;
    #if defined(__clang__)
 if (LIKELY(ofBits > 1)) {
    #else
 if (ofBits > 1) {
    #endif
 ZSTD_STATIC_ASSERT(ZSTD_lo_isLongOffset == 1);

From profile-annotated assembly, the probability of ofBits > 1 is about 75%
(101k counts out of 135k counts). This is much smaller than the recommended
likelihood to use __builtin_expect which is 99%. As a result, clang moved the
else block further away which hurts cache locality. Removing this
__built_expect along with two others in ZSTD_decodeSequence gave better
performance when PGO is enabled. I suggest to remove these branch hints and
rely on PGO which leverages runtime profiles from actual workload to calculate
branch probability instead.
lib/decompress/zstd_decompress_block.c