No optimization on some codelines

KG_DK:
In order to finetune delay between pulses I use to store '0' in PORTD several times.

Table720Ptr++;
for(byte i=0; i<3; i++)
{
NB_pulspar(); //Send pulsepair
delayMicroseconds(10);
PIOD->PIO_ODSR = 0; // Write to make delay.
PIOD->PIO_ODSR = 0; // Write to make delay.
PIOD->PIO_ODSR = 0; // Write to make delay.
PIOD->PIO_ODSR = 0; // Write to make delay.
}
Table720Ptr++;

But it don't help to ad more lined with "PIOD->PIO_ODSR = 0;", so I need to tell the compiler not to make optimization on those lines!
Is it possible?
And how to to do it?

Kurt

The Due executes instructions at 84 million instructions per second so adding a couple of extra write calls is unlikely to make a difference that's easy to see. Register writes are never optimized - they're declared volatile and the compiler already won't try to optimize them out. But, I don't know of any reason why the write couldn't execute at 84MHz like all the other instructions. Of course you can't really set ports that rapidly but I think you can set the register that quickly - it just won't toggle the pin at that speed. 4 writes in a row is likely only 4 instruction times (depending on register speed) and that's 47 nanoseconds. That's a pretty small extra delay. With four instructions you're adding 1/210th of the "delayMicroseconds(10);" line. What happens if you do like 10 or 20 of those register writes? Or, do a loop of 100 and see what happens. I'm wondering if perhaps it is having an effect just not as much of one as you thought it would

At any rate, my answer is that register accesses aren't optimized so that shouldn't be your issue.