This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to use __builtin_expect in fp-bit.c
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 25 Nov 2005 13:16:26 +0000 (UTC)
- Subject: Patch to use __builtin_expect in fp-bit.c
This patch slightly speeds up fp-bit.c by using __builtin_expect to
optimize for numbers that are not NaNs or infinities. It yields a
0.4% improvement (geometric mean) in EEMBC results on IBM PowerPC 440
(--with-cpu=440 compiler).
Tested with no regressions with cross-compilers (--with-cpu=440) to
powerpc-ibm-linux-gnu. Applied to csl-ppc4xx-branch. OK to commit to
mainline?
2005-11-25 Joseph S. Myers <joseph@codesourcery.com>
* config/fp-bit.c (isnan, isinf, pack_d, unpack_d): Use
__builtin_expect.
diff -rupN GCC.fpadd/gcc/config/fp-bit.c GCC.bexp/gcc/config/fp-bit.c
--- GCC.fpadd/gcc/config/fp-bit.c 2005-11-22 21:13:25.000000000 +0000
+++ GCC.bexp/gcc/config/fp-bit.c 2005-11-22 22:50:42.000000000 +0000
@@ -160,14 +160,15 @@ INLINE
static int
isnan ( fp_number_type * x)
{
- return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
+ return __builtin_expect (x->class == CLASS_SNAN || x->class == CLASS_QNAN,
+ 0);
}
INLINE
static int
isinf ( fp_number_type * x)
{
- return x->class == CLASS_INFINITY;
+ return __builtin_expect (x->class == CLASS_INFINITY, 0);
}
#endif /* NO_NANS */
@@ -249,7 +250,7 @@ pack_d ( fp_number_type * src)
}
else
{
- if (src->normal_exp < NORMAL_EXPMIN)
+ if (__builtin_expect (src->normal_exp < NORMAL_EXPMIN, 0))
{
#ifdef NO_DENORMALS
/* Go straight to a zero representation if denormals are not
@@ -296,7 +297,7 @@ pack_d ( fp_number_type * src)
#endif /* NO_DENORMALS */
}
else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
- && src->normal_exp > EXPBIAS)
+ && __builtin_expect (src->normal_exp > EXPBIAS, 0))
{
exp = EXPMAX;
fraction = 0;
@@ -560,7 +561,8 @@ unpack_d (FLO_union_type * src, fp_numbe
dst->fraction.ll = fraction;
}
}
- else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
+ else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
+ && __builtin_expect (exp == EXPMAX, 0))
{
/* Huge exponent*/
if (fraction == 0)
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)