From owner-freebsd-arch@FreeBSD.ORG Sat Mar 13 09:24:45 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 0179F106564A for ; Sat, 13 Mar 2010 09:24:45 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail04.syd.optusnet.com.au (mail04.syd.optusnet.com.au [211.29.132.185]) by mx1.freebsd.org (Postfix) with ESMTP id 8E8C18FC0C for ; Sat, 13 Mar 2010 09:24:44 +0000 (UTC) Received: from c220-239-227-59.carlnfd1.nsw.optusnet.com.au (c220-239-227-59.carlnfd1.nsw.optusnet.com.au [220.239.227.59]) by mail04.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o2D9OcgS005617 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 13 Mar 2010 20:24:42 +1100 Date: Sat, 13 Mar 2010 20:24:39 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Max Laier In-Reply-To: <201003121513.38721.max@love2party.net> Message-ID: <20100313200155.O22734@delplex.bde.org> References: <20100312122559.GU8200@hoeg.nl> <20100312124258.GE1738@mole.fafoe.narf.at> <201003121513.38721.max@love2party.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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: Sat, 13 Mar 2010 09:24:45 -0000 On Fri, 12 Mar 2010, Max Laier wrote: > On Friday 12 March 2010 13:42:59 Stefan Farfeleder wrote: >> On Fri, Mar 12, 2010 at 01:26:08PM +0100, Ed Schouten wrote: >>> Hi Ivan, >>> >>> * Ivan Voras wrote: >>>> Wouldn't it be more convenient to have a single global definition of >>>> them, under #ifdef __GNUC__ for example in sys/stddef.h ? >>> >>> Wouldn't it be better to have them in sys/cdefs.h? >> >> Putting macros 'likely' and 'unlikely' into sys/cdefs.h creates a big >> namespace violation problem; C code using those identifiers will break. > > In addition, I don't think it's a good thing to make these too easy to use ... IIndeed. The existing spelling of them in sys/cdefs.h (__predict_true and __predict_false) is bad enough. > I found that they are a pessimisation more often than not. In addition, it > seems that at least our base gcc version does forget to apply any other > optimizations if it encounters one of these. Interesting. I thought they were about as useful as "register". But the compiler ignores "register", so "register" is not even a pessimization. > My point is: Handle with care!!! Trust your compiler/CPU predictors/... - > most of the time, they are smarter than you are ;) These macros may have useful 15-25 years ago for i386, i486 and Pentium1, since CPU branch predictors were either nonexistent or not so good. After that, CPU branch predictors became quite good. The macros should have been mostly unused 15-25 years ago too, since they optimize for unreadability and unwritability. Fortunately they are rarely used in FreeBSD. They were imported from NetBSD in 2003 where they are used more (306 instances in 2005 NetBSD /sys vs 28 instances in 2004 FreeBSD /sys; there are 2208 instances of likely() in 2004 linux-2.6.10). Bruce