Patchwork [libgfortran] Add a comment to libgfortran.h explaining what the (un)likely() macros do

login
register
mail settings
Submitter Tobias Burnus
Date March 8, 2014, 6:50 p.m.
Message ID <531B668D.8050301@net-b.de>
Download mbox | patch
Permalink /patch/328230/
State New
Headers show

Comments

Tobias Burnus - March 8, 2014, 6:50 p.m.
OK for the trunk?

Tobias
Steve Kargl - March 8, 2014, 9:19 p.m.
On Sat, Mar 08, 2014 at 07:50:53PM +0100, Tobias Burnus wrote:
> OK for the trunk?
> 
> diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
> index d7e15ad..2664e1f 100644
> --- a/libgfortran/libgfortran.h
> +++ b/libgfortran/libgfortran.h
> @@ -97,6 +97,16 @@ typedef off_t gfc_offset;
>  #define NULL (void *) 0
>  #endif
>  
> +
> +/* The following macros can be used to annotate conditions which are likely or
> +   unlikely to be true.  Avoid using them when a condition is only slightly
> +   more likely/less unlikely than average to avoid the performance penalties of
> +   branch misprediction. In addition, as __builtin_expect overrides the compiler
> +   heuristic, do not use in conditions where one of the branches ends with a
> +   call to a function with __attributee__((noreturn)): the compiler internal

s/__attributee/__attribute

> +   heuristic will mark this branch as much less likely as unlikely() would
> +   do.  */

OK with the above change.

Patch

diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index d7e15ad..2664e1f 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -97,6 +97,16 @@  typedef off_t gfc_offset;
 #define NULL (void *) 0
 #endif
 
+
+/* The following macros can be used to annotate conditions which are likely or
+   unlikely to be true.  Avoid using them when a condition is only slightly
+   more likely/less unlikely than average to avoid the performance penalties of
+   branch misprediction. In addition, as __builtin_expect overrides the compiler
+   heuristic, do not use in conditions where one of the branches ends with a
+   call to a function with __attributee__((noreturn)): the compiler internal
+   heuristic will mark this branch as much less likely as unlikely() would
+   do.  */
+
 #ifndef __GNUC__
 #define __attribute__(x)
 #define likely(x)       (x)