likely and unlikely

Andriy Gapon avg at icyb.net.ua
Fri Mar 12 12:46:49 UTC 2010


on 12/03/2010 14:18 Ivan Voras said the following:
> While looking into branch prediction in gcc I found this post describing
> the "likely" and "unlikely" macros in Linux:
> 
> http://kerneltrap.org/node/4705
> 
> In short, they are wrappers for the gcc-specific __builtin_expect for
> static branch prediction.
> 
> Grepping around I see it is defined and used locally in several places:
> 
> amd64/include/xen/xen-os.h:#define likely(x)  __builtin_expect((x),1)
> amd64/include/xen/xen-os.h:#define unlikely(x)  __builtin_expect((x),0)
> dev/nxge/xge-osdep.h:#define xge_os_unlikely(x)    (x)
> gnu/fs/xfs/FreeBSD/xfs_compat.h:#define    likely(x)   
> __builtin_expect((x), 1)
> gnu/fs/xfs/FreeBSD/xfs_compat.h:#define    unlikely(x)   
> __builtin_expect((x), 0)
> i386/include/xen/xen-os.h:#define likely(x)  __builtin_expect((x),1)
> i386/include/xen/xen-os.h:#define unlikely(x)  __builtin_expect((x),0)
> sun4v/include/cpu.h:#define likely(x)  __builtin_expect((x),1)
> sun4v/include/cpu.h:#define unlikely(x)  __builtin_expect((x),0)
> 
> Wouldn't it be more convenient to have a single global definition of
> them, under #ifdef __GNUC__ for example in sys/stddef.h ?

__predict_true/__predict_false


-- 
Andriy Gapon


More information about the freebsd-arch mailing list