From: Norbert Lange <nolange79@gmail.com>
To: xenomai@xenomai.org
Subject: [PATCH v2 2/2] Simplify xenomai_count_leading_zeros
Date: Wed, 10 Apr 2019 13:17:37 +0200 [thread overview]
Message-ID: <20190410111737.19098-3-norbert.lange@andritz.com> (raw)
In-Reply-To: <20190410111737.19098-1-norbert.lange@andritz.com>
Covers now all standard integer types,
no need for corner cases.
Signed-off-by: Norbert Lange <norbert.lange@andritz.com>
---
include/boilerplate/compiler.h | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/include/boilerplate/compiler.h b/include/boilerplate/compiler.h
index 0cd71b80a..94b9f8cad 100644
--- a/include/boilerplate/compiler.h
+++ b/include/boilerplate/compiler.h
@@ -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
}
--
2.20.1
next prev parent reply other threads:[~2019-04-10 11:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-10 11:17 Norbert Lange
2019-04-10 11:17 ` [PATCH v2 1/2] Rename __ctz to xenomai_count_trailing_zeros Norbert Lange
2019-04-10 11:17 ` Norbert Lange [this message]
2019-04-10 14:15 ` (unknown) Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190410111737.19098-3-norbert.lange@andritz.com \
--to=nolange79@gmail.com \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.