Re: [PATCH] libstdc++: Optimize std::has_single_bit

2022-04-14 Thread Patrick Palka via Gcc-patches
On Thu, Apr 14, 2022 at 2:59 PM Jonathan Wakely wrote: > > On Thu, 14 Apr 2022 at 19:17, Patrick Palka via Libstdc++ > wrote: > > > > This reimplements std::has_single_bit using the well-known bit-twiddilng > > trick[1], which is much faster than popcount on x86_64. > > Is that always true for

Re: [PATCH] libstdc++: Optimize std::has_single_bit

2022-04-14 Thread Jonathan Wakely via Gcc-patches
On Thu, 14 Apr 2022 at 19:17, Patrick Palka via Libstdc++ wrote: > > This reimplements std::has_single_bit using the well-known bit-twiddilng > trick[1], which is much faster than popcount on x86_64. Is that always true for all microarchitectures? We have https://gcc.gnu.org/PR97759 on this

[PATCH] libstdc++: Optimize std::has_single_bit

2022-04-14 Thread Patrick Palka via Gcc-patches
This reimplements std::has_single_bit using the well-known bit-twiddilng trick[1], which is much faster than popcount on x86_64. Note that when __x is signed and maximally negative then this implementation invokes UB due to signed overflow, whereas the previous implementation would return true.