Skip to content
Snippets Groups Projects
Commit 3d98741f authored by Marcus Comstedt's avatar Marcus Comstedt
Browse files

CritBit: Fix FloatTree with 128bit floats

parent a6616abd
No related branches found
No related tags found
No related merge requests found
...@@ -165,6 +165,23 @@ static INLINE unsigned INT64 ATTRIBUTE((unused)) bswap64(unsigned INT64 x) { ...@@ -165,6 +165,23 @@ static INLINE unsigned INT64 ATTRIBUTE((unused)) bswap64(unsigned INT64 x) {
} }
#endif /* !HAVE___BSWAP64 && !HAVE_BSWAP64 */ #endif /* !HAVE___BSWAP64 && !HAVE_BSWAP64 */
#if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__ == 16
/**
* Counts the number of leading zeros in a 128-bit unsigned
* integer. Returns a value between 0 and 128.
*/
static INLINE unsigned INT32 PIKE_UNUSED_ATTRIBUTE clz128(unsigned __int128 i) {
# if SIZEOF_LONG == 16 && defined(HAS___BUILTIN_CLZL)
return i ? __builtin_clzl(i) : 128;
# elif SIZEOF_LONG_LONG == 16 && defined(HAS___BUILTIN_CLZLL)
return i ? __builtin_clzll(i) : 128;
# else
unsigned INT64 hi = i >> 64;
return hi? clz64(hi) : 64 + clz64((unsigned INT64)i);
# endif
}
#endif /* __SIZEOF_INT128__ */
static INLINE unsigned INT64 PIKE_UNUSED_ATTRIBUTE round_up64(unsigned INT64 v) { static INLINE unsigned INT64 PIKE_UNUSED_ATTRIBUTE round_up64(unsigned INT64 v) {
unsigned INT32 i; unsigned INT32 i;
......
...@@ -7,9 +7,14 @@ ...@@ -7,9 +7,14 @@
#if SIZEOF_FLOAT_TYPE == 8 #if SIZEOF_FLOAT_TYPE == 8
typedef unsigned INT64 CB_NAME(string); typedef unsigned INT64 CB_NAME(string);
typedef unsigned INT64 CB_NAME(char); typedef unsigned INT64 CB_NAME(char);
#else #elif SIZEOF_FLOAT_TYPE == 4
typedef unsigned INT32 CB_NAME(string); typedef unsigned INT32 CB_NAME(string);
typedef unsigned INT32 CB_NAME(char); typedef unsigned INT32 CB_NAME(char);
#elif SIZEOF_FLOAT_TYPE == 16 && defined(__SIZEOF_INT128__) && __SIZEOF_INT128__ == 16
typedef unsigned __int128 CB_NAME(string);
typedef unsigned __int128 CB_NAME(char);
#else
#error Size of FLOAT_TYPE not supported.
#endif #endif
...@@ -26,8 +31,10 @@ typedef unsigned INT32 CB_NAME(char); ...@@ -26,8 +31,10 @@ typedef unsigned INT32 CB_NAME(char);
#ifdef CB_SOURCE #ifdef CB_SOURCE
#if SIZEOF_FLOAT_TYPE == 4 #if SIZEOF_FLOAT_TYPE == 4
# define gclz(x) clz32(x) # define gclz(x) clz32(x)
#else #elif SIZEOF_FLOAT_TYPE == 8
# define gclz(x) clz64(x) # define gclz(x) clz64(x)
#else
# define gclz(x) clz128(x)
#endif #endif
#define bitsof(x) (sizeof(x)*8) #define bitsof(x) (sizeof(x)*8)
#define int2float(x) (*(FLOAT_TYPE*)&(x)) #define int2float(x) (*(FLOAT_TYPE*)&(x))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment