4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
29 * char *memset(sp, c, n)
31 * Set an array of n chars starting at sp to the character c.
34 * Fast assembler language version of the following C-program for memset
35 * which represents the `standard' for the C-library.
38 * memset(void *sp1, int c, size_t n)
50 #include <sys/asm_linkage.h>
51 #include <sys/sun4asi.h>
53 ANSI_PRAGMA_WEAK
(memset
,function
)
55 #define ALIGN8(X) (((X) + 7) & ~7)
62 cmp %o2
, 12 ! if small counts
, just write bytes
64 mov
%o0
, %o5
! copy sp1 before using it
67 deccc
%o2
! byte clearing loop
69 bgeu
,a,pt
%ncc
, .wrchar
70 stb %o1
, [%o5
+ -1] ! we
've already incremented the address
73 .empty ! next instruction is safe, %o0 still good
76 andcc %o5, 7, %o3 ! is sp1 aligned on a 8 byte bound
77 bz,pt %ncc, .blkchk ! already double aligned
78 and %o1, 0xff, %o1 ! o1 is (char)c
79 sub %o3, 8, %o3 ! -(bytes till double aligned)
80 add %o2, %o3, %o2 ! update o2 with new count
82 ! Set -(%o3) bytes till sp1 double aligned
83 1: stb %o1, [%o5] ! there is at least 1 byte to set
84 inccc %o3 ! byte clearing loop
89 ! Now sp1 is double aligned (sp1 is found in %o5)
92 or %o1, %o3, %o1 ! now o1 has 2 bytes of c
95 or %o1, %o3, %o1 ! now o1 has 4 bytes of c
97 cmp %o2, 4095 ! if large count use Block ld/st
100 or %o1, %o3, %o1 ! now o1 has 8 bytes of c
102 bgu,a,pn %ncc, .blkwr ! Do block write for large count
103 andcc %o5, 63, %o3 ! is sp1 block aligned?
105 and %o2, 24, %o3 ! o3 is {0, 8, 16, 24}
107 1: subcc %o3, 8, %o3 ! double-word loop
110 stx %o1, [%o5 - 8] ! already incremented the address
112 andncc %o2, 31, %o4 ! o4 has 32 byte aligned count
113 bz,pn %ncc, 3f ! First instruction of icache line
115 subcc %o4, 32, %o4 ! main loop, 32 bytes per iteration
124 and %o2, 7, %o2 ! o2 has the remaining bytes (<8)
127 deccc %o2 ! byte clearing loop
130 stb %o1, [%o5 - 9] ! already incremented the address
133 nop ! %o0 still preserved
136 bz,pn %ncc, .blalign ! now block aligned
137 sub %o3, 64, %o3 ! o3 is -(bytes till block aligned)
138 add %o2, %o3, %o2 ! o2 is the remainder
140 ! Store -(%o3) bytes till dst is block (64 byte) aligned.
141 ! Use double word stores.
142 ! Recall that dst is already double word aligned
149 ! sp1 is block aligned
151 rd %fprs, %g1 ! g1 = fprs
153 and %o2, 63, %o3 ! calc bytes left after blk store.
155 andcc %g1, 0x4, %g1 ! fprs.du = fprs.dl = 0
156 bz,a %ncc, 2f ! Is fprs.fef == 0
157 wr %g0, 0x4, %fprs ! fprs.fef = 1
159 brnz,pn %o1, 3f ! %o1 is safe to check all 64-bits
160 andn %o2, 63, %o4 ! calc size of blocks in bytes
171 ! allocate 8 bytes of scratch space on the stack
172 add %sp, -SA(16), %sp
173 stx %o1, [%sp + STACK_BIAS + ALIGN8(MINFRAME)] ! move %o1 to %d0
174 ldd [%sp + STACK_BIAS + ALIGN8(MINFRAME)], %d0
177 add %sp, SA(16), %sp ! deallocate the scratch space
186 ! 1st quadrant has 64 bytes of c
187 ! instructions 32-byte aligned here
190 prefetch [%o5 + (3 * BLOCK_SIZE)], 22
191 prefetch [%o5 + (6 * BLOCK_SIZE)], 22
201 ! Cheetah/Jaguar code
202 stda %d0, [%o5]ASI_BLK_P
208 ! Set the remaining doubles
209 subcc %o3, 8, %o3 ! Can we store any doubles?
211 and %o2, 7, %o2 ! calc bytes left after doubles
214 std %d0, [%o5] ! store the doubles
219 ! Set the remaining bytes
220 brz %o2, .exit ! safe to check all 64-bits
223 ! Terminate the copy with a partial store. (bug 1200071 does not apply)
224 ! The data should be at d0
225 dec %o2 ! needed to get the mask right
227 stda %d0, [%o5]%o4, ASI_PST8_P
237 membar #StoreLoad|#StoreStore
238 retl ! %o0 was preserved
239 wr %g1, %g0, %fprs ! fprs = g1 restore fprs