Subject: Re: USB stack needs early review (Re: Someone should fix our USB
To: Jason Thorpe <thorpej@shagadelic.org>
From: Johnny Billquist <bqt@softjar.se>
List: tech-kern
Date: 03/22/2007 19:44:41
Jason Thorpe wrote:
>
> On Mar 22, 2007, at 11:03 AM, Johnny Billquist wrote:
>
>> No good. The compiler is still allowed to make optimizations on the
>> accesses if you don't declare it volatile. And that might cause the
>> code to break anyway. It's not only a cache problem.
>
> 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.
Yes. But what I said was that if you for instance just do a read of the
variable, and don't use the returned value until after the function
call, then the compiler can optimize and move the read to after the
function call, which might create something entirely different, which
you didn't intend.
Or if you just read the variable, but never do anything with it. Then
the compiler will totally remove the access, since the value isn't used
anywhere. But the actual access itself might be important. So those kind
of optimizations aren't good either.
Or for that matter, if you first set the value to one thing, and then
set it to another. That will result in only the last value being written.
Johnny