Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame^] | 1 | From 1eeb59366d6140a799f6051fb9f57d988b81fd5b Mon Sep 17 00:00:00 2001 |
| 2 | From: easyaspi314 <easyaspi314@users.noreply.github.com> |
| 3 | Date: Wed, 12 Apr 2023 13:33:07 +0800 |
| 4 | Subject: [PATCH] Change whether to inline XXH3_hashLong_withSecret to a config |
| 5 | option |
| 6 | |
| 7 | Change whether to inline XXH3_hashLong_withSecret to a config option to fix |
| 8 | GCC 12 -Og. |
| 9 | |
| 10 | Upstream-Status: Submitted [https://github.com/php/php-src/pull/11062] |
| 11 | |
| 12 | Signed-off-by: Mingli Yu <mingli.yu@windriver.com> |
| 13 | --- |
| 14 | ext/hash/xxhash/xxhash.h | 35 +++++++++++++++++++++++++++++++++-- |
| 15 | 1 file changed, 33 insertions(+), 2 deletions(-) |
| 16 | |
| 17 | diff --git a/ext/hash/xxhash/xxhash.h b/ext/hash/xxhash/xxhash.h |
| 18 | index b5bd2864..8e816c05 100644 |
| 19 | --- a/ext/hash/xxhash/xxhash.h |
| 20 | +++ b/ext/hash/xxhash/xxhash.h |
| 21 | @@ -1375,6 +1375,23 @@ XXH3_128bits_reset_withSecretandSeed(XXH3_state_t* statePtr, |
| 22 | */ |
| 23 | # define XXH_NO_INLINE_HINTS 0 |
| 24 | |
| 25 | +/*! |
| 26 | + * @def XXH3_INLINE_SECRET |
| 27 | + * @brief Determines whether to inline the XXH3 withSecret code. |
| 28 | + * |
| 29 | + * When the secret size is known, the compiler can improve the performance |
| 30 | + * of XXH3_64bits_withSecret() and XXH3_128bits_withSecret(). |
| 31 | + * |
| 32 | + * However, if the secret size is not known, it doesn't have any benefit. This |
| 33 | + * happens when xxHash is compiled into a global symbol. Therefore, if |
| 34 | + * @ref XXH_INLINE_ALL is *not* defined, this will be defined to 0. |
| 35 | + * |
| 36 | + * Additionally, this defaults to 0 on GCC 12+, which has an issue with function pointers |
| 37 | + * that are *sometimes* force inline on -Og, and it is impossible to automatically |
| 38 | + * detect this optimization level. |
| 39 | + */ |
| 40 | +# define XXH3_INLINE_SECRET 0 |
| 41 | + |
| 42 | /*! |
| 43 | * @def XXH32_ENDJMP |
| 44 | * @brief Whether to use a jump for `XXH32_finalize`. |
| 45 | @@ -1439,6 +1456,15 @@ XXH3_128bits_reset_withSecretandSeed(XXH3_state_t* statePtr, |
| 46 | # endif |
| 47 | #endif |
| 48 | |
| 49 | +#ifndef XXH3_INLINE_SECRET |
| 50 | +# if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12) \ |
| 51 | + || !defined(XXH_INLINE_ALL) |
| 52 | +# define XXH3_INLINE_SECRET 0 |
| 53 | +# else |
| 54 | +# define XXH3_INLINE_SECRET 1 |
| 55 | +# endif |
| 56 | +#endif |
| 57 | + |
| 58 | #ifndef XXH32_ENDJMP |
| 59 | /* generally preferable for performance */ |
| 60 | # define XXH32_ENDJMP 0 |
| 61 | @@ -1515,6 +1541,11 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) |
| 62 | # define XXH_NO_INLINE static |
| 63 | #endif |
| 64 | |
| 65 | +#if XXH3_INLINE_SECRET |
| 66 | +# define XXH3_WITH_SECRET_INLINE XXH_FORCE_INLINE |
| 67 | +#else |
| 68 | +# define XXH3_WITH_SECRET_INLINE XXH_NO_INLINE |
| 69 | +#endif |
| 70 | |
| 71 | |
| 72 | /* ************************************* |
| 73 | @@ -4465,7 +4496,7 @@ XXH3_hashLong_64b_internal(const void* XXH_RESTRICT input, size_t len, |
| 74 | * so that the compiler can properly optimize the vectorized loop. |
| 75 | * This makes a big performance difference for "medium" keys (<1 KB) when using AVX instruction set. |
| 76 | */ |
| 77 | -XXH_FORCE_INLINE XXH64_hash_t |
| 78 | +XXH3_WITH_SECRET_INLINE XXH64_hash_t |
| 79 | XXH3_hashLong_64b_withSecret(const void* XXH_RESTRICT input, size_t len, |
| 80 | XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen) |
| 81 | { |
| 82 | @@ -5263,7 +5294,7 @@ XXH3_hashLong_128b_default(const void* XXH_RESTRICT input, size_t len, |
| 83 | * It's important for performance to pass @secretLen (when it's static) |
| 84 | * to the compiler, so that it can properly optimize the vectorized loop. |
| 85 | */ |
| 86 | -XXH_FORCE_INLINE XXH128_hash_t |
| 87 | +XXH3_WITH_SECRET_INLINE XXH128_hash_t |
| 88 | XXH3_hashLong_128b_withSecret(const void* XXH_RESTRICT input, size_t len, |
| 89 | XXH64_hash_t seed64, |
| 90 | const void* XXH_RESTRICT secret, size_t secretLen) |
| 91 | -- |
| 92 | 2.25.1 |
| 93 | |