[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] xen: make sure that likely and unlikely convert the expression to a boolean



commit e5545fb6d0dc5e2c48b2e450d18246d9bc1ae35b
Author:     Ian Campbell <ian.campbell@xxxxxxxxxx>
AuthorDate: Mon Apr 7 12:07:04 2014 +0100
Commit:     Ian Campbell <ian.campbell@xxxxxxxxxx>
CommitDate: Thu Apr 10 12:11:34 2014 +0100

    xen: make sure that likely and unlikely convert the expression to a boolean
    
    According to http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
    __builtin_expect has the prototype:
        long __builtin_expect (long exp, long c)
    
    If sizeof(exp) > sizeof(long) then this will effectively mask off the top 
bits
    of exp, meaning that the if in "if (unlikey(x))" will see the masked 
version,
    which might be false when true was expected, likely has the same issue.
    
    This is mostly likely to affect x86_32 and arm32 builds.  x86_32 is not
    present on 4.3 onwards and a quick grep of current staging shows that all 
the
    existing arm32  uses of both likely and unlikely already pass a boolean. I
    noticed this with an as yet unposted patch which did not have this property.
    
    Also the defintion of likely might not have had the expected affect for 
cases
    where a true value > 1 might be passed.
    
    Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    Cc: Keir Fraser <keir@xxxxxxx>
    Cc: Tim Deegan <tim@xxxxxxx>
---
 xen/include/xen/compiler.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
index 6e07990..4b3472d 100644
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -7,8 +7,8 @@
 
 #define barrier()     __asm__ __volatile__("": : :"memory")
 
-#define likely(x)     __builtin_expect((x),1)
-#define unlikely(x)   __builtin_expect((x),0)
+#define likely(x)     __builtin_expect(!!(x),1)
+#define unlikely(x)   __builtin_expect(!!(x),0)
 
 #define inline        __inline__
 #define always_inline __inline__ __attribute__ ((always_inline))
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.