This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: powerpc gcc strange assembler for bitfields


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
  (void)*ptr;

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]