mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:14:14 +08:00
mdbx: drop E2K libc obsolete workarounds.
This commit is contained in:
parent
9b3faee630
commit
f9ad835680
51
mdbx.h
51
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 <string.h>
|
||||
#include <strings.h>
|
||||
#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
|
||||
|
114
src/core.c
114
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. */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user