bugAVR C Runtime Library - Bugs: bug #36611, _delay_loop_2 must not use...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #36611: _delay_loop_2 must not use constraint "w" with all targets

Submitter:  Georg-Johann Lay <gjlayde>
Submitted:  Fri 08 Jun 2012 10:36:27 PM UTC
   
 
Category:  Header Severity:  3 - Normal
Priority:  9 - Immediate Item Group:  Header files
Status:  None Assigned to:  None
Percent Complete:  0% Open/Closed:  Open
Release:  1.8.0 Fixed Release:  None

Wed 10 May 2017 01:45:07 AM UTC, comment #4: 

I ran into this problem and just re-wrote the _delay_loop_2 assembly.

This should be equivalent for all AVRs. It should even take the same number of clock cycles (since sbiw takes 2 clock cycles).

My initial tests suggest this is working. Since __count is a 2 byte number, %A0 and %B0 should always work as expected.


void
_delay_loop_2(uint16_t __count)
{
        __asm__ volatile (
                "1: subi %A0,1" "\n\t"
                "sbci %B0,0" "\n\t"
                "brne 1b"
                : "=d" (__count)
                : "0" (__count)
        );
}


Cameron Tacklind <cinderblock>
Fri 16 Nov 2012 09:17:17 PM UTC, comment #3: 

We'll need to verify that __builtin_delay_cycles in gcc is still valid.

Eric Weddington <arcanum>
Group administrator
Fri 16 Nov 2012 09:04:06 PM UTC, comment #2: 

Factor out the ISA / architecture by means of #if / #ifdef _HAVE_ADIW_ or _HAVE_CONSTRAINT_W_ or _AVR_ARCH_ or whatever your tools provide and use 2-insn decrement alongside with "d".

If your tools have __builtin_delay_cycles you can use that, but make sure that respective insn constraint does not suffer from the same flaw (AFAIR this is the case with Atmel patches)

Georg-Johann Lay <gjlayde>
Fri 16 Nov 2012 06:13:05 PM UTC, comment #1: 

Johann, what do you recommend to fix this?

Eric Weddington <arcanum>
Group administrator
Fri 08 Jun 2012 10:36:27 PM UTC, original submission:  

./include/util/delay_basic.h

implements:

void
_delay_loop_2(uint16_t __count)
{
_asm_ volatile (
"1: sbiw %0,1" "\n\t"
"brne 1b"
: "=w" (__count)
: "0" (__count)
);
}

This won't work for tiny tiny targets because

- they don't have SBIW
- compiler with suprt for these targets empty the register
  class associated with "w".  Thus, the compiler will throw
  an error if it sees "w".



Georg-Johann Lay <gjlayde>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by cinderblock (Posted a comment)
  • -email is unavailable- added by arcanum (Posted a comment)
  • -email is unavailable- added by gjlayde (Submitted the item)
  •  

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-11-16 arcanum Priority5 - Normal 9 - Immediate

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code