user26481: I have the following snippet that seems to be taking a total of 6 CPU cycles per invocation.
Can I speed this up somehow? x  is a byte with the 3 lowest bits set.
#define SET_COLOR(x) PORTB = (PORTB & ~(7)) | x


user368: 4 cycles:
IN Rd,PORTB
CBR Rd,7
ORI Rd,x
OUT PORTB,Rd

Translation into proper GCC inline assembly syntax is left as an exercise for the reader.

26481: <p>I have the following snippet that seems to be taking a total of 6 CPU cycles per invocation.</p>

<p>Can I speed this up somehow? <code>x</code>  is a byte with the 3 lowest bits set.</p>

<pre><code>#define SET_COLOR(x) PORTB = (PORTB &amp; ~(7)) | x
</code></pre>
 368: <p>4 cycles:</p>

<pre><code>IN Rd,PORTB
CBR Rd,7
ORI Rd,x
OUT PORTB,Rd
</code></pre>

<p>Translation into proper GCC inline assembly syntax is left as an exercise for the reader.</p>
