Multiplying an unsigned char by 64U produces bigger slower code than necessary.
avr-gcc (WinAVR 20081205) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Windows XP
avr-gcc -c -mmcu=atmega168 -save-temps -Wall -std=gnu99 -Os ../64.c
No terminal output.
64.i:
# 1 "../64.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "../64.c"
unsigned mult(unsigned char arg)
{
return arg*64U;
}
compiled into this:
Code:
mov r18,r24
ldi r19,lo8(0)
ldi r24,6
1: lsl r18
rol r19
dec r24
brne 1b
movw r24,r18
ret
Not this:
Code:
mov r19,r24
ldi r18,0
lsr r19
ror r18
lsr r19
ror r18
movw r24,r18
ret
or this
Code:
mov r25,r24
ldi r24,0
lsr r25
ror r24
lsr r25
ror r24
ret
Each example is faster than the previous.
If R0 and R1 had been deemed available,
using MUL would have been even faster,
but MUL doesn't get used even in that case.
--
Summary: unsigned char times 64U produces long slow loop
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hennebry at web dot cs dot ndsu dot nodak dot edu
GCC build triplet: avr-gcc (WinAVR 20081205) 4.3.2?
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39250