[PATCH] Use __builtin_expect() within gcc_assert().

David Daney ddaney@caviumnetworks.com
Wed Jul 1 16:30:00 GMT 2009


This patch adds a __builtin_expect() to the gcc_assert macro.  We
expect that all assertions will be true, so it seems plausible to use
__builtin_expect here.

Just above the patched chunk, we already add a definition of
__builtin_expect for compilers that don't implement it, so this should
not adversely affect the ability to bootstrap with non-GCC (or very
old GCC) compilers.

Before the patch in gcc/ (best of three consecutive runs):

$ rm *.o
$ time make cc1
.
.
.
real	6m7.041s
user	5m43.602s
sys	0m21.602s

After the patch

real	6m6.291s
user	5m42.921s
sys	0m21.763s


A savings of 0.681s of user time or 0.681/342 = 0.2%.  Not a lot but
it seems to be consistently be a very small amount faster.  However, I
don't discount the possibility that it could all be measurement noise
either.

Bootstrapped and tested on x86_64-pc-linux-gnu.

OK to commit?

2009-07-01  David Daney  <ddaney@caviumnetworks.com>

	* system.h (gcc_assert): Use __builtin_expect.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: assert-expect.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20090701/a81da676/attachment.ksh>


More information about the Gcc-patches mailing list