[PATCH 3/7] Remove atomic_bit_set/bit_test_set
H.J. Lu
hjl.tools@gmail.com
Tue Jul 12 18:09:21 GMT 2022
On Tue, Jul 12, 2022 at 10:47 AM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 06/07/22 17:56, H.J. Lu via Libc-alpha wrote:
> > On Wed, Jul 6, 2022 at 1:31 PM Noah Goldstein via Libc-alpha
> > <libc-alpha@sourceware.org> wrote:
> >>
> >> On Wed, Jul 6, 2022 at 1:14 PM Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
> >>>
> >>> Hi Noah,
> >>>
> >>> The goal here is to move to the standard atomics, not to invent our own set for
> >>> convenience or just for fun to be different etc. There were 2 uses of atomic_bit_set
> >>> in all of GLIBC, and I cannot believe that atomic_fetch_or (&x, 1 << bit) could cause
> >>> any confusion given that it is very similar to x |= 1 << bit. We don't wrap such
> >>> expressions in macros like bitset (x, bit) either - it just doesn't make sense.
> >>>
> >>> As I mentioned, I'll use EXITING_BITMASK rather than 1 << EXITING_BIT.
> >>
> >> Alright.
> >
> > Before GCC 12,
> >
> > (__atomic_fetch_or (&x, MASK, __ATOMIC_ACQUIRE) & MASK) != 0;
> >
> > will be optimized to "lock btsl" only if x is unsigned. But cancelhandling in
> >
> > if (atomic_bit_test_set (&pd->cancelhandling, TERMINATED_BIT) == 0)
> >
> > is signed which leads to the much worse code when GCC 11 or older are
> > used.
> >
>
> I think it should be safe to change cancelhandling to be unsigned,
> although this is really a micro-optimization that we should handle
> in the compiler instead roll-out our own atomics.
We should help older compilers in this case. Can we change cancelhandling
to unsigned?
Thanks.
--
H.J.
More information about the Libc-alpha
mailing list