Subject: Re: USB stack needs early review (Re: Someone should fix our USB stack...)
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Jason Thorpe <thorpej@shagadelic.org>
List: tech-kern
Date: 03/22/2007 16:11:49
On Mar 22, 2007, at 3:11 PM, der Mouse wrote:
>
>>
>>>
>>>> [...volatile...]
>>
>>> No, the compiler is not allowed to keep cached in a register a
>>
>>> memory access across a function call, precisely because it cannot
>>
>>> know if that function call modifies the memory.
>> don't callee vs. caller saved regs give the compiler a way around
>> this?
>
> Not really. The point is, if you write, for example,
>
> x = ...something...;
> somefunction();
> y = x;
>
> then, in terms of the C abstract machine, the compiler must re-fetch x
> when assigning to y rather than re-using the value from the former
> assignment (which it may well have lying around in a register, whether
> caller-saved, callee-saved, hardware-saved, or what, is irrelevant).
> This is because, in terms of the C abstract machine, somefunction()
> could modify x.
Uh, no, I don't think so. In the case of:
void
foo(int *addr)
{
int x, y;
x = *addr;
somefunction();
y = x;
...
}
"x" is not memory, "*addr" is memory. So, it WOULD have to refetch if:
void
foo(int *addr)
{
int x, y;
x = *addr;
somefunction();
y = *addr;
...
}
i.e. the assignment of y could NOT be optimized into "y = x;"
-- thorpej