1 /* Optimized mempcpy implementation for POWER7.
2 Copyright (C) 2010-2019 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 <https://www.gnu.org/licenses/>. */
22 /* void * [r3] __mempcpy (void *dst [r3], void *src [r4], size_t len [r5]);
23 Returns 'dst' + 'len'. */
26 EALIGN (__mempcpy, 5, 0)
30 cfi_adjust_cfa_offset(32)
32 cfi_offset(30,(20-32))
38 ble cr1,L(copy_LT_32) /* If move < 32 bytes use short move
41 andi. 11,3,7 /* Check alignment of DST. */
42 clrlwi 10,4,29 /* Check alignment of SRC. */
43 cmplw cr6,10,11 /* SRC and DST alignments match? */
46 bne cr6,L(copy_GE_32_unaligned)
48 srwi 9,5,3 /* Number of full quadwords remaining. */
50 beq L(copy_GE_32_aligned_cont)
56 /* Get the SRC aligned to 8 bytes. */
74 clrlwi 10,12,29 /* Check alignment of SRC again. */
75 srwi 9,31,3 /* Number of full doublewords remaining. */
77 L(copy_GE_32_aligned_cont):
87 /* Copy 1~3 doublewords so the main loop starts
88 at a multiple of 32 bytes. */
107 1: /* Copy 1 doubleword and set the counter. */
117 4: /* Main aligned copy loop. Copies 32-bytes at a time. */
132 /* Check for tail bytes. */
142 /* At this point we have a tail of 0-7 bytes and we know that the
143 destination is doubleword-aligned. */
144 4: /* Copy 4 bytes. */
151 2: /* Copy 2 bytes. */
158 1: /* Copy 1 byte. */
163 0: /* Return DST + LEN pointer. */
170 /* Handle copies of 0~31 bytes. */
178 /* At least 9 bytes to go. */
184 beq L(copy_LT_32_aligned)
186 /* Force 4-bytes alignment for SRC. */
195 1: 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. */
231 4: /* Copy 4 bytes. */
238 2: /* Copy 2-3 bytes. */
247 /* Return DST + LEN pointer. */
254 1: /* Copy 1 byte. */
259 0: /* Return DST + LEN pointer. */
265 /* Handles copies of 0~8 bytes. */
270 /* Though we could've used lfd/stfd here, they are still
271 slow for unaligned cases. */
278 /* Return DST + LEN pointer. */
285 4: /* Copies 4~7 bytes. */
297 /* Return DST + LEN pointer. */
304 5: /* Copy 1 byte. */
310 0: /* Return DST + LEN pointer. */
316 /* Handle copies of 32+ bytes where DST is aligned (to quadword) but
317 SRC is not. Use aligned quadword loads from SRC, shifted to realign
318 the data, allowing for aligned DST stores. */
320 L(copy_GE_32_unaligned):
321 andi. 11,3,15 /* Check alignment of DST. */
322 clrlwi 0,0,28 /* Number of bytes until the 1st
324 srwi 9,5,4 /* Number of full quadwords remaining. */
326 beq L(copy_GE_32_unaligned_cont)
328 /* DST is not quadword aligned, get it aligned. */
333 /* Vector instructions work best when proper alignment (16-bytes)
334 is present. Move 0~15 bytes as needed to get DST quadword-aligned. */
335 1: /* Copy 1 byte. */
342 2: /* Copy 2 bytes. */
349 4: /* Copy 4 bytes. */
356 8: /* Copy 8 bytes. */
364 clrlwi 10,12,28 /* Check alignment of SRC. */
365 srwi 9,31,4 /* Number of full quadwords remaining. */
367 /* The proper alignment is present, it is OK to copy the bytes now. */
368 L(copy_GE_32_unaligned_cont):
370 /* Setup two indexes to speed up the indexed vector operations. */
372 li 6,16 /* Index for 16-bytes offsets. */
373 li 7,32 /* Index for 32-bytes offsets. */
375 srwi 8,31,5 /* Setup the loop counter. */
380 #ifdef __LITTLE_ENDIAN__
386 bf 31,L(setup_unaligned_loop)
388 /* Copy another 16 bytes to align to 32-bytes due to the loop . */
390 #ifdef __LITTLE_ENDIAN__
400 L(setup_unaligned_loop):
402 ble cr6,L(end_unaligned_loop)
404 /* Copy 32 bytes at a time using vector instructions. */
408 /* Note: vr6/vr10 may contain data that was already copied,
409 but in order to get proper alignment, we may have to copy
410 some portions again. This is faster than having unaligned
411 vector instructions though. */
413 lvx 4,11,6 /* vr4 = r11+16. */
414 #ifdef __LITTLE_ENDIAN__
419 lvx 3,11,7 /* vr3 = r11+32. */
420 #ifdef __LITTLE_ENDIAN__
430 bdnz L(unaligned_loop)
433 L(end_unaligned_loop):
435 /* Check for tail bytes. */
443 /* We have 1~15 tail bytes to copy, and DST is quadword aligned. */
444 8: /* Copy 8 bytes. */
453 4: /* Copy 4 bytes. */
460 2: /* Copy 2~3 bytes. */
467 1: /* Copy 1 byte. */
472 0: /* Return DST + LEN pointer. */
480 libc_hidden_def (__mempcpy)
481 weak_alias (__mempcpy, mempcpy)
482 libc_hidden_builtin_def (mempcpy)