From: Andrew Cooper Date: Wed, 2 Jul 2014 12:46:42 +0000 (+0200) Subject: minios: fix incorrect {, un}likely() definitions X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=72553d3a4c8adf716c8c2d43f6998b3fa80cebb3;p=people%2Fliuw%2Flibxenctrl-split%2Fmini-os.git minios: fix incorrect {, un}likely() definitions As identified in e5545fb6, likely() and unlikely() must convert their expressions to booleans before comparing to 1 or 0, to avoid truncation issues. While editing this file, add inclusion guards. Signed-off-by: Andrew Cooper Acked-by: Samuel Thibault --- diff --git a/include/compiler.h b/include/compiler.h index e35c9d5..4188277 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -1,5 +1,10 @@ +#ifndef __MINIOS_COMPILER_H_ +#define __MINIOS_COMPILER_H_ + #if __GNUC__ == 2 && __GNUC_MINOR__ < 96 #define __builtin_expect(x, expected_value) (x) #endif -#define unlikely(x) __builtin_expect((x),0) -#define likely(x) __builtin_expect((x),1) +#define unlikely(x) __builtin_expect(!!(x),0) +#define likely(x) __builtin_expect(!!(x),1) + +#endif /* __MINIOS_COMPILER_H_ */