source: trunk/libs/newlib/src/newlib/libc/machine/arc/strlen-bs.S @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.3 KB
Line 
1/*
2   Copyright (c) 2015, Synopsys, Inc. All rights reserved.
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.  */
34#if !defined (__OPTIMIZE_SIZE__) && !defined (PREFER_SIZE_OVER_SPEED)
35
36#include "asm.h"
37
38#if (defined (__ARC600__) || !defined (__ARC_NORM__)) && !defined (__ARC601__) \
39    && defined (__ARC_BARREL_SHIFTER__)
40/* This code is optimized for the ARC600 pipeline.  */
41
42ENTRY (strlen)
43        or      r3,r0,7
44        ld      r2,[r3,-7]
45        ld.a    r6,[r3,-3]
46        mov     r4,0x01010101
47        ; uses long immediate
48#ifdef __LITTLE_ENDIAN__
49        asl_s   r1,r0,3
50        btst_s  r0,2
51        asl     r7,r4,r1
52        ror     r5,r4
53        sub     r1,r2,r7
54        bic_l   r1,r1,r2
55        mov.eq  r7,r4
56        sub     r12,r6,r7
57        bic     r12,r12,r6
58        or.eq   r12,r12,r1
59        and     r12,r12,r5
60        brne    r12,0,.Learly_end
61#else /* BIG ENDIAN */
62        ror     r5,r4
63        btst_s  r0,2
64        mov_s   r1,31
65        sub3    r7,r1,r0
66        sub     r1,r2,r4
67        bic_l   r1,r1,r2
68        bmsk    r1,r1,r7
69        sub     r12,r6,r4
70        bic     r12,r12,r6
71        bmsk.ne r12,r12,r7
72        or.eq   r12,r12,r1
73        and     r12,r12,r5
74        brne    r12,0,.Learly_end
75#endif /* ENDIAN */
76
77.Loop:
78        ld_s    r2,[r3,4]
79        ld.a    r6,[r3,8]
80        ; stall for load result
81        sub     r1,r2,r4
82        bic_s   r1,r1,r2
83        sub     r12,r6,r4
84        bic     r12,r12,r6
85        or_s    r12,r12,r1
86        and     r12,r12,r5
87        breq_s  r12,0,.Loop
88.Lend:
89        and.f   r1,r1,r5
90        sub.ne  r3,r3,4
91#ifdef __LITTLE_ENDIAN__
92        mov.eq  r1,r12
93        asr.f   0,r1,8
94        bmsk.f  0,r1,15
95        sub     r0,r3,r0
96        add.cc  r0,r0,1
97        jne.d   [blink]
98        asl.f   0,r1,9
99        j_s.d   [blink]
100        sbc     r0,r0,-2
101#else /* BIG ENDIAN */
102        mov.eq  r2,r6
103        asl_s   r2,r2,7
104        mov.eq  r1,r12
105        bic_s   r1,r1,r2
106        asr.f   0,r1,16
107        sub     r0,r3,r0
108        add.pl  r0,r0,1
109        jne.d   [blink]
110        add.eq  r0,r0,1
111        j_s.d   [blink]
112        add.cc  r0,r0,1
113#endif /* ENDIAN */
114
115        .balign 4
116.Learly_end:
117        b.d     .Lend
118        sub_s.ne r1,r1,r1
119ENDFUNC (strlen)
120#endif /* (__ARC600__ || !__ARC_NORM__) && !__ARC601__ && __ARC_BARREL_SHIFTER__ */
121
122#endif /* !__OPTIMIZE_SIZE__ && !PREFER_SIZE_OVER_SPEED */
Note: See TracBrowser for help on using the repository browser.