<div dir="ltr">The only guaranteed way I can think of to ensure compiler support is to try compiling source that calls one intrinsic from each of the used groups.  I can see that being "more correct" but I can't really think of a situation where just checking for the __AVX2__ define will fail to build wither.<br><div class="gmail_extra"><br clear="all"><div><div data-smartmail="gmail_signature"><div dir="ltr">- Chuck<br></div></div></div>
<br><div class="gmail_quote">On Tue, Jun 28, 2016 at 2:10 PM, Chuck Atkins <span dir="ltr"><<a href="mailto:chuck.atkins@kitware.com" target="_blank">chuck.atkins@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">So this seems to be different across versions as well.  It looks like __AVX__ and __AVX2__ are the only ones we can really count on being there.  I can drop the second check to just __AVX2__.  I think it's redundant by chance though that all CPUs that supported AVX2 also seem to support the additional 2 instructions.<span><font color="#888888"><br></font></span></div><div class="gmail_extra"><span><font color="#888888"><br clear="all"><div><div data-smartmail="gmail_signature"><div dir="ltr">- Chuck<br></div></div></div></font></span><div><div>
<br><div class="gmail_quote">On Tue, Jun 28, 2016 at 1:52 PM, Rowley, Timothy O <span dir="ltr"><<a href="mailto:timothy.o.rowley@intel.com" target="_blank">timothy.o.rowley@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><br>
> On Jun 28, 2016, at 8:24 AM, Chuck Atkins <<a href="mailto:chuck.atkins@kitware.com" target="_blank">chuck.atkins@kitware.com</a>> wrote:<br>
><br>
> Encapsulate the test for which flags are needed to get a compiler to<br>
> support certain features.  Along with this, give various options to try<br>
> for AVX and AVX2 support.  Ideally we want to use specific instruction<br>
> set feature flags, like -mavx2 for instance instead of -march=haswell,<br>
> but the flags required for certain compilers are different.  This<br>
> allows, for AVX2 for instance, GCC to use -mavx2 -mfma -mbmi2 -mf16c<br>
> while the Intel compiler which doesn't support those flags can fall<br>
> back to using -march=core-avx2.<br>
><br>
> This addresses a bug where the Intel compiler will silently ignore the<br>
> AVX2 instruction feature flags and then potentially fail to build.<br>
><br>
> Cc: Tim Rowley <<a href="mailto:timothy.o.rowley@intel.com" target="_blank">timothy.o.rowley@intel.com</a>><br>
> Signed-off-by: Chuck Atkins <<a href="mailto:chuck.atkins@kitware.com" target="_blank">chuck.atkins@kitware.com</a>><br>
> ---<br>
> <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 86 +++++++++++++++++++++++++++++++++++++++++++-----------------<br>
> 1 file changed, 62 insertions(+), 24 deletions(-)<br>
><br>
> diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> index cc9bc47..806850e 100644<br>
> --- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> +++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> @@ -2330,6 +2330,39 @@ swr_llvm_check() {<br>
>     fi<br>
> }<br>
><br>
> +swr_cxx_feature_flags_check() {<br>
> +    ifndef_test=$1<br>
> +    option_list="$2"<br>
> +    unset SWR_CXX_FEATURE_FLAGS<br>
> +    AC_LANG_PUSH([C++])<br>
> +    save_CXXFLAGS="$CXXFLAGS"<br>
> +    save_IFS="$IFS"<br>
> +    IFS=","<br>
> +    found=0<br>
> +    for opts in $option_list<br>
> +    do<br>
> +        unset IFS<br>
> +        CXXFLAGS="$opts $save_CXXFLAGS"<br>
> +        AC_COMPILE_IFELSE(<br>
> +            [AC_LANG_PROGRAM(<br>
> +                [   $ifndef_test<br>
> +                    #error<br>
> +                    #endif<br>
> +                ])],<br>
> +            [found=1; break],<br>
> +            [])<br>
> +        IFS=","<br>
> +    done<br>
> +    IFS="$save_IFS"<br>
> +    CXXFLAGS="$save_CXXFLAGS"<br>
> +    AC_LANG_POP([C++])<br>
> +    if test $found -eq 1; then<br>
> +        SWR_CXX_FEATURE_FLAGS="$opts"<br>
> +        return 0<br>
> +    fi<br>
> +    return 1<br>
> +}<br>
> +<br>
> dnl Duplicates in GALLIUM_DRIVERS_DIRS are removed by sorting it after this block<br>
> if test -n "$with_gallium_drivers"; then<br>
>     gallium_drivers=`IFS=', '; echo $with_gallium_drivers`<br>
> @@ -2399,31 +2432,36 @@ if test -n "$with_gallium_drivers"; then<br>
>         xswr)<br>
>             swr_llvm_check "swr"<br>
><br>
> -            AC_MSG_CHECKING([whether $CXX supports c++11/AVX/AVX2])<br>
> -            SWR_AVX_CXXFLAGS="-mavx"<br>
> -            SWR_AVX2_CXXFLAGS="-mavx2 -mfma -mbmi2 -mf16c"<br>
> -<br>
> -            AC_LANG_PUSH([C++])<br>
> -            save_CXXFLAGS="$CXXFLAGS"<br>
> -            CXXFLAGS="-std=c++11 $CXXFLAGS"<br>
> -            AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],[],<br>
> -                              [AC_MSG_ERROR([c++11 compiler support not detected])])<br>
> -            CXXFLAGS="$save_CXXFLAGS"<br>
> -<br>
> -            save_CXXFLAGS="$CXXFLAGS"<br>
> -            CXXFLAGS="$SWR_AVX_CXXFLAGS $CXXFLAGS"<br>
> -            AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],[],<br>
> -                              [AC_MSG_ERROR([AVX compiler support not detected])])<br>
> -            CXXFLAGS="$save_CXXFLAGS"<br>
> -<br>
> -            save_CFLAGS="$CXXFLAGS"<br>
> -            CXXFLAGS="$SWR_AVX2_CXXFLAGS $CXXFLAGS"<br>
> -            AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],[],<br>
> -                              [AC_MSG_ERROR([AVX2 compiler support not detected])])<br>
> -            CXXFLAGS="$save_CXXFLAGS"<br>
> -            AC_LANG_POP([C++])<br>
> -<br>
> +            AC_MSG_CHECKING([whether $CXX supports c++11])<br>
> +            if ! swr_cxx_feature_flags_check \<br>
> +                "#if __cplusplus < 201103L" \<br>
> +                ",-std=c++11"; then<br>
> +                AC_MSG_RESULT([no])<br>
> +                AC_MSG_ERROR([swr requires C++11 support])<br>
> +            fi<br>
> +            AC_MSG_RESULT([$SWR_CXX_FEATURE_FLAGS])<br>
</div></div>> +            CXXFLAGS="$SWR_CXX_FEATURE_FLAGS $CXXFLAGS”<br>
<br>
We don’t want to globally override CXXFLAGS; AC_SUBST on a SWR_CXXFLAGS and using that in swr’s Makefile.am would be better.<br>
<span><br>
> +<br>
> +            AC_MSG_CHECKING([whether $CXX supports AVX])<br>
> +            if ! swr_cxx_feature_flags_check \<br>
> +                "#ifndef __AVX__" \<br>
> +                ",-mavx,-march=core-avx"; then<br>
> +                AC_MSG_RESULT([no])<br>
> +                AC_MSG_ERROR([swr requires AVX compiler support])<br>
> +            fi<br>
> +            AC_MSG_RESULT([$SWR_CXX_FEATURE_FLAGS])<br>
> +            SWR_AVX_CXXFLAGS="$SWR_CXX_FEATURE_FLAGS"<br>
>             AC_SUBST([SWR_AVX_CXXFLAGS])<br>
> +<br>
> +            AC_MSG_CHECKING([whether $CXX supports AVX2])<br>
> +            if ! swr_cxx_feature_flags_check \<br>
</span>> +                "#if !(defined(__AVX2__)&&defined(__FMA__)&&defined(__BMI2__)&&defined(__F16C__))” \<br>
<br>
Is there any standard that says these are defined if the compiler supports them?  With icc 16.0.3, the test falls into the #error path when it tries the fallback test of -march=core-avx2.<br>
<div><div><br>
> +                ",-mavx2 -mfma -mbmi2 -mf16c,-march=core-avx2"; then<br>
> +                AC_MSG_RESULT([no])<br>
> +                AC_MSG_ERROR([swr requires AVX2 compiler support])<br>
> +            fi<br>
> +            AC_MSG_RESULT([$SWR_CXX_FEATURE_FLAGS])<br>
> +            SWR_AVX2_CXXFLAGS="$SWR_CXX_FEATURE_FLAGS"<br>
>             AC_SUBST([SWR_AVX2_CXXFLAGS])<br>
><br>
>             HAVE_GALLIUM_SWR=yes<br>
> --<br>
> 2.5.5<br>
><br>
<br>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div>