Optimize x86-64 math inline header a bit

This commit is contained in:
Ulrich Drepper 2012-01-28 21:20:06 -05:00
parent 56f6f6a240
commit 96bc5b45a6
2 changed files with 38 additions and 8 deletions

View File

@ -1,5 +1,12 @@
2012-01-28 Ulrich Drepper <drepper@gmail.com> 2012-01-28 Ulrich Drepper <drepper@gmail.com>
* sysdeps/x86_64/fpu/bits/mathinline.h (__signbitl): Optimize a bit.
Avoid unnecessary __WORDSIZE == 64 test.
(fmaxf): Use VEX format if possible.
(fmax): Likewise.
(fminf): Likewise.
(fmin): Likewise.
* config.h.in: Define HAVE_SSE2AVX_SUPPORT. * config.h.in: Define HAVE_SSE2AVX_SUPPORT.
* math/math_private.h: Remove libc_fegetround* and * math/math_private.h: Remove libc_fegetround* and
libc_fesetround*. libc_fesetround*.

View File

@ -1,5 +1,5 @@
/* Inline math functions for x86-64. /* Inline math functions for x86-64.
Copyright (C) 2002-2004, 2007, 2009, 2011 Free Software Foundation, Inc. Copyright (C) 2002-2004,2007,2009,2011,2012 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@ -64,21 +64,20 @@ __MATH_INLINE int
__NTH (__signbitl (long double __x)) __NTH (__signbitl (long double __x))
{ {
__extension__ union { long double __l; int __i[3]; } __u = { __l: __x }; __extension__ union { long double __l; int __i[3]; } __u = { __l: __x };
return (__u.__i[2] & 0x8000) != 0; return __u.__i[2] & 0x8000;
} }
__END_NAMESPACE_C99 __END_NAMESPACE_C99
#endif #endif
#if (__GNUC_PREREQ (2, 8) && !defined __NO_MATH_INLINES \ #if __GNUC_PREREQ (2, 8) && !defined __NO_MATH_INLINES && defined __OPTIMIZE__
&& defined __OPTIMIZE__)
# ifdef __USE_ISOC99 # ifdef __USE_ISOC99
__BEGIN_NAMESPACE_C99 __BEGIN_NAMESPACE_C99
/* Round to nearest integer. */ /* Round to nearest integer. */
# if __WORDSIZE == 64 || defined __SSE_MATH__ # ifdef __SSE_MATH__
__MATH_INLINE long int __MATH_INLINE long int
__NTH (lrintf (float __x)) __NTH (lrintf (float __x))
{ {
@ -87,7 +86,7 @@ __NTH (lrintf (float __x))
return __res; return __res;
} }
# endif # endif
# if __WORDSIZE == 64 || defined __SSE2_MATH__ # ifdef __SSE2_MATH__
__MATH_INLINE long int __MATH_INLINE long int
__NTH (lrint (double __x)) __NTH (lrint (double __x))
{ {
@ -114,40 +113,64 @@ __NTH (llrint (double __x))
# endif # endif
# if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0 \ # if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0 \
&& (__WORDSIZE == 64 || defined __SSE2_MATH__) && defined __SSE2_MATH__
/* Determine maximum of two values. */ /* Determine maximum of two values. */
__MATH_INLINE float __MATH_INLINE float
__NTH (fmaxf (float __x, float __y)) __NTH (fmaxf (float __x, float __y))
{ {
# ifdef __AVX__
float __res;
__asm ("vmaxss %2, %1, %0" : "=x" (__res) : "x" (x), "xm" (__y));
return __res;
# else
__asm ("maxss %1, %0" : "+x" (__x) : "xm" (__y)); __asm ("maxss %1, %0" : "+x" (__x) : "xm" (__y));
return __x; return __x;
# endif
} }
__MATH_INLINE double __MATH_INLINE double
__NTH (fmax (double __x, double __y)) __NTH (fmax (double __x, double __y))
{ {
# ifdef __AVX__
float __res;
__asm ("vmaxsd %2, %1, %0" : "=x" (__res) : "x" (x), "xm" (__y));
return __res;
# else
__asm ("maxsd %1, %0" : "+x" (__x) : "xm" (__y)); __asm ("maxsd %1, %0" : "+x" (__x) : "xm" (__y));
return __x; return __x;
# endif
} }
/* Determine minimum of two values. */ /* Determine minimum of two values. */
__MATH_INLINE float __MATH_INLINE float
__NTH (fminf (float __x, float __y)) __NTH (fminf (float __x, float __y))
{ {
# ifdef __AVX__
float __res;
__asm ("vminss %2, %1, %0" : "=x" (__res) : "x" (x), "xm" (__y));
return __res;
# else
__asm ("minss %1, %0" : "+x" (__x) : "xm" (__y)); __asm ("minss %1, %0" : "+x" (__x) : "xm" (__y));
return __x; return __x;
# endif
} }
__MATH_INLINE double __MATH_INLINE double
__NTH (fmin (double __x, double __y)) __NTH (fmin (double __x, double __y))
{ {
# ifdef __AVX__
float __res;
__asm ("vminsd %2, %1, %0" : "=x" (__res) : "x" (x), "xm" (__y));
return __res;
# else
__asm ("minsd %1, %0" : "+x" (__x) : "xm" (__y)); __asm ("minsd %1, %0" : "+x" (__x) : "xm" (__y));
return __x; return __x;
# endif
} }
# endif # endif
__END_NAMESPACE_C99 __END_NAMESPACE_C99
# endif # endif
# if defined __SSE4_1__ && (__WORDSIZE == 64 || defined __SSE2_MATH__) # if defined __SSE4_1__ && defined __SSE2_MATH__
# if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99 # if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
__BEGIN_NAMESPACE_C99 __BEGIN_NAMESPACE_C99