[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Multiply improvement [1]
From: |
Anatoly Sokolov |
Subject: |
[avr-gcc-list] Multiply improvement [1] |
Date: |
Sun, 27 Apr 2008 21:46:54 +0400 |
Hello.
Now AVR-GCC for multiplication of two unsigned and two signed char
operands uses instructions 'MUL' and 'MULS' accordingly and is
8x8=16bits operation. Multiplication signed on unsigned chars is carried
out as multiplication of two 16-bit values, though in AVR core there
is instruction MULSU. This patch adds a pattern usmulqihi3 for use
of instruction MULSU.
Testcase:
extern unsigned char _a;
extern char _b;
volatile extern int _r;
int
main (void)
{
_r = (unsigned int)_a * (int)_b;
return 0;
}
Now:
lds r24,_b
clr r25 ; 6 extendqihi2/1 [length = 3]
sbrc r24,7
com r25
lds r18,_a ; 7 *movqi/4 [length = 2]
ldi r19,lo8(0) ; 28 *movqi/2 [length = 1]
movw r20,r24 ; 26 *movhi/1 [length = 1]
mul r20,r18 ; 9 *mulhi3_enh [length = 7]
movw r24,r0
mul r20,r19
add r25,r0
mul r21,r18
add r25,r0
clr r1
sts (_r)+1,r25 ; 10 *movhi/3 [length = 4]
sts _r,r24
With patch:
lds r18,_a ; 5 *movqi/4 [length = 2]
lds r20,_b ; 6 *movqi/4 [length = 2]
mulsu r20,r18 ; 7 usmulqihi3 [length = 3]
movw r18,r0
clr r1
sts (_r)+1,r19 ; 8 *movhi/3 [length = 4]
sts _r,r18
Anatoly.
mulsu_v2.diff.txt
Description: Text document
- [avr-gcc-list] Multiply improvement [1],
Anatoly Sokolov <=