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 /* __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 /* Align copies using VSX instructions to quadword. It is to avoid alignment
40 traps when memcpy is used on non-cacheable memory (for instance, memory
44 cmpld cr6,10,11 /* SRC and DST alignments match? */
47 bne cr6,L(copy_GE_32_unaligned)
53 /* Get the DST and SRC aligned to 16 bytes. */
81 /* Main aligned copy loop. Copies 128 bytes at a time. */
97 /* for the 2nd + iteration of this loop. */
119 bdnz L(aligned_128head)
154 4: /* Copies 4~7 bytes. */
164 /* Return original DST pointer. */
168 /* Handle copies of 0~31 bytes. */
176 /* At least 9 bytes to go. */
180 beq L(copy_LT_32_aligned)
182 /* Force 4-byte alignment for SRC. */
192 bf 31,L(end_4bytes_alignment)
199 L(end_4bytes_alignment):
203 L(copy_LT_32_aligned):
204 /* At least 6 bytes to go, and SRC is word-aligned. */
218 8: /* Copy 8 bytes. */
228 /* Copies 4~7 bytes. */
239 /* Return original DST pointer. */
243 /* Copies 2~3 bytes. */
265 /* Return original DST pointer. */
269 /* Handles copies of 0~8 bytes. */
274 /* Though we could've used ld/std here, they are still
275 slow for unaligned cases. */
284 /* Handle copies of 32+ bytes where DST is aligned (to quadword) but
285 SRC is not. Use aligned quadword loads from SRC, shifted to realign
286 the data, allowing for aligned DST stores. */
288 L(copy_GE_32_unaligned):
289 clrldi 0,0,60 /* Number of bytes until the 1st dst quadword. */
290 srdi 9,cnt,4 /* Number of full quadwords remaining. */
292 beq L(copy_GE_32_unaligned_cont)
294 /* DST is not quadword aligned, get it aligned. */
299 /* Vector instructions work best when proper alignment (16-bytes)
300 is present. Move 0~15 bytes as needed to get DST quadword-aligned. */
326 srdi 9,cnt,4 /* Number of full quadwords remaining. */
328 /* The proper alignment is present, it is OK to copy the bytes now. */
329 L(copy_GE_32_unaligned_cont):
331 /* Setup two indexes to speed up the indexed vector operations. */
333 li 6,16 /* Index for 16-bytes offsets. */
334 li 7,32 /* Index for 32-bytes offsets. */
336 srdi 8,cnt,5 /* Setup the loop counter. */
339 #ifdef __LITTLE_ENDIAN__
346 bf 31,L(setup_unaligned_loop)
348 /* Copy another 16 bytes to align to 32-bytes due to the loop. */
350 #ifdef __LITTLE_ENDIAN__
361 L(setup_unaligned_loop):
363 ble cr6,L(end_unaligned_loop)
365 /* Copy 32 bytes at a time using vector instructions. */
369 /* Note: vr6/vr10 may contain data that was already copied,
370 but in order to get proper alignment, we may have to copy
371 some portions again. This is faster than having unaligned
372 vector instructions though. */
375 #ifdef __LITTLE_ENDIAN__
381 #ifdef __LITTLE_ENDIAN__
390 bdnz L(unaligned_loop)
395 L(end_unaligned_loop):
397 /* Check for tail bytes. */
403 /* We have 1~15 tail bytes to copy, and DST is quadword aligned. */
412 4: /* Copy 4~7 bytes. */
422 /* Return original DST pointer. */
425 END_GEN_TB (memcpy,TB_TOCLESS)
426 libc_hidden_builtin_def (memcpy)