Skip to content

Commit

Permalink
Merge pull request #804 from easyaspi314/gcc12-Og
Browse files Browse the repository at this point in the history
Fix GCC 12 -Og
  • Loading branch information
Cyan4973 committed Mar 9, 2023
2 parents adc4fc8 + ace22bd commit 449372c
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions xxhash.h
Expand Up @@ -1632,6 +1632,23 @@ XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr,
*/
# define XXH_NO_INLINE_HINTS 0

/*!
* @def XXH3_INLINE_SECRET
* @brief Determines whether to inline the XXH3 withSecret code.
*
* When the secret size is known, the compiler can improve the performance
* of XXH3_64bits_withSecret() and XXH3_128bits_withSecret().
*
* However, if the secret size is not known, it doesn't have any benefit. This
* happens when xxHash is compiled into a global symbol. Therefore, if
* @ref XXH_INLINE_ALL is *not* defined, this will be defined to 0.
*
* Additionally, this defaults to 0 on GCC 12+, which has an issue with function pointers
* that are *sometimes* force inline on -Og, and it is impossible to automatically
* detect this optimization level.
*/
# define XXH3_INLINE_SECRET 0

/*!
* @def XXH32_ENDJMP
* @brief Whether to use a jump for `XXH32_finalize`.
Expand Down Expand Up @@ -1706,6 +1723,15 @@ XXH3_128bits_reset_withSecretandSeed(XXH_NOESCAPE XXH3_state_t* statePtr,
# endif
#endif

#ifndef XXH3_INLINE_SECRET
# if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 12) \
|| !defined(XXH_INLINE_ALL)
# define XXH3_INLINE_SECRET 0
# else
# define XXH3_INLINE_SECRET 1
# endif
#endif

#ifndef XXH32_ENDJMP
/* generally preferable for performance */
# define XXH32_ENDJMP 0
Expand Down Expand Up @@ -1802,6 +1828,11 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size)
# define XXH_NO_INLINE static
#endif

#if XXH3_INLINE_SECRET
# define XXH3_WITH_SECRET_INLINE XXH_FORCE_INLINE
#else
# define XXH3_WITH_SECRET_INLINE XXH_NO_INLINE
#endif


/* *************************************
Expand Down Expand Up @@ -5155,8 +5186,10 @@ XXH3_hashLong_64b_internal(const void* XXH_RESTRICT input, size_t len,
* It's important for performance to transmit secret's size (when it's static)
* so that the compiler can properly optimize the vectorized loop.
* This makes a big performance difference for "medium" keys (<1 KB) when using AVX instruction set.
* When the secret size is unknown, or on GCC 12 where the mix of NO_INLINE and FORCE_INLINE
* breaks -Og, this is XXH_NO_INLINE.
*/
XXH_FORCE_INLINE XXH64_hash_t
XXH3_WITH_SECRET_INLINE XXH64_hash_t
XXH3_hashLong_64b_withSecret(const void* XXH_RESTRICT input, size_t len,
XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen)
{
Expand Down Expand Up @@ -5968,8 +6001,11 @@ XXH3_hashLong_128b_default(const void* XXH_RESTRICT input, size_t len,
/*
* It's important for performance to pass @p secretLen (when it's static)
* to the compiler, so that it can properly optimize the vectorized loop.
*
* When the secret size is unknown, or on GCC 12 where the mix of NO_INLINE and FORCE_INLINE
* breaks -Og, this is XXH_NO_INLINE.
*/
XXH_FORCE_INLINE XXH128_hash_t
XXH3_WITH_SECRET_INLINE XXH128_hash_t
XXH3_hashLong_128b_withSecret(const void* XXH_RESTRICT input, size_t len,
XXH64_hash_t seed64,
const void* XXH_RESTRICT secret, size_t secretLen)
Expand Down

0 comments on commit 449372c

Please sign in to comment.