2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc32 / memset.S
blobe6204e8ac9983b67b3bf7bd7d70de840bc13c57e
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>.
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.
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.
18    You should have received a copy of the GNU Lesser General Public
19    License along with the GNU C Library; if not, write to the Free
20    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21    02111-1307 USA.  */
23 #include <sysdep.h>
25         /* Store 64 bytes at (BASE + OFFSET) using value SOURCE. */
26 #define ZERO_BIG_BLOCK(base, offset, source)            \
27         std             source, [base + offset + 0x00]; \
28         std             source, [base + offset + 0x08]; \
29         std             source, [base + offset + 0x10]; \
30         std             source, [base + offset + 0x18]; \
31         std             source, [base + offset + 0x20]; \
32         std             source, [base + offset + 0x28]; \
33         std             source, [base + offset + 0x30]; \
34         std             source, [base + offset + 0x38];
36 #define ZERO_LAST_BLOCKS(base, offset, source)          \
37         std             source, [base - offset - 0x38]; \
38         std             source, [base - offset - 0x30]; \
39         std             source, [base - offset - 0x28]; \
40         std             source, [base - offset - 0x20]; \
41         std             source, [base - offset - 0x18]; \
42         std             source, [base - offset - 0x10]; \
43         std             source, [base - offset - 0x08]; \
44         std             source, [base - offset - 0x00];
46         .text
47         .align 4
48 ENTRY(__bzero)
49         b               1f
50          mov            %g0, %g3
52 3:      cmp             %o2, 3
53         be              2f
54          stb            %g3, [%o0]
56         cmp             %o2, 2
57         be              2f
58          stb            %g3, [%o0 + 0x01]
60         stb             %g3, [%o0 + 0x02]
61 2:      sub             %o2, 4, %o2
62         add             %o1, %o2, %o1
63         b               4f
64          sub            %o0, %o2, %o0
65 END(__bzero)
67 ENTRY(memset)
68         and             %o1, 0xff, %g3
69         sll             %g3, 8, %g2
70         or              %g3, %g2, %g3
71         sll             %g3, 16, %g2
72         or              %g3, %g2, %g3
73         orcc            %o2, %g0, %o1
74 1:      cmp             %o1, 7
75         bleu            7f
76          mov            %o0, %g1
78         andcc           %o0, 3, %o2
79         bne             3b
80 4:       andcc          %o0, 4, %g0
82         be              2f
83          mov            %g3, %g2
85         st              %g3, [%o0]
86         sub             %o1, 4, %o1
87         add             %o0, 4, %o0
88 2:      andcc           %o1, 0xffffff80, %o3
89         be              9f
90          andcc          %o1, 0x78, %o2
91 4:      ZERO_BIG_BLOCK  (%o0, 0x00, %g2)
92         subcc           %o3, 128, %o3
93         ZERO_BIG_BLOCK  (%o0, 0x40, %g2)
94         bne             4b
95          add            %o0, 128, %o0
97         orcc            %o2, %g0, %g0
98 9:      be              6f
99          andcc          %o1, 7, %o1
101         mov             %o7, %g4
102 101:    call            100f
103          srl            %o2, 1, %o3
104         mov             %g4, %o7
105         jmpl            %o4 + (20f + 64 - 101b), %g0
106          add            %o0, %o2, %o0
108 100:    retl
109          sub            %o7, %o3, %o4
111 20:     ZERO_LAST_BLOCKS(%o0, 0x48, %g2)
112         ZERO_LAST_BLOCKS(%o0, 0x08, %g2)
114 6:      be              8f
115          andcc          %o1, 4, %g0
116         be              1f
117          andcc          %o1, 2, %g0
118         st              %g3, [%o0]
119         add             %o0, 4, %o0
120 1:      be              1f
121          andcc          %o1, 1, %g0
122         sth             %g3, [%o0]
123         add             %o0, 2, %o0
124 1:      bne,a           8f
125          stb            %g3, [%o0]
126 8:      retl
127          mov            %g1, %o0
128 7:      orcc            %o1, 0, %g0
129         be              0f
130          subcc          %o1, 1, %o1
131         stb             %g3, [%o0]
132         be              0f
133          subcc          %o1, 1, %o1
134         stb             %g3, [%o0 + 1]
135         be              0f
136          subcc          %o1, 1, %o1
137         stb             %g3, [%o0 + 2]
138         be              0f
139          subcc          %o1, 1, %o1
140         stb             %g3, [%o0 + 3]
141         be              0f
142          subcc          %o1, 1, %o1
143         stb             %g3, [%o0 + 4]
144         be              0f
145          subcc          %o1, 1, %o1
146         stb             %g3, [%o0 + 5]
147         be              0f
148          subcc          %o1, 1, %o1
149         stb             %g3, [%o0 + 6]
150 0:      retl
151          nop
152 END(memset)
153 libc_hidden_builtin_def (memset)
155 weak_alias (__bzero, bzero)