This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Suggestion for better code


> So, my suggestion is to modify egcs for the SH-3 target, to not emit code
> to perform sign extensions when dealing with chars. I believe this would
> apply to shorts as well, but I have not investigated this. I do not know
> the SH-1, SH-2 or SH-4, but I believe that this will apply for them as well.

egcs-1.1.2 is pretty old (about a year or so), and doesn't incorporate 
many of the recent egcs improvements for SH code generation.

...
> _tstrcpy:
>         mov.l   r14,@-r15
>         mov     r4,r0
>         mov.b   @r5+,r1 <--- Data is sign extended by the mov.b instruction
>         mov     r0,r2
>         mov.b   r1,@r2
>         exts.b  r1,r1   <--- r1 is already sign extended, no need for this
>         bra     L6
>         mov     r15,r14
>         .align 4
> L2:
>         mov.b   @r5+,r1
>         mov.b   r1,@r0
>         exts.b  r1,r1   <--- This instruction is redundant as well.
> L6:
>         tst     r1,r1
>         bf.s    L2
>         add     #1,r0
>         mov     r2,r0
>         mov     r14,r15
>         rts
>         mov.l   @r15+,r14
> 
> The loop could be reduced from 6 cycles to 5 cycles per execution,
> giving a 17% improvement for the code.

Here is the code I get from my current toolchain; it is much better.

_tstrcpy:
        mov.l   r14,@-r15
        mov     r4,r0
        mov     r0,r2
        mov     r15,r14
        .align 2
L5:
        mov.b   @r5+,r1		<- No redundant sign extension
        mov.b   r1,@r0		<- ditto
        tst     r1,r1
        add     #1,r0
        bf      L5
        mov     r2,r0
        mov     r14,r15
        rts
        mov.l   @r15+,r14

You may want to switch to egcs-current or the next version of egcs/gcc
when it is released. You should see some improvements.

Toshi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]