Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Nov 2011 12:09:19 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        David Schultz <das@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Eitan Adler <eadler@freebsd.org>
Subject:   Re: svn commit: r227812 - head/lib/libc/string
Message-ID:  <201111221209.19728.jhb@freebsd.org>
In-Reply-To: <20111122153332.GA20145@zim.MIT.EDU>
References:  <201111220250.pAM2oPWC070856@svn.freebsd.org> <20111122153332.GA20145@zim.MIT.EDU>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday, November 22, 2011 10:33:32 am David Schultz wrote:
> 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.

I concur, it should just use boolean logic since it is doing a boolean
test.

-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201111221209.19728.jhb>