user6215: I want to set one pin's output value, and then set a different pin's output value so that the two pins change value one after the other.
However, the compiler optimises the two calls to change both pins in one go.

PORTD |= _BV(0);    //set pd0 to high
PORTD |= _BV(1);    //set pd1 to high
PORTD &= ~(_BV(1)); //set pd1 to low

The two pins go high simultaneously. I tried inserting a NOP between these but it doesn't change behaviour.
(I originally intended to include an oscilloscope screengrab to show what was happening - that's how I knew (or got the wrong impression) that the two pins were changing at the same time. But the photo wasn't shifting from my Nexus 7 for me to access it from my laptop.)

user4143: I certainly can't duplicate what you are saying.  The small code snippet:
void setup() {
    PORTD |= _BV(0);
    PORTD |= _BV(1);
    PORTD &= ~(_BV(1));
}

void loop() {
}

compiles into:
000000a6 <setup>:
  a6:   58 9a           sbi 0x0b, 0 ; 11
  a8:   59 9a           sbi 0x0b, 1 ; 11
  aa:   59 98           cbi 0x0b, 1 ; 11
  ac:   08 95           ret

000000ae <loop>:
  ae:   08 95           ret

That is clearly two separate bit sets followed by a bit clear.
I am using UECIDE that is set to use GCC 4.3.2
If I switch to GCC 4.8.1 instead, the code generated is identical.
Even turning on full -O3 optimization I still get the same results.
So how are you determining that it's happening at the same time?

6215: <p>I want to set one pin's output value, and then set a different pin's output value so that the two pins change value one after the other.
However, the compiler optimises the two calls to change both pins in one go.</p>

<p><code>
PORTD |= _BV(0);    //set pd0 to high
PORTD |= _BV(1);    //set pd1 to high
PORTD &amp;= ~(_BV(1)); //set pd1 to low
</code></p>

<p>The two pins go high simultaneously. I tried inserting a NOP between these but it doesn't change behaviour.</p>

<p>(I originally intended to include an oscilloscope screengrab to show what was happening - that's how I knew (or got the wrong impression) that the two pins were changing at the same time. But the photo wasn't shifting from my Nexus 7 for me to access it from my laptop.)</p>
 4143: <p>I certainly can't duplicate what you are saying.  The small code snippet:</p>

<pre><code>void setup() {
    PORTD |= _BV(0);
    PORTD |= _BV(1);
    PORTD &amp;= ~(_BV(1));
}

void loop() {
}
</code></pre>

<p>compiles into:</p>

<pre><code>000000a6 &lt;setup&gt;:
  a6:   58 9a           sbi 0x0b, 0 ; 11
  a8:   59 9a           sbi 0x0b, 1 ; 11
  aa:   59 98           cbi 0x0b, 1 ; 11
  ac:   08 95           ret

000000ae &lt;loop&gt;:
  ae:   08 95           ret
</code></pre>

<p>That is clearly two separate bit sets followed by a bit clear.</p>

<p>I am using UECIDE that is set to use GCC 4.3.2</p>

<p>If I switch to GCC 4.8.1 instead, the code generated is identical.</p>

<p>Even turning on full -O3 optimization I still get the same results.</p>

<p>So how are you determining that it's happening at the same time?</p>
