locale: use a better fallback
[uclibc-ng.git] / libc / string / arc / arcv2 / memset.S
blob343cfaf81c6da07c3515398d8b97c7d1df139789
2 /*
3  * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
4  *
5  * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
6  */
8 #include <features.h>
9 #include <sysdep.h>
11 #ifdef DONT_USE_PREALLOC
12 #define PREWRITE(A,B)   prefetchw [(A),(B)]
13 #else
14 #define PREWRITE(A,B)   prealloc [(A),(B)]
15 #endif
17 ENTRY(memset)
18         prefetchw [r0]          ; Prefetch the write location
19         mov.f   0, r2
20 ;;; if size is zero
21         jz.d    [blink]
22         mov     r3, r0          ; don't clobber ret val
24 ;;; if length < 8
25         brls.d.nt       r2, 8, .Lsmallchunk
26         mov.f   lp_count,r2
28         and.f   r4, r0, 0x03
29         rsub    lp_count, r4, 4
30         lpnz    @.Laligndestination
31         ;; LOOP BEGIN
32         stb.ab  r1, [r3,1]
33         sub     r2, r2, 1
34 .Laligndestination:
36 ;;; Destination is aligned
37         and     r1, r1, 0xFF
38         asl     r4, r1, 8
39         or      r4, r4, r1
40         asl     r5, r4, 16
41         or      r5, r5, r4
42         mov     r4, r5
44         sub3    lp_count, r2, 8
45         cmp     r2, 64
46         bmsk.hi r2, r2, 5
47         mov.ls  lp_count, 0
48         add3.hi r2, r2, 8
50 ;;; Convert len to Dwords, unfold x8
51         lsr.f   lp_count, lp_count, 6
52         lpnz    @.Lset64bytes
53         ;; LOOP START
54         PREWRITE(r3, 64)        ;Prefetch the next write location
55 #if defined(__LL64__) || defined(__ARC_LL64__)
56         std.ab  r4, [r3, 8]
57         std.ab  r4, [r3, 8]
58         std.ab  r4, [r3, 8]
59         std.ab  r4, [r3, 8]
60         std.ab  r4, [r3, 8]
61         std.ab  r4, [r3, 8]
62         std.ab  r4, [r3, 8]
63         std.ab  r4, [r3, 8]
64 #else
65         st.ab   r4, [r3, 4]
66         st.ab   r4, [r3, 4]
67         st.ab   r4, [r3, 4]
68         st.ab   r4, [r3, 4]
69         st.ab   r4, [r3, 4]
70         st.ab   r4, [r3, 4]
71         st.ab   r4, [r3, 4]
72         st.ab   r4, [r3, 4]
73         st.ab   r4, [r3, 4]
74         st.ab   r4, [r3, 4]
75         st.ab   r4, [r3, 4]
76         st.ab   r4, [r3, 4]
77         st.ab   r4, [r3, 4]
78         st.ab   r4, [r3, 4]
79         st.ab   r4, [r3, 4]
80         st.ab   r4, [r3, 4]
81 #endif
82 .Lset64bytes:
84         lsr.f   lp_count, r2, 5 ;Last remaining  max 124 bytes
85         lpnz    .Lset32bytes
86         ;; LOOP START
87         prefetchw [r3, 32]      ;Prefetch the next write location
88 #if defined(__LL64__) || defined(__ARC_LL64__)
89         std.ab  r4, [r3, 8]
90         std.ab  r4, [r3, 8]
91         std.ab  r4, [r3, 8]
92         std.ab  r4, [r3, 8]
93 #else
94         st.ab   r4, [r3, 4]
95         st.ab   r4, [r3, 4]
96         st.ab   r4, [r3, 4]
97         st.ab   r4, [r3, 4]
98         st.ab   r4, [r3, 4]
99         st.ab   r4, [r3, 4]
100         st.ab   r4, [r3, 4]
101         st.ab   r4, [r3, 4]
102 #endif
103 .Lset32bytes:
105         and.f   lp_count, r2, 0x1F ;Last remaining 31 bytes
106 .Lsmallchunk:
107         lpnz    .Lcopy3bytes
108         ;; LOOP START
109         stb.ab  r1, [r3, 1]
110 .Lcopy3bytes:
112         j       [blink]
114 END(memset)
115 libc_hidden_def(memset)