[PATCH] Simplified construction of constants for __popcountSI2/__popcountDI2 in libgcc2.c
Stefan Kanthak
stefan.kanthak@nexgo.de
Fri Nov 20 11:20:55 GMT 2020
Jakub Jelinek <jakub@redhat.com> wrote:
> On Fri, Nov 20, 2020 at 11:08:41AM +0100, Stefan Kanthak wrote:
>> The construction of the "magic" constants 0x55...55, 0x33...33, 0x0f...0f
>> and 0x01...01 in __popcountSI2 and __popcountDI2 with macros is awkward;
>> these constants can simply be written as ((UWtype) ~0 / 3),
>> ((UWtype) ~0 / 5), ((UWtype) ~0 / 17) and ((UWtype) ~0 / 255)
>
> (UWtype) ~0 will only work if UWtype is unsigned int,
Hmmm... U*type is but unsigned, and both (__uint128_t) ~0 / 3 as well as
(unsigned long long) ~0 / 3 yield the expected constant 0x55...55 here,
and the other constants of course too.
> don't you really mean ~(UWtype) 0 instead?
This is indeed the better^Wcorrect solution.
Corrected patch attached.
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libgcc2.patch
Type: application/octet-stream
Size: 2732 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20201120/fdab6ca3/attachment.obj>
More information about the Gcc-patches
mailing list