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.