Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libutils: add kernel word size related CTZ macro #176

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 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 @@ -25,8 +27,22 @@

#if CONFIG_WORD_SIZE == 32
#define BSWAP_WORD(x) __builtin_bswap32(x)
compile_time_assert(long_is_32bits, sizeof(long) == 4)
#define CTZ_WORD(x) CTZL(x)
#define CLZ_WORD(x) CLZL(x)

#elif CONFIG_WORD_SIZE == 64
#define BSWAP_WORD(x) __builtin_bswap64(x)
compile_time_assert(long_long_is_64bits, sizeof(long long) == 8)
#define CTZ_WORD(x) CTZLL(x)
#define CLZ_WORD(x) CLZLL(x)

#else
/*
* This library aims to be agnostic of the "word" concept, so don't raise an
* error if CONFIG_WORD_SIZE is unsupported or not set. We just don't provide
* the macros at all in this case.
*/
#endif

/* The UNREACHABLE macro is used in some code that is imported to Isabelle via
Expand Down
Loading