powerpc gcc strange assembler for bitfields

Nathan Sidwell nathan@codesourcery.com
Fri Apr 22 07:26:00 GMT 2005

Florian Weimer wrote:
> * Nathan Sidwell:

> Ahem, you (or Pete) should use explicit assembler instructions if you
> want to make sure that you end up with certain instructions.
> Future compiler versions might optimize the explicit masking as well.
> (Even the volatile keyword would not prevent this.)

I disagree.  A volatile memory access must be visible outside the
abstract machine.  Where is the abstract machine?  Well, that's a little
vague and implementation defined.  But I would consider that any compiler
which did not perform word accesses on the following code to be broken.

void SetBit (volatile int *ptr, unsigned char mask)
    int tmp = *ptr;
    tmp |= mask;  // we know only the bottom 8 bits can be affected
    *ptr = tmp;

The conclusion of your train of thought would be that the compiler is
free to remove the following dereference, regardless of volatility

Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

More information about the Gcc-help mailing list