arc: Merge ARCv2 string routines in generic ARC .S files
[uclibc-ng.git] / libc / string / arc / memset.S
blob0b74ddc7fca81d75407951c3c71f1facf22285e9
1 /*
2  * Copyright (C) 2013, 2014-2015, 2017 Synopsys, Inc. (www.synopsys.com)
3  * Copyright (C) 2007 ARC International (UK) LTD
4  *
5  * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
6  */
8 #include <sysdep.h>
10 #if !defined(__ARC700__) && !defined(__ARCHS__)
11 #error "Neither ARC700 nor ARCHS is defined!"
12 #endif
14 ENTRY(memset)
16 #ifdef __ARC700__
17 #define SMALL   7 /* Must be at least 6 to deal with alignment/loop issues.  */
19         mov_s   r4,r0
20         or      r12,r0,r2
21         bmsk.f  r12,r12,1
22         extb_s  r1,r1
23         asl     r3,r1,8
24         beq.d   .Laligned
25         or_s    r1,r1,r3
26         brls    r2,SMALL,.Ltiny
27         add     r3,r2,r0
28         stb     r1,[r3,-1]
29         bclr_s  r3,r3,0
30         stw     r1,[r3,-2]
31         bmsk.f  r12,r0,1
32         add_s   r2,r2,r12
33         sub.ne  r2,r2,4
34         stb.ab  r1,[r4,1]
35         and     r4,r4,-2
36         stw.ab  r1,[r4,2]
37         and     r4,r4,-4
38 .Laligned:      ; This code address should be aligned for speed.
39         asl     r3,r1,16
40         lsr.f   lp_count,r2,2
41         or_s    r1,r1,r3
42         lpne    .Loop_end
43         st.ab   r1,[r4,4]
44 .Loop_end:
45         j_s     [blink]
48         .balign 4
49 .Ltiny:
50         mov.f   lp_count,r2
51         lpne    .Ltiny_end
52         stb.ab  r1,[r4,1]
53 .Ltiny_end:
54         j_s     [blink]
55 #endif /* __ARC700__ */
57 #ifdef __ARCHS__
58 #ifdef DONT_USE_PREALLOC
59 #define PREWRITE(A,B)   prefetchw [(A),(B)]
60 #else
61 #define PREWRITE(A,B)   prealloc [(A),(B)]
62 #endif
64         prefetchw [r0]          ; Prefetch the write location
65         mov.f   0, r2
66 ;;; if size is zero
67         jz.d    [blink]
68         mov     r3, r0          ; don't clobber ret val
70 ;;; if length < 8
71         brls.d.nt       r2, 8, .Lsmallchunk
72         mov.f   lp_count,r2
74         and.f   r4, r0, 0x03
75         rsub    lp_count, r4, 4
76         lpnz    @.Laligndestination
77         ;; LOOP BEGIN
78         stb.ab  r1, [r3,1]
79         sub     r2, r2, 1
80 .Laligndestination:
82 ;;; Destination is aligned
83         and     r1, r1, 0xFF
84         asl     r4, r1, 8
85         or      r4, r4, r1
86         asl     r5, r4, 16
87         or      r5, r5, r4
88         mov     r4, r5
90         sub3    lp_count, r2, 8
91         cmp     r2, 64
92         bmsk.hi r2, r2, 5
93         mov.ls  lp_count, 0
94         add3.hi r2, r2, 8
96 ;;; Convert len to Dwords, unfold x8
97         lsr.f   lp_count, lp_count, 6
98         lpnz    @.Lset64bytes
99         ;; LOOP START
100         PREWRITE(r3, 64)        ;Prefetch the next write location
101 #if defined(__LL64__) || defined(__ARC_LL64__)
102         std.ab  r4, [r3, 8]
103         std.ab  r4, [r3, 8]
104         std.ab  r4, [r3, 8]
105         std.ab  r4, [r3, 8]
106         std.ab  r4, [r3, 8]
107         std.ab  r4, [r3, 8]
108         std.ab  r4, [r3, 8]
109         std.ab  r4, [r3, 8]
110 #else
111         st.ab   r4, [r3, 4]
112         st.ab   r4, [r3, 4]
113         st.ab   r4, [r3, 4]
114         st.ab   r4, [r3, 4]
115         st.ab   r4, [r3, 4]
116         st.ab   r4, [r3, 4]
117         st.ab   r4, [r3, 4]
118         st.ab   r4, [r3, 4]
119         st.ab   r4, [r3, 4]
120         st.ab   r4, [r3, 4]
121         st.ab   r4, [r3, 4]
122         st.ab   r4, [r3, 4]
123         st.ab   r4, [r3, 4]
124         st.ab   r4, [r3, 4]
125         st.ab   r4, [r3, 4]
126         st.ab   r4, [r3, 4]
127 #endif
128 .Lset64bytes:
130         lsr.f   lp_count, r2, 5 ;Last remaining  max 124 bytes
131         lpnz    .Lset32bytes
132         ;; LOOP START
133         prefetchw [r3, 32]      ;Prefetch the next write location
134 #if defined(__LL64__) || defined(__ARC_LL64__)
135         std.ab  r4, [r3, 8]
136         std.ab  r4, [r3, 8]
137         std.ab  r4, [r3, 8]
138         std.ab  r4, [r3, 8]
139 #else
140         st.ab   r4, [r3, 4]
141         st.ab   r4, [r3, 4]
142         st.ab   r4, [r3, 4]
143         st.ab   r4, [r3, 4]
144         st.ab   r4, [r3, 4]
145         st.ab   r4, [r3, 4]
146         st.ab   r4, [r3, 4]
147         st.ab   r4, [r3, 4]
148 #endif
149 .Lset32bytes:
151         and.f   lp_count, r2, 0x1F ;Last remaining 31 bytes
152 .Lsmallchunk:
153         lpnz    .Lcopy3bytes
154         ;; LOOP START
155         stb.ab  r1, [r3, 1]
156 .Lcopy3bytes:
158         j       [blink]
159 #endif /* __ARCHS__ */
161 END(memset)
162 libc_hidden_def(memset)