# AVR bit manipulation compilation in GCC: can not get SEI instead of read-modify-write

I'm trying to set bit 2 in TIMSK register and using the following C code:

TIMSK |= (1<<2);


Compiler makes the following code:

TIMSK |= (1<<TOIE1);
108:    89 b7           in  r24, 0x39   ; 57
10a:    84 60           ori r24, 0x04   ; 4
10c:    89 bf           out 0x39, r24   ; 57


So it is Read-Modify-Write operation which is a) slow, b) not very consistent as sometimes it is better not to disturb any excess bits.

However if I'd replace TIMSK with let's say PORTA I will get SEI as expected:

PORTA |= (1<<2);
108:    da 9a           sbi 0x1b, 2 ; 27


So how do I force the compiler to compile the instruction above as bit instruction instead of RMW?

Or this (TIMSK) register is not bit accessible?

• The resulting code is not disturbing any excess bits. It reads the register, performs the OR and writes the result, it's exactly the OR-IS you typed in C code. Further, SEI is the global interrupt enable instruction (brother of CLI), you mean SBI as in your second code block. – Asmyldof Jun 1 '15 at 12:43