1 /* Optimized memcpy implementation for PowerPC64/POWER7.
2 Copyright (C) 2010-2017 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 /* void * [r3] memcpy (void *dst [r3], void *src [r4], size_t len [r5]);
27 # define MEMCPY memcpy
30 #define dst 11 /* Use r11 so r3 kept unchanged. */
35 ENTRY_TOCLESS (MEMCPY, 5)
40 ble cr1, L(copy_LT_32) /* If move < 32 bytes use short move
43 /* Align copies using VSX instructions to quadword. It is to avoid alignment
44 traps when memcpy is used on non-cacheable memory (for instance, memory
48 cmpld cr6,10,11 /* SRC and DST alignments match? */
51 bne cr6,L(copy_GE_32_unaligned)
57 /* Get the DST and SRC aligned to 16 bytes. */
85 /* Main aligned copy loop. Copies 128 bytes at a time. */
101 /* for the 2nd + iteration of this loop. */
123 bdnz L(aligned_128head)
158 4: /* Copies 4~7 bytes. */
168 /* Return original DST pointer. */
172 /* Handle copies of 0~31 bytes. */
180 /* At least 9 bytes to go. */
184 beq L(copy_LT_32_aligned)
186 /* Force 4-byte alignment for SRC. */
196 bf 31,L(end_4bytes_alignment)
203 L(end_4bytes_alignment):
207 L(copy_LT_32_aligned):
208 /* At least 6 bytes to go, and SRC is word-aligned. */
222 8: /* Copy 8 bytes. */
232 /* Copies 4~7 bytes. */
243 /* Return original DST pointer. */
247 /* Copies 2~3 bytes. */
269 /* Return original DST pointer. */
273 /* Handles copies of 0~8 bytes. */
278 /* Though we could've used ld/std here, they are still
279 slow for unaligned cases. */
288 /* Handle copies of 32+ bytes where DST is aligned (to quadword) but
289 SRC is not. Use aligned quadword loads from SRC, shifted to realign
290 the data, allowing for aligned DST stores. */
292 L(copy_GE_32_unaligned):
293 clrldi 0,0,60 /* Number of bytes until the 1st dst quadword. */
294 srdi 9,cnt,4 /* Number of full quadwords remaining. */
296 beq L(copy_GE_32_unaligned_cont)
298 /* DST is not quadword aligned, get it aligned. */
303 /* Vector instructions work best when proper alignment (16-bytes)
304 is present. Move 0~15 bytes as needed to get DST quadword-aligned. */
330 srdi 9,cnt,4 /* Number of full quadwords remaining. */
332 /* The proper alignment is present, it is OK to copy the bytes now. */
333 L(copy_GE_32_unaligned_cont):
335 /* Setup two indexes to speed up the indexed vector operations. */
337 li 6,16 /* Index for 16-bytes offsets. */
338 li 7,32 /* Index for 32-bytes offsets. */
340 srdi 8,cnt,5 /* Setup the loop counter. */
343 #ifdef __LITTLE_ENDIAN__
350 bf 31,L(setup_unaligned_loop)
352 /* Copy another 16 bytes to align to 32-bytes due to the loop. */
354 #ifdef __LITTLE_ENDIAN__
365 L(setup_unaligned_loop):
367 ble cr6,L(end_unaligned_loop)
369 /* Copy 32 bytes at a time using vector instructions. */
373 /* Note: vr6/vr10 may contain data that was already copied,
374 but in order to get proper alignment, we may have to copy
375 some portions again. This is faster than having unaligned
376 vector instructions though. */
379 #ifdef __LITTLE_ENDIAN__
385 #ifdef __LITTLE_ENDIAN__
394 bdnz L(unaligned_loop)
399 L(end_unaligned_loop):
401 /* Check for tail bytes. */
407 /* We have 1~15 tail bytes to copy, and DST is quadword aligned. */
416 4: /* Copy 4~7 bytes. */
426 /* Return original DST pointer. */
429 END_GEN_TB (MEMCPY,TB_TOCLESS)
430 libc_hidden_builtin_def (memcpy)