Skip to content
Commit 3843cebb authored by Andy Ross's avatar Andy Ross Committed by Christopher Friedt
Browse files

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: default avatarAndy Ross <andyross@google.com>
parent 7df2ca6e
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment