Re: powerpc gcc strange assembler for bitfields

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx    ::     http://www.planetfall.pwp.blueyonder.co.uk


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux