mirror of
https://github.com/isar/libmdbx.git
synced 2025-11-07 07:18:56 +08:00
mdbx: новые настройки clang-format (косметика).
This commit is contained in:
@@ -9,16 +9,14 @@ static inline double key2double(const int64_t key) {
|
||||
double f;
|
||||
} casting;
|
||||
|
||||
casting.u = (key < 0) ? key + UINT64_C(0x8000000000000000)
|
||||
: UINT64_C(0xffffFFFFffffFFFF) - key;
|
||||
casting.u = (key < 0) ? key + UINT64_C(0x8000000000000000) : UINT64_C(0xffffFFFFffffFFFF) - key;
|
||||
return casting.f;
|
||||
}
|
||||
|
||||
static inline uint64_t double2key(const double *const ptr) {
|
||||
STATIC_ASSERT(sizeof(double) == sizeof(int64_t));
|
||||
const int64_t i = *(const int64_t *)ptr;
|
||||
const uint64_t u = (i < 0) ? UINT64_C(0xffffFFFFffffFFFF) - i
|
||||
: i + UINT64_C(0x8000000000000000);
|
||||
const uint64_t u = (i < 0) ? UINT64_C(0xffffFFFFffffFFFF) - i : i + UINT64_C(0x8000000000000000);
|
||||
if (ASSERT_ENABLED()) {
|
||||
const double f = key2double(u);
|
||||
assert(memcmp(&f, ptr, sizeof(double)) == 0);
|
||||
@@ -32,16 +30,14 @@ static inline float key2float(const int32_t key) {
|
||||
float f;
|
||||
} casting;
|
||||
|
||||
casting.u =
|
||||
(key < 0) ? key + UINT32_C(0x80000000) : UINT32_C(0xffffFFFF) - key;
|
||||
casting.u = (key < 0) ? key + UINT32_C(0x80000000) : UINT32_C(0xffffFFFF) - key;
|
||||
return casting.f;
|
||||
}
|
||||
|
||||
static inline uint32_t float2key(const float *const ptr) {
|
||||
STATIC_ASSERT(sizeof(float) == sizeof(int32_t));
|
||||
const int32_t i = *(const int32_t *)ptr;
|
||||
const uint32_t u =
|
||||
(i < 0) ? UINT32_C(0xffffFFFF) - i : i + UINT32_C(0x80000000);
|
||||
const uint32_t u = (i < 0) ? UINT32_C(0xffffFFFF) - i : i + UINT32_C(0x80000000);
|
||||
if (ASSERT_ENABLED()) {
|
||||
const float f = key2float(u);
|
||||
assert(memcmp(&f, ptr, sizeof(float)) == 0);
|
||||
@@ -49,21 +45,13 @@ static inline uint32_t float2key(const float *const ptr) {
|
||||
return u;
|
||||
}
|
||||
|
||||
uint64_t mdbx_key_from_double(const double ieee754_64bit) {
|
||||
return double2key(&ieee754_64bit);
|
||||
}
|
||||
uint64_t mdbx_key_from_double(const double ieee754_64bit) { return double2key(&ieee754_64bit); }
|
||||
|
||||
uint64_t mdbx_key_from_ptrdouble(const double *const ieee754_64bit) {
|
||||
return double2key(ieee754_64bit);
|
||||
}
|
||||
uint64_t mdbx_key_from_ptrdouble(const double *const ieee754_64bit) { return double2key(ieee754_64bit); }
|
||||
|
||||
uint32_t mdbx_key_from_float(const float ieee754_32bit) {
|
||||
return float2key(&ieee754_32bit);
|
||||
}
|
||||
uint32_t mdbx_key_from_float(const float ieee754_32bit) { return float2key(&ieee754_32bit); }
|
||||
|
||||
uint32_t mdbx_key_from_ptrfloat(const float *const ieee754_32bit) {
|
||||
return float2key(ieee754_32bit);
|
||||
}
|
||||
uint32_t mdbx_key_from_ptrfloat(const float *const ieee754_32bit) { return float2key(ieee754_32bit); }
|
||||
|
||||
#define IEEE754_DOUBLE_MANTISSA_SIZE 52
|
||||
#define IEEE754_DOUBLE_EXPONENTA_BIAS 0x3FF
|
||||
@@ -78,8 +66,7 @@ static inline int clz64(uint64_t value) {
|
||||
return __builtin_clz(value);
|
||||
if (sizeof(value) == sizeof(long))
|
||||
return __builtin_clzl(value);
|
||||
#if (defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8) || \
|
||||
__has_builtin(__builtin_clzll)
|
||||
#if (defined(__SIZEOF_LONG_LONG__) && __SIZEOF_LONG_LONG__ == 8) || __has_builtin(__builtin_clzll)
|
||||
return __builtin_clzll(value);
|
||||
#endif /* have(long long) && long long == uint64_t */
|
||||
#endif /* GNU C */
|
||||
@@ -105,11 +92,10 @@ static inline int clz64(uint64_t value) {
|
||||
value |= value >> 8;
|
||||
value |= value >> 16;
|
||||
value |= value >> 32;
|
||||
static const uint8_t debruijn_clz64[64] = {
|
||||
63, 16, 62, 7, 15, 36, 61, 3, 6, 14, 22, 26, 35, 47, 60, 2,
|
||||
9, 5, 28, 11, 13, 21, 42, 19, 25, 31, 34, 40, 46, 52, 59, 1,
|
||||
17, 8, 37, 4, 23, 27, 48, 10, 29, 12, 43, 20, 32, 41, 53, 18,
|
||||
38, 24, 49, 30, 44, 33, 54, 39, 50, 45, 55, 51, 56, 57, 58, 0};
|
||||
static const uint8_t debruijn_clz64[64] = {63, 16, 62, 7, 15, 36, 61, 3, 6, 14, 22, 26, 35, 47, 60, 2,
|
||||
9, 5, 28, 11, 13, 21, 42, 19, 25, 31, 34, 40, 46, 52, 59, 1,
|
||||
17, 8, 37, 4, 23, 27, 48, 10, 29, 12, 43, 20, 32, 41, 53, 18,
|
||||
38, 24, 49, 30, 44, 33, 54, 39, 50, 45, 55, 51, 56, 57, 58, 0};
|
||||
return debruijn_clz64[value * UINT64_C(0x03F79D71B4CB0A89) >> 58];
|
||||
}
|
||||
|
||||
@@ -134,17 +120,12 @@ uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer) {
|
||||
mantissa = round_mantissa(u64, --shift);
|
||||
}
|
||||
|
||||
assert(mantissa >= IEEE754_DOUBLE_IMPLICIT_LEAD &&
|
||||
mantissa <= IEEE754_DOUBLE_MANTISSA_AMAX);
|
||||
const uint64_t exponent = (uint64_t)IEEE754_DOUBLE_EXPONENTA_BIAS +
|
||||
IEEE754_DOUBLE_MANTISSA_SIZE - shift;
|
||||
assert(mantissa >= IEEE754_DOUBLE_IMPLICIT_LEAD && mantissa <= IEEE754_DOUBLE_MANTISSA_AMAX);
|
||||
const uint64_t exponent = (uint64_t)IEEE754_DOUBLE_EXPONENTA_BIAS + IEEE754_DOUBLE_MANTISSA_SIZE - shift;
|
||||
assert(exponent > 0 && exponent <= IEEE754_DOUBLE_EXPONENTA_MAX);
|
||||
const uint64_t key = bias + (exponent << IEEE754_DOUBLE_MANTISSA_SIZE) +
|
||||
(mantissa - IEEE754_DOUBLE_IMPLICIT_LEAD);
|
||||
#if !defined(_MSC_VER) || \
|
||||
defined( \
|
||||
_DEBUG) /* Workaround for MSVC error LNK2019: unresolved external \
|
||||
symbol __except1 referenced in function __ftol3_except */
|
||||
const uint64_t key = bias + (exponent << IEEE754_DOUBLE_MANTISSA_SIZE) + (mantissa - IEEE754_DOUBLE_IMPLICIT_LEAD);
|
||||
#if !defined(_MSC_VER) || defined(_DEBUG) /* Workaround for MSVC error LNK2019: unresolved external \
|
||||
symbol __except1 referenced in function __ftol3_except */
|
||||
assert(key == mdbx_key_from_double((double)json_integer));
|
||||
#endif /* Workaround for MSVC */
|
||||
return key;
|
||||
@@ -160,17 +141,13 @@ uint64_t mdbx_key_from_jsonInteger(const int64_t json_integer) {
|
||||
mantissa = round_mantissa(u64, --shift);
|
||||
}
|
||||
|
||||
assert(mantissa >= IEEE754_DOUBLE_IMPLICIT_LEAD &&
|
||||
mantissa <= IEEE754_DOUBLE_MANTISSA_AMAX);
|
||||
const uint64_t exponent = (uint64_t)IEEE754_DOUBLE_EXPONENTA_BIAS +
|
||||
IEEE754_DOUBLE_MANTISSA_SIZE - shift;
|
||||
assert(mantissa >= IEEE754_DOUBLE_IMPLICIT_LEAD && mantissa <= IEEE754_DOUBLE_MANTISSA_AMAX);
|
||||
const uint64_t exponent = (uint64_t)IEEE754_DOUBLE_EXPONENTA_BIAS + IEEE754_DOUBLE_MANTISSA_SIZE - shift;
|
||||
assert(exponent > 0 && exponent <= IEEE754_DOUBLE_EXPONENTA_MAX);
|
||||
const uint64_t key = bias - 1 - (exponent << IEEE754_DOUBLE_MANTISSA_SIZE) -
|
||||
(mantissa - IEEE754_DOUBLE_IMPLICIT_LEAD);
|
||||
#if !defined(_MSC_VER) || \
|
||||
defined( \
|
||||
_DEBUG) /* Workaround for MSVC error LNK2019: unresolved external \
|
||||
symbol __except1 referenced in function __ftol3_except */
|
||||
const uint64_t key =
|
||||
bias - 1 - (exponent << IEEE754_DOUBLE_MANTISSA_SIZE) - (mantissa - IEEE754_DOUBLE_IMPLICIT_LEAD);
|
||||
#if !defined(_MSC_VER) || defined(_DEBUG) /* Workaround for MSVC error LNK2019: unresolved external \
|
||||
symbol __except1 referenced in function __ftol3_except */
|
||||
assert(key == mdbx_key_from_double((double)json_integer));
|
||||
#endif /* Workaround for MSVC */
|
||||
return key;
|
||||
@@ -185,21 +162,17 @@ int64_t mdbx_jsonInteger_from_key(const MDBX_val v) {
|
||||
const uint64_t bias = UINT64_C(0x8000000000000000);
|
||||
const uint64_t covalent = (key > bias) ? key - bias : bias - key - 1;
|
||||
const int shift = IEEE754_DOUBLE_EXPONENTA_BIAS + 63 -
|
||||
(IEEE754_DOUBLE_EXPONENTA_MAX &
|
||||
(int)(covalent >> IEEE754_DOUBLE_MANTISSA_SIZE));
|
||||
(IEEE754_DOUBLE_EXPONENTA_MAX & (int)(covalent >> IEEE754_DOUBLE_MANTISSA_SIZE));
|
||||
if (unlikely(shift < 1))
|
||||
return (key < bias) ? INT64_MIN : INT64_MAX;
|
||||
if (unlikely(shift > 63))
|
||||
return 0;
|
||||
|
||||
const uint64_t unscaled = ((covalent & IEEE754_DOUBLE_MANTISSA_MASK)
|
||||
<< (63 - IEEE754_DOUBLE_MANTISSA_SIZE)) +
|
||||
bias;
|
||||
const uint64_t unscaled = ((covalent & IEEE754_DOUBLE_MANTISSA_MASK) << (63 - IEEE754_DOUBLE_MANTISSA_SIZE)) + bias;
|
||||
const int64_t absolute = unscaled >> shift;
|
||||
const int64_t value = (key < bias) ? -absolute : absolute;
|
||||
assert(key == mdbx_key_from_jsonInteger(value) ||
|
||||
(mdbx_key_from_jsonInteger(value - 1) < key &&
|
||||
key < mdbx_key_from_jsonInteger(value + 1)));
|
||||
(mdbx_key_from_jsonInteger(value - 1) < key && key < mdbx_key_from_jsonInteger(value + 1)));
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -220,6 +193,5 @@ int32_t mdbx_int32_from_key(const MDBX_val v) {
|
||||
|
||||
int64_t mdbx_int64_from_key(const MDBX_val v) {
|
||||
assert(v.iov_len == 8);
|
||||
return (int64_t)(unaligned_peek_u64(2, v.iov_base) -
|
||||
UINT64_C(0x8000000000000000));
|
||||
return (int64_t)(unaligned_peek_u64(2, v.iov_base) - UINT64_C(0x8000000000000000));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user