From f9ad835680cfcff6b8ea2afb153825426a4d51f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Wed, 17 Aug 2022 21:27:32 +0300 Subject: [PATCH] mdbx: drop E2K libc obsolete workarounds. --- mdbx.h | 51 ------------------------ src/core.c | 114 ----------------------------------------------------- 2 files changed, 165 deletions(-) diff --git a/mdbx.h b/mdbx.h index a99d4143..f536d41d 100644 --- a/mdbx.h +++ b/mdbx.h @@ -5242,57 +5242,6 @@ LIBMDBX_API int mdbx_env_turn_for_recovery(MDBX_env *env, unsigned target_meta); /** end of c_api @} */ -/******************************************************************************* - * Workaround for mmaped-lookahead-cross-page-boundary bug - * in an obsolete versions of Elbrus's libc and kernels. */ -#if defined(__e2k__) && defined(MDBX_E2K_MLHCPB_WORKAROUND) && \ - MDBX_E2K_MLHCPB_WORKAROUND -LIBMDBX_API int mdbx_e2k_memcmp_bug_workaround(const void *s1, const void *s2, - size_t n); -LIBMDBX_API int mdbx_e2k_strcmp_bug_workaround(const char *s1, const char *s2); -LIBMDBX_API int mdbx_e2k_strncmp_bug_workaround(const char *s1, const char *s2, - size_t n); -LIBMDBX_API size_t mdbx_e2k_strlen_bug_workaround(const char *s); -LIBMDBX_API size_t mdbx_e2k_strnlen_bug_workaround(const char *s, - size_t maxlen); -#ifdef __cplusplus -namespace std { -inline int mdbx_e2k_memcmp_bug_workaround(const void *s1, const void *s2, - size_t n) { - return ::mdbx_e2k_memcmp_bug_workaround(s1, s2, n); -} -inline int mdbx_e2k_strcmp_bug_workaround(const char *s1, const char *s2) { - return ::mdbx_e2k_strcmp_bug_workaround(s1, s2); -} -inline int mdbx_e2k_strncmp_bug_workaround(const char *s1, const char *s2, - size_t n) { - return ::mdbx_e2k_strncmp_bug_workaround(s1, s2, n); -} -inline size_t mdbx_e2k_strlen_bug_workaround(const char *s) { - return ::mdbx_e2k_strlen_bug_workaround(s); -} -inline size_t mdbx_e2k_strnlen_bug_workaround(const char *s, size_t maxlen) { - return ::mdbx_e2k_strnlen_bug_workaround(s, maxlen); -} -} // namespace std -#endif /* __cplusplus */ - -#include -#include -#undef memcmp -#define memcmp mdbx_e2k_memcmp_bug_workaround -#undef bcmp -#define bcmp mdbx_e2k_memcmp_bug_workaround -#undef strcmp -#define strcmp mdbx_e2k_strcmp_bug_workaround -#undef strncmp -#define strncmp mdbx_e2k_strncmp_bug_workaround -#undef strlen -#define strlen mdbx_e2k_strlen_bug_workaround -#undef strnlen -#define strnlen mdbx_e2k_strnlen_bug_workaround -#endif /* MDBX_E2K_MLHCPB_WORKAROUND */ - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/core.c b/src/core.c index eaf9c818..9e91e4a5 100644 --- a/src/core.c +++ b/src/core.c @@ -781,120 +781,6 @@ get_key_optional(const MDBX_node *node, MDBX_val *keyptr /* __may_null */) { get_key(node, keyptr); } -/*------------------------------------------------------------------------------ - * Workaround for mmaped-lookahead-cross-page-boundary bug - * in an obsolete versions of Elbrus's libc and kernels. */ -#if defined(__e2k__) && defined(MDBX_E2K_MLHCPB_WORKAROUND) && \ - MDBX_E2K_MLHCPB_WORKAROUND -__hot int mdbx_e2k_memcmp_bug_workaround(const void *s1, const void *s2, - size_t n) { - if (unlikely(n > 42 - /* LY: align followed access if reasonable possible */ - && (((uintptr_t)s1) & 7) != 0 && - (((uintptr_t)s1) & 7) == (((uintptr_t)s2) & 7))) { - if (((uintptr_t)s1) & 1) { - const int diff = *(uint8_t *)s1 - *(uint8_t *)s2; - if (diff) - return diff; - s1 = (char *)s1 + 1; - s2 = (char *)s2 + 1; - n -= 1; - } - - if (((uintptr_t)s1) & 2) { - const uint16_t a = *(uint16_t *)s1; - const uint16_t b = *(uint16_t *)s2; - if (likely(a != b)) - return (__builtin_bswap16(a) > __builtin_bswap16(b)) ? 1 : -1; - s1 = (char *)s1 + 2; - s2 = (char *)s2 + 2; - n -= 2; - } - - if (((uintptr_t)s1) & 4) { - const uint32_t a = *(uint32_t *)s1; - const uint32_t b = *(uint32_t *)s2; - if (likely(a != b)) - return (__builtin_bswap32(a) > __builtin_bswap32(b)) ? 1 : -1; - s1 = (char *)s1 + 4; - s2 = (char *)s2 + 4; - n -= 4; - } - } - - while (n >= 8) { - const uint64_t a = *(uint64_t *)s1; - const uint64_t b = *(uint64_t *)s2; - if (likely(a != b)) - return (__builtin_bswap64(a) > __builtin_bswap64(b)) ? 1 : -1; - s1 = (char *)s1 + 8; - s2 = (char *)s2 + 8; - n -= 8; - } - - if (n & 4) { - const uint32_t a = *(uint32_t *)s1; - const uint32_t b = *(uint32_t *)s2; - if (likely(a != b)) - return (__builtin_bswap32(a) > __builtin_bswap32(b)) ? 1 : -1; - s1 = (char *)s1 + 4; - s2 = (char *)s2 + 4; - } - - if (n & 2) { - const uint16_t a = *(uint16_t *)s1; - const uint16_t b = *(uint16_t *)s2; - if (likely(a != b)) - return (__builtin_bswap16(a) > __builtin_bswap16(b)) ? 1 : -1; - s1 = (char *)s1 + 2; - s2 = (char *)s2 + 2; - } - - return (n & 1) ? *(uint8_t *)s1 - *(uint8_t *)s2 : 0; -} - -__hot int mdbx_e2k_strcmp_bug_workaround(const char *s1, const char *s2) { - while (true) { - int diff = *(uint8_t *)s1 - *(uint8_t *)s2; - if (likely(diff != 0) || *s1 == '\0') - return diff; - s1 += 1; - s2 += 1; - } -} - -__hot int mdbx_e2k_strncmp_bug_workaround(const char *s1, const char *s2, - size_t n) { - while (n > 0) { - int diff = *(uint8_t *)s1 - *(uint8_t *)s2; - if (likely(diff != 0) || *s1 == '\0') - return diff; - s1 += 1; - s2 += 1; - n -= 1; - } - return 0; -} - -__hot size_t mdbx_e2k_strlen_bug_workaround(const char *s) { - size_t n = 0; - while (*s) { - s += 1; - n += 1; - } - return n; -} - -__hot size_t mdbx_e2k_strnlen_bug_workaround(const char *s, size_t maxlen) { - size_t n = 0; - while (maxlen > n && *s) { - s += 1; - n += 1; - } - return n; -} -#endif /* MDBX_E2K_MLHCPB_WORKAROUND */ - /*------------------------------------------------------------------------------ * safe read/write volatile 64-bit fields on 32-bit architectures. */