include/sys/util: Rework _Generic & C++11 usage
The recently-added LOG2 family of macros were implemented using either
a compile-time expanded C11 _Generic expression or a C++11 constexpr
template. As it happens, Cadence xt-xcc supports neither of these
constructs, and integration for the next-generation xt-clang[1] hasn't
arrived yet.
Let's back out to a more portable (heh) implementation using gcc
__typeof__. This keeps the advantage of expanding to a single
__builtin_clz() for common case usage and is result-compatible with
the new LOG2/LOG2CEIL/NHPOT.
The one downside is that the generic code was able to be used in a
constant context, something that statement expressions can't do. So
the resulting macros are (like the earlier LOG2CEIL was) unhygienic
and multi-expand their arguments. I added a warning to this effect in
the docs.
[1] Which is still based on an ancient clang tree, but more recent
than their GCC 4.2 compiler.
Signed-off-by:
Andy Ross <andyross@google.com>
Loading
Please sign in to comment