Can I force a word read-modify-write instread of a byte write?

Rask Ingemann Lambertsen rask@sygehus.dk
Mon Jul 2 20:56:00 GMT 2007


On Mon, Jul 02, 2007 at 10:17:13AM -0700, Ian Lance Taylor wrote:
> volatile uint32_t* ptr = .....;
> uint32_t v = *ptr;
> v = (v & 0xffffff00) | 123;
> *ptr = v;
> 
> Note that if you don't use the volatile qualifier, gcc is wholly
> capable of optimizing that into an 8-bit memory write.

   Or more precisely, it used to, and we intend it to regain that capability
in the future. See bug 15184.

   When it comes to a back end solution, one existing target (MT) has an
option to not generate byte loads and stores, and there was a long thread
about modifying the ARM back end to generate byte writes such that, at the
hardware level, they would become a cache line wide read-modify-write
access. Search the GCC mailing list for this:

Modifying ARM code generator for elimination of 8bit writes - need help

   The ARM solution relies on assistance form the hardware, so I suggest you
look at the MT back end first to see if it does something clever.

-- 
Rask Ingemann Lambertsen



More information about the Gcc-help mailing list