1 /* Optimized memcpy implementation for PowerPC64/POWER7.
2 Copyright (C) 2010-2014 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/>. */
23 /* __ptr_t [r3] memcpy (__ptr_t dst [r3], __ptr_t src [r4], size_t len [r5]);
26 #define dst 11 /* Use r11 so r3 kept unchanged. */
36 ble cr1, L(copy_LT_32) /* If move < 32 bytes use short move
39 #ifdef __LITTLE_ENDIAN__
40 /* In little-endian mode, power7 takes an alignment trap on any lxvd2x
41 or stxvd2x crossing a 32-byte boundary, so ensure the aligned_copy
42 loop is only used for quadword aligned copies. */
46 andi. 10,3,7 /* Check alignment of DST. */
47 clrldi 11,4,61 /* Check alignment of SRC. */
49 cmpld cr6,10,11 /* SRC and DST alignments match? */
52 bne cr6,L(copy_GE_32_unaligned)
56 #ifdef __LITTLE_ENDIAN__
62 /* Get the DST and SRC aligned to 8 bytes (16 for little-endian). */
82 #ifdef __LITTLE_ENDIAN__
92 /* Main aligned copy loop. Copies 128 bytes at a time. */
108 /* for the 2nd + iteration of this loop. */
130 bdnz L(aligned_128head)
165 4: /* Copies 4~7 bytes. */
175 /* Return original DST pointer. */
179 /* Handle copies of 0~31 bytes. */
187 /* At least 9 bytes to go. */
191 beq L(copy_LT_32_aligned)
193 /* Force 4-byte alignment for SRC. */
203 bf 31,L(end_4bytes_alignment)
210 L(end_4bytes_alignment):
214 L(copy_LT_32_aligned):
215 /* At least 6 bytes to go, and SRC is word-aligned. */
229 8: /* Copy 8 bytes. */
239 /* Copies 4~7 bytes. */
250 /* Return original DST pointer. */
254 /* Copies 2~3 bytes. */
276 /* Return original DST pointer. */
280 /* Handles copies of 0~8 bytes. */
285 /* Though we could've used ld/std here, they are still
286 slow for unaligned cases. */
295 /* Handle copies of 32+ bytes where DST is aligned (to quadword) but
296 SRC is not. Use aligned quadword loads from SRC, shifted to realign
297 the data, allowing for aligned DST stores. */
299 L(copy_GE_32_unaligned):
300 clrldi 0,0,60 /* Number of bytes until the 1st dst quadword. */
301 #ifndef __LITTLE_ENDIAN__
302 andi. 10,3,15 /* Check alignment of DST (against quadwords). */
304 srdi 9,cnt,4 /* Number of full quadwords remaining. */
306 beq L(copy_GE_32_unaligned_cont)
308 /* DST is not quadword aligned, get it aligned. */
313 /* Vector instructions work best when proper alignment (16-bytes)
314 is present. Move 0~15 bytes as needed to get DST quadword-aligned. */
340 srdi 9,cnt,4 /* Number of full quadwords remaining. */
342 /* The proper alignment is present, it is OK to copy the bytes now. */
343 L(copy_GE_32_unaligned_cont):
345 /* Setup two indexes to speed up the indexed vector operations. */
347 li 6,16 /* Index for 16-bytes offsets. */
348 li 7,32 /* Index for 32-bytes offsets. */
350 srdi 8,cnt,5 /* Setup the loop counter. */
353 #ifdef __LITTLE_ENDIAN__
360 bf 31,L(setup_unaligned_loop)
362 /* Copy another 16 bytes to align to 32-bytes due to the loop. */
364 #ifdef __LITTLE_ENDIAN__
375 L(setup_unaligned_loop):
377 ble cr6,L(end_unaligned_loop)
379 /* Copy 32 bytes at a time using vector instructions. */
383 /* Note: vr6/vr10 may contain data that was already copied,
384 but in order to get proper alignment, we may have to copy
385 some portions again. This is faster than having unaligned
386 vector instructions though. */
389 #ifdef __LITTLE_ENDIAN__
395 #ifdef __LITTLE_ENDIAN__
404 bdnz L(unaligned_loop)
409 L(end_unaligned_loop):
411 /* Check for tail bytes. */
417 /* We have 1~15 tail bytes to copy, and DST is quadword aligned. */
426 4: /* Copy 4~7 bytes. */
436 /* Return original DST pointer. */
439 END_GEN_TB (memcpy,TB_TOCLESS)
440 libc_hidden_builtin_def (memcpy)