Re: What is faster: jne or jge?

David Wragg (
03 Jun 1998 22:40:48 +0000

Tigran Aivazian <> writes:
> What is better:
> This: if (some_syscall() < 0) {
> ....
> }
> Or this: if (some_syscall() == -1) {
> ....
> }

No-one seems to have mentioned the following point yet, which
surprises me.

Intel's x86 processors (I'm not certain about the clones) will predict
forward conditional branches as NOT taken if there is no BTB entry.

Thus this code (assuming an error will occur in the minority of cases)

if (syscall() >= 0) {

minimizes pipeline stalls.

This ordering is often seen in the kernel sources as:

err = call();
if (err < 0)
goto out;


return err;

Some other processors have a hint bit in the branch instructions, and
even for x86 it would be possible for a compiler to rearrange the
order of the basic blocks. The problem is that the compiler doesn't
usually know which the exceptional route might be. Is anyone working
on profile driven compilation for egcs?

Of course, premature attempts at optimization are a bad thing, and it
is more important to structure the code well, concentrate on
algorithmic efficiency, and later use profiling to discover which
parts of the code can benefit most from these kinds of tuning.

Dave Wragg

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to