Hi I've been working on a project using an Arduino Uno (so ATmega328p) where timing is quite important and so I wanted to see into which instructions the compiler was converting my code. And in there I have a uint8_t
which I shift one bit to the right on each iteration using data >>= 1
and it seems the compiler translated this into 5 instructions (data
is in r24
):
mov r18, r24
ldi r19, 0x00
asr r19
ror r18
mov r24, r18
But if I look into the instruction set documentation I see an instruction which does exactly this: lsr r24
Do I overlook something or why isn't the compiler using this as well? The registers r18
and r19
are not used anywhere else.
I'm using an Ardunio but if I'm correct it does just use the normal avr-gcc
compiler. This is the code (trimmed) which generates the sequence:
ISR(PCINT0_vect) {
uint8_t data = 0;
for (uint8_t i = 8; i > 0; --i) {
// asm volatile ("lsr %0": "+w" (data));
data >>= 1;
if (PINB & (1 << PB0))
data |= 0x80;
}
host_data = data;
}
As far as I can see the Ardunino IDE is using the AVR gcc compiler provided by the system which is version 6.2.0-1.fc24. Both are installed via the package manger so should be up to date.