1 /* Optimized memset implementation for PowerPC32/POWER7.
2 Copyright (C) 2010 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, write to the Free
18 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
25 /* __ptr_t [r3] memset (__ptr_t s [r3], int c [r4], size_t n [r5]));
29 EALIGN (BP_SYM (memset), 5, 0)
36 mr 10,3 /* Save original argument for later. */
37 mr 7,1 /* Save original r1 for later. */
40 /* Replicate byte to word. */
44 ble cr6,L(small) /* If length <= 8, use short copy code. */
47 ble cr7,L(medium) /* If length < 32, use medium copy code. */
49 /* Save our word twice to create a doubleword that we will later
52 andi. 11,10,7 /* Check alignment of DST. */
62 /* Get DST aligned to 8 bytes. */
71 4: bf 29,L(big_aligned)
83 srwi 9,5,3 /* Number of full doublewords remaining. */
88 /* From this point on, we'll copy 32+ bytes and the value
89 isn't 0 (so we can't use dcbz). */
97 /* Copy 1~3 doublewords so the main loop starts
98 at a multiple of 32 bytes. */
113 blt cr1,L(tail_bytes)
118 1: /* Copy 1 doubleword. */
125 /* First use a 32-bytes loop with stw's to try and avoid the LHS due
126 to the lfd we will do next. Also, ping-pong through r10 and r12
127 to avoid AGEN delays. */
150 bdnz L(big_loop_fast_setup)
155 /* Now that we're probably past the LHS window, use the VSX to
156 speed up the loop. */
157 L(big_loop_fast_setup):
172 bdnz L(big_loop_fast)
179 /* Check for tail bytes. */
180 mr 1,7 /* Restore r1. */
186 /* At this point we have a tail of 0-7 bytes and we know that the
187 destination is doubleword-aligned. */
188 4: /* Copy 4 bytes. */
193 2: /* Copy 2 bytes. */
198 1: /* Copy 1 byte. */
205 /* Special case when value is 0 and we have a long length to deal
206 with. Use dcbz to zero out 128-bytes at a time. Before using
207 dcbz though, we need to get the destination 128-bytes aligned. */
220 /* Get DST aligned to 128 bytes. */
247 1: bf 31,L(huge_aligned)
258 /* Copies 128-bytes at a time. */
265 /* We have a tail of 0~127 bytes to handle. */
266 mr 1,7 /* Restore r1. */
275 /* We have a tail o 1~127 bytes. Copy up to 15 doublewords for
276 speed. We'll handle the resulting tail bytes later. */
310 /* Handle the rest of the tail bytes here. */
331 /* Expanded tree to copy tail bytes without increments. */
366 /* Handle copies of 9~31 bytes. */
369 /* At least 9 bytes to go. */
372 beq L(medium_aligned)
374 /* Force 4-bytes alignment for DST. */
377 1: /* Copy 1 byte. */
382 2: /* Copy 2 bytes. */
383 bf 30,L(medium_aligned)
390 /* At least 6 bytes to go, and DST is word-aligned. */
401 8: /* Copy 8 bytes. */
407 4: /* Copy 4 bytes. */
412 2: /* Copy 2-3 bytes. */
417 1: /* Copy 1 byte. */
423 /* Handles copies of 0~8 bytes. */
433 END (BP_SYM (memset))
434 libc_hidden_builtin_def (memset)