Re: stdc_bit_ceil(3) and wrapping

2023-01-06 Thread Alejandro Colomar via Gcc
On 12/30/22 23:33, Alejandro Colomar wrote: Hi Yann, On 12/30/22 21:33, Alejandro Colomar wrote: On 12/30/22 21:18, Yann Droneaud wrote: What's wrong with the following ? [...] unsigned long max = upper_bound - 1; unsigned long mask = ULONG_MAX >> __builtin_clzl(max); I

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Alejandro Colomar via Gcc
Hi Yann, On 12/30/22 21:33, Alejandro Colomar wrote: On 12/30/22 21:18, Yann Droneaud wrote: What's wrong with the following ? [...] unsigned long max = upper_bound - 1; unsigned long mask = ULONG_MAX >> __builtin_clzl(max); I hate coding these magic operations out of a

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Alejandro Colomar via Gcc
On 12/30/22 22:01, Alejandro Colomar wrote: On 12/30/22 21:56, Joseph Myers wrote: On Fri, 30 Dec 2022, Alejandro Colomar via Gcc wrote: For the C standard, shifts have wrap around semantics for unsigned types: Only if the shift count is nonnegative and strictly less than the width of the

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Alejandro Colomar via Gcc
On 12/30/22 21:56, Joseph Myers wrote: On Fri, 30 Dec 2022, Alejandro Colomar via Gcc wrote: For the C standard, shifts have wrap around semantics for unsigned types: Only if the shift count is nonnegative and strictly less than the width of the type. This is about shifting by an amount

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Joseph Myers
On Fri, 30 Dec 2022, Alejandro Colomar via Gcc wrote: > For the C standard, shifts have wrap around semantics for unsigned types: Only if the shift count is nonnegative and strictly less than the width of the type. This is about shifting by an amount equal to the width of the type, which has

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Alejandro Colomar via Gcc
Hi Yann, On 12/30/22 21:18, Yann Droneaud wrote: 30 décembre 2022 à 20:55 "Alejandro Colomar via Libc-alpha" a écrit: I'm implementing a small part of equivalent code for shadow. I need stdc_bit_ceilul() for a random number generator limited to a range (you've seen some of this in the

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Alejandro Colomar via Gcc
Hi Joseph, On 12/30/22 21:38, Joseph Myers wrote: On Fri, 30 Dec 2022, Alejandro Colomar via Gcc wrote: I was wondering if there was any reason to make that UB in the standard, when unsigned wrapping has always been well-defined, and this is a case that is likely to be implemented with some

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Joseph Myers
On Fri, 30 Dec 2022, Alejandro Colomar via Gcc wrote: > I was wondering if there was any reason to make that UB in the standard, when > unsigned wrapping has always been well-defined, and this is a case that is > likely to be implemented with some operation that wraps around, right? I It's

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Alejandro Colomar via Gcc
Hi Yann, On 12/30/22 21:18, Yann Droneaud wrote: Hi, 30 décembre 2022 à 20:55 "Alejandro Colomar via Libc-alpha" a écrit: I'm implementing a small part of equivalent code for shadow. I need stdc_bit_ceilul() for a random number generator limited to a range (you've seen some of this in the

Re: stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Yann Droneaud
Hi, 30 décembre 2022 à 20:55 "Alejandro Colomar via Libc-alpha" a écrit: > > I'm implementing a small part of equivalent code for shadow. I > need > stdc_bit_ceilul() for a random number generator limited to a range (you've > seen > some of this in the glibc mailing list. > > $ grepc

stdc_bit_ceil(3) and wrapping

2022-12-30 Thread Alejandro Colomar via Gcc
Hi Joseph, I'm implementing a small part of equivalent code for shadow. I need stdc_bit_ceilul() for a random number generator limited to a range (you've seen some of this in the glibc mailing list. $ grepc -tfd shadow_random_uniform ./libmisc/random.c:76: unsigned long