]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/string/metag/strcmp.S
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / string / metag / strcmp.S
1 !    Copyright (C) 2013 Imagination Technologies Ltd.
2
3 !    Licensed under LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
4
5
6 #include <features.h>
7
8         .text
9         .global _strcmp
10         .type   _strcmp,function
11 !D1Ar1 s1
12 !D0Ar2 s2
13 _strcmp:
14         TST     D1Ar1,#3
15         TSTZ    D0Ar2,#3
16         MOVT    D1Re0,#0x0101
17         ADD     D1Re0,D1Re0,#0x0101
18         BNZ     $Lstrcmp_slow
19         GETD    D1Ar3,[D1Ar1+#4++]      ! Load 32-bits from s1
20         GETD    D1Ar5,[D0Ar2+#4++]      ! Load 32-bits from s2
21         LSL     D0FrT,D1Re0,#7          ! D0FrT = 0x80808080
22 $Lstrcmp4_loop:
23         SUB     D0Re0,D1Ar3,D1Re0       ! D1Re0 = 0x01010101
24         MOV     D0Ar6,D1Ar3
25         SUBS    D0Ar4,D1Ar3,D1Ar5       ! Calculate difference
26         XOR     D0Ar6,D0Ar6,#-1
27         GETD    D1Ar3,[D1Ar1+#4++]      ! Load 32-bits from s1
28         AND     D0Re0,D0Re0,D0Ar6
29         ANDSZ   D0Ar6,D0Re0,D0FrT       ! D0FrT = 0x80808080
30         GETD    D1Ar5,[D0Ar2+#4++]      ! Load 32-bits from s2
31         BZ      $Lstrcmp4_loop
32         AND     D0Ar6, D0Re0, D0FrT     ! D0FrT = 0x80808080
33 !
34 ! Either they are different or they both contain a NULL + junk
35 !
36 $Lstrcmp4_end:
37         LSLS    D0Re0,D0Ar4,#24         ! Was Byte[0] the same?
38         LSLSZ   D0Ar2,D0Ar6,#24         ! Yes: AND they where not zero?
39         LSLSZ   D0Re0,D0Ar4,#16         ! Yes: Was Byte[1] the same?
40         LSLSZ   D0Ar2,D0Ar6,#16         ! Yes: AND they where not zero?
41         LSLSZ   D0Re0,D0Ar4,#8          ! Tes: Was Byte[2] the same?
42         LSLSZ   D0Ar2,D0Ar6,#8          ! Yes: AND they where not zero?
43         MOVZ    D0Re0,D0Ar4             ! Yes: Must by Byte[3] thats the result
44         ASR     D0Re0,D0Re0,#24         ! Sign extend result to integer
45         MOV     PC,D1RtP
46 !
47 ! Misaligned case, byte at a time
48 !
49 $Lstrcmp_slow:
50         GETB    D1Ar3,[D1Ar1++]         ! Load char from s1
51         GETB    D1Ar5,[D0Ar2++]         ! Load char from s2
52         CMP     D1Ar3,#1                ! Null -> C and NZ, rest -> NC (\1->Z)
53         CMPNC   D1Ar3,D1Ar5             ! NOT Null: Same -> Z, else -> NZ
54         BZ      $Lstrcmp_slow           ! NOT Null and Same: Loop
55         SUB     D0Re0,D1Ar3,D1Ar5       ! Generate result
56         MOV     PC,D1RtP
57
58         .size _strcmp,.-_strcmp
59
60
61 libc_hidden_def(strcmp)
62 #ifndef __UCLIBC_HAS_LOCALE__
63 strong_alias(strcmp,strcoll)
64 libc_hidden_def(strcoll)
65 #endif