OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [machine/] [sh/] [strcmp.S] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
! SH5 code Copyright 2002 SuperH Ltd.
! SH5 code Copyright 2002 SuperH Ltd.
#include "asm.h"
#include "asm.h"
ENTRY(strcmp)
ENTRY(strcmp)
#if __SHMEDIA__
#if __SHMEDIA__
        ld.ub   r2,0,r4
        ld.ub   r2,0,r4
        pt/l    quickret0,tr0
        pt/l    quickret0,tr0
        ld.ub   r3,0,r5
        ld.ub   r3,0,r5
        ptabs   r18,tr2
        ptabs   r18,tr2
        beqi/u  r4,0,tr0
        beqi/u  r4,0,tr0
        ld.ub   r2,1,r6
        ld.ub   r2,1,r6
        bne/u   r4,r5,tr0
        bne/u   r4,r5,tr0
        pt/l    quickret1,tr1
        pt/l    quickret1,tr1
        ld.ub   r3,1,r7
        ld.ub   r3,1,r7
        beqi/u  r6,0,tr1
        beqi/u  r6,0,tr1
        ld.ub   r2,2,r4
        ld.ub   r2,2,r4
        bne/u   r6,r7,tr1
        bne/u   r6,r7,tr1
        ld.ub   r3,2,r5
        ld.ub   r3,2,r5
        beqi/u  r4,0,tr0
        beqi/u  r4,0,tr0
        ld.ub   r2,3,r6
        ld.ub   r2,3,r6
        bne/u   r4,r5,tr0
        bne/u   r4,r5,tr0
        ld.ub   r3,3,r7
        ld.ub   r3,3,r7
        beqi/u  r6,0,tr1
        beqi/u  r6,0,tr1
        ld.ub   r2,4,r4
        ld.ub   r2,4,r4
        bne/u   r6,r7,tr1
        bne/u   r6,r7,tr1
        ld.ub   r3,4,r5
        ld.ub   r3,4,r5
        beqi/u  r4,0,tr0
        beqi/u  r4,0,tr0
        ld.ub   r2,5,r6
        ld.ub   r2,5,r6
        bne/u   r4,r5,tr0
        bne/u   r4,r5,tr0
        ld.ub   r3,5,r7
        ld.ub   r3,5,r7
        beqi/u  r6,0,tr1
        beqi/u  r6,0,tr1
        ld.ub   r2,6,r4
        ld.ub   r2,6,r4
        bne/u   r6,r7,tr1
        bne/u   r6,r7,tr1
        ld.ub   r3,6,r5
        ld.ub   r3,6,r5
        beqi/u  r4,0,tr0
        beqi/u  r4,0,tr0
        ld.ub   r2,7,r6
        ld.ub   r2,7,r6
        bne/u   r4,r5,tr0
        bne/u   r4,r5,tr0
        ld.ub   r3,7,r7
        ld.ub   r3,7,r7
        beqi/u  r6,0,tr1
        beqi/u  r6,0,tr1
        sub     r3,r2,r3
        sub     r3,r2,r3
        bne/u   r6,r7,tr1
        bne/u   r6,r7,tr1
        andi    r2,-8,r2
        andi    r2,-8,r2
        add     r3,r2,r3
        add     r3,r2,r3
        ldlo.q  r3,8,r23
        ldlo.q  r3,8,r23
        pt      r23_zero,tr0
        pt      r23_zero,tr0
        shlli   r3,3,r22
        shlli   r3,3,r22
        sub     r63,r22,r20
        sub     r63,r22,r20
        movi    0x101,r6
        movi    0x101,r6
        mperm.w r6,r63,r6
        mperm.w r6,r63,r6
        SHLO    r6,r22,r7
        SHLO    r6,r22,r7
        msubs.ub r7,r23,r8
        msubs.ub r7,r23,r8
        pt      loop,tr1
        pt      loop,tr1
        bnei/u  r8,0,tr0 // r23_zero
        bnei/u  r8,0,tr0 // r23_zero
        pt      found_zero,tr0
        pt      found_zero,tr0
        addi    r3,15,r3
        addi    r3,15,r3
        andi    r3,-8,r3
        andi    r3,-8,r3
        sub     r3,r2,r3
        sub     r3,r2,r3
        bne/l   r7,r6,tr1 // loop
        bne/l   r7,r6,tr1 // loop
        /* The strings are aligned to each other.  */
        /* The strings are aligned to each other.  */
        /* It is possible to have a loop with six cycles / iteration
        /* It is possible to have a loop with six cycles / iteration
           by re-ordering the exit conditions, but then it needs extra
           by re-ordering the exit conditions, but then it needs extra
           time and/or code to sort out the r4 != r5 case.  */
           time and/or code to sort out the r4 != r5 case.  */
        pt      al_loop,tr1
        pt      al_loop,tr1
        pt      al_found_zero,tr0
        pt      al_found_zero,tr0
al_loop:
al_loop:
        ld.q    r2,8,r4
        ld.q    r2,8,r4
        ldx.q   r2,r3,r5
        ldx.q   r2,r3,r5
        addi    r2,8,r2
        addi    r2,8,r2
        mcmpeq.b r63,r4,r8
        mcmpeq.b r63,r4,r8
        pt      cmp_quad,tr3
        pt      cmp_quad,tr3
        bnei/u  r8,0,tr0  // al_found_zero
        bnei/u  r8,0,tr0  // al_found_zero
        beq/l   r4,r5,tr1 // al_loop
        beq/l   r4,r5,tr1 // al_loop
        blink   tr3,r63   // cmp_quad
        blink   tr3,r63   // cmp_quad
        .balign 8
        .balign 8
quickret0:
quickret0:
        sub     r4,r5,r2
        sub     r4,r5,r2
        blink   tr2,r63
        blink   tr2,r63
quickret1:
quickret1:
        sub     r6,r7,r2
        sub     r6,r7,r2
        blink   tr2,r63
        blink   tr2,r63
loop:
loop:
        ld.q    r2,8,r4
        ld.q    r2,8,r4
        ldx.q   r2,r3,r19
        ldx.q   r2,r3,r19
        addi    r2,8,r2
        addi    r2,8,r2
        msubs.ub r6,r4,r8
        msubs.ub r6,r4,r8
        mcmpeq.b r63,r19,r9
        mcmpeq.b r63,r19,r9
        SHHI    r19,r20,r21
        SHHI    r19,r20,r21
        or      r21,r23,r5
        or      r21,r23,r5
        SHLO    r19,r22,r23
        SHLO    r19,r22,r23
        bne/u   r8,r9,tr0 // found_zero
        bne/u   r8,r9,tr0 // found_zero
        beq/l   r4,r5,tr1 // loop
        beq/l   r4,r5,tr1 // loop
cmp_quad:
cmp_quad:
#ifdef __LITTLE_ENDIAN__
#ifdef __LITTLE_ENDIAN__
        byterev r4,r4
        byterev r4,r4
        byterev r5,r5
        byterev r5,r5
#endif
#endif
        cmpgtu  r4,r5,r6
        cmpgtu  r4,r5,r6
        cmpgtu  r5,r4,r7
        cmpgtu  r5,r4,r7
        sub     r6,r7,r2
        sub     r6,r7,r2
        blink tr2,r63
        blink tr2,r63
found_zero:
found_zero:
        pt      zero_now,tr0
        pt      zero_now,tr0
        pt      cmp_quad,tr1
        pt      cmp_quad,tr1
        SHHI    r9,r20,r7
        SHHI    r9,r20,r7
        bne/u   r8,r7,tr0 // zero_now
        bne/u   r8,r7,tr0 // zero_now
        bne/u   r4,r5,tr1 // cmp_quad
        bne/u   r4,r5,tr1 // cmp_quad
        SHLO    r9,r22,r8
        SHLO    r9,r22,r8
r23_zero:
r23_zero:
        ld.q    r2,8,r4
        ld.q    r2,8,r4
        add     r23,r63,r5
        add     r23,r63,r5
zero_now:
zero_now:
al_found_zero:
al_found_zero:
/* We konw that one of the values has at lest one zero, and r8 holds
/* We konw that one of the values has at lest one zero, and r8 holds
   an 0x01 or 0xff mask for every zero found in one of the operands.
   an 0x01 or 0xff mask for every zero found in one of the operands.
   If both operands have the first zero in the same place, this mask
   If both operands have the first zero in the same place, this mask
   allows us to truncate the comparison to the valid bytes in the
   allows us to truncate the comparison to the valid bytes in the
   strings.  If the first zero is in different places, it doesn't
   strings.  If the first zero is in different places, it doesn't
   matter if some invalid bytes are included, since the comparison
   matter if some invalid bytes are included, since the comparison
   of the zero with the non-zero will determine the outcome.  */
   of the zero with the non-zero will determine the outcome.  */
#ifdef __LITTLE_ENDIAN__
#ifdef __LITTLE_ENDIAN__
        shlli   r8,8,r8
        shlli   r8,8,r8
        addi    r8,-1,r9
        addi    r8,-1,r9
        andc    r9,r8,r8
        andc    r9,r8,r8
        and     r8,r4,r4
        and     r8,r4,r4
        and     r8,r5,r5
        and     r8,r5,r5
#else
#else
        shlri r8,1,r8
        shlri r8,1,r8
        nsb     r8,r8
        nsb     r8,r8
        addi    r8,8,r8
        addi    r8,8,r8
        andi    r8,56,r8
        andi    r8,56,r8
        sub     r63,r8,r8
        sub     r63,r8,r8
        shlrd   r4,r8,r4
        shlrd   r4,r8,r4
        shlrd   r5,r8,r5
        shlrd   r5,r8,r5
#endif
#endif
#ifdef __LITTLE_ENDIAN__
#ifdef __LITTLE_ENDIAN__
        byterev r4,r4
        byterev r4,r4
        byterev r5,r5
        byterev r5,r5
#endif
#endif
        cmpgtu  r4,r5,r6
        cmpgtu  r4,r5,r6
        cmpgtu  r5,r4,r7
        cmpgtu  r5,r4,r7
        sub     r6,r7,r2
        sub     r6,r7,r2
        blink tr2,r63
        blink tr2,r63
#else /* ! __SHMEDIA__, i.e. SH 1..4 / SHcompact */
#else /* ! __SHMEDIA__, i.e. SH 1..4 / SHcompact */
#ifdef __SH5__
#ifdef __SH5__
#define STR1 r2
#define STR1 r2
#define STR2 r3
#define STR2 r3
#define RESULT r2
#define RESULT r2
#define TMP r4
#define TMP r4
#else
#else
! Entry: r4: string1
! Entry: r4: string1
!        r5: string2
!        r5: string2
! Exit:  r0: result
! Exit:  r0: result
!        r1-r2,r4-r5: clobbered
!        r1-r2,r4-r5: clobbered
#define STR1 r4
#define STR1 r4
#define STR2 r5
#define STR2 r5
#define RESULT r0
#define RESULT r0
#define TMP r2
#define TMP r2
#endif /* __SH5__ */
#endif /* __SH5__ */
        mov     STR1,r0
        mov     STR1,r0
        or      STR2,r0
        or      STR2,r0
        tst     #3,r0
        tst     #3,r0
        bf      L_setup_char_loop
        bf      L_setup_char_loop
        mov     #0,r0
        mov     #0,r0
#ifdef DELAYED_BRANCHES
#ifdef DELAYED_BRANCHES
        mov.l   @STR1+,r1
        mov.l   @STR1+,r1
        .align  2
        .align  2
Longword_loop:
Longword_loop:
        mov.l   @STR2+,TMP
        mov.l   @STR2+,TMP
        cmp/str r0,r1
        cmp/str r0,r1
        bt      Longword_loop_end
        bt      Longword_loop_end
        cmp/eq  r1,TMP
        cmp/eq  r1,TMP
        bt.s    Longword_loop
        bt.s    Longword_loop
        mov.l   @STR1+,r1
        mov.l   @STR1+,r1
        add #-4, STR1
        add #-4, STR1
Longword_loop_end:
Longword_loop_end:
        add #-4, STR1
        add #-4, STR1
        add #-4, STR2
        add #-4, STR2
L_setup_char_loop:
L_setup_char_loop:
        mov.b   @STR1+,r0
        mov.b   @STR1+,r0
        .align  2
        .align  2
L_char_loop:
L_char_loop:
        mov.b   @STR2+,r1
        mov.b   @STR2+,r1
        tst     r0,r0
        tst     r0,r0
        bt      L_return
        bt      L_return
        cmp/eq  r0,r1
        cmp/eq  r0,r1
        bt.s L_char_loop
        bt.s L_char_loop
        mov.b   @STR1+,r0
        mov.b   @STR1+,r0
        add     #-2,STR1
        add     #-2,STR1
        mov.b   @STR1,r0
        mov.b   @STR1,r0
#else /* ! DELAYED_BRANCHES */
#else /* ! DELAYED_BRANCHES */
        .align  2
        .align  2
Longword_loop:
Longword_loop:
        mov.l   @r4+,r1
        mov.l   @r4+,r1
        mov.l   @r5+,r2
        mov.l   @r5+,r2
        cmp/str r0,r1
        cmp/str r0,r1
        bt      Longword_loop_end
        bt      Longword_loop_end
        cmp/eq  r1,r2
        cmp/eq  r1,r2
        bt      Longword_loop
        bt      Longword_loop
Longword_loop_end:
Longword_loop_end:
        add #-4, r4
        add #-4, r4
        add #-4, r5
        add #-4, r5
        .align  2
        .align  2
L_setup_char_loop:
L_setup_char_loop:
L_char_loop:
L_char_loop:
        mov.b   @r4+,r0
        mov.b   @r4+,r0
        mov.b   @r5+,r1
        mov.b   @r5+,r1
        tst     r0,r0
        tst     r0,r0
        bt      L_return
        bt      L_return
        cmp/eq  r0,r1
        cmp/eq  r0,r1
        bt L_char_loop
        bt L_char_loop
#endif
#endif
L_return:
L_return:
        extu.b  r0,RESULT
        extu.b  r0,RESULT
        extu.b  r1,r1
        extu.b  r1,r1
        rts
        rts
        sub     r1,RESULT
        sub     r1,RESULT
#endif /* ! __SHMEDIA__ */
#endif /* ! __SHMEDIA__ */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.