avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Optimizing a 16-bit * 8-bit -> 24-bit multiplication


From: Shaun Jackman
Subject: Re: [avr-gcc-list] Optimizing a 16-bit * 8-bit -> 24-bit multiplication
Date: Wed, 6 Dec 2006 11:25:58 -0700

On 12/1/06, Galen Seitz <address@hidden> wrote:
Not exactly what you want, but this might help you get started.

galen


extern inline int16_t
mult_s16_u8s16(uint8_t a, int16_t b)
...

Thanks for the code snippet, Galen. Using your mult_s16_u8s16 for
inspiration, I wrote mul_16_8 (u16 * u8 -> u24). Perhaps these
functions should be added to avr-libc.

Cheers,
Shaun

static inline uint32_t mul_16_8(uint16_t a, uint8_t b)
{
        uint32_t product;
        asm (
                "mul %A1, %2\n\t"
                "movw %A0, r0\n\t"
                "clr %C0\n\t"
                "clr %D0\n\t"
                "mul %B1, %2\n\t"
                "add %B0, r0\n\t"
                "adc %C0, r1\n\t"
                "clr r1"
                : "=&r" (product)
                : "r" (a), "r" (b));
        return product;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]