Re: patch for 2.1.55 pre-1 minix/sysv/affs

Linus Torvalds (torvalds@transmeta.com)
Wed, 10 Sep 1997 14:00:26 -0700 (PDT)


On Wed, 10 Sep 1997, Ralf Baechle wrote:
> > which would go inside an "if" statement, and cause gcc to do exactly
> > what Bill is doing up there by hand....
>
> For very good reasons GCC tries not to support #pragma.

Not supporting #pragma has some logical reasons (mainly the fact that you
can't have #pragma's in #defines).

But supporting hints about which way is the likely branch would be good.
I'd prefer something like

__builtin_unlikely_if (x) {
}

which would work fine inside #defines and inline functions etc.

> Actually your answer already contains the solution to the problem:
> Put the code for the common case into if.

No. That results in extremely ugly code, often much uglier than using
goto's etc. The main problem is nesting level etc.

For example, I find it a lot more readable to have

if (!x)
return;

if (y == 5)
return;

... normal code that doesn't have to worry about x == 0, y == 5 ..

than to have multiple if-statements inside each other:

if (x) {
if (y != 5) {
... normal code that is now indented way too much ...
}
}

Also, a "__builtin_unlikely_if()" can be used to move the unlikely code
away from the likely case, so that it doesn't pollute the icache at all
(into another ELF segment etc).

Linus