mdbx: add MDBX_HAVE_BUILTIN_CPU_SUPPORTS build option.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-08-26 18:52:35 +03:00
parent b36a07a512
commit b73727d73e
2 changed files with 21 additions and 6 deletions

View File

@ -1174,7 +1174,7 @@ static __inline int rthc_atexit(void (*dtor)(void *), void *obj,
#ifndef MDBX_HAVE_CXA_THREAD_ATEXIT_IMPL
#if defined(LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL) || \
defined(HAVE___CXA_THREAD_ATEXIT_IMPL) || __GLIBC_PREREQ(2, 18) || \
defined(ANDROID)
defined(BIONIC)
#define MDBX_HAVE_CXA_THREAD_ATEXIT_IMPL 1
#else
#define MDBX_HAVE_CXA_THREAD_ATEXIT_IMPL 0
@ -6232,10 +6232,7 @@ __hot static pgno_t *scan4seq_neon(pgno_t *range, const size_t len,
#ifdef scan4seq
/* The scan4seq() is the best or no alternatives */
#else
#if !(__has_builtin(__builtin_cpu_supports) || \
defined(__BUILTIN_CPU_SUPPORTS__) || \
(defined(__ia32__) && __GNUC_PREREQ(4, 8) && __GLIBC_PREREQ(2, 23)))
#elif !MDBX_HAVE_BUILTIN_CPU_SUPPORTS
/* The scan4seq_default() will be used since no cpu-features detection support
* from compiler. Please don't ask to implement cpuid-based detection and don't
* make such PRs. */
@ -6272,7 +6269,6 @@ static pgno_t *scan4seq_resolver(pgno_t *range, const size_t len,
scan4seq = choice ? choice : scan4seq_default;
return scan4seq(range, len, seq);
}
#endif /* __has_builtin(__builtin_cpu_supports */
#endif /* scan4seq */
//------------------------------------------------------------------------------

View File

@ -194,6 +194,25 @@
#ifndef MDBX_HAVE_C11ATOMICS
#endif /* MDBX_HAVE_C11ATOMICS */
/** If defined then enables use the GCC's `__builtin_cpu_supports()`
* for runtime dispatching depending on the CPU's capabilities. */
#ifndef MDBX_HAVE_BUILTIN_CPU_SUPPORTS
#if defined(__APPLE__) || defined(BIONIC)
/* Never use any modern features on Apple's or Google's OSes
* since a lot of troubles with compatibility and/or performance */
#define MDBX_HAVE_BUILTIN_CPU_SUPPORTS 0
#elif __has_builtin(__builtin_cpu_supports) || \
defined(__BUILTIN_CPU_SUPPORTS__) || \
(defined(__ia32__) && __GNUC_PREREQ(4, 8) && __GLIBC_PREREQ(2, 23))
#define MDBX_HAVE_BUILTIN_CPU_SUPPORTS 1
#else
#define MDBX_HAVE_BUILTIN_CPU_SUPPORTS 0
#endif
#elif !(MDBX_HAVE_BUILTIN_CPU_SUPPORTS == 0 || \
MDBX_HAVE_BUILTIN_CPU_SUPPORTS == 1)
#error MDBX_HAVE_BUILTIN_CPU_SUPPORTS must be defined as 0 or 1
#endif /* MDBX_HAVE_BUILTIN_CPU_SUPPORTS */
//------------------------------------------------------------------------------
/** Win32 File Locking API for \ref MDBX_LOCKING */