1 /* $NetBSD: memset.S,v 1.4 2001/08/02 01:17:28 eeh Exp $ */
4 * Copyright (c) 2001, Eduardo E. Horvath
6 * This software was developed by the Computer Systems Engineering group
7 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
8 * contributed to Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * from: Header: bzero.s,v 1.1 92/06/25 12:52:46 torek Exp
41 #include <machine/asm.h>
45 #include <machine/ctlreg.h>
46 #include <machine/frame.h>
47 #include <machine/psl.h>
49 #if defined(LIBC_SCCS) && !defined(lint)
50 RCSID("$NetBSD: memset.S,v 1.4 2001/08/02 01:17:28 eeh Exp $")
51 #endif /* LIBC_SCCS and not lint */
56 * We want to use VIS instructions if we're clearing out more than
57 * 256 bytes, but to do that we need to properly save and restore the
58 * FP registers. Unfortunately the code to do that in the kernel needs
59 * to keep track of the current owner of the FPU, hence the different
62 * XXXXX To produce more efficient code, we do not allow lengths
63 * greater than 0x80000000000000000, which are negative numbers.
64 * This should not really be an issue since the VA hole should
65 * cause any such ranges to fail anyway.
68 ! %o0 = addr, %o1 = len
70 clr %o1 ! Initialize our pattern
72 * memset(addr, c, len)
76 ! %o0 = addr, %o1 = pattern, %o2 = len
77 mov %o0, %o4 ! Save original pointer
80 btst 7, %o0 ! Word aligned?
84 deccc %o2 ! Store up to 7 bytes
85 bge,a,pt %xcc, Lbzero_internal
88 retl ! Duplicate Lbzero_done
92 * Duplicate the pattern so it fills 64-bits.
94 andcc %o1, 0x0ff, %o1 ! No need to extend zero
96 sllx %o1, 8, %o3 ! sigh. all dependent insns.
104 !! Now we are 64-bit aligned
105 cmp %o2, 256 ! Use block clear if len > 256
106 bge,pt %xcc, Lbzero_block ! use block store insns
110 bl,pn %xcc, Lbzero_cleanup ! Less than 8 bytes left
116 stx %o1, [%o0 - 8] ! Do 1 longword at a time
119 * Len is in [-8..-1] where -8 => done, -7 => 1 byte to zero,
120 * -6 => two bytes, etc. Mop up this remainder, if any.
124 bz,pt %xcc, 5f ! if (len & 4) {
126 stw %o1, [%o0] ! *(int *)addr = 0;
127 inc 4, %o0 ! addr += 4;
130 bz,pt %xcc, 7f ! if (len & 2) {
132 sth %o1, [%o0] ! *(short *)addr = 0;
133 inc 2, %o0 ! addr += 2;
136 bnz,a %icc, Lbzero_done ! if (len & 1)
137 stb %o1, [%o0] ! *addr = 0;
140 mov %o4, %o0 ! Restore ponter for memset (ugh)
147 * Floating point registers are volatile. What luck.
149 * See locore.s for the kernel version.
152 ! wr %g0, FPRS_FEF, %fprs ! Enable FPU
154 !! We are now 8-byte aligned. We need to become 64-byte aligned.
166 brz %o1, 3f ! Skip the memory op
167 fzero %f0 ! for bzero
169 stx %o1, [%o0] ! Flush this puppy to RAM
173 fmovd %f0, %f2 ! Duplicate the pattern
181 !! Remember: we were 8 bytes too far
182 dec 56, %o2 ! Go one iteration too far
184 stda %f0, [%o0] ASI_BLK_P ! Store 64 bytes
191 * Now we're done we need to load the FPU state from where
194 ba,pt %xcc, Lbzero_longs ! Finish up the remainder
195 inccc 56, %o2 ! Restore the count