On Sat, May 27, 2023 at 2:25 PM Stefan Kanthak <stefan.kant...@nexgo.de> wrote:
>
> Just to show how SLOPPY, INCONSEQUENTIAL and INCOMPETENT GCC's developers are:
>
> --- dontcare.c ---
> int ispowerof2(unsigned __int128 argument) {
>     return __builtin_popcountll(argument) + __builtin_popcountll(argument >> 
> 64) == 1;
> }
> --- EOF ---
>
> GCC 13.3    gcc -march=haswell -O3
>
> https://gcc.godbolt.org/z/PPzYsPzMc
> ispowerof2(unsigned __int128):
>         popcnt  rdi, rdi
>         popcnt  rsi, rsi
>         add     esi, edi
>         xor     eax, eax
>         cmp     esi, 1
>         sete    al
>         ret
>
> OOPS: what about Intel's CPU errata regarding the false dependency on POPCNTs 
> output?

Because the popcount is going to the same register, there is no false
dependency ....
The false dependency errata only applies if the result of the popcnt
is going to a different register, the processor thinks it depends on
the result in that register from a previous instruction but it does
not (which is why it is called a false dependency). In this case it
actually does depend on the previous result since the input is the
same as the input.

Thanks,
Andrew

>
> See https://gcc.godbolt.org/z/jdjTc3EET for comparison!
>
> FIX YOUR BUGS, KIDS!
>
> Stefan

Reply via email to