should cpus_in_xmon be volatile?

Segher Boessenkool segher at
Tue Nov 23 16:55:35 EST 2004

> Well, to make >>that particular<< loop work correctly, the volatile is 
> not
> needed. Why? Because cpus_weight() is extern __bitmap_weight() and 
> since
> its extern, the compiler must be definition invoke it each time in the
> loop, since the compiler must assume that the called routine is 
> changing
> the value of the thing being pointed at. i.e. the call has a 
> side-effect.

That's not correct.  External linkage is an abstract concept, and by no
means prevents the compiler from optimising across the boundaries of a
translation unit (e.g., when performing whole-program optimisation).

Of course, that's not the current (default) behaviour of GCC, but that
doesn't make it a correct C program.

> However, if someone changed the extern __bitmap_weight() to be
> inline __bitmap_weight(), then the compiler could potentially see that
> it had no side effects, and decide to optimize away the entire loop.

It can potentially do that anyway.  Nothing in the C standard prevents
it from doing that.


More information about the Linuxppc64-dev mailing list