Hi Pádraig,

Pádraig Brady <[email protected]> writes:

> The attached 2 patches, add a new cpu-supports module,
> and updates the crc-x86_64 module to use it.
> This ensures that any users of the crc-x86_64 module
> will honor the GLIBC_TUNABLES environment variable.
> Specifically it will allow disabling of the hardware acceleration
> used by crc-x86_64 using:

>   export GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX
>
> Note this is a general mechanism provided by glibc
> to tune hardware acceleration within glibc and also
> determines what libs are loaded with its dynamic dispatch mechanism:
> On my "x86-64-v3" system for example:
>
> $ ld.so --help | grep -B1 x86-64-v
> Subdirectories of glibc-hwcaps directories, in priority order:
>   x86-64-v4
>   x86-64-v3 (supported, searched)
>   x86-64-v2 (supported, searched)
> $ ld.so --help | GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX \
>  grep -B1 x86-64-v
> Subdirectories of glibc-hwcaps directories, in priority order:
>   x86-64-v4
>   x86-64-v3 (supported, searched)
>   x86-64-v2 (supported, searched)
>
> This module will also be used by coreutils to ensure
> its various uses of __builtin_cpu_supports() are similarly gated.

Ah, I should have known that we needed this in Gnulib for crc32. Thanks
for working on it.

I'll give a more through review later, but one thing that that popped
out to me during an initial skim:

> +  if (0);
> +# if defined __x86_64__
> +  else if (STREQ (feature, "avx"))          hwcap = "-AVX";
> +  else if (STREQ (feature, "avx2"))         hwcap = "-AVX2";
> +  else if (STREQ (feature, "avx512bw"))     hwcap = "-AVX512BW";
> +  else if (STREQ (feature, "avx512f"))      hwcap = "-AVX512F";
> +  else if (STREQ (feature, "pclmul"))       hwcap = "-PCLMULQDQ";
> +  else if (STREQ (feature, "vpclmulqdq"))   hwcap = "-VPCLMULQDQ";
> +# elif defined __aarch64__
> +  else if (STREQ (feature, "pmull"))        hwcap "-PMULL";
> +# endif
> +
> +  return hwcap;
> +}

I like the attempt to minimize lines of code, but I recall clang warning
about this by default:

    $ cat main.c
    int
    main (void)
    {
      if (0);
      return 0;
    }
    $ clang main.c
    main.c:5:9: warning: if statement has empty body [-Wempty-body]
        5 |   if (0);
          |         ^
    main.c:5:9: note: put the semicolon on a separate line to silence this 
warning
    1 warning generated.
    $ clang -v 2>&1 | head -n 1
    clang version 20.1.8 (Fedora 20.1.8-4.fc42)

Also, lib/cpu-supports.c needs a copyright header.

Collin

Reply via email to