Skip to contentSkip to conversation

PATCH New Norbert Lange 2 participants 4 messages Apr 10, 2019

lore
Share & tools
lore
#0 lore raw

V2 of the patchset. Fixed checkstyle issues, better identation, and aded casts to silence (false) pedantic warnings.

#1 lore raw

PATCH v2 1/2 Rename __ctz to xenomai_count_trailing_zeros

Because of conflicts with libc++ (v1/bit include file). Simplify the macro as there shouldn't be any bad cornercases

---
 include/boilerplate/compiler.h    | 31 ++++++++++---------------------
 lib/boilerplate/heapmem.c         |  2 +-
 lib/copperplate/heapobj-pshared.c |  2 +-
 3 files changed, 12 insertions(+), 23 deletions(-)
include/boilerplate/compiler.h +10 -21
index 0fcc17be1..0cd71b80a 100644
@@ -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 */
lib/boilerplate/heapmem.c +1 -1
index 8728e0d15..e6369c715 100644
@@ -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
lib/copperplate/heapobj-pshared.c +1 -1
index 5310d9092..d6cc51ae9 100644
@@ -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
Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 2/2 Simplify xenomai_count_leading_zeros

In reply to Norbert Lange

Covers now all standard integer types,
no need for corner cases.

---
 include/boilerplate/compiler.h | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
include/boilerplate/compiler.h +8 -20
index 0cd71b80a..94b9f8cad 100644
@@ -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
 }
Signature · 1 line
2.20.1
#3 lore raw

Re: (unknown)

In reply to Norbert Lange
Quoted 3 lines · Norbert Lange via Xenomai

V2 of the patchset. Fixed checkstyle issues, better identation, and aded casts to silence (false) pedantic warnings.

Both applied to next, thanks.

You probably want to edit your cover letter subject as well - or use git format-patch.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux