From: Norbert Lange <nolange79@gmail.com>
To: xenomai@xenomai.org
Subject: [PATCH v2 1/2] Rename __ctz to xenomai_count_trailing_zeros
Date: Wed, 10 Apr 2019 13:17:36 +0200 [thread overview]
Message-ID: <20190410111737.19098-2-norbert.lange@andritz.com> (raw)
In-Reply-To: <20190410111737.19098-1-norbert.lange@andritz.com>
Because of conflicts with libc++ (v1/bit include file).
Simplify the macro as there shouldn't be any bad cornercases
Signed-off-by: Norbert Lange <norbert.lange@andritz.com>
---
include/boilerplate/compiler.h | 31 ++++++++++---------------------
lib/boilerplate/heapmem.c | 2 +-
lib/copperplate/heapobj-pshared.c | 2 +-
3 files changed, 12 insertions(+), 23 deletions(-)
diff --git a/include/boilerplate/compiler.h b/include/boilerplate/compiler.h
index 0fcc17be1..0cd71b80a 100644
--- a/include/boilerplate/compiler.h
+++ b/include/boilerplate/compiler.h
@@ -71,27 +71,16 @@
#ifdef __cplusplus
extern "C" {
#endif
-
+
void __invalid_operand_size(void);
-#define __ctz(__v) \
- ({ \
- int __ret; \
- if (!__v) \
- __ret = sizeof(__v) * 8; \
- else \
- switch (sizeof(__v)) { \
- case sizeof(int): \
- __ret = __builtin_ctz((unsigned int)__v); \
- break; \
- case sizeof(long long): \
- __ret = __builtin_ctzll(__v); \
- break; \
- default: \
- __invalid_operand_size(); \
- } \
- __ret; \
- })
+#define xenomai_count_trailing_zeros(x) \
+ ((x) == 0 ? (int)(sizeof(x) * __CHAR_BIT__) \
+ : sizeof(x) <= sizeof(unsigned int) ? \
+ __builtin_ctz((unsigned int)x) \
+ : sizeof(x) <= sizeof(unsigned long) ? \
+ __builtin_ctzl((unsigned long)x) \
+ : __builtin_ctzll(x))
#define xenomai_count_leading_zeros(__v) \
({ \
@@ -111,9 +100,9 @@ void __invalid_operand_size(void);
} \
__ret; \
})
-
+
#ifdef __cplusplus
}
#endif
-
+
#endif /* _BOILERPLATE_COMPILER_H */
diff --git a/lib/boilerplate/heapmem.c b/lib/boilerplate/heapmem.c
index 8728e0d15..e6369c715 100644
--- a/lib/boilerplate/heapmem.c
+++ b/lib/boilerplate/heapmem.c
@@ -476,7 +476,7 @@ void *heapmem_alloc(struct heap_memory *heap, size_t size)
bmask = ext->pagemap[pg].map;
if (bmask == -1U)
break;
- b = __ctz(~bmask);
+ b = xenomai_count_trailing_zeros(~bmask);
/*
* Got one block from the heading per-bucket
diff --git a/lib/copperplate/heapobj-pshared.c b/lib/copperplate/heapobj-pshared.c
index 5310d9092..d6cc51ae9 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -529,7 +529,7 @@ static void *sheapmem_alloc(struct shared_heap_memory *heap, size_t size)
bmask = ext->pagemap[pg].map;
if (bmask == -1U)
break;
- b = __ctz(~bmask);
+ b = xenomai_count_trailing_zeros(~bmask);
/*
* Got one block from the heading per-bucket
--
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 ` Norbert Lange [this message]
2019-04-10 11:17 ` [PATCH v2 2/2] Simplify xenomai_count_leading_zeros Norbert Lange
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-2-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.