icc and microsoft have a _xgetbv intrinsic for the XGETBV instruction, which is needed to check if AVX or MPX are supported by the kernel.
gcc is missing an intrinsic for that, so everyone has to write inline assembler. Should add one.
You need more than an intrinsic to know if AVX or MPX is available.
So far, run-time implementation has no issue with inline asm statement.
Portability is one main reason to add missing intrinsics... with combination of cpuid check and _xgetbv() we can cleanly check if AVX or MPX is available at run-time. We can also check specific instructions during configure process to see if we need to add workarounds for bad or missing functions/intrinsics.
Some developers think that cleanliness of the code is more important than need to reduplicate hand-written assembler code every time for optimal performance.
We have to remember that gcc is not only used for BSD-like operating systems, including OS/X, Linux, *BSD etc, but for Cygwin, MSYS/MSYS2 and MinGW which benefit from gcc being as close as possible compiler of Visual C++ regarding intrinsics support.
(In reply to postmaster from comment #2)
> Portability is one main reason to add missing intrinsics... with combination
> of cpuid check and _xgetbv() we can cleanly check if AVX or MPX is available
> at run-time. We can also check specific instructions during configure
> process to see if we need to add workarounds for bad or missing
+1. We were trying to use Intel's algorithm described at https://software.intel.com/en-us/blogs/2011/04/14/is-avx-enabled . We should only need __get_cpuid and _xgetbv. We should not need that nasty GCC inline assembly.
This intrinsics was added in gcc 8. Initial implementation was buggy (see r85684) and was fixed in 8.2 However there is one more issue here: Intel Intrinsics Guide says that it should be available by including <immintrin.h>, however in gcc you need to include <xsaveintrin.h>.
Additionally there are no defines for XFEATURE_ENABLED_MASK and possible output values.
I meant pr85684
Date: Mon Jan 21 12:23:49 2019
New Revision: 268113
i386: Move Intel intrinsics head files to <immintrin.h>
According to Intel Intrinsics Guide:
Intel intrinsics should be available by including <immintrin.h>. This
patch moves remaining Intel intrinsics head files from <x86intrin.h> to
* config/i386/adxintrin.h: Just check _IMMINTRIN_H_INCLUDED.
* config/i386/clflushoptintrin.h: Check _IMMINTRIN_H_INCLUDED
instead of _X86INTRIN_H_INCLUDED.
* onfig/i386/clwbintrin.h: Likewise.
* config/i386/pkuintrin.h: Likewise.
* config/i386/prfchwintrin.h: Likewise.
* config/i386/rdseedintrin.h: Likewise.
* config/i386/wbnoinvdintrin.h: Likewise.
* config/i386/xsavecintrin.h: Likewise.
* config/i386/xsavesintrin.h: Likewise.
* config/i386/fxsrintrin.h: Enable _IMMINTRIN_H_INCLUDED check.
* config/i386/xsaveintrin.h: Likewise.
* config/i386/xsaveoptintrin.h: Likewise.
* config/i386/x86intrin.h: Move "#include" <rdseedintrin.h>,
<prfchwintrin.h>, <fxsrintrin.h>, <xsaveintrin.h>,
<xsaveoptintrin.h>, <adxintrin.h>, <clwbintrin.h>,
<clflushoptintrin.h>, <xsavesintrin.h>, <xsavecintrin.h>,
<wbnoinvdintrin.h> and <pkuintrin.h> to ...
* config/i386/immintrin.h: Here.
(In reply to Daniel Fruzynski from comment #4)
> This intrinsics was added in gcc 8. Initial implementation was buggy (see
> r85684) and was fixed in 8.2 However there is one more issue here: Intel
> Intrinsics Guide says that it should be available by including
> <immintrin.h>, however in gcc you need to include <xsaveintrin.h>.
Fixed for GCC 9.
> Additionally there are no defines for XFEATURE_ENABLED_MASK and possible
> output values.
I will investigate it.