diff mbox

[v4,1/2] configure: detect ifunc and avx2 attribute

Message ID 1453280742-20718-2-git-send-email-liang.z.li@intel.com
State New
Headers show

Commit Message

Li, Liang Z Jan. 20, 2016, 9:05 a.m. UTC
Detect if the compiler can support the ifun and avx2, if so, set
CONFIG_AVX2_OPT which will be used to turn on the avx2 instruction
optimization.

Signed-off-by: Liang Li <liang.z.li@intel.com>
---
 configure | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Paolo Bonzini Jan. 20, 2016, 9:50 a.m. UTC | #1
On 20/01/2016 10:05, Liang Li wrote:
> Detect if the compiler can support the ifun and avx2, if so, set
> CONFIG_AVX2_OPT which will be used to turn on the avx2 instruction
> optimization.
> 
> Signed-off-by: Liang Li <liang.z.li@intel.com>
> ---
>  configure | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/configure b/configure
> index 44ac9ab..b7f4661 100755
> --- a/configure
> +++ b/configure
> @@ -310,6 +310,7 @@ smartcard=""
>  libusb=""
>  usb_redir=""
>  opengl=""
> +avx2_opt=""
>  zlib="yes"
>  lzo=""
>  snappy=""
> @@ -1827,6 +1828,20 @@ EOF
>  fi
>  
>  ##########################################
> +# avx2 optimization requirement check
> +
> +cat > $TMPC << EOF
> +static void bar(void) {}

Might be nicer to use "void *" and return an actual function name:

static void bar(void) {}
static void *bar_ifunc(void) { return (void *)bar; }
void foo(void) __attribute__((ifunc("bar_ifunc")));

And also you probably should use "readelf --syms ... | grep IFUNC.*foo"
to check that the attribute was not ignored.

Paolo


> +static void foo(void) __attribute__((ifunc("bar")));
> +int main(void) { foo(); return 0; }
> +EOF
> +if compile_prog "" "-mavx2" ; then
> +    avx2_opt="yes"
> +else
> +    avx2_opt="no"
> +fi
> +
> +#########################################
>  # zlib check
>  
>  if test "$zlib" != "no" ; then
> @@ -4855,6 +4870,7 @@ echo "bzip2 support     $bzip2"
>  echo "NUMA host support $numa"
>  echo "tcmalloc support  $tcmalloc"
>  echo "jemalloc support  $jemalloc"
> +echo "avx2 optimization $avx2_opt"
>  
>  if test "$sdl_too_old" = "yes"; then
>  echo "-> Your SDL version is too old - please upgrade to have SDL support"
> @@ -5236,6 +5252,10 @@ if test "$opengl" = "yes" ; then
>    echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
>  fi
>  
> +if test "$avx2_opt" = "yes" ; then
> +  echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
> +fi
> +
>  if test "$lzo" = "yes" ; then
>    echo "CONFIG_LZO=y" >> $config_host_mak
>  fi
>
Li, Liang Z Jan. 20, 2016, 10:43 a.m. UTC | #2
> On 20/01/2016 10:05, Liang Li wrote:
> > Detect if the compiler can support the ifun and avx2, if so, set
> > CONFIG_AVX2_OPT which will be used to turn on the avx2 instruction
> > optimization.
> >
> > Signed-off-by: Liang Li <liang.z.li@intel.com>
> > ---
> >  configure | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> >
> > diff --git a/configure b/configure
> > index 44ac9ab..b7f4661 100755
> > --- a/configure
> > +++ b/configure
> > @@ -310,6 +310,7 @@ smartcard=""
> >  libusb=""
> >  usb_redir=""
> >  opengl=""
> > +avx2_opt=""
> >  zlib="yes"
> >  lzo=""
> >  snappy=""
> > @@ -1827,6 +1828,20 @@ EOF
> >  fi
> >
> >  ##########################################
> > +# avx2 optimization requirement check
> > +
> > +cat > $TMPC << EOF
> > +static void bar(void) {}
> 
> Might be nicer to use "void *" and return an actual function name:
> 
> static void bar(void) {}
> static void *bar_ifunc(void) { return (void *)bar; } void foo(void)
> __attribute__((ifunc("bar_ifunc")));
> 
> And also you probably should use "readelf --syms ... | grep IFUNC.*foo"
> to check that the attribute was not ignored.
> 
> Paolo
> 

Got it, will change in the next version.

Liang
diff mbox

Patch

diff --git a/configure b/configure
index 44ac9ab..b7f4661 100755
--- a/configure
+++ b/configure
@@ -310,6 +310,7 @@  smartcard=""
 libusb=""
 usb_redir=""
 opengl=""
+avx2_opt=""
 zlib="yes"
 lzo=""
 snappy=""
@@ -1827,6 +1828,20 @@  EOF
 fi
 
 ##########################################
+# avx2 optimization requirement check
+
+cat > $TMPC << EOF
+static void bar(void) {}
+static void foo(void) __attribute__((ifunc("bar")));
+int main(void) { foo(); return 0; }
+EOF
+if compile_prog "" "-mavx2" ; then
+    avx2_opt="yes"
+else
+    avx2_opt="no"
+fi
+
+#########################################
 # zlib check
 
 if test "$zlib" != "no" ; then
@@ -4855,6 +4870,7 @@  echo "bzip2 support     $bzip2"
 echo "NUMA host support $numa"
 echo "tcmalloc support  $tcmalloc"
 echo "jemalloc support  $jemalloc"
+echo "avx2 optimization $avx2_opt"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -5236,6 +5252,10 @@  if test "$opengl" = "yes" ; then
   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
 fi
 
+if test "$avx2_opt" = "yes" ; then
+  echo "CONFIG_AVX2_OPT=y" >> $config_host_mak
+fi
+
 if test "$lzo" = "yes" ; then
   echo "CONFIG_LZO=y" >> $config_host_mak
 fi