[clang] [clang] Introduce elementwise clz/ctz builtins (PR #131995)
Fraser Cormack via cfe-commits
cfe-commits at lists.llvm.org
Tue May 13 02:06:23 PDT 2025
================
@@ -831,6 +832,14 @@ of different sizes and signs is forbidden in binary and ternary builtins.
semantics, see `LangRef
<http://llvm.org/docs/LangRef.html#llvm-min-intrinsics-comparation>`_
for the comparison.
+ T __builtin_elementwise_clz(T x[, T y]) return the number of leading 0 bits in the first argument. If integer types
+ the first argument is 0 and an optional second argument is provided,
+ the second argument is returned. If the first argument is 0 but only
+ one argument is provided, the behaviour is undefined.
+ T __builtin_elementwise_ctz(T x[, T y]) return the number of trailing 0 bits in the first argument. If integer types
+ the first argument is 0 and an optional second argument is provided,
+ the second argument is returned. If the first argument is 0 but only
+ one argument is provided, the behaviour is undefined.
----------------
frasercrmck wrote:
As expected, nobody has any strong opinions. Neither do I, to be honest. I think either `__builtin_elementwise_ctz` or `__builtin_elementwise_cttz`. Having `g` doesn't make much sense to me if there are no non-g alternatives.
There are already builtins like `__builtin_elementwise_popcount` which map to `llvm.ctpop` so my inclination is to stick with the GCC names. If you feel strongly about having the intrinsic naming I'll go with that.
https://github.com/llvm/llvm-project/pull/131995
More information about the cfe-commits
mailing list