Is it possible that gcc reorders a series of read/write operations?
Marco Manfredini
mldb@gmx.net
Wed Sep 3 12:28:00 GMT 2008
On Wednesday 03 September 2008, Pan ruochen wrote:
> Hi All,
> It is very common to read/write hardware registers frequently when
> developing a hardware driver, like
...
> I wonder if there is any possibility that gcc reorders the read/write
> operations in a way it thinks more optimal, which may be a disaster to
> the hardware driver.
The language guarantees that any operation on a 'volatile' object is complete
when a sequence point is reached and that none of the subsequent operations
on that volatile object will have been taken place. This prevents the
compiler from reordering volatile accesses. However, that compiler has no
knowledge about the underlying memory system - the CPU may reorder writes.
Preventing this is quite hardware specific and may require hardware
configuration or memory barriers.
More information about the Gcc-help
mailing list