]>
Commit | Line | Data |
---|---|---|
c0a99f02 | 1 | /* |
d85bb55f | 2 | Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved. |
c0a99f02 AK |
3 | |
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions are met: | |
6 | ||
7 | 1) Redistributions of source code must retain the above copyright notice, | |
8 | this list of conditions and the following disclaimer. | |
9 | ||
10 | 2) Redistributions in binary form must reproduce the above copyright notice, | |
11 | this list of conditions and the following disclaimer in the documentation | |
12 | and/or other materials provided with the distribution. | |
13 | ||
14 | 3) Neither the name of the Synopsys, Inc., nor the names of its contributors | |
15 | may be used to endorse or promote products derived from this software | |
16 | without specific prior written permission. | |
17 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
28 | POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | ||
31 | /* This implementation is optimized for performance. For code size a generic | |
32 | implementation of this function from newlib/libc/string/strcmp.c will be | |
33 | used. */ | |
d85bb55f CZ |
34 | #if !defined (__OPTIMIZE_SIZE__) && !defined (PREFER_SIZE_OVER_SPEED) \ |
35 | && !defined (__ARC_RF16__) | |
c0a99f02 AK |
36 | |
37 | #include "asm.h" | |
38 | ||
06537f05 | 39 | #ifdef __ARCHS__ |
c0a99f02 AK |
40 | ENTRY (strcmp) |
41 | or r2, r0, r1 | |
42 | bmsk_s r2, r2, 1 | |
43 | brne r2, 0, @.Lcharloop | |
44 | ||
45 | ; s1 and s2 are word aligned | |
46 | ld.ab r2, [r0, 4] | |
47 | ||
48 | mov_s r12, 0x01010101 | |
49 | ror r11, r12 | |
50 | .align 4 | |
51 | .LwordLoop: | |
52 | ld.ab r3, [r1, 4] | |
53 | ; Detect NULL char in str1 | |
54 | sub r4, r2, r12 | |
55 | ld.ab r5, [r0, 4] | |
56 | bic r4, r4, r2 | |
57 | and r4, r4, r11 | |
58 | brne.d.nt r4, 0, .LfoundNULL | |
59 | ; Check if the read locations are the same | |
60 | cmp r2, r3 | |
61 | beq.d .LwordLoop | |
62 | mov.eq r2, r5 | |
63 | ||
64 | ; A match is found, spot it out | |
65 | #ifdef __LITTLE_ENDIAN__ | |
66 | swape r3, r3 | |
67 | mov_s r0, 1 | |
68 | swape r2, r2 | |
69 | #else | |
70 | mov_s r0, 1 | |
71 | #endif | |
72 | cmp_s r2, r3 | |
73 | j_s.d [blink] | |
74 | bset.lo r0, r0, 31 | |
75 | ||
76 | .align 4 | |
77 | .LfoundNULL: | |
78 | #ifdef __BIG_ENDIAN__ | |
79 | swape r4, r4 | |
80 | swape r2, r2 | |
81 | swape r3, r3 | |
82 | #endif | |
83 | ; Find null byte | |
84 | ffs r0, r4 | |
85 | bmsk r2, r2, r0 | |
86 | bmsk r3, r3, r0 | |
87 | swape r2, r2 | |
88 | swape r3, r3 | |
89 | ; make the return value | |
90 | sub.f r0, r2, r3 | |
91 | mov.hi r0, 1 | |
92 | j_s.d [blink] | |
93 | bset.lo r0, r0, 31 | |
94 | ||
95 | .align 4 | |
96 | .Lcharloop: | |
97 | ldb.ab r2, [r0, 1] | |
98 | ldb.ab r3, [r1, 1] | |
99 | nop | |
100 | breq r2, 0, .Lcmpend | |
101 | breq r2, r3, .Lcharloop | |
102 | ||
103 | .align 4 | |
104 | .Lcmpend: | |
105 | j_s.d [blink] | |
106 | sub r0, r2, r3 | |
107 | ENDFUNC (strcmp) | |
06537f05 | 108 | #endif /* __ARCHS__ */ |
c0a99f02 AK |
109 | |
110 | #endif /* !__OPTIMIZE_SIZE__ && !PREFER_SIZE_OVER_SPEED */ |