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

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

Re: [avr-gcc-list] movw and asm


From: Bruce D. Lightner
Subject: Re: [avr-gcc-list] movw and asm
Date: Wed, 06 Aug 2003 09:26:07 -0700
User-agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.3.1) Gecko/20030425

James

Thanks Rune!  These links are helpful, and they answered my next question.
But I am still wondering about parameters passed into asm blocks.  For
instance..

inline unsigned long Test(unsigned long Input)
{
    unsigned long Output;

    Input = ((Input << 4) ^ (Input >> 5)) + Input;

    asm
    (
        "mov %A0,%A1\n\t"
        "mov %B0,%B1\n\t"
        "mov %C0,%C1\n\t"
        "mov %D0,%D1\n\t"
        :"=r"(Output)
        :"r"(Input)
    );

    Output = Output << 4;

    return Output;
}

Is there is any determinism in how the compiler arranges the 8 registers
used to hold "Output" and "Input" before it falls into the asm block?  I'm
also looking to see if there is a trick to emit conditional statements to
gas, like "if A0 and A1 are even registers and B0 and B1 are adjacent to
them then use movd" or whatever.

At this point, we met the benchmark by writing the whole routine over in
assembler.  However, I'd still like to know.  Atmel added movd to their
enhanced core.. It would be nice to be able to make use of it.

This works for me using avr-gcc version 3.3 20030421 (prerelease), targeted to the ATmega162, which of course has the "movw" instruction...

 inline unsigned long Test(unsigned long Input)
 {
    unsigned long Output;

    Input = ((Input << 4) ^ (Input >> 5)) + Input;

    asm
    (
        "movw %w0,%w1\n\t"
        "movw %C0,%C1\n\t"
        :"=r"(Output)
        :"r"(Input)
    );

    Output = Output << 4;

    return Output;
 }

Note the use of "w", which specifies one of the "special upper register pairs": r24/r25, r26/r27, r28/r29, or r30/r31. This gives the code generator only 4 of the technically possible 16 register-pairs to work with, but it may be fine for your purposes.

Until such time as the syntax of the avr-gcc inline assembler is augmented to allow the specification of *even* register pairs, this is likely the best that one can do with inline assembly. It would indeed be a nice option.

I just started using the ATmega162 a couple of days ago and have not looked at the avr-gcc generated code for copying "longs". Is "movw" not being used when appropriate?

Best regards,

Bruce

P.S.- I note that Harald Kipp's wonderful in-line assembly "HOWTO" document at...

http://savannah.nongnu.org/download/avr-libc/doc/avr-libc-user-manual/inline_asm.html

...is missing the assembly "mnemonic" for "movw". Clearly it works. Also, the link there to Harald's Web site has a problem: "http://www.ethernut.de."; should be something like "http://www.ethernut.de/"; instead.

--
 Bruce D. Lightner
 Lightner Engineering
 La Jolla, California
 Voice: +1-858-551-4011
 FAX: +1-858-551-0777
 Email: address@hidden
 URL: http://www.lightner.net/lightner/bruce/



reply via email to

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