Bruno Haible via Gnulib discussion list <[email protected]> writes:
> The original code in lib/crc.c was using
>
> 0 < __builtin_cpu_supports (feature)
>
> Can __builtin_cpu_supports return negative values or values > 1 ?
It appears that it cannot return values other than 0 or 1. See some i386
definitions where "true" and "false" are used [1]. Furthermore,
throughout GCC it is usually treated like it returns a bool. I.e., one
of the following:
if (__builtin_cpu_supports ("avx2") { }
if (! __builtin_cpu_supports ("avx2")) { }
Pádraig, should be fine to push after addressing the rest of Bruno's
points. I definitely agree that some documentation in the header above
definitions/declarations would be nice.
It would be nice to add a test module, but I'm conflicted on whether it
is too much of a chore. Since there isn't an easy way to check if a
hwcap is supported at runtime.
Procfs isn't portable, and I don't think we could use CPU predefines.
For example, compiling with the following:
$ echo | gcc -mavx512f -dM -E - | grep AVX
#define __AVX512F__ 1
But my CPU doesn't support AVX512.
Thanks,
Collin
[1]
https://github.com/gcc-mirror/gcc/blob/908edc130910c5bea6d2d6b2a390793e7c106a6a/gcc/config/i386/i386-builtins.cc#L1334