Performance tuning PORTB manipulation - mask 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 &amp; ~(7)) | x
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.