Commit 1b579717 authored by Norbert Lange via Xenomai's avatar Norbert Lange via Xenomai Committed by Jan Kiszka

Simplify xenomai_count_leading_zeros

Covers now all standard integer types,
no need for corner cases.
Signed-off-by: default avatarNorbert Lange <norbert.lange@andritz.com>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent 5e535080
......@@ -72,8 +72,6 @@
extern "C" {
#endif
void __invalid_operand_size(void);
#define xenomai_count_trailing_zeros(x) \
((x) == 0 ? (int)(sizeof(x) * __CHAR_BIT__) \
: sizeof(x) <= sizeof(unsigned int) ? \
......@@ -82,24 +80,14 @@ void __invalid_operand_size(void);
__builtin_ctzl((unsigned long)x) \
: __builtin_ctzll(x))
#define xenomai_count_leading_zeros(__v) \
({ \
int __ret; \
if (!__v) \
__ret = sizeof(__v) * 8; \
else \
switch (sizeof(__v)) { \
case sizeof(int): \
__ret = __builtin_clz((unsigned int)__v); \
break; \
case sizeof(long long): \
__ret = __builtin_clzll(__v); \
break; \
default: \
__invalid_operand_size(); \
} \
__ret; \
})
#define xenomai_count_leading_zeros(x) \
((x) == 0 ? (int)(sizeof(x) * __CHAR_BIT__) \
: sizeof(x) <= sizeof(unsigned int) ? \
__builtin_clz((unsigned int)x) + \
(int)(sizeof(unsigned int) - sizeof(x)) \
: sizeof(x) <= sizeof(unsigned long) ? \
__builtin_clzl((unsigned long)x) \
: __builtin_clzll(x))
#ifdef __cplusplus
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment