avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] [bug #12739] Gcc assumes that target libc provides ff


From: Björn Haase
Subject: Re: [avr-libc-dev] [bug #12739] Gcc assumes that target libc provides ffs function
Date: Thu, 21 Apr 2005 10:09:56 +0200
User-agent: KMail/1.7.1

Am Donnerstag, 21. April 2005 10:40 schrieb Dmitry K.:
> On Thursday 21 April 2005 15:58, Joerg Wunsch wrote:
> > As Dmitry K. wrote:
> > > I have look 'ffs' from newlib (1.12.0).  It take up to 800 (!)
> > > clocks.  Reason: shift is included to loop.
> >
> > The slightly modified BSD code (counter reduced to 8 bits) yields
> >
> >         sbiw r24,0
> >         breq .L1
> >         ldi r18,lo8(1)
> > .L9:
> >         sbrc r24,0
> >         rjmp .L8
> >         lsr r25
> >         ror r24
> >         subi r18,lo8(-(1))
> >         rjmp .L9
> > .L8:
> >         mov r24,r18
> >         clr r25
> > .L1:
> >         ret
> >
> > This makes 6 clocks per cycle, so up to ~ 100 clocks max.
>
> Misprint: 7 clocks per cycle (rjmp).
>
> > I'm interested in seeing Dmitry's code...
>
> I have use byte-width shift:
>
>    #define val_lo  r24
>    #define val_hi  r25
>    #define cntr    r30
>         ...
>    ffs:
>         ldi     cntr, 1
>         tst     val_lo
>         brne    2f
>         or      val_lo, val_hi
>         breq    9f
>         ldi     cntr, 8
>    1:   inc     cntr
>    2:   ror     val_lo
>         brcc    1b
>         mov     r24, cntr
>         clr     r25
>    9:   ret
>
> Summary:  6+4*7+3+2 = 39 clocks (max), without call/ret.
>
> ffsl:   the same idea    --> 18 words.
> ffsll:  movw+sbiw usage  --> 26 words.
>
> Dmitry.
>
Good ! Again an example of how today an intelligent brain could outperform 
today's compiler. :-).

Yours,

Björn




reply via email to

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