Joerg Wunsch <[EMAIL PROTECTED]> wrote:
> "David Brown" <[EMAIL PROTECTED]> wrote:
>
> > ..., and it will also change "multiply by constant" into a series of
> > shifts and adds. The target chip has a hardware multiplier and
> > divider, but they are slower than the shift-and-add sequences.
>
> Unfortunately, AVR-GCC also does this, even though the hardware
> multiplier is faster than a series of shift and add. :-(
>
Because I wanted more control over multiplies, I've started creating
routines like these:
extern inline uint16_t
mult_u16_u8u8(uint8_t a, uint8_t b)
{
uint16_t product;
asm (
"mul %1, %2" "\n\t"
"movw %0, r0" "\n\t"
"clr r1" "\n\t"
: "=w" (product)
: "r" (a), "r" (b)
);
return product;
}
extern inline uint16_t
mult_u8h_u8u8(uint8_t a, uint8_t b)
{
uint8_t product_high;
asm (
"mul %1, %2" "\n\t"
"mov %0, r1" "\n\t"
"clr r1" "\n\t"
: "=w" (product_high)
: "r" (a), "r" (b)
);
return product_high;
}
I have a few others if people are interested.
galen
_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list