evilsong / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

patch: use __builtin_expect() if available #465

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
__builtin_expect() can allow a compiler to generate better code.

The main motivation for this is cpp_alloc(), which is structured as

 for (;;) { void* p = do_malloc(size); if (...) { ... } else return p; }

This causes gcc (at least in the instance I tried) to "plan" for a loop that 
will run at least a few iterations.  Of course, that's unlikely, but it can't 
see that without help.

Patch attached.  (I didn't include generated files in the patch... I wasn't 
sure what's expected.)

Original issue reported on code.google.com by gp...@chromium.org on 17 Sep 2012 at 8:54

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by chapp...@gmail.com on 3 Nov 2012 at 4:47

GoogleCodeExporter commented 9 years ago
r189 | chappedm@gmail.com | 2012-12-22 15:06:47 -0500 (Sat, 22 Dec 2012) | 7 
lines

issue-465: Adding automagic support for __builtin_expect

Previously __builtin_ expect was based on a macro check against gcc version.
Now we perform the check via AM which is a cleaner approach. There are also
a number of code changes here to utilize LIKELY/UNLIKELY macros based on
__builtin_expect to improve performance.

Original comment by chapp...@gmail.com on 22 Dec 2012 at 8:07