Re: drivers/char/sysrq.c

Jörn Engel (joern@wohnheim.fh-wedel.de)
Fri, 30 May 2003 20:01:30 +0200


On Fri, 30 May 2003 17:13:17 +0200, J.A. Magallon wrote:
> On 05.30, Jörn Engel wrote:
> > On Fri, 30 May 2003 16:44:55 +0200, Margit Schubert-While wrote:
> > >
> > > In drivers/char/sysrq.c (2.4 and 2.5) we have :
> > >
> > > if ((key >= '0') & (key <= '9')) {
> > > retval = key - '0';
> > > } else if ((key >= 'a') & (key <= 'z')) {
> > >
> > > Shouldn't the "&" be (pedantically) "&&" ?
> >
> > It is semantically the same. If you can show that gcc optimization
> > also creates the same assembler code, few people will object to a
> > patch.
> >
>
> I see a diff:
> - & is bitwise and you always perform the op
> - && is logical and gcc must shortcut it
>
> I think people use & 'cause they prefer the extra argument calculation
> than the branch for the shortcut (AFAIR...)

Yes, it is an optimization, nothing more. Either code will behave the
same, but one version might be a little faster, depending on the cpu,
unless the compiler is already clever enough to do this himself.

Just wrote a small test program with both variants and tested on i386
with gcc 3.2.3 and 2.95.4, with -O2 and -Os. The code generated was
identical in all eight cases. So if ever this zero optimization
reduces readability of the code, write a patch and make it better.
Beats any spelling fixes.

Jörn

-- 
Eighty percent of success is showing up.
-- Woody Allen
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/