On Fri, Nov 10, 2023 at 10:44:12AM +0100, Jakub Jelinek wrote: > Because the builtins are just something matching in behavior to existing > builtins which can be used for those macros, not exact implementation of > those.
BTW, the new builtins also allow implementation of generic signed_type_for and unsigned_type_for macros in C (together with __builtin_classify_type), I think _Generic over known standard and extended types plus for _BitInt (__builtin_classify_type (__typeof (x)) == 18) something like in the following source: void bar (_BitInt(193) *, unsigned _BitInt(193) *); void foo (void) { unsigned _BitInt(193) a = 0uwb; _BitInt(__builtin_popcountg ((__typeof (a)) -1)) b = 0wb; bar (&b, &a); } void baz (void) { _BitInt(193) a = 0wb; unsigned _BitInt(__builtin_clrsbg ((__typeof (a)) - 1) + 1) b = 0uwb; bar (&a, &b); } One needs to use __builtin_popcountg on all ones for unsigned types and 1 + __builtin_clrsbg on all ones for signed types, but otherwise it seems to work fine. Of course, for signed_type_for one would need to decide what to do with unsigned _BitInt(1) type which doesn't have signed counterpart, but that can be dealt in _Generic. Jakub