From owner-freebsd-arch@FreeBSD.ORG Fri Mar 12 12:46:49 2010 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 590EB106564A for ; Fri, 12 Mar 2010 12:46:49 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id A0E628FC1C for ; Fri, 12 Mar 2010 12:46:48 +0000 (UTC) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id OAA20586; Fri, 12 Mar 2010 14:30:52 +0200 (EET) (envelope-from avg@icyb.net.ua) Message-ID: <4B9A33FB.4020108@icyb.net.ua> Date: Fri, 12 Mar 2010 14:30:51 +0200 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.23 (X11/20100211) MIME-Version: 1.0 To: Ivan Voras References: In-Reply-To: X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: freebsd-arch@freebsd.org Subject: Re: likely and unlikely X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2010 12:46:49 -0000 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