]> git.ipfire.org Git - thirdparty/systemd.git/commit
basic/util: add macro variants of log2 functions
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 26 Nov 2021 10:46:54 +0000 (11:46 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 29 Nov 2021 10:12:52 +0000 (11:12 +0100)
commitf4ada1b42ffd14a12bbad48b40d65332673bc869
treee2e2a0e1b1b2a7873fbcf8cfea25b7a9d746d728
parent58c34be864fd47ebca7d1cc5acfb716a8731bc8c
basic/util: add macro variants of log2 functions

The macro variants can be used in static initializers.

The same guard against calling __builtin_clz(0) is added as for
__builtin_clzll(0), since that's undefined behaviour too. Our code
wouldn't call it, but this avoids a potential pitfall with the macro.
All variants map 0→0. Otherwise we'd often have to handle 0 specially
in callers.

__builtin_clz takes unsigned as the argument, so there's no LOG2I macro.
src/basic/util.h
src/test/test-util.c