[clang] [clang] Implement __builtin_{clzg,ctzg} (PR #83431)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 19 21:57:47 PDT 2024


================
@@ -3504,6 +3504,47 @@ argument can be of any unsigned integer type.
 ``__builtin_popcount{,l,ll}`` builtins, with support for other integer types,
 such as ``unsigned __int128`` and C23 ``unsigned _BitInt(N)``.
 
+``__builtin_clzg`` and ``__builtin_ctzg``
+-----------------------------------------
+
+``__builtin_clzg`` (respectively ``__builtin_ctzg``) returns the number of
+leading (respectively trailing) 0 bits in the first argument. The first argument
+can be of any unsigned integer type.
+
+If the first argument is 0 and an optional second argument of ``int`` type is
+provided, then the second argument is returned. If the first argument is 0, but
+only one argument is provided, then the returned value is undefined.
----------------
efriedma-quic wrote:

Probably should say "the behavior is undefined", to match the C standard wording for this sort of thing.  (The IR intrinsic returns poison, but "poison" isn't a C language concept.)

https://github.com/llvm/llvm-project/pull/83431


More information about the cfe-commits mailing list