2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 // =============================
27 // BZERO and MEMSET FOR Mac OS X
28 // =============================
30 // We use DCBZ, and therefore are dependent on the cache block size (32.)
31 // Bzero and memset need to be in the same file since they are tightly
32 // coupled, so we can use bzero for memset of 0 without incurring extra
33 // overhead. (The issue is that bzero must preserve r3 for memset.)
36 // r3 = original ptr, not changed since memset returns it
37 // r4 = count of bytes to set ("rc")
38 // r11 = working operand ptr ("rp")
39 // r10 = value to set ("rv")
45 #define __APPLE_API_PRIVATE
46 #include <machine/cpu_capabilities.h>
48 #include <architecture/ppc/asm_help.h>
59 _bzero: // void bzero(void *b, size_t len);
62 // store up to 31 trailing bytes
63 // rv = value to store (in all 4 bytes)
64 // rc = #bytes to store (0..31)
66 andi. r5,rc,16 // bit 27 set in length?
67 mtcrf 0x01,rc // low 4 bits of length to cr7
68 beq 1f // test bits of length
98 _memset: // void * memset(void *b, int c, size_t len);
99 andi. rv,r4,0xFF // copy value to working register, test for 0
100 mr rc,r5 // move length to working register
101 cmplwi cr1,r5,32 // length < 32 ?
102 beqa++ _COMM_PAGE_BZERO
103 rlwimi rv,rv,8,16,23 // replicate value to low 2 bytes
104 mr rp,r3 // make working copy of operand ptr
105 rlwimi rv,rv,16,0,15 // value now in all 4 bytes
106 blt cr1,Ltail // length<32, so use common tail routine
107 neg r5,rp // start to compute #bytes to align
108 andi. r6,r5,0x7 // r6 <- #bytes to align on dw
109 beq- Lmemset1 // already aligned
111 ; align on 8-byte boundary
113 mtcrf 0x01,r6 // move count to cr7 (faster if only 1 cr)
114 sub rc,rc,r6 // adjust length
127 // loop on 16-byte blocks
129 stw rv,0(rp) // store first 8 bytes from rv
131 srwi r5,rc,4 // r5 <- #blocks (>=1)
132 mtcrf 0x01,rc // leftover length to cr7
133 mtctr r5 // set up loop count
134 lfd f0,0(rp) // pick up in a fp register
135 b 2f // enter loop in middle
137 1: // loop on 16-byte blocks
144 // store up to 16 trailing bytes (count in cr7)