This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Merging changes to volatile bitfield structs
- From: "Phil Endecott" <spam_from_gcc_help_2 at chezphil dot org>
- To: "John Love-Jensen" <eljay at adobe dot com>, "MSX to GCC" <gcc-help at gcc dot gnu dot org>
- Date: Tue, 16 Oct 2007 18:30:20 +0100
- Subject: Re: Merging changes to volatile bitfield structs
- References: <C33A0B3C.26049%eljay@adobe.com>
John Love-Jensen wrote:
Hi Phil,
Can anyone share their preferred approach to this sort of problem?
Reg workingReg = reg;
workingReg.a = 0;
workingReg.b = 0;
workingReg.c = 0;
reg = workingReg;
Thanks, that's obviously a sensible approach.
One subtlety is that if my reg is 32 bits and all of my changes are
within 8 bits of it, I would prefer to do a byte read-modify-write (or
even just a byte write), while that will (I think) do a word read-modify-write.
Does anyone have any thoughts about the idea of not declaring it
volatile and placing "memory barriers" around it? Google tells me that
I should use an asm statement that says it "clobbers memory" as a
memory barrier. So if I write
#define MEMORY_BARRIER asm("":"":"":"":"memory") // haven't checked syntax
struct ctrl_regs* regs;
// regs gets initialised to point to some hardware
MEMORY_BARRIER
regs->a = 0;
regs->b = 0;
MEMORY_BARRIER
or something equivalent with a reference, will gcc do what I want?
Regards,
Phil.