author | Mark J. Nelson <Mark.J.Nelson@Sun.COM> |
Wed, 06 Aug 2008 16:29:39 -0600 | |
changeset 7298 | b69e27387f74 |
parent 6812 | febeba71273d |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
3900
0388bcf80faf
6507249 memset in sun4v 32 bit libc_psr fails when size argument is 0
mathue
parents:
0
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
0388bcf80faf
6507249 memset in sun4v 32 bit libc_psr fails when size argument is 0
mathue
parents:
0
diff
changeset
|
6 |
* You may not use this file except in compliance with the License. |
0 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
6812 | 21 |
|
0 | 22 |
/* |
6812 | 23 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
0 | 24 |
* Use is subject to license terms. |
25 |
*/ |
|
26 |
||
7298
b69e27387f74
6733918 Teamware has retired, please welcome your new manager, Mercurial
Mark J. Nelson <Mark.J.Nelson@Sun.COM>
parents:
6812
diff
changeset
|
27 |
.file "memset.s" |
6812 | 28 |
|
0 | 29 |
/* |
30 |
* char *memset(sp, c, n) |
|
31 |
* |
|
32 |
* Set an array of n chars starting at sp to the character c. |
|
33 |
* Return sp. |
|
34 |
* |
|
35 |
* Fast assembler language version of the following C-program for memset |
|
36 |
* which represents the `standard' for the C-library. |
|
37 |
* |
|
38 |
* void * |
|
39 |
* memset(void *sp1, int c, size_t n) |
|
40 |
* { |
|
41 |
* if (n != 0) { |
|
42 |
* char *sp = sp1; |
|
43 |
* do { |
|
44 |
* *sp++ = (char)c; |
|
45 |
* } while (--n != 0); |
|
46 |
* } |
|
47 |
* return (sp1); |
|
48 |
* } |
|
49 |
* |
|
50 |
* Flow : |
|
51 |
* |
|
52 |
* For small 6 or fewer bytes stores, bytes will be stored. |
|
53 |
* |
|
54 |
* For less than 32 bytes stores, align the address on 4 byte boundary. |
|
55 |
* Then store as many 4-byte chunks, followed by trailing bytes. |
|
56 |
* |
|
57 |
* For sizes greater than 32 bytes, align the address on 8 byte boundary. |
|
58 |
* if (count > 64) { |
|
59 |
* store as many 8-bytes chunks to block align the address |
|
60 |
* store using ASI_BLK_INIT_ST_QUAD_LDD_P |
|
61 |
* } |
|
62 |
* Store as many 8-byte chunks, followed by trialing bytes. |
|
63 |
* |
|
64 |
*/ |
|
65 |
||
66 |
#include <sys/asm_linkage.h> |
|
67 |
#include <sys/niagaraasi.h> |
|
68 |
#include <sys/asi.h> |
|
69 |
||
70 |
ANSI_PRAGMA_WEAK(memset,function) |
|
71 |
||
72 |
.section ".text" |
|
73 |
.align 32 |
|
74 |
||
75 |
ENTRY(memset) |
|
76 |
||
77 |
mov %o0, %o5 ! copy sp1 before using it |
|
78 |
cmp %o2, 7 ! if small counts, just write bytes |
|
79 |
blu,pn %ncc, .wrchar |
|
80 |
and %o1, 0xff, %o1 ! o1 is (char)c |
|
81 |
||
82 |
sll %o1, 8, %o3 |
|
83 |
or %o1, %o3, %o1 ! now o1 has 2 bytes of c |
|
84 |
sll %o1, 16, %o3 |
|
85 |
||
86 |
cmp %o2, 0x20 |
|
87 |
blu,pn %ncc, .wdalign |
|
88 |
or %o1, %o3, %o1 ! now o1 has 4 bytes of c |
|
89 |
||
90 |
sllx %o1, 32, %o3 |
|
91 |
or %o1, %o3, %o1 ! now o1 has 8 bytes of c |
|
92 |
||
93 |
.dbalign: |
|
94 |
andcc %o5, 7, %o3 ! is sp1 aligned on a 8 byte bound |
|
95 |
bz,pt %ncc, .blkalign ! already double aligned |
|
96 |
sub %o3, 8, %o3 ! -(bytes till double aligned) |
|
97 |
add %o2, %o3, %o2 ! update o2 with new count |
|
98 |
||
99 |
! Set -(%o3) bytes till sp1 double aligned |
|
100 |
1: stb %o1, [%o5] ! there is at least 1 byte to set |
|
101 |
inccc %o3 ! byte clearing loop |
|
102 |
bl,pt %ncc, 1b |
|
103 |
inc %o5 |
|
104 |
||
105 |
! Now sp1 is double aligned (sp1 is found in %o5) |
|
106 |
.blkalign: |
|
107 |
mov ASI_BLK_INIT_ST_QUAD_LDD_P, %asi |
|
108 |
||
109 |
cmp %o2, 0x40 ! check if there are 64 bytes to set |
|
110 |
blu,pn %ncc, 5f |
|
111 |
mov %o2, %o3 |
|
112 |
||
113 |
andcc %o5, 63, %o3 ! is sp1 block aligned? |
|
114 |
bz,pt %ncc, .blkwr ! now block aligned |
|
115 |
sub %o3, 64, %o3 ! o3 is -(bytes till block aligned) |
|
116 |
add %o2, %o3, %o2 ! o2 is the remainder |
|
117 |
||
118 |
! Store -(%o3) bytes till dst is block (64 byte) aligned. |
|
119 |
! Use double word stores. |
|
120 |
! Recall that dst is already double word aligned |
|
121 |
1: |
|
122 |
stx %o1, [%o5] |
|
123 |
addcc %o3, 8, %o3 |
|
124 |
bl,pt %ncc, 1b |
|
125 |
add %o5, 8, %o5 |
|
126 |
||
127 |
! Now sp1 is block aligned |
|
128 |
.blkwr: |
|
129 |
and %o2, 63, %o3 ! calc bytes left after blk store. |
|
130 |
andn %o2, 63, %o4 ! calc size of blocks in bytes |
|
131 |
||
132 |
cmp %o4, 0x100 ! check if there are 256 bytes to set |
|
133 |
blu,pn %ncc, 3f |
|
134 |
nop |
|
135 |
2: |
|
136 |
stxa %o1, [%o5+0x0]%asi |
|
137 |
stxa %o1, [%o5+0x40]%asi |
|
138 |
stxa %o1, [%o5+0x80]%asi |
|
139 |
stxa %o1, [%o5+0xc0]%asi |
|
140 |
||
141 |
stxa %o1, [%o5+0x8]%asi |
|
142 |
stxa %o1, [%o5+0x10]%asi |
|
143 |
stxa %o1, [%o5+0x18]%asi |
|
144 |
stxa %o1, [%o5+0x20]%asi |
|
145 |
stxa %o1, [%o5+0x28]%asi |
|
146 |
stxa %o1, [%o5+0x30]%asi |
|
147 |
stxa %o1, [%o5+0x38]%asi |
|
148 |
||
149 |
stxa %o1, [%o5+0x48]%asi |
|
150 |
stxa %o1, [%o5+0x50]%asi |
|
151 |
stxa %o1, [%o5+0x58]%asi |
|
152 |
stxa %o1, [%o5+0x60]%asi |
|
153 |
stxa %o1, [%o5+0x68]%asi |
|
154 |
stxa %o1, [%o5+0x70]%asi |
|
155 |
stxa %o1, [%o5+0x78]%asi |
|
156 |
||
157 |
stxa %o1, [%o5+0x88]%asi |
|
158 |
stxa %o1, [%o5+0x90]%asi |
|
159 |
stxa %o1, [%o5+0x98]%asi |
|
160 |
stxa %o1, [%o5+0xa0]%asi |
|
161 |
stxa %o1, [%o5+0xa8]%asi |
|
162 |
stxa %o1, [%o5+0xb0]%asi |
|
163 |
stxa %o1, [%o5+0xb8]%asi |
|
164 |
||
165 |
stxa %o1, [%o5+0xc8]%asi |
|
166 |
stxa %o1, [%o5+0xd0]%asi |
|
167 |
stxa %o1, [%o5+0xd8]%asi |
|
168 |
stxa %o1, [%o5+0xe0]%asi |
|
169 |
stxa %o1, [%o5+0xe8]%asi |
|
170 |
stxa %o1, [%o5+0xf0]%asi |
|
171 |
stxa %o1, [%o5+0xf8]%asi |
|
172 |
||
173 |
sub %o4, 0x100, %o4 |
|
174 |
cmp %o4, 0x100 |
|
175 |
bgu,pt %ncc, 2b |
|
176 |
add %o5, 0x100, %o5 |
|
177 |
||
178 |
3: |
|
179 |
cmp %o4, 0x40 ! check if 64 bytes to set |
|
180 |
blu %ncc, 5f |
|
181 |
nop |
|
182 |
4: |
|
183 |
stxa %o1, [%o5+0x0]%asi |
|
184 |
stxa %o1, [%o5+0x8]%asi |
|
185 |
stxa %o1, [%o5+0x10]%asi |
|
186 |
stxa %o1, [%o5+0x18]%asi |
|
187 |
stxa %o1, [%o5+0x20]%asi |
|
188 |
stxa %o1, [%o5+0x28]%asi |
|
189 |
stxa %o1, [%o5+0x30]%asi |
|
190 |
stxa %o1, [%o5+0x38]%asi |
|
191 |
||
192 |
subcc %o4, 0x40, %o4 |
|
193 |
bgu,pt %ncc, 4b |
|
194 |
add %o5, 0x40, %o5 |
|
195 |
||
196 |
5: |
|
197 |
! Set the remaining doubles |
|
198 |
membar #Sync |
|
199 |
mov ASI_PNF, %asi ! restore %asi to default |
|
200 |
! ASI_PRIMARY_NOFAULT value |
|
201 |
subcc %o3, 8, %o3 ! Can we store any doubles? |
|
202 |
blu,pn %ncc, .wrchar |
|
203 |
and %o2, 7, %o2 ! calc bytes left after doubles |
|
204 |
||
205 |
6: |
|
206 |
stx %o1, [%o5] ! store the doubles |
|
207 |
subcc %o3, 8, %o3 |
|
208 |
bgeu,pt %ncc, 6b |
|
209 |
add %o5, 8, %o5 |
|
210 |
||
211 |
ba .wrchar |
|
212 |
nop |
|
213 |
||
214 |
.wdalign: |
|
215 |
andcc %o5, 3, %o3 ! is sp1 aligned on a word boundary |
|
216 |
bz,pn %ncc, .wrword |
|
217 |
andn %o2, 3, %o3 ! create word sized count in %o3 |
|
218 |
||
219 |
dec %o2 ! decrement count |
|
220 |
stb %o1, [%o5] ! clear a byte |
|
221 |
b .wdalign |
|
222 |
inc %o5 ! next byte |
|
223 |
||
224 |
.wrword: |
|
225 |
st %o1, [%o5] ! 4-byte writing loop |
|
226 |
subcc %o3, 4, %o3 |
|
227 |
bnz,pt %ncc, .wrword |
|
228 |
inc 4, %o5 |
|
229 |
||
230 |
and %o2, 3, %o2 ! leftover count, if any |
|
231 |
||
232 |
.wrchar: |
|
3900
0388bcf80faf
6507249 memset in sun4v 32 bit libc_psr fails when size argument is 0
mathue
parents:
0
diff
changeset
|
233 |
! Set the remaining bytes, if any |
0388bcf80faf
6507249 memset in sun4v 32 bit libc_psr fails when size argument is 0
mathue
parents:
0
diff
changeset
|
234 |
cmp %o2, 0 |
0388bcf80faf
6507249 memset in sun4v 32 bit libc_psr fails when size argument is 0
mathue
parents:
0
diff
changeset
|
235 |
be %ncc, .exit |
0 | 236 |
nop |
237 |
||
238 |
7: |
|
239 |
deccc %o2 |
|
240 |
stb %o1, [%o5] |
|
241 |
bgu,pt %ncc, 7b |
|
242 |
inc %o5 |
|
243 |
||
244 |
.exit: |
|
245 |
retl ! %o0 was preserved |
|
246 |
nop |
|
247 |
||
248 |
SET_SIZE(memset) |