1 /* Optimized memset implementation for PowerPC64.
2 Copyright (C) 1997, 1999, 2000, 2002, 2003, 2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 .tc __cache_line_size[TC],__cache_line_size
31 /* __ptr_t [r3] memset (__ptr_t s [r3], int c [r4], size_t n [r5]));
34 The memset is done in three sizes: byte (8 bits), word (32 bits),
35 cache line (256 bits). There is a special case for setting cache lines
36 to 0, to take advantage of the dcbz instruction. */
38 EALIGN (BP_SYM (memset), 5, 0)
42 #define rRTN r3 /* Initial value of 1st argument. */
43 #if __BOUNDED_POINTERS__
44 # define rMEMP0 r4 /* Original value of 1st arg. */
45 # define rCHR r5 /* Char to set in each byte. */
46 # define rLEN r6 /* Length of region to set. */
47 # define rMEMP r10 /* Address at which we are storing. */
49 # define rMEMP0 r3 /* Original value of 1st arg. */
50 # define rCHR r4 /* Char to set in each byte. */
51 # define rLEN r5 /* Length of region to set. */
52 # define rMEMP r6 /* Address at which we are storing. */
54 #define rALIGN r7 /* Number of bytes we are setting now (when aligning). */
57 #define rNEG64 r8 /* Constant -64 for clearing with dcbz. */
58 #define rCLS r8 /* Cache line size obtained from static. */
59 #define rCLM r9 /* Cache line size mask to check for cache alignment. */
61 #if __BOUNDED_POINTERS__
63 CHECK_BOUNDS_BOTH_WIDE (rMEMP0, rTMP, rTMP2, rLEN)
65 STORE_RETURN_VALUE (rMEMP0)
66 STORE_RETURN_BOUNDS (rTMP, rTMP2)
69 /* Take care of case for size <= 4. */
71 andi. rALIGN, rMEMP0, 7
75 /* Align to doubleword boundary. */
77 rlwimi rCHR, rCHR, 8, 16, 23 /* Replicate byte to halfword. */
80 subfic rALIGN, rALIGN, 8
81 cror 28,30,31 /* Detect odd word aligned. */
82 add rMEMP, rMEMP, rALIGN
83 sub rLEN, rLEN, rALIGN
84 rlwimi rCHR, rCHR, 16, 0, 15 /* Replicate halfword to word. */
86 /* Process the even word of doubleword. */
95 /* Process the odd word of doubleword. */
97 bf 28, L(g4x) /* If false, word aligned on odd word. */
104 /* Handle the case of size < 31. */
106 rlwimi rCHR, rCHR, 16, 0, 15 /* Replicate halfword to word. */
110 /* Align to 32-byte boundary. */
111 andi. rALIGN, rMEMP, 0x18
112 subfic rALIGN, rALIGN, 0x20
113 insrdi rCHR,rCHR,32,0 /* Replicate word to double word. */
116 add rMEMP, rMEMP, rALIGN
117 sub rLEN, rLEN, rALIGN
118 cmplwi cr1, rALIGN, 0x10
121 stdu rCHR, -8(rMEMP2)
122 L(a1): blt cr1, L(a2)
124 stdu rCHR, -16(rMEMP2)
127 /* Now aligned to a 32 byte boundary. */
130 clrrdi. rALIGN, rLEN, 5
132 beq cr1, L(zloopstart) /* Special case for clearing memory using dcbz. */
136 beq L(medium) /* We may not actually get to do a full line. */
137 clrldi. rLEN, rLEN, 59
138 add rMEMP, rMEMP, rALIGN
142 L(c3): dcbtst rNEG64, rMEMP
146 stdu rCHR, -32(rMEMP)
153 stdu rCHR, -32(rMEMP)
155 add rMEMP, rMEMP, rALIGN
159 /* Clear lines of memory in 128-byte chunks. */
161 /* If the remaining length is less the 32 bytes, don't bother getting
162 the cache line size. */
166 /* If the cache line size was not set just goto to L(nondcbz) which is
167 safe for any cache line size. */
172 /* Now we know the cache line size, and it is not 32-bytes, but
173 we may not yet be aligned to the cache line. May have a partial
174 line to fill, so touch it 1st. */
180 blt cr1,L(handletail32)
190 /* Now we are aligned to the cache line and can use dcbz. */
193 blt cr1,L(handletail32)
199 /* We are here because the cache line size was set and was not 32-bytes
200 and the remainder (rLEN) is less than the actual cache line size.
201 So set up the preconditions for L(nondcbz) and go there. */
203 clrrwi. rALIGN, rLEN, 5
208 /* Memset of 8 bytes or less. */
231 /* Memset of 0-31 bytes. */
234 insrdi rCHR,rCHR,32,0 /* Replicate word to double word. */
237 add rMEMP, rMEMP, rLEN
239 bt- 31, L(medium_31t)
240 bt- 30, L(medium_30t)
242 bt- 29, L(medium_29t)
244 bge- cr1, L(medium_27t)
251 bf- 30, L(medium_30f)
254 bf- 29, L(medium_29f)
257 blt- cr1, L(medium_27f)
260 stdu rCHR, -16(rMEMP)
266 END_GEN_TB (BP_SYM (memset),TB_TOCLESS)
267 libc_hidden_builtin_def (memset)
269 /* Copied from bzero.S to prevent the linker from inserting a stub
270 between bzero and memset. */
271 ENTRY (BP_SYM (__bzero))
273 #if __BOUNDED_POINTERS__
277 /* Tell memset that we don't want a return value. */
285 END_GEN_TB (BP_SYM (__bzero),TB_TOCLESS)
287 weak_alias (BP_SYM (__bzero), BP_SYM (bzero))