Skip to content

Commit

Permalink
libutils: add kernel word size related CTZ macro
Browse files Browse the repository at this point in the history
Add kernel word size related macros CxZ_WORD() for ctz and clz builtin
func. And also add CxZLL() macro for 64bits data size.

Signed-off-by: colorglass <[email protected]>
  • Loading branch information
colorglass committed Jan 31, 2024
1 parent 5a0472c commit 082f077
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libutils/include/utils/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define CLZ(x) __builtin_clz(x)
#define CTZL(x) __builtin_ctzl(x)
#define CLZL(x) __builtin_clzl(x)
#define CTZLL(x) __builtin_ctzll(x)
#define CLZLL(x) __builtin_clzll(x)
#define FFS(x) __builtin_ffs(x)
#define FFSL(x) __builtin_ffsl(x)
#define OFFSETOF(type, member) __builtin_offsetof(type, member)
Expand All @@ -29,6 +31,18 @@
#define BSWAP_WORD(x) __builtin_bswap64(x)
#endif

#if CONFIG_WORD_SIZE == 32
#define CTZ_WORD(x) CTZL(x)
#elif CONFIG_WORD_SIZE == 64
#define CTZ_WORD(x) CTZLL(x)
#endif

#if CONFIG_WORD_SIZE == 32
#define CLZ_WORD(x) CLZL(x)
#elif CONFIG_WORD_SIZE == 64
#define CLZ_WORD(x) CLZLL(x)
#endif

/* The UNREACHABLE macro is used in some code that is imported to Isabelle via
* the C-to-Simpl parser. This parser can handle calls to uninterpreted
* functions, but it needs to see a function declaration before the call site,
Expand Down

0 comments on commit 082f077

Please sign in to comment.