On Mon, Nov 20, 2023 at 02:55:33PM +0000, Joseph Myers wrote: > On Sat, 18 Nov 2023, Jakub Jelinek wrote: > > > +@defbuiltin{@var{type} __builtin_stdc_bit_ceil (@var{type} @var{arg})} > > +The @code{__builtin_stdc_bit_ceil} function is available only > > +in C. It is type-generic, the argument can be any unsigned integer > > +(standard, extended or bit-precise). No integral argument promotions are > > +performed on the argument. It is equivalent to > > +@code{@var{arg} <= 1 ? (@var{type}) 1 > > +: (@var{type}) 1 << (@var{prec} - __builtin_clzg ((@var{type}) (@var{arg} > > - 1)))} > > +where @var{prec} is bit width of @var{type}, except that side-effects > > +in @var{arg} are evaluated just once. > > +@enddefbuiltin > > Note that stdc_bit_ceil now has defined behavior (return 0) on overflow: > CD2 comment FR-135 was accepted for the DIS at the June WG14 meeting. > This affects both the documentation and the implementation, as they need > to avoid an undefined shift by the width of the type. That's why my > stdbit.h implementations have two shifts (not claiming that's necessarily > the optimal way of ensuring the correct result in the overflow case). > > return __x <= 1 ? 1 : ((uint64_t) 1) << (__bw64_inline (__x - 1) - 1) << 1;
So return __x <= 1 ? 1 : ((uint64_t) 2) << (__bw64_inline (__x - 1) - 1); then? Jakub