On Tue, Nov 21, 2023 at 12:12:18AM +0000, Joseph Myers wrote: > On Mon, 20 Nov 2023, Jakub Jelinek wrote: > > > and be done with that. If there is an agreement we should do that > > for all 14 rather than just those 3 + the 2 ugly hacks (__builtin_c{l,t}zg > > with > > 0ULL second argument and __builtin_bit_complement), I can change the > > I tend to agree with the "ugly hack" description of the 0ULL second > argument special case.
It could be done differently, e.g. by adding optional third argument with the meaning that if that third argument is present and constant non-zero, the return value on 0 first argument would be second argument + bitsize of the first argument, while if the third argument is not present or constant zero, it is the current behavior of second argument on constant zero. Given that I've already posted all 14 __builtin_stdc_*, that isn't strictly needed for stdbit.h, the only question is if it would be useful for users in other cases. If there is the _Generic extension or say even just a new builtin like __builtin_save_expr (x, y) which would introduce some special fixed identifier when evaluating y for the value (but not side-effects) of x, that wouldn't be needed and I agree going for something like that would be cleaner. Jakub