mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:54:14 +08:00
mdbx-windows: fix nasty clz()
(i.e. using _BitScanReverse()
bug.
This commit is contained in:
parent
fe20de136c
commit
beda291692
@ -11,6 +11,7 @@ New:
|
|||||||
Fixes:
|
Fixes:
|
||||||
|
|
||||||
- Fixed an extra check for `MDBX_APPENDDUP` inside `mdbx_cursor_put()` which could result in returning `MDBX_EKEYMISMATCH` for valid cases.
|
- Fixed an extra check for `MDBX_APPENDDUP` inside `mdbx_cursor_put()` which could result in returning `MDBX_EKEYMISMATCH` for valid cases.
|
||||||
|
- Fixed nasty `clz()` bug (by using `_BitScanReverse()`, only MSVC builds affected).
|
||||||
|
|
||||||
Minors:
|
Minors:
|
||||||
|
|
||||||
|
17
src/core.c
17
src/core.c
@ -5905,16 +5905,27 @@ MDBX_MAYBE_UNUSED static const pgno_t *scan4range_checker(const MDBX_PNL pnl,
|
|||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(__builtin_clz) && \
|
#if defined(_MSC_VER) && !defined(__builtin_clz) && \
|
||||||
!__has_builtin(__builtin_clz)
|
!__has_builtin(__builtin_clz)
|
||||||
MDBX_MAYBE_UNUSED static __always_inline size_t __builtin_clz(unsigned value) {
|
MDBX_MAYBE_UNUSED static __always_inline size_t __builtin_clz(uint32_t value) {
|
||||||
unsigned long index;
|
unsigned long index;
|
||||||
_BitScanReverse(&index, value);
|
_BitScanReverse(&index, value);
|
||||||
return index;
|
return 31 - index;
|
||||||
}
|
}
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(__builtin_clzl) && \
|
#if defined(_MSC_VER) && !defined(__builtin_clzl) && \
|
||||||
!__has_builtin(__builtin_clzl)
|
!__has_builtin(__builtin_clzl)
|
||||||
#define __builtin_clzl(value) __builtin_clz(value)
|
MDBX_MAYBE_UNUSED static __always_inline size_t __builtin_clzl(size_t value) {
|
||||||
|
unsigned long index;
|
||||||
|
#ifdef _WIN64
|
||||||
|
assert(sizeof(value) == 8);
|
||||||
|
_BitScanReverse64(&index, value);
|
||||||
|
return 63 - index;
|
||||||
|
#else
|
||||||
|
assert(sizeof(value) == 4);
|
||||||
|
_BitScanReverse(&index, value);
|
||||||
|
return 31 - index;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
#if !defined(MDBX_ATTRIBUTE_TARGET) && \
|
#if !defined(MDBX_ATTRIBUTE_TARGET) && \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user