aboutsummaryrefslogtreecommitdiffstats
path: root/src/internals.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-15 23:19:01 +0100
committerMattias Andrée <maandree@kth.se>2016-03-15 23:19:59 +0100
commitac0d3a625a5f0e2f81522b7d6d7ca6a6c3f158e2 (patch)
tree12933e1ae8fefbd8c0899d271b7cb35cfa9be3d7 /src/internals.h
parentRemove unnecessary trim (diff)
downloadlibzahl-ac0d3a625a5f0e2f81522b7d6d7ca6a6c3f158e2.tar.gz
libzahl-ac0d3a625a5f0e2f81522b7d6d7ca6a6c3f158e2.tar.bz2
libzahl-ac0d3a625a5f0e2f81522b7d6d7ca6a6c3f158e2.tar.xz
Fix bug in libzahl_msb_nz_* and optimise and simplify libzahl_realloc
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/internals.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/internals.h b/src/internals.h
index da8ce0c..a9d9af5 100644
--- a/src/internals.h
+++ b/src/internals.h
@@ -150,15 +150,15 @@ zmemset(zahl_char_t *a, register zahl_char_t v, register size_t n)
#endif
#if defined(__GNUC__) || defined(__clang__)
-# define libzahl_msb_nz_lu(x) (8 * sizeof(unsigned long int) - (size_t)__builtin_clzl(x));
-# define libzahl_msb_nz_llu(x) (8 * sizeof(unsigned long long int) - (size_t)__builtin_clzll(x));
+# define libzahl_msb_nz_lu(x) (8 * sizeof(unsigned long int) - 1 - (size_t)__builtin_clzl(x))
+# define libzahl_msb_nz_llu(x) (8 * sizeof(unsigned long long int) - 1 - (size_t)__builtin_clzll(x))
#else
static inline size_t
libzahl_msb_nz_lu(unsigned long int x)
{
size_t r = 0;
for (; x; x >>= 1, r++);
- return r;
+ return r - 1;
}
static inline size_t
@@ -166,7 +166,7 @@ libzahl_msb_nz_llu(unsigned long long int x)
{
size_t r = 0;
for (; x; x >>= 1, r++);
- return r;
+ return r - 1;
}
#endif