1 /* Optimized memset implementation for PowerPC64.
2 Copyright (C) 1997-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
23 .tc __cache_line_size[TC],__cache_line_size
27 /* __ptr_t [r3] memset (__ptr_t s [r3], int c [r4], size_t n [r5]));
30 The memset is done in three sizes: byte (8 bits), word (32 bits),
31 cache line (256 bits). There is a special case for setting cache lines
32 to 0, to take advantage of the dcbz instruction. */
38 #define rRTN r3 /* Initial value of 1st argument. */
39 #define rMEMP0 r3 /* Original value of 1st arg. */
40 #define rCHR r4 /* Char to set in each byte. */
41 #define rLEN r5 /* Length of region to set. */
42 #define rMEMP r6 /* Address at which we are storing. */
43 #define rALIGN r7 /* Number of bytes we are setting now (when aligning). */
46 #define rNEG64 r8 /* Constant -64 for clearing with dcbz. */
47 #define rCLS r8 /* Cache line size obtained from static. */
48 #define rCLM r9 /* Cache line size mask to check for cache alignment. */
50 /* Take care of case for size <= 4. */
52 andi. rALIGN, rMEMP0, 7
56 /* Align to doubleword boundary. */
58 insrdi rCHR, rCHR, 8, 48 /* Replicate byte to halfword. */
61 subfic rALIGN, rALIGN, 8
62 cror 28,30,31 /* Detect odd word aligned. */
63 add rMEMP, rMEMP, rALIGN
64 sub rLEN, rLEN, rALIGN
65 insrdi rCHR, rCHR, 16, 32 /* Replicate halfword to word. */
67 /* Process the even word of doubleword. */
76 /* Process the odd word of doubleword. */
78 bf 28, L(g4x) /* If false, word aligned on odd word. */
85 /* Handle the case of size < 31. */
87 insrdi rCHR, rCHR, 16, 32 /* Replicate halfword to word. */
91 /* Align to 32-byte boundary. */
92 andi. rALIGN, rMEMP, 0x18
93 subfic rALIGN, rALIGN, 0x20
94 insrdi rCHR, rCHR, 32, 0 /* Replicate word to double word. */
97 add rMEMP, rMEMP, rALIGN
98 sub rLEN, rLEN, rALIGN
99 cmplwi cr1, rALIGN, 0x10
102 stdu rCHR, -8(rMEMP2)
103 L(a1): blt cr1, L(a2)
105 stdu rCHR, -16(rMEMP2)
108 /* Now aligned to a 32 byte boundary. */
111 clrrdi. rALIGN, rLEN, 5
113 beq cr1, L(zloopstart) /* Special case for clearing memory using dcbz. */
117 beq L(medium) /* We may not actually get to do a full line. */
118 clrldi. rLEN, rLEN, 59
119 add rMEMP, rMEMP, rALIGN
123 L(c3): dcbtst rNEG64, rMEMP
127 stdu rCHR, -32(rMEMP)
134 stdu rCHR, -32(rMEMP)
136 add rMEMP, rMEMP, rALIGN
140 /* Clear lines of memory in 128-byte chunks. */
142 /* If the remaining length is less the 32 bytes, don't bother getting
143 the cache line size. */
147 /* If the cache line size was not set just goto to L(nondcbz) which is
148 safe for any cache line size. */
153 /* Now we know the cache line size, and it is not 32-bytes, but
154 we may not yet be aligned to the cache line. May have a partial
155 line to fill, so touch it 1st. */
161 blt cr1,L(handletail32)
171 /* Now we are aligned to the cache line and can use dcbz. */
174 blt cr1,L(handletail32)
180 /* We are here because the cache line size was set and was not 32-bytes
181 and the remainder (rLEN) is less than the actual cache line size.
182 So set up the preconditions for L(nondcbz) and go there. */
184 clrrwi. rALIGN, rLEN, 5
189 /* Memset of 8 bytes or less. */
212 /* Memset of 0-31 bytes. */
215 insrdi rCHR, rCHR, 32, 0 /* Replicate word to double word. */
218 add rMEMP, rMEMP, rLEN
220 bt- 31, L(medium_31t)
221 bt- 30, L(medium_30t)
223 bt- 29, L(medium_29t)
225 bge- cr1, L(medium_27t)
232 bf- 30, L(medium_30f)
235 bf- 29, L(medium_29f)
238 blt- cr1, L(medium_27f)
241 stdu rCHR, -16(rMEMP)
247 END_GEN_TB (memset,TB_TOCLESS)
248 libc_hidden_builtin_def (memset)
250 #ifndef NO_BZERO_IMPL
251 /* Copied from bzero.S to prevent the linker from inserting a stub
252 between bzero and memset. */
258 END_GEN_TB (__bzero,TB_TOCLESS)
260 weak_alias (__bzero, bzero)