Module: xenomai-3 Branch: stable-3.0.x Commit: 5defc2afa24f72d8fc138582a1f4e51c21eeb2a5 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=5defc2afa24f72d8fc138582a1f4e51c21eeb2a5
Author: Philippe Gerum <r...@xenomai.org> Date: Tue Jun 7 10:10:17 2016 +0200 boilerplate: provide count-leading/trailing-bits ops --- include/boilerplate/compiler.h | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/boilerplate/compiler.h b/include/boilerplate/compiler.h index e558f73..0509e33 100644 --- a/include/boilerplate/compiler.h +++ b/include/boilerplate/compiler.h @@ -58,4 +58,52 @@ #define __deprecated __attribute__((__deprecated__)) #endif +#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 clz(__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; \ + }) + +#ifdef __cplusplus +} +#endif + #endif /* _BOILERPLATE_COMPILER_H */ _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org https://xenomai.org/mailman/listinfo/xenomai-git