bump version for 1.0.48 release
[uclibc-ng.git] / libc / string / arc / memset.S
blob5aa5d6c655c8385bd3ea835d884e7282fd211cf0
1 /*
2  * Copyright (C) 2013, 2014-2015, 2017, 2022 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 ENTRY(memset)
12 #if defined(__ARC700__)
13 #define SMALL   7 /* Must be at least 6 to deal with alignment/loop issues.  */
15         mov_s   r4,r0
16         or      r12,r0,r2
17         bmsk.f  r12,r12,1
18         extb_s  r1,r1
19         asl     r3,r1,8
20         beq.d   .Laligned
21         or_s    r1,r1,r3
22         brls    r2,SMALL,.Ltiny
23         add     r3,r2,r0
24         stb     r1,[r3,-1]
25         bclr_s  r3,r3,0
26         stw     r1,[r3,-2]
27         bmsk.f  r12,r0,1
28         add_s   r2,r2,r12
29         sub.ne  r2,r2,4
30         stb.ab  r1,[r4,1]
31         and     r4,r4,-2
32         stw.ab  r1,[r4,2]
33         and     r4,r4,-4
34 .Laligned:      ; This code address should be aligned for speed.
35         asl     r3,r1,16
36         lsr.f   lp_count,r2,2
37         or_s    r1,r1,r3
38         lpne    .Loop_end
39         st.ab   r1,[r4,4]
40 .Loop_end:
41         j_s     [blink]
44         .balign 4
45 .Ltiny:
46         mov.f   lp_count,r2
47         lpne    .Ltiny_end
48         stb.ab  r1,[r4,1]
49 .Ltiny_end:
50         j_s     [blink]
52 #elif defined(__ARCHS__)
53 #ifdef DONT_USE_PREALLOC
54 #define PREWRITE(A,B)   prefetchw [(A),(B)]
55 #else
56 #define PREWRITE(A,B)   prealloc [(A),(B)]
57 #endif
59         prefetchw [r0]          ; Prefetch the write location
60         mov.f   0, r2
61 ;;; if size is zero
62         jz.d    [blink]
63         mov     r3, r0          ; don't clobber ret val
65 ;;; if length < 8
66         brls.d.nt       r2, 8, .Lsmallchunk
67         mov.f   lp_count,r2
69         and.f   r4, r0, 0x03
70         rsub    lp_count, r4, 4
71         lpnz    @.Laligndestination
72         ;; LOOP BEGIN
73         stb.ab  r1, [r3,1]
74         sub     r2, r2, 1
75 .Laligndestination:
77 ;;; Destination is aligned
78         and     r1, r1, 0xFF
79         asl     r4, r1, 8
80         or      r4, r4, r1
81         asl     r5, r4, 16
82         or      r5, r5, r4
83         mov     r4, r5
85         sub3    lp_count, r2, 8
86         cmp     r2, 64
87         bmsk.hi r2, r2, 5
88         mov.ls  lp_count, 0
89         add3.hi r2, r2, 8
91 ;;; Convert len to Dwords, unfold x8
92         lsr.f   lp_count, lp_count, 6
93         lpnz    @.Lset64bytes
94         ;; LOOP START
95         PREWRITE(r3, 64)        ;Prefetch the next write location
96 #if defined(__LL64__) || defined(__ARC_LL64__)
97         std.ab  r4, [r3, 8]
98         std.ab  r4, [r3, 8]
99         std.ab  r4, [r3, 8]
100         std.ab  r4, [r3, 8]
101         std.ab  r4, [r3, 8]
102         std.ab  r4, [r3, 8]
103         std.ab  r4, [r3, 8]
104         std.ab  r4, [r3, 8]
105 #else
106         st.ab   r4, [r3, 4]
107         st.ab   r4, [r3, 4]
108         st.ab   r4, [r3, 4]
109         st.ab   r4, [r3, 4]
110         st.ab   r4, [r3, 4]
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 #endif
123 .Lset64bytes:
125         lsr.f   lp_count, r2, 5 ;Last remaining  max 124 bytes
126         lpnz    .Lset32bytes
127         ;; LOOP START
128         prefetchw [r3, 32]      ;Prefetch the next write location
129 #if defined(__LL64__) || defined(__ARC_LL64__)
130         std.ab  r4, [r3, 8]
131         std.ab  r4, [r3, 8]
132         std.ab  r4, [r3, 8]
133         std.ab  r4, [r3, 8]
134 #else
135         st.ab   r4, [r3, 4]
136         st.ab   r4, [r3, 4]
137         st.ab   r4, [r3, 4]
138         st.ab   r4, [r3, 4]
139         st.ab   r4, [r3, 4]
140         st.ab   r4, [r3, 4]
141         st.ab   r4, [r3, 4]
142         st.ab   r4, [r3, 4]
143 #endif
144 .Lset32bytes:
146         and.f   lp_count, r2, 0x1F ;Last remaining 31 bytes
147 .Lsmallchunk:
148         lpnz    .Lcopy3bytes
149         ;; LOOP START
150         stb.ab  r1, [r3, 1]
151 .Lcopy3bytes:
153         j       [blink]
155 #elif defined(__ARC64_ARCH32__)
156         ;; Based on Synopsys code from newlib's arc64/memset.S
158         ;; Assemble the bytes to 32bit words
159         bmsk_s  r1, r1, 7               ; treat it like unsigned char
160         lsl8    r3, r1
161         or_s    r1, r1, r3
162         lsl16   r3, r1
163         or      r6, r1, r3
164         mov r7,r6
166         lsr.f   r5, r2, 4               ; counter for 16-byte chunks
167         beq.d   @.L_write_15_bytes
168         mov     r4, r0                  ; work on a copy of "r0"
170 .L_write_16_bytes:
171 #if defined(__ARC64_LL64__)
172         std.ab  r6, [r4, 8]
173         std.ab  r6, [r4, 8]
174         dbnz    r5, @.L_write_16_bytes
175 #else
176         st.ab   r6, [r4, 4]
177         st.ab   r6, [r4, 4]
178         st.ab   r6, [r4, 4]
179         dbnz.d  r5, @.L_write_16_bytes
180         st.ab   r6, [r4, 4]
181 #endif
182         bmsk_s  r2, r2, 3
184 .L_write_15_bytes:
185         bbit0.d r2, 1, @1f
186         lsr     r3, r2, 2
187         sth.ab  r6, [r4, 2]
189         bbit0.d r2, 0, @1f
190         xor     r3, r3, 3
191         stb.ab  r6, [r4, 1]
193         bi      [r3]
194         st.ab   r6,[r4, 4]
195         st.ab   r6,[r4, 4]
196         st.ab   r6,[r4, 4]
198         j_s     [blink]
200 #else
201 #error "Unsupported ARC CPU type"
202 #endif
204 END(memset)
205 libc_hidden_def(memset)