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

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

Re: [avr-gcc-list] Wrong excution order in 4.1.1, but not 3.4.5, regress


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Wrong excution order in 4.1.1, but not 3.4.5, regression?
Date: Wed, 21 Feb 2007 13:06:20 +0100 (MET)

In article <address@hidden> you write:

>OK - here's my program which works under 3.4.5 and fails under 4.1.1.

Thanks for stripping it down to that!

>It seems like a bug to me, but I figured I'll wait to hear some other
>people's opinions. If it is indeed a bug, then I'm more than happy to
>file a bug report.

The bug is in your inline asm.  You didn't tell the compiler that you
are going to modify parameter 0/1 inside the asm.  Now that the
compiler inlined the function call(s), it didn't know it had to
(re)load the parameter ms.

The following version works correctly:

static void ms_spin( unsigned short ms )
{
    if (!ms)
            return;

    /* the inner loop takes 4 cycles per iteration */
    __asm__ __volatile__ (
            "1:                     \n"
            "       ldi r26, %3     \n"
            "       ldi r27, %2     \n"
            "2:     sbiw r26, 1     \n"
            "       brne 2b         \n"
            "       sbiw %1, 1      \n"
            "       brne 1b         \n"
            : "+w" (ms)
            : "w" (ms), "i" (LOOPS_PER_MS >> 8), "i" (0xff & LOOPS_PER_MS)
            : "r26", "r27"
            );
}

(You didn't telll the compiler about clobbering rr26 either.)

I agree though that it's an optimization regression that GCC 4.x even
inlines these function calls at all, as inlining a function that is
being called more than once will generate larger code than minimally
necessary, so it violates the objective of -Os (to include only those
level 2 optimizations that won't increase the code size).  I filed a
bug report for this, after verifying it's still the same for the code
on GCC's trunk.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30908

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)




reply via email to

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