]>
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/strlen.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" | |
06537f05 AK |
38 | #if (defined (__ARC700__) || defined (__ARCEM__) || defined (__ARCHS__)) \ |
39 | && defined (__ARC_NORM__) && defined (__ARC_BARREL_SHIFTER__) | |
c0a99f02 AK |
40 | |
41 | ENTRY (strlen) | |
42 | or r3,r0,7 | |
43 | ld r2,[r3,-7] | |
44 | ld.a r6,[r3,-3] | |
45 | mov r4,0x01010101 | |
46 | ; uses long immediate | |
47 | #ifdef __LITTLE_ENDIAN__ | |
48 | asl_s r1,r0,3 | |
49 | btst_s r0,2 | |
50 | asl r7,r4,r1 | |
51 | ror r5,r4 | |
52 | sub r1,r2,r7 | |
53 | bic_s r1,r1,r2 | |
54 | mov.eq r7,r4 | |
55 | sub r12,r6,r7 | |
56 | bic r12,r12,r6 | |
57 | or.eq r12,r12,r1 | |
58 | and r12,r12,r5 | |
59 | brne r12,0,.Learly_end | |
60 | #else /* BIG ENDIAN */ | |
61 | ror r5,r4 | |
62 | btst_s r0,2 | |
63 | mov_s r1,31 | |
64 | sub3 r7,r1,r0 | |
65 | sub r1,r2,r4 | |
66 | bic_s r1,r1,r2 | |
67 | bmsk r1,r1,r7 | |
68 | sub r12,r6,r4 | |
69 | bic r12,r12,r6 | |
70 | bmsk.ne r12,r12,r7 | |
71 | or.eq r12,r12,r1 | |
72 | and r12,r12,r5 | |
73 | brne r12,0,.Learly_end | |
74 | #endif /* ENDIAN */ | |
75 | ||
76 | .Loop: | |
77 | ld_s r2,[r3,4] | |
78 | ld.a r6,[r3,8] | |
79 | ; stall for load result | |
80 | sub r1,r2,r4 | |
81 | bic_s r1,r1,r2 | |
82 | sub r12,r6,r4 | |
83 | bic r12,r12,r6 | |
84 | or_l r12,r12,r1 | |
85 | and r12,r12,r5 | |
86 | breq_l r12,0,.Loop | |
87 | .Lend: | |
88 | and.f r1,r1,r5 | |
89 | sub.ne r3,r3,4 | |
90 | mov.eq r1,r12 | |
91 | #ifdef __LITTLE_ENDIAN__ | |
92 | sub_s r2,r1,1 | |
93 | bic_s r2,r2,r1 | |
94 | norm r1,r2 | |
95 | sub_s r0,r0,3 | |
96 | lsr_s r1,r1,3 | |
97 | sub r0,r3,r0 | |
98 | j_s.d [blink] | |
99 | sub_l r0,r0,r1 | |
100 | #else /* BIG ENDIAN */ | |
101 | lsr_s r1,r1,7 | |
102 | mov.eq r2,r6 | |
103 | bic_s r1,r1,r2 | |
104 | norm r1,r1 | |
105 | sub r0,r3,r0 | |
106 | lsr_s r1,r1,3 | |
107 | j_s.d [blink] | |
108 | add_l r0,r0,r1 | |
109 | #endif /* ENDIAN */ | |
110 | .Learly_end: | |
111 | b.d .Lend | |
112 | sub_s.ne r1,r1,r1 | |
113 | ENDFUNC (strlen) | |
06537f05 AK |
114 | #endif /* (__ARC700__ || __ARCEM__ || __ARCHS__) && __ARC_NORM__ |
115 | && __ARC_BARREL_SHIFTER__ */ | |
c0a99f02 AK |
116 | |
117 | #endif /* !__OPTIMIZE_SIZE__ && !PREFER_SIZE_OVER_SPEED */ |