PORTB.DIR |= 0b010
is 5 instructions.PORTB.DIRSET = 0b010
is 2 instructions, one of which is double width (2 tick?).VPORTB.DIR |= 0b010
is optimized by the compiler to 1 instruction.
The magic sauce is that VPORTB
is mapped to 0x0000 (PORTB
is mapped to 0x0400), the chips have instructions to
bit twiddle in a single instruction but only on addresses 0x00 to 0x1F. The higher mapping has extra costs on an 8bit CPU.
// PORTB.DIR |= PIN3_bm;
80a: e0 e2 ldi r30, 0x20 ; 32