Re: Structure vs purism ?

Philipp Rumpf (prumpf@jcsbs.lanobis.de)
Fri, 22 Jan 1999 16:19:33 +0000


On Thu, Jan 21, 1999 at 10:51:51AM +0100, Krzysztof G. Baranowski wrote:
> On Wed, 20 Jan 1999, Dave Jones. wrote:
> > Just under 1000 goto's. Some of which are trivial. Goto's to one-liners,
> > which are easily tidied. Other files are real snakes-nests. Following the
> > trail of goto's as they double back on themselves is no fun for the brain,
> > even less so for a CPU, as modern features such as branch prediction are
> > misused.
> The goto's are mostly used in "fast-path", where we want to avoid
> jumping in non-error case. Look at a quick example:

This is exactly the thing we could change by giving the compiler hints.

> --- no.c ---
> main(void)
> {
> int i, j;
>
> scanf("%d %d\n", &i, &j);
>
> if (!i)
> exit();
> i++;
> if (!j)
> _exit();
> j++;
> }
> --- end ---

This is quite readable.

> --- yes.c ---
> main(void)
> {
> int i, j;
>
> scanf("%d %d\n", &i, &j);
>
> if (!i)
> goto out;
> i++;
> if (!j)
> goto out1;
> j++;
> out:
> exit();
> out1:
> _exit();
> }
> --- end ---

what I would like is something like

--- yestoo.c ---
int main(void)
{
int i,j;

scanf("%d %d\n", &i, &j);

__builtin_hint(i != 0);
if (!i)
exit();

i++;

__builtin_hint(j != 0);
if (!j)
_exit()

j++;
}
----

> --- yes.dump ---

The assembly output should be quite the same for yes.c and my version ...

-
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/