I'm using and x86 based core to manipulate a 32-bit memory mapped register. My hardware behaves correctly only if the CPU generates 32-bit wide reads and writes to this register. The register is aligned on a 32-bit address and is not addressable at byte granularity.
What can I do to guarantee that my C (or C99) compiler will only generate full 32-bit wide reads and writes in all cases?
For example, if I do a read-modify-write operation like this:
volatile uint32_t* p_reg = 0xCAFE0000;
*p_reg |= 0x01;
I don't want the compiler to get smart about the fact that only the bottom byte changes and generate 8-bit wide read/writes. Since the machine code is often more dense for 8-bit operations on x86, I'm afraid of unwanted optimizations. Disabling optimizations in general is not an option.
----- EDIT -------
An interesting and very relevant paper: http://www.cs.utah.edu/~regehr/papers/emsoft08-preprint.pdf