From owner-freebsd-arch@FreeBSD.ORG Fri Mar 12 12:18:40 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 CB835106564A for ; Fri, 12 Mar 2010 12:18:40 +0000 (UTC) (envelope-from freebsd-arch@m.gmane.org) Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mx1.freebsd.org (Postfix) with ESMTP id 875148FC1F for ; Fri, 12 Mar 2010 12:18:39 +0000 (UTC) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Nq3p8-0006Tl-3h for freebsd-arch@freebsd.org; Fri, 12 Mar 2010 13:18:38 +0100 Received: from lara.cc.fer.hr ([161.53.72.113]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 12 Mar 2010 13:18:38 +0100 Received: from ivoras by lara.cc.fer.hr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 12 Mar 2010 13:18:38 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-arch@freebsd.org From: Ivan Voras Date: Fri, 12 Mar 2010 13:18:29 +0100 Lines: 23 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: lara.cc.fer.hr User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.1.5) Gecko/20100118 Thunderbird/3.0 Subject: 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:18:40 -0000 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 ?