Skip to content

Commit ace22bd

Browse files
committed
Change whether to inline XXH3_hashLong_withSecret to a config option
1 parent 268fde4 commit ace22bd

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

xxhash.h

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,23 @@ XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr,
16271627
*/
16281628
# define XXH_NO_INLINE_HINTS 0
16291629

1630+
/*!
1631+
* @def XXH3_INLINE_SECRET
1632+
* @brief Determines whether to inline the XXH3 withSecret code.
1633+
*
1634+
* When the secret size is known, the compiler can improve the performance
1635+
* of XXH3_64bits_withSecret() and XXH3_128bits_withSecret().
1636+
*
1637+
* However, if the secret size is not known, it doesn't have any benefit. This
1638+
* happens when xxHash is compiled into a global symbol. Therefore, if
1639+
* @ref XXH_INLINE_ALL is *not* defined, this will be defined to 0.
1640+
*
1641+
* Additionally, this defaults to 0 on GCC 12+, which has an issue with function pointers
1642+
* that are *sometimes* force inline on -Og, and it is impossible to automatically
1643+
* detect this optimization level.
1644+
*/
1645+
# define XXH3_INLINE_SECRET 0
1646+
16301647
/*!
16311648
* @def XXH32_ENDJMP
16321649
* @brief Whether to use a jump for `XXH32_finalize`.
@@ -1701,6 +1718,15 @@ XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr,
17011718
# endif
17021719
#endif
17031720

1721+
#ifndef XXH3_INLINE_SECRET
1722+
# if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12) \
1723+
|| !defined(XXH_INLINE_ALL)
1724+
# define XXH3_INLINE_SECRET 0
1725+
# else
1726+
# define XXH3_INLINE_SECRET 1
1727+
# endif
1728+
#endif
1729+
17041730
#ifndef XXH32_ENDJMP
17051731
/* generally preferable for performance */
17061732
# define XXH32_ENDJMP 0
@@ -1797,6 +1823,11 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size)
17971823
# define XXH_NO_INLINE static
17981824
#endif
17991825

1826+
#if XXH3_INLINE_SECRET
1827+
# define XXH3_WITH_SECRET_INLINE XXH_FORCE_INLINE
1828+
#else
1829+
# define XXH3_WITH_SECRET_INLINE XXH_NO_INLINE
1830+
#endif
18001831

18011832

18021833
/* *************************************
@@ -5149,12 +5180,7 @@ XXH3_hashLong_64b_internal(const void* XXH_RESTRICT input, size_t len,
51495180
* When the secret size is unknown, or on GCC 12 where the mix of NO_INLINE and FORCE_INLINE
51505181
* breaks -Og, this is XXH_NO_INLINE.
51515182
*/
5152-
#if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12) || !defined(XXH_INLINE_ALL)
5153-
XXH_NO_INLINE
5154-
#else
5155-
XXH_FORCE_INLINE
5156-
#endif
5157-
XXH64_hash_t
5183+
XXH3_WITH_SECRET_INLINE XXH64_hash_t
51585184
XXH3_hashLong_64b_withSecret(const void* XXH_RESTRICT input, size_t len,
51595185
XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen)
51605186
{
@@ -5977,12 +6003,7 @@ XXH3_hashLong_128b_default(const void* XXH_RESTRICT input, size_t len,
59776003
* When the secret size is unknown, or on GCC 12 where the mix of NO_INLINE and FORCE_INLINE
59786004
* breaks -Og, this is XXH_NO_INLINE.
59796005
*/
5980-
#if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12) || !defined(XXH_INLINE_ALL)
5981-
XXH_NO_INLINE
5982-
#else
5983-
XXH_FORCE_INLINE
5984-
#endif
5985-
XXH128_hash_t
6006+
XXH3_WITH_SECRET_INLINE XXH128_hash_t
59866007
XXH3_hashLong_128b_withSecret(const void* XXH_RESTRICT input, size_t len,
59876008
XXH64_hash_t seed64,
59886009
const void* XXH_RESTRICT secret, size_t secretLen)

0 commit comments

Comments
 (0)