OSDN Git Service

6d02fc1a8686cd3b7dbcba29c16a7469cf906990
[uclinux-h8/uClibc.git] / libc / string / sparc / sparc32 / memset.S
1 /* Set a block of memory to some byte value.
2    For SPARC v7.
3    Copyright (C) 1996, 1999, 2003 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5    Contributed by David S. Miller <davem@caip.rutgers.edu> and
6                   Jakub Jelinek <jj@ultra.linux.cz>.
7
8    The GNU C Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public
10    License as published by the Free Software Foundation; either
11    version 2.1 of the License, or (at your option) any later version.
12
13    The GNU C Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the GNU C Library; if not, see
20    <http://www.gnu.org/licenses/>.  */
21
22 #include <features.h>
23
24         /* Store 64 bytes at (BASE + OFFSET) using value SOURCE. */
25 #define ZERO_BIG_BLOCK(base, offset, source)            \
26         std             source, [base + offset + 0x00]; \
27         std             source, [base + offset + 0x08]; \
28         std             source, [base + offset + 0x10]; \
29         std             source, [base + offset + 0x18]; \
30         std             source, [base + offset + 0x20]; \
31         std             source, [base + offset + 0x28]; \
32         std             source, [base + offset + 0x30]; \
33         std             source, [base + offset + 0x38];
34
35 #define ZERO_LAST_BLOCKS(base, offset, source)          \
36         std             source, [base - offset - 0x38]; \
37         std             source, [base - offset - 0x30]; \
38         std             source, [base - offset - 0x28]; \
39         std             source, [base - offset - 0x20]; \
40         std             source, [base - offset - 0x18]; \
41         std             source, [base - offset - 0x10]; \
42         std             source, [base - offset - 0x08]; \
43         std             source, [base - offset - 0x00];
44
45         .text
46         .align 4
47 #ifdef __UCLIBC_SUSV3_LEGACY__
48 ENTRY(bzero)
49         b               1f
50          mov            %g0, %g3
51 #endif
52
53 3:      cmp             %o2, 3
54         be              2f
55          stb            %g3, [%o0]
56
57         cmp             %o2, 2
58         be              2f
59          stb            %g3, [%o0 + 0x01]
60
61         stb             %g3, [%o0 + 0x02]
62 2:      sub             %o2, 4, %o2
63         add             %o1, %o2, %o1
64         b               4f
65          sub            %o0, %o2, %o0
66 #ifdef __UCLIBC_SUSV3_LEGACY__
67 END(bzero)
68 #endif
69
70 ENTRY(memset)
71         and             %o1, 0xff, %g3
72         sll             %g3, 8, %g2
73         or              %g3, %g2, %g3
74         sll             %g3, 16, %g2
75         or              %g3, %g2, %g3
76         orcc            %o2, %g0, %o1
77 1:      cmp             %o1, 7
78         bleu            7f
79          mov            %o0, %g1
80
81         andcc           %o0, 3, %o2
82         bne             3b
83 4:       andcc          %o0, 4, %g0
84
85         be              2f
86          mov            %g3, %g2
87
88         st              %g3, [%o0]
89         sub             %o1, 4, %o1
90         add             %o0, 4, %o0
91 2:      andcc           %o1, 0xffffff80, %o3
92         be              9f
93          andcc          %o1, 0x78, %o2
94 4:      ZERO_BIG_BLOCK  (%o0, 0x00, %g2)
95         subcc           %o3, 128, %o3
96         ZERO_BIG_BLOCK  (%o0, 0x40, %g2)
97         bne             4b
98          add            %o0, 128, %o0
99
100         orcc            %o2, %g0, %g0
101 9:      be              6f
102          andcc          %o1, 7, %o1
103
104         mov             %o7, %g4
105 101:    call            100f
106          srl            %o2, 1, %o3
107         mov             %g4, %o7
108         jmpl            %o4 + (20f + 64 - 101b), %g0
109          add            %o0, %o2, %o0
110
111 100:    retl
112          sub            %o7, %o3, %o4
113
114 20:     ZERO_LAST_BLOCKS(%o0, 0x48, %g2)
115         ZERO_LAST_BLOCKS(%o0, 0x08, %g2)
116
117 6:      be              8f
118          andcc          %o1, 4, %g0
119         be              1f
120          andcc          %o1, 2, %g0
121         st              %g3, [%o0]
122         add             %o0, 4, %o0
123 1:      be              1f
124          andcc          %o1, 1, %g0
125         sth             %g3, [%o0]
126         add             %o0, 2, %o0
127 1:      bne,a           8f
128          stb            %g3, [%o0]
129 8:      retl
130          mov            %g1, %o0
131 7:      orcc            %o1, 0, %g0
132         be              0f
133          subcc          %o1, 1, %o1
134         stb             %g3, [%o0]
135         be              0f
136          subcc          %o1, 1, %o1
137         stb             %g3, [%o0 + 1]
138         be              0f
139          subcc          %o1, 1, %o1
140         stb             %g3, [%o0 + 2]
141         be              0f
142          subcc          %o1, 1, %o1
143         stb             %g3, [%o0 + 3]
144         be              0f
145          subcc          %o1, 1, %o1
146         stb             %g3, [%o0 + 4]
147         be              0f
148          subcc          %o1, 1, %o1
149         stb             %g3, [%o0 + 5]
150         be              0f
151          subcc          %o1, 1, %o1
152         stb             %g3, [%o0 + 6]
153 0:      retl
154          nop
155 END(memset)
156 libc_hidden_def(memset)