Re: a small doubt

Alan Cox (alan@lxorguk.ukuu.org.uk)
Sat, 9 Oct 1999 15:19:36 +0100 (BST)


> > I can understand the former, but the latter would be a bit
> > rediculious.
>
> Have you ever used AIX? Dereferencing a null pointer returns a value of
> 0x0. I'm told it was a deliberate design decision to expedite code
> optimization in the native compiler.

This is quite common. The idea is to make sure the compiler can re-order
NULL checks for performance.

while(x!=NULL)
{
a+=*x;
x=x->next;
}

often unrolls better something like

y = x->next; /* This goes to memory so takes time */
v = *x; /* Ditto */
if(x==NULL) /* Hide the condition check in the latency */
break;
a+=*x;

This kind of zero page abuse works well. Mapping the zero page over it also lets
you do maths ops without checking conditions.

Nevertheless - if you are debugging you don't want this optimisation feature 8)

Alan

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