2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/appleapiopts.h>
26 #include <machine/cpu_capabilities.h>
27 #include <machine/commpage.h>
33 /* *********************
34 * * M E M S E T _ G 4 *
35 * *********************
37 * This is a subroutine called by Libc memset and memset_pattern for large nonzero
38 * operands (zero operands are funneled into bzero.) This version is for
39 * 32-bit processors with a 32-byte cache line and Altivec.
42 * r4 = count of bytes to store (must be >= 32)
43 * r8 = ptr to the 1st byte to store (16-byte aligned)
44 * r9 = ptr to 16-byte pattern to store (16-byte aligned)
46 * r3 = not changed, since memset returns it
47 * r4 = bytes remaining to store (will be <32)
49 * r8 = ptr to next byte to store (still 16-byte aligned)
50 * r12 = not changed (holds return value for memset)
53 #define kBig (3*64) // big enough to warrant using dcba (NB: must be >= 3*64)
57 cmplwi cr1,r4,kBig // big enough to warrant using dcbz?
58 mfspr r2,vrsave // we'll be using VRs
59 oris r0,r2,0x8000 // we use vr0
60 andi. r5,r8,0x10 // is ptr 32-byte aligned?
62 li r5,16 // get offsets for "stvx"
63 lvx v0,0,r9 // load the pattern into v0
65 blt cr1,LShort // not big enough to bother with dcba
70 beq 2f // already aligned
71 stvx v0,0,r8 // store another 16 bytes to align
75 // Set up for inner loop.
77 srwi r0,r4,6 // get count of 64-byte chunks (>=2)
78 dcba 0,r8 // pre-allocate first cache line (possibly nop'd)
79 rlwinm r4,r4,0,0x3F // mask down to residual count (0..63)
80 subic r0,r0,1 // loop 1-too-few times
81 li r10,64 // get offsets to DCBA one chunk ahead
84 dcba r6,r8 // zero 2nd cache line (possibly nop'd)
85 b 3f // enter DCBA loop
87 // Loop over 64-byte chunks. We DCBA one chunk ahead, which is a little faster.
88 // Note that some G4s do not benefit from the DCBAs. We nop them in that case.
92 dcba r10,r8 // zero one 64-byte chunk ahead (possibly nop'd)
101 // Last chunk, which we've already DCBAd.
109 // loop over 32-byte chunks at end
111 srwi. r0,r4,5 // get count of 32-byte chunks
112 rlwinm r4,r4,0,0x1F // mask down to residual count (0..31)
113 beq 7f // no chunks so done
121 mtspr vrsave,r2 // restore caller's vrsave
125 COMMPAGE_DESCRIPTOR(memset_g4,_COMM_PAGE_MEMSET_PATTERN,kCache32+kHasAltivec,0, \
126 kCommPageDCBA+kCommPage32)