sys/cdefs.h: fix __predict_false fallback implementation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

sys/cdefs.h: fix __predict_false fallback implementation

Jeremie Courreges-Anglas-2

Found while looking at __ISO_C_VISIBLE.  I'm not sure which compilers
would be affected.  The fallback could simply be
 #define __predict_true(exp) (exp)
 #define __predict_false(exp) (exp)
but I settled for a minimal change.

ok?


Index: cdefs.h
===================================================================
RCS file: /d/cvs/src/sys/sys/cdefs.h,v
retrieving revision 1.43
diff -u -p -p -u -r1.43 cdefs.h
--- cdefs.h 29 Oct 2018 17:10:40 -0000 1.43
+++ cdefs.h 11 Feb 2020 18:27:18 -0000
@@ -193,7 +193,7 @@
 #define __predict_false(exp) __builtin_expect(((exp) != 0), 0)
 #else
 #define __predict_true(exp) ((exp) != 0)
-#define __predict_false(exp) ((exp) != 0)
+#define __predict_false(exp) ((exp) == 0)
 #endif
 
 /* Delete pseudo-keywords wherever they are not available or needed. */


--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply | Threaded
Open this post in threaded view
|

Re: sys/cdefs.h: fix __predict_false fallback implementation

Nicholas Marriott-2

Looks like the existing code is OK, you still want to test the original
expression even if you are predicting it is false, no?



On Tue, Feb 11, 2020 at 07:33:19PM +0100, Jeremie Courreges-Anglas wrote:

>
> Found while looking at __ISO_C_VISIBLE.  I'm not sure which compilers
> would be affected.  The fallback could simply be
>  #define __predict_true(exp) (exp)
>  #define __predict_false(exp) (exp)
> but I settled for a minimal change.
>
> ok?
>
>
> Index: cdefs.h
> ===================================================================
> RCS file: /d/cvs/src/sys/sys/cdefs.h,v
> retrieving revision 1.43
> diff -u -p -p -u -r1.43 cdefs.h
> --- cdefs.h 29 Oct 2018 17:10:40 -0000 1.43
> +++ cdefs.h 11 Feb 2020 18:27:18 -0000
> @@ -193,7 +193,7 @@
>  #define __predict_false(exp) __builtin_expect(((exp) != 0), 0)
>  #else
>  #define __predict_true(exp) ((exp) != 0)
> -#define __predict_false(exp) ((exp) != 0)
> +#define __predict_false(exp) ((exp) == 0)
>  #endif
>  
>  /* Delete pseudo-keywords wherever they are not available or needed. */
>
>
> --
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE
>

Reply | Threaded
Open this post in threaded view
|

Re: sys/cdefs.h: fix __predict_false fallback implementation

Todd C. Miller-3
On Tue, 11 Feb 2020 21:44:21 +0000, Nicholas Marriott wrote:

> Looks like the existing code is OK, you still want to test the original
> expression even if you are predicting it is false, no?

Right, the code is correct as written.

 - todd

Reply | Threaded
Open this post in threaded view
|

Re: sys/cdefs.h: fix __predict_false fallback implementation

Jeremie Courreges-Anglas-2
On Tue, Feb 11 2020, "Todd C. Miller" <[hidden email]> wrote:
> On Tue, 11 Feb 2020 21:44:21 +0000, Nicholas Marriott wrote:
>
>> Looks like the existing code is OK, you still want to test the original
>> expression even if you are predicting it is false, no?
>
> Right, the code is correct as written.

Woops, brain fart on my side, thanks.

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE