locale: use a better fallback
[uclibc-ng.git] / libc / string / arc / arcv2 / strcmp.S
blob2e0e64a0c39465502886fe821fd1e34f6dcc71dc
1 /*
2  * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
3  *
4  * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
5  */
7 #include <features.h>
8 #include <sysdep.h>
10 ENTRY(strcmp)
11         or      r2, r0, r1
12         bmsk_s  r2, r2, 1
13         brne    r2, 0, @.Lcharloop
15 ;;; s1 and s2 are word aligned
16         ld.ab   r2, [r0, 4]
18         mov_s   r12, 0x01010101
19         ror     r11, r12
20         .align  4
21 .LwordLoop:
22         ld.ab   r3, [r1, 4]
23         ;; Detect NULL char in str1
24         sub     r4, r2, r12
25         ld.ab   r5, [r0, 4]
26         bic     r4, r4, r2
27         and     r4, r4, r11
28         brne.d.nt       r4, 0, .LfoundNULL
29         ;; Check if the read locations are the same
30         cmp     r2, r3
31         beq.d   .LwordLoop
32         mov.eq  r2, r5
34         ;; A match is found, spot it out
35 #ifdef __LITTLE_ENDIAN__
36         swape   r3, r3
37         mov_s   r0, 1
38         swape   r2, r2
39 #else
40         mov_s   r0, 1
41 #endif
42         cmp_s   r2, r3
43         j_s.d   [blink]
44         bset.lo r0, r0, 31
46         .align 4
47 .LfoundNULL:
48 #ifdef __BIG_ENDIAN__
49         swape   r4, r4
50         swape   r2, r2
51         swape   r3, r3
52 #endif
53         ;; Find null byte
54         ffs     r0, r4
55         bmsk    r2, r2, r0
56         bmsk    r3, r3, r0
57         swape   r2, r2
58         swape   r3, r3
59         ;; make the return value
60         sub.f   r0, r2, r3
61         mov.hi  r0, 1
62         j_s.d   [blink]
63         bset.lo r0, r0, 31
65         .align 4
66 .Lcharloop:
67         ldb.ab  r2, [r0, 1]
68         ldb.ab  r3, [r1, 1]
69         nop
70         breq    r2, 0, .Lcmpend
71         breq    r2, r3, .Lcharloop
73         .align 4
74 .Lcmpend:
75         j_s.d   [blink]
76         sub     r0, r2, r3
77 END(strcmp)
78 libc_hidden_def(strcmp)
80 #ifndef __UCLIBC_HAS_LOCALE__
81 strong_alias(strcmp,strcoll)
82 libc_hidden_def(strcoll)
83 #endif