1 /* Optimized memset implementation for PowerPC64/POWER7.
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
3 Contributed by Luis Machado <luisgpm@br.ibm.com>.
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, see
18 <http://www.gnu.org/licenses/>. */
22 /* __ptr_t [r3] memset (__ptr_t s [r3], int c [r4], size_t n [r5]));
34 /* Replicate byte to word. */
37 ble cr6,L(small) /* If length <= 8, use short copy code. */
40 ble cr7,L(medium) /* If length < 32, use medium copy code. */
42 andi. 11,10,7 /* Check alignment of SRC. */
43 insrdi 4,4,32,0 /* Replicate word to double word. */
52 /* Get DST aligned to 8 bytes. */
61 4: bf 29,L(big_aligned)
73 srdi 9,5,3 /* Number of full doublewords remaining. */
78 /* From this point on, we'll copy 32+ bytes and the value
79 isn't 0 (so we can't use dcbz). */
87 /* Copy 1~3 doublewords so the main loop starts
88 at a multiple of 32 bytes. */
100 blt cr1,L(tail_bytes)
104 1: /* Copy 1 doubleword. */
110 /* Main aligned copy loop. Copies 32-bytes at a time and
111 ping-pong through r10 and r12 to avoid AGEN delays. */
134 /* Check for tail bytes. */
140 /* At this point we have a tail of 0-7 bytes and we know that the
141 destination is doubleword-aligned. */
142 4: /* Copy 4 bytes. */
147 2: /* Copy 2 bytes. */
152 1: /* Copy 1 byte. */
158 /* Special case when value is 0 and we have a long length to deal
159 with. Use dcbz to zero out 128-bytes at a time. Before using
160 dcbz though, we need to get the destination 128-bytes aligned. */
172 /* Get DST aligned to 128 bytes. */
199 1: bf 31,L(huge_aligned)
217 /* Check how many bytes are still left. */
226 /* We have a tail o 1~127 bytes. Copy up to 15 doublewords for
227 speed. We'll handle the resulting tail bytes later. */
261 /* Handle the rest of the tail bytes here. */
281 /* Expanded tree to copy tail bytes without increments. */
316 /* Handle copies of 9~31 bytes. */
319 /* At least 9 bytes to go. */
322 beq L(medium_aligned)
324 /* Force 4-bytes alignment for DST. */
327 1: /* Copy 1 byte. */
332 2: /* Copy 2 bytes. */
333 bf 30,L(medium_aligned)
340 /* At least 6 bytes to go, and DST is word-aligned. */
351 8: /* Copy 8 bytes. */
357 4: /* Copy 4 bytes. */
362 2: /* Copy 2-3 bytes. */
367 1: /* Copy 1 byte. */
373 /* Handles copies of 0~8 bytes. */
383 END_GEN_TB (memset,TB_TOCLESS)
384 libc_hidden_builtin_def (memset)
386 /* Copied from bzero.S to prevent the linker from inserting a stub
387 between bzero and memset. */
393 END_GEN_TB (__bzero,TB_TOCLESS)
395 weak_alias (__bzero, bzero)