2012-10-02  H.J. Lu  <hongjiu.lu@intel.com>

	* config.make.in (config-cflags-avx128): New.
	* configure.in (libc_cv_cc_avx128): AC_SUBST.
	* sysdeps/i386/configure.in: Add -mprefer-avx128 check.
	* sysdeps/x86_64/configure.in: Likewise.
	* configure: Regenerated.
	* sysdeps/i386/configure: Likewise.
	* sysdeps/x86_64/configure: Likewise.
	* sysdeps/x86_64/fpu/multiarch/Makefile (CFLAGS-e_atan2-avx.c):
	Set to -mavx -mprefer-avx128 if supported.
	(CFLAGS-e_exp-avx.c): Likewise.
	(CFLAGS-e_log-avx.c): Likewise.
	(CFLAGS-mpa-avx.c): Likewise.
	(CFLAGS-mpexp-avx.c): Likewise.
	(CFLAGS-mplog-avx.c): Likewise.
	(CFLAGS-s_atan-avx.c): Likewise.
	(CFLAGS-s_sin-avx.c): Likewise.
	(CFLAGS-slowexp-avx.c): Likewise.
	(CFLAGS-s_tan-avx.c): Likewise.

diff --git a/config.make.in b/config.make.in
index b6d1c94..0474d0c 100644
--- a/config.make.in
+++ b/config.make.in
@@ -38,6 +38,7 @@ asflags-cpu = @libc_cv_cc_submachine@
 config-extra-cflags = @libc_extra_cflags@
 config-cflags-sse4 = @libc_cv_cc_sse4@
 config-cflags-avx = @libc_cv_cc_avx@
+config-cflags-avx128 = @libc_cv_cc_avx128@
 config-cflags-sse2avx = @libc_cv_cc_sse2avx@
 config-cflags-novzeroupper = @libc_cv_cc_novzeroupper@
 config-cflags-nofma = @libc_cv_cc_nofma@
diff --git a/configure b/configure
index 739d2bd..d496f27 100755
--- a/configure
+++ b/configure
@@ -587,6 +587,7 @@ libc_cv_cc_nofma
 libc_cv_cc_fma4
 libc_cv_cc_novzeroupper
 libc_cv_cc_sse2avx
+libc_cv_cc_avx128
 libc_cv_cc_avx
 libc_cv_cc_sse4
 libc_cv_forced_unwind
@@ -7499,6 +7500,7 @@ fi
 
 
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -fPIC is default" >&5
 $as_echo_n "checking whether -fPIC is default... " >&6; }
 if ${libc_cv_pic_default+:} false; then :
diff --git a/configure.in b/configure.in
index 878bf1a..d093f6e 100644
--- a/configure.in
+++ b/configure.in
@@ -2149,6 +2149,7 @@ AC_SUBST(libc_cv_forced_unwind)
 dnl sysdeps/CPU/configure.in checks set this via arch-specific asm tests
 AC_SUBST(libc_cv_cc_sse4)
 AC_SUBST(libc_cv_cc_avx)
+AC_SUBST(libc_cv_cc_avx128)
 AC_SUBST(libc_cv_cc_sse2avx)
 AC_SUBST(libc_cv_cc_novzeroupper)
 AC_SUBST(libc_cv_cc_fma4)
diff --git a/sysdeps/i386/configure b/sysdeps/i386/configure
index 608ff29..eb82e39 100644
--- a/sysdeps/i386/configure
+++ b/sysdeps/i386/configure
@@ -162,6 +162,7 @@ else
 fi
 
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SSE4 support" >&5
 $as_echo_n "checking for SSE4 support... " >&6; }
 if ${libc_cv_cc_sse4+:} false; then :
@@ -230,6 +231,26 @@ if test $libc_cv_cc_avx = yes; then
 
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking -mprefer-avx128 support" >&5
+$as_echo_n "checking -mprefer-avx128 support... " >&6; }
+if ${libc_cv_cc_avx128+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if { ac_try='${CC-cc} -mprefer-avx128 -xc /dev/null -S -o /dev/null'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  libc_cv_cc_avx128=yes
+else
+  libc_cv_cc_avx128=no
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_avx128" >&5
+$as_echo "$libc_cv_cc_avx128" >&6; }
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for AVX encoding of SSE instructions" >&5
 $as_echo_n "checking for AVX encoding of SSE instructions... " >&6; }
 if ${libc_cv_cc_sse2avx+:} false; then :
@@ -299,3 +320,4 @@ fi
 $as_echo "$libc_cv_cc_novzeroupper" >&6; }
 
 $as_echo "#define PI_STATIC_AND_HIDDEN 1" >>confdefs.h
+
diff --git a/sysdeps/i386/configure.in b/sysdeps/i386/configure.in
index 36cb3e4..5e6ec9d 100644
--- a/sysdeps/i386/configure.in
+++ b/sysdeps/i386/configure.in
@@ -28,6 +28,13 @@ if test $libc_cv_cc_avx = yes; then
   AC_DEFINE(HAVE_AVX_SUPPORT)
 fi
 
+dnl Check if -mprefer-avx128 works.
+AC_CACHE_CHECK(-mprefer-avx128 support, libc_cv_cc_avx128, [dnl
+LIBC_TRY_CC_OPTION([-mprefer-avx128],
+		   [libc_cv_cc_avx128=yes],
+		   [libc_cv_cc_avx128=no])
+])
+
 dnl Check if -msse2avx works.
 AC_CACHE_CHECK(for AVX encoding of SSE instructions, libc_cv_cc_sse2avx, [dnl
 LIBC_TRY_CC_OPTION([-msse2avx],
diff --git a/sysdeps/x86_64/configure b/sysdeps/x86_64/configure
index adbaeee..b839fc2 100644
--- a/sysdeps/x86_64/configure
+++ b/sysdeps/x86_64/configure
@@ -72,10 +72,6 @@ $as_echo X/"$0" |
   chmod +x "$as_me.lineno" ||
     { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
 
-  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
-  # already done that, so ensure we don't try to do so again and fall
-  # in an infinite loop.  This has already happened in practice.
-  _as_can_reexec=no; export _as_can_reexec
   # Don't try to exec as it changes $[0], causing all sort of problems
   # (the dirname of $[0] is not the place where we might find the
   # original and so on.  Autoconf is especially sensitive to this).
@@ -215,6 +211,26 @@ if test $libc_cv_cc_avx = yes; then
 
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking -mprefer-avx128 support" >&5
+$as_echo_n "checking -mprefer-avx128 support... " >&6; }
+if ${libc_cv_cc_avx128+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if { ac_try='${CC-cc} -mprefer-avx128 -xc /dev/null -S -o /dev/null'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  libc_cv_cc_avx128=yes
+else
+  libc_cv_cc_avx128=no
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_avx128" >&5
+$as_echo "$libc_cv_cc_avx128" >&6; }
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for AVX encoding of SSE instructions" >&5
 $as_echo_n "checking for AVX encoding of SSE instructions... " >&6; }
 if ${libc_cv_cc_sse2avx+:} false; then :
diff --git a/sysdeps/x86_64/configure.in b/sysdeps/x86_64/configure.in
index 94bcd19..829f0fe 100644
--- a/sysdeps/x86_64/configure.in
+++ b/sysdeps/x86_64/configure.in
@@ -21,6 +21,13 @@ if test $libc_cv_cc_avx = yes; then
   AC_DEFINE(HAVE_AVX_SUPPORT)
 fi
 
+dnl Check if -mprefer-avx128 works.
+AC_CACHE_CHECK(-mprefer-avx128 support, libc_cv_cc_avx128, [dnl
+LIBC_TRY_CC_OPTION([-mprefer-avx128],
+		   [libc_cv_cc_avx128=yes],
+		   [libc_cv_cc_avx128=no])
+])
+
 dnl Check if -msse2avx works.
 AC_CACHE_CHECK(for AVX encoding of SSE instructions, libc_cv_cc_sse2avx, [dnl
 LIBC_TRY_CC_OPTION([-msse2avx],
diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile
index 12b0526..5fb764c 100644
--- a/sysdeps/x86_64/fpu/multiarch/Makefile
+++ b/sysdeps/x86_64/fpu/multiarch/Makefile
@@ -33,12 +33,24 @@ CFLAGS-s_sin-fma4.c = -mfma4
 CFLAGS-s_tan-fma4.c = -mfma4
 endif
 
-ifeq ($(config-cflags-sse2avx),yes)
+ifneq ($(config-cflags-sse2avx)$(config-cflags-avx128),nono)
 libm-sysdep_routines += e_exp-avx e_log-avx s_atan-avx \
 			e_atan2-avx s_sin-avx s_tan-avx \
 			mplog-avx mpa-avx slowexp-avx \
 			mpexp-avx
 
+ifeq ($(config-cflags-avx128),yes)
+CFLAGS-e_atan2-avx.c = -mavx -mprefer-avx128
+CFLAGS-e_exp-avx.c = -mavx -mprefer-avx128
+CFLAGS-e_log-avx.c = -mavx -mprefer-avx128
+CFLAGS-mpa-avx.c = -mavx -mprefer-avx128
+CFLAGS-mpexp-avx.c = -mavx -mprefer-avx128
+CFLAGS-mplog-avx.c = -mavx -mprefer-avx128
+CFLAGS-s_atan-avx.c = -mavx -mprefer-avx128
+CFLAGS-s_sin-avx.c = -mavx -mprefer-avx128
+CFLAGS-slowexp-avx.c = -mavx -mprefer-avx128
+CFLAGS-s_tan-avx.c = -mavx -mprefer-avx128
+else
 CFLAGS-e_atan2-avx.c = -msse2avx -DSSE2AVX
 CFLAGS-e_exp-avx.c = -msse2avx -DSSE2AVX
 CFLAGS-e_log-avx.c = -msse2avx -DSSE2AVX
@@ -51,3 +63,4 @@ CFLAGS-slowexp-avx.c = -msse2avx -DSSE2AVX
 CFLAGS-s_tan-avx.c = -msse2avx -DSSE2AVX
 endif
 endif
+endif
