Re: [PATCH 6/8] i386: bitops: Don't mark memory as clobberedunnecessarily

From: Linus Torvalds
Date: Tue Jul 24 2007 - 16:09:48 EST




On Tue, 24 Jul 2007, Andi Kleen wrote:
>
> Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> writes:
> >
> > (Yes, the "asm volatile" may do so too, but it's very unclear what the
> > "volatile" on the asm actually does, so ..)
>
> Without the volatile they get completely optimized away :/
> [tried that, cost a lot of debugging time -- empty string functions
> cause a lot of strange side effects]

Sure, that's *one* thing that "volatile" guarantees (it guarantees that
gcc won't optimize away things where the end result isn't actually visibly
used).

But gcc docs also talk about the other things volatile means, including
"not significantly moved".

Is that "not significantly moved" already equivalent to "not moved past
something that can change memory"? Probably not. Which is why it's a good
idea to have the "memory" clobber there too, because the semantics of the
"volatile" just aren't very well defined from a code movement standpoint
(while a general memory clobber is *very* clear: if gcc moves the inline
asm across another thing that uses/changes memory, that's a gcc bug, plain
and simple (*)).

Linus

(*) Other than pure internal gcc spills/reloads. Spilling/reloading local
registers that haven't had their address taken obviously cannot be seen as
memory accesses.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/