From owner-svn-src-all@FreeBSD.ORG Tue Nov 22 15:33:34 2011 Return-Path: Delivered-To: svn-src-all@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 11886106566B; Tue, 22 Nov 2011 15:33:34 +0000 (UTC) (envelope-from das@FreeBSD.ORG) Received: from zim.MIT.EDU (ZIM.MIT.EDU [18.95.3.101]) by mx1.freebsd.org (Postfix) with ESMTP id 8DF238FC14; Tue, 22 Nov 2011 15:33:33 +0000 (UTC) Received: from zim.MIT.EDU (localhost [127.0.0.1]) by zim.MIT.EDU (8.14.5/8.14.2) with ESMTP id pAMFXW2Z020261; Tue, 22 Nov 2011 10:33:32 -0500 (EST) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by zim.MIT.EDU (8.14.5/8.14.2/Submit) id pAMFXWsi020260; Tue, 22 Nov 2011 10:33:32 -0500 (EST) (envelope-from das@FreeBSD.ORG) Date: Tue, 22 Nov 2011 10:33:32 -0500 From: David Schultz To: Eitan Adler Message-ID: <20111122153332.GA20145@zim.MIT.EDU> Mail-Followup-To: Eitan Adler , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201111220250.pAM2oPWC070856@svn.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201111220250.pAM2oPWC070856@svn.freebsd.org> Cc: svn-src-head@FreeBSD.ORG, svn-src-all@FreeBSD.ORG, src-committers@FreeBSD.ORG Subject: Re: svn commit: r227812 - head/lib/libc/string X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Nov 2011 15:33:34 -0000 On Tue, Nov 22, 2011, Eitan Adler wrote: > + /* use a bitwise or to avoid an additional branch instruction */ > + if ((s1 == s2) | (n == 0)) > + return (0); I think there are three issues with this. First, the comment suggesting that using '|' instead of '||' isn't correct; any reasonable compiler knows how to optimize side-effect-free expressions like these. (The reverse transformation, from the arithmetic expression to the boolean one, is actually harder for the compiler in general.) Second, the overwhelming precedent in FreeBSD is to use boolean operators to combine boolean expressions, so you might try to get some consensus on the issue before you go around replacing them with bitwise operators. I for one don't find the bitwise operators clearer, but I don't speak for everyone else. Third, it's not clear that checking whether s1 == s2 is even an optimization. Most programs simply aren't going to pass identical pointers as arguments to strcmp(), so for the overwhelming majority of cases, this is just a wasted test and a wasted slot in a branch predict table. (FWIW, I doubt that a realistic benchmark would demonstrate any measurable difference.)