1 /* Optimized memset implementation for PowerPC64.
2 Copyright (C) 1997,99, 2000,02,03, 2006 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, write to the Free
17 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
24 /* __ptr_t [r3] memset (__ptr_t s [r3], int c [r4], size_t n [r5]));
27 The memset is done in three sizes: byte (8 bits), word (32 bits),
28 cache line (1024 bits). There is a special case for setting cache lines
29 to 0, to take advantage of the dcbz instruction. */
32 EALIGN (BP_SYM (memset), 5, 0)
36 #define rRTN r3 /* Initial value of 1st argument. */
37 #define rMEMP0 r3 /* Original value of 1st arg. */
38 #define rCHR r4 /* Char to set in each byte. */
39 #define rLEN r5 /* Length of region to set. */
40 #define rMEMP r6 /* Address at which we are storing. */
41 #define rALIGN r7 /* Number of bytes we are setting now (when aligning). */
44 #define rNEG64 r8 /* Constant -64 for clearing with dcbz. */
45 #define rCLS r8 /* Cache line size (known to be 128). */
46 #define rCLM r9 /* Cache line size mask to check for cache alignment. */
48 /* Take care of case for size <= 4. */
50 andi. rALIGN, rMEMP0, 3
54 /* Align to word boundary. */
56 rlwimi rCHR, rCHR, 8, 16, 23 /* Replicate byte to halfword. */
59 subfic rALIGN, rALIGN, 4
60 add rMEMP, rMEMP, rALIGN
61 sub rLEN, rLEN, rALIGN
68 /* Handle the case of size < 31. */
71 rlwimi rCHR, rCHR, 16, 0, 15 /* Replicate halfword to word. */
73 /* Align to 32-byte boundary. */
74 andi. rALIGN, rMEMP, 0x1C
75 subfic rALIGN, rALIGN, 0x20
78 add rMEMP, rMEMP, rALIGN
79 sub rLEN, rLEN, rALIGN
80 cmplwi cr1, rALIGN, 0x10
89 stwu rCHR, -16(rMEMP2)
90 L(a2): bf 29, L(caligned)
93 /* Now aligned to a 32 byte boundary. */
96 clrrwi. rALIGN, rLEN, 5
98 beq cr1, L(zloopstart) /* Special case for clearing memory using dcbz. */
102 beq L(medium) /* We may not actually get to do a full line. */
103 clrlwi. rLEN, rLEN, 27
104 add rMEMP, rMEMP, rALIGN
109 L(c3): dcbtst rNEG64, rMEMP
117 stwu rCHR, -32(rMEMP)
128 stwu rCHR, -32(rMEMP)
130 add rMEMP, rMEMP, rALIGN
134 /* Clear lines of memory in 128-byte chunks. */
136 /* If the remaining length is less the 32 bytes, don't bother getting
137 the cache line size. */
139 li rCLS,128 /* cache line size is 128 */
144 blt cr1,L(handletail32)
158 /* Now we are aligned to the cache line and can use dcbz. */
162 blt cr1,L(handletail32)
168 /* We are here because the cache line size was set and the remainder
169 (rLEN) is less than the actual cache line size.
170 So set up the preconditions for L(nondcbz) and go there. */
172 clrrwi. rALIGN, rLEN, 5
177 /* Memset of 4 bytes or less. */
190 /* Memset of 0-31 bytes. */
195 add rMEMP, rMEMP, rLEN
197 bt- 31, L(medium_31t)
198 bt- 30, L(medium_30t)
200 bt- 29, L(medium_29t)
202 bge- cr1, L(medium_27t)
210 bf- 30, L(medium_30f)
213 bf- 29, L(medium_29f)
216 blt- cr1, L(medium_27f)
221 stwu rCHR, -16(rMEMP)
228 END (BP_SYM (memset))
229 libc_hidden_builtin_def (memset)