Re: Kernel bugs found using inspect tool

From: Q (Q@ping.be)
Date: Wed Feb 23 2000 - 15:26:31 EST


On Wed, Feb 23, 2000 at 10:19:11AM -0600, nathan.zook@amd.com wrote:
>
> > But there are plenty of places in the kernel code where people write
> > if ((a == b) || (c == d) || (e < f)) ... It drives me batty, but Linus
> > does not seem to mind.
> >
>
> With out-of-order execution, note that if((a == b) | (c == d) | (e < f))
> runs faster if c, d, e, and f have no side effects--and the parens ARE
> required.

First of all, you should let the compiler decide which way is the
fastest/best.

Second, a | is not a sequence point, while || is. The expression can
depend on that. It could be that if (a == b), that you should not use c.
It will also do all three, while one can be more then enough.

And last, there is such a thing as branch prediction, and I have no idea
which would be "better" for it :)

I also did some little test here comparing both, and the one with | seems
to be slower when using no optimization because it needs to do more
instructions. They got the same result using -O2, if only the third is
true. But then again, what do those stupid tests show.

Q

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Feb 23 2000 - 21:00:34 EST