2010-01-18 20:40:29 +00:00
|
|
|
/* Optimized memcpy implementation for CELL BE PowerPC.
|
2018-01-01 00:32:25 +00:00
|
|
|
Copyright (C) 2010-2018 Free Software Foundation, Inc.
|
2010-01-18 20:40:29 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2010-01-18 20:40:29 +00:00
|
|
|
|
|
|
|
#include <sysdep.h>
|
|
|
|
|
2017-04-11 17:18:35 +00:00
|
|
|
#ifndef MEMCPY
|
|
|
|
# define MEMCPY memcpy
|
|
|
|
#endif
|
|
|
|
|
2010-01-18 20:40:29 +00:00
|
|
|
#define PREFETCH_AHEAD 6 /* no cache lines SRC prefetching ahead */
|
|
|
|
#define ZERO_AHEAD 4 /* no cache lines DST zeroing ahead */
|
|
|
|
|
|
|
|
/* memcpy routine optimized for CELL-BE-PPC v2.0
|
|
|
|
*
|
|
|
|
* The CELL PPC core has 1 integer unit and 1 load/store unit
|
|
|
|
* CELL:
|
|
|
|
* 1st level data cache = 32K
|
|
|
|
* 2nd level data cache = 512K
|
|
|
|
* 3rd level data cache = 0K
|
|
|
|
* With 3.2 GHz clockrate the latency to 2nd level cache is >36 clocks,
|
|
|
|
* latency to memory is >400 clocks
|
|
|
|
* To improve copy performance we need to prefetch source data
|
|
|
|
* far ahead to hide this latency
|
2013-01-07 17:20:53 +00:00
|
|
|
* For best performance instruction forms ending in "." like "andi."
|
2010-01-18 20:40:29 +00:00
|
|
|
* should be avoided as the are implemented in microcode on CELL.
|
|
|
|
* The below code is loop unrolled for the CELL cache line of 128 bytes
|
|
|
|
*/
|
|
|
|
|
|
|
|
.align 7
|
|
|
|
|
PowerPC64 ENTRY_TOCLESS
A number of functions in the sysdeps/powerpc/powerpc64/ tree don't use
or change r2, yet declare a global entry that sets up r2. This patch
fixes that problem, and consolidates the ENTRY and EALIGN macros.
* sysdeps/powerpc/powerpc64/sysdep.h: Formatting.
(NOPS, ENTRY_3): New macros.
(ENTRY): Rewrite.
(ENTRY_TOCLESS): Define.
(EALIGN, EALIGN_W_0, EALIGN_W_1, EALIGN_W_2, EALIGN_W_4, EALIGN_W_5,
EALIGN_W_6, EALIGN_W_7, EALIGN_W_8): Delete.
* sysdeps/powerpc/powerpc64/a2/memcpy.S: Replace EALIGN with ENTRY.
* sysdeps/powerpc/powerpc64/dl-trampoline.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_ceil.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_ceilf.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_floor.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_floorf.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_nearbyint.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_nearbyintf.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_rint.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_rintf.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_round.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_roundf.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_trunc.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_truncf.S: Likewise.
* sysdeps/powerpc/powerpc64/memset.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/fpu/s_finite.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/fpu/s_isinf.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/fpu/s_isnan.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strstr.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/fpu/e_expf.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/fpu/s_cosf.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/fpu/s_sinf.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strcasestr.S: Likewise.
* sysdeps/powerpc/powerpc64/addmul_1.S: Use ENTRY_TOCLESS.
* sysdeps/powerpc/powerpc64/cell/memcpy.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_copysign.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_copysignl.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_fabsl.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_isnan.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_llrint.S: Likewise.
* sysdeps/powerpc/powerpc64/fpu/s_llrintf.S: Likewise.
* sysdeps/powerpc/powerpc64/lshift.S: Likewise.
* sysdeps/powerpc/powerpc64/memcpy.S: Likewise.
* sysdeps/powerpc/powerpc64/mul_1.S: Likewise.
* sysdeps/powerpc/powerpc64/power4/memcmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power4/memcpy.S: Likewise.
* sysdeps/powerpc/powerpc64/power4/memset.S: Likewise.
* sysdeps/powerpc/powerpc64/power4/strncmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_ceil.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_ceilf.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_floor.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_floorf.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_llround.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_round.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_roundf.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_trunc.S: Likewise.
* sysdeps/powerpc/powerpc64/power5+/fpu/s_truncf.S: Likewise.
* sysdeps/powerpc/powerpc64/power5/fpu/s_isnan.S: Likewise.
* sysdeps/powerpc/powerpc64/power6/fpu/s_copysign.S: Likewise.
* sysdeps/powerpc/powerpc64/power6/fpu/s_isnan.S: Likewise.
* sysdeps/powerpc/powerpc64/power6/memcpy.S: Likewise.
* sysdeps/powerpc/powerpc64/power6/memset.S: Likewise.
* sysdeps/powerpc/powerpc64/power6x/fpu/s_isnan.S: Likewise.
* sysdeps/powerpc/powerpc64/power6x/fpu/s_llrint.S: Likewise.
* sysdeps/powerpc/powerpc64/power6x/fpu/s_llround.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/add_n.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/memchr.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/memcmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/memcpy.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/memmove.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/mempcpy.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/memrchr.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/memset.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/rawmemchr.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strcasecmp.S (strcasecmp_l):
Likewise.
* sysdeps/powerpc/powerpc64/power7/strchr.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strchrnul.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strcmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strlen.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strncmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strncpy.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strnlen.S: Likewise.
* sysdeps/powerpc/powerpc64/power7/strrchr.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/fpu/s_finite.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/fpu/s_isinf.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/fpu/s_isnan.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/fpu/s_llrint.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/fpu/s_llround.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/memcmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/memset.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strchr.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strcmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strcpy.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strlen.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strncmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strncpy.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strnlen.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strrchr.S: Likewise.
* sysdeps/powerpc/powerpc64/power8/strspn.S: Likewise.
* sysdeps/powerpc/powerpc64/power9/strcmp.S: Likewise.
* sysdeps/powerpc/powerpc64/power9/strncmp.S: Likewise.
* sysdeps/powerpc/powerpc64/strchr.S: Likewise.
* sysdeps/powerpc/powerpc64/strcmp.S: Likewise.
* sysdeps/powerpc/powerpc64/strlen.S: Likewise.
* sysdeps/powerpc/powerpc64/strncmp.S: Likewise.
* sysdeps/powerpc/powerpc64/ppc-mcount.S: Store LR earlier. Don't
add nop when SHARED.
* sysdeps/powerpc/powerpc64/start.S: Fix comment.
* sysdeps/powerpc/powerpc64/multiarch/strrchr-power8.S (ENTRY): Don't
define.
(ENTRY_TOCLESS): Define.
* sysdeps/powerpc/powerpc32/sysdep.h (ENTRY_TOCLESS): Define.
* sysdeps/powerpc/fpu/s_fma.S: Use ENTRY_TOCLESS.
* sysdeps/powerpc/fpu/s_fmaf.S: Likewise.
2017-06-14 01:15:50 +00:00
|
|
|
ENTRY_TOCLESS (MEMCPY, 5)
|
2010-01-18 20:43:47 +00:00
|
|
|
CALL_MCOUNT 3
|
2010-01-18 20:40:29 +00:00
|
|
|
|
|
|
|
dcbt 0,r4 /* Prefetch ONE SRC cacheline */
|
|
|
|
cmpldi cr1,r5,16 /* is size < 16 ? */
|
2010-01-18 20:43:47 +00:00
|
|
|
mr r6,r3
|
2010-01-18 20:40:29 +00:00
|
|
|
blt+ cr1,.Lshortcopy
|
|
|
|
|
|
|
|
.Lbigcopy:
|
|
|
|
neg r8,r3 /* LS 3 bits = # bytes to 8-byte dest bdry */
|
2013-08-21 17:48:48 +00:00
|
|
|
clrldi r8,r8,64-4 /* align to 16byte boundary */
|
2010-01-18 20:40:29 +00:00
|
|
|
sub r7,r4,r3
|
|
|
|
cmpldi cr0,r8,0
|
|
|
|
beq+ .Ldst_aligned
|
|
|
|
|
|
|
|
.Ldst_unaligned:
|
|
|
|
mtcrf 0x01,r8 /* put #bytes to boundary into cr7 */
|
|
|
|
subf r5,r8,r5
|
|
|
|
|
|
|
|
bf cr7*4+3,1f
|
|
|
|
lbzx r0,r7,r6 /* copy 1 byte */
|
|
|
|
stb r0,0(r6)
|
|
|
|
addi r6,r6,1
|
|
|
|
1: bf cr7*4+2,2f
|
|
|
|
lhzx r0,r7,r6 /* copy 2 byte */
|
|
|
|
sth r0,0(r6)
|
|
|
|
addi r6,r6,2
|
|
|
|
2: bf cr7*4+1,4f
|
|
|
|
lwzx r0,r7,r6 /* copy 4 byte */
|
|
|
|
stw r0,0(r6)
|
|
|
|
addi r6,r6,4
|
|
|
|
4: bf cr7*4+0,8f
|
|
|
|
ldx r0,r7,r6 /* copy 8 byte */
|
|
|
|
std r0,0(r6)
|
|
|
|
addi r6,r6,8
|
|
|
|
8:
|
|
|
|
add r4,r7,r6
|
|
|
|
|
|
|
|
.Ldst_aligned:
|
|
|
|
|
|
|
|
cmpdi cr5,r5,128-1
|
|
|
|
|
|
|
|
neg r7,r6
|
|
|
|
addi r6,r6,-8 /* prepare for stdu */
|
|
|
|
addi r4,r4,-8 /* prepare for ldu */
|
|
|
|
|
|
|
|
clrldi r7,r7,64-7 /* align to cacheline boundary */
|
|
|
|
ble+ cr5,.Llessthancacheline
|
|
|
|
|
|
|
|
cmpldi cr6,r7,0
|
|
|
|
subf r5,r7,r5
|
|
|
|
srdi r7,r7,4 /* divide size by 16 */
|
|
|
|
srdi r10,r5,7 /* number of cache lines to copy */
|
|
|
|
|
|
|
|
cmpldi r10,0
|
|
|
|
li r11,0 /* number cachelines to copy with prefetch */
|
|
|
|
beq .Lnocacheprefetch
|
|
|
|
|
|
|
|
cmpldi r10,PREFETCH_AHEAD
|
|
|
|
li r12,128+8 /* prefetch distance */
|
|
|
|
ble .Llessthanmaxprefetch
|
|
|
|
|
|
|
|
subi r11,r10,PREFETCH_AHEAD
|
|
|
|
li r10,PREFETCH_AHEAD
|
|
|
|
|
|
|
|
.Llessthanmaxprefetch:
|
|
|
|
mtctr r10
|
|
|
|
|
|
|
|
.LprefetchSRC:
|
|
|
|
dcbt r12,r4
|
2010-01-18 20:43:47 +00:00
|
|
|
addi r12,r12,128
|
|
|
|
bdnz .LprefetchSRC
|
2010-01-18 20:40:29 +00:00
|
|
|
|
|
|
|
.Lnocacheprefetch:
|
|
|
|
mtctr r7
|
|
|
|
cmpldi cr1,r5,128
|
|
|
|
clrldi r5,r5,64-7
|
|
|
|
beq cr6,.Lcachelinealigned
|
|
|
|
|
|
|
|
.Laligntocacheline:
|
2010-01-18 20:43:47 +00:00
|
|
|
ld r9,0x08(r4)
|
2010-01-18 20:40:29 +00:00
|
|
|
ldu r7,0x10(r4)
|
|
|
|
std r9,0x08(r6)
|
|
|
|
stdu r7,0x10(r6)
|
|
|
|
bdnz .Laligntocacheline
|
|
|
|
|
|
|
|
|
|
|
|
.Lcachelinealigned: /* copy while cache lines */
|
|
|
|
|
2010-01-18 20:43:47 +00:00
|
|
|
blt- cr1,.Llessthancacheline /* size <128 */
|
2010-01-18 20:40:29 +00:00
|
|
|
|
|
|
|
.Louterloop:
|
2010-01-18 20:43:47 +00:00
|
|
|
cmpdi r11,0
|
2010-01-18 20:40:29 +00:00
|
|
|
mtctr r11
|
|
|
|
beq- .Lendloop
|
|
|
|
|
|
|
|
li r11,128*ZERO_AHEAD +8 /* DCBZ dist */
|
|
|
|
|
|
|
|
.align 4
|
|
|
|
/* Copy whole cachelines, optimized by prefetching SRC cacheline */
|
2010-01-18 20:43:47 +00:00
|
|
|
.Lloop: /* Copy aligned body */
|
2010-01-18 20:40:29 +00:00
|
|
|
dcbt r12,r4 /* PREFETCH SOURCE some cache lines ahead */
|
|
|
|
ld r9, 0x08(r4)
|
|
|
|
dcbz r11,r6
|
|
|
|
ld r7, 0x10(r4) /* 4 register stride copy is optimal */
|
2013-01-07 17:20:53 +00:00
|
|
|
ld r8, 0x18(r4) /* to hide 1st level cache latency. */
|
2010-01-18 20:40:29 +00:00
|
|
|
ld r0, 0x20(r4)
|
|
|
|
std r9, 0x08(r6)
|
|
|
|
std r7, 0x10(r6)
|
|
|
|
std r8, 0x18(r6)
|
|
|
|
std r0, 0x20(r6)
|
|
|
|
ld r9, 0x28(r4)
|
|
|
|
ld r7, 0x30(r4)
|
|
|
|
ld r8, 0x38(r4)
|
|
|
|
ld r0, 0x40(r4)
|
|
|
|
std r9, 0x28(r6)
|
|
|
|
std r7, 0x30(r6)
|
|
|
|
std r8, 0x38(r6)
|
|
|
|
std r0, 0x40(r6)
|
|
|
|
ld r9, 0x48(r4)
|
|
|
|
ld r7, 0x50(r4)
|
|
|
|
ld r8, 0x58(r4)
|
|
|
|
ld r0, 0x60(r4)
|
|
|
|
std r9, 0x48(r6)
|
|
|
|
std r7, 0x50(r6)
|
|
|
|
std r8, 0x58(r6)
|
|
|
|
std r0, 0x60(r6)
|
|
|
|
ld r9, 0x68(r4)
|
|
|
|
ld r7, 0x70(r4)
|
|
|
|
ld r8, 0x78(r4)
|
|
|
|
ldu r0, 0x80(r4)
|
|
|
|
std r9, 0x68(r6)
|
|
|
|
std r7, 0x70(r6)
|
|
|
|
std r8, 0x78(r6)
|
|
|
|
stdu r0, 0x80(r6)
|
|
|
|
|
|
|
|
bdnz .Lloop
|
|
|
|
|
|
|
|
.Lendloop:
|
|
|
|
cmpdi r10,0
|
|
|
|
sldi r10,r10,2 /* adjust from 128 to 32 byte stride */
|
|
|
|
beq- .Lendloop2
|
|
|
|
mtctr r10
|
|
|
|
|
2010-01-18 20:43:47 +00:00
|
|
|
.Lloop2: /* Copy aligned body */
|
2010-01-18 20:40:29 +00:00
|
|
|
ld r9, 0x08(r4)
|
|
|
|
ld r7, 0x10(r4)
|
|
|
|
ld r8, 0x18(r4)
|
|
|
|
ldu r0, 0x20(r4)
|
|
|
|
std r9, 0x08(r6)
|
|
|
|
std r7, 0x10(r6)
|
|
|
|
std r8, 0x18(r6)
|
|
|
|
stdu r0, 0x20(r6)
|
|
|
|
|
|
|
|
bdnz .Lloop2
|
|
|
|
.Lendloop2:
|
|
|
|
|
|
|
|
.Llessthancacheline: /* less than cache to do ? */
|
|
|
|
cmpldi cr0,r5,16
|
|
|
|
srdi r7,r5,4 /* divide size by 16 */
|
|
|
|
blt- .Ldo_lt16
|
|
|
|
mtctr r7
|
|
|
|
|
|
|
|
.Lcopy_remaining:
|
2010-01-18 20:43:47 +00:00
|
|
|
ld r8,0x08(r4)
|
2010-01-18 20:40:29 +00:00
|
|
|
ldu r7,0x10(r4)
|
|
|
|
std r8,0x08(r6)
|
|
|
|
stdu r7,0x10(r6)
|
|
|
|
bdnz .Lcopy_remaining
|
|
|
|
|
|
|
|
.Ldo_lt16: /* less than 16 ? */
|
|
|
|
cmpldi cr0,r5,0 /* copy remaining bytes (0-15) */
|
2010-01-18 20:43:47 +00:00
|
|
|
beqlr+ /* no rest to copy */
|
2010-01-18 20:40:29 +00:00
|
|
|
addi r4,r4,8
|
|
|
|
addi r6,r6,8
|
|
|
|
|
|
|
|
.Lshortcopy: /* SIMPLE COPY to handle size =< 15 bytes */
|
|
|
|
mtcrf 0x01,r5
|
|
|
|
sub r7,r4,r6
|
|
|
|
bf- cr7*4+0,8f
|
|
|
|
ldx r0,r7,r6 /* copy 8 byte */
|
|
|
|
std r0,0(r6)
|
|
|
|
addi r6,r6,8
|
|
|
|
8:
|
|
|
|
bf cr7*4+1,4f
|
|
|
|
lwzx r0,r7,r6 /* copy 4 byte */
|
|
|
|
stw r0,0(r6)
|
|
|
|
addi r6,r6,4
|
|
|
|
4:
|
|
|
|
bf cr7*4+2,2f
|
|
|
|
lhzx r0,r7,r6 /* copy 2 byte */
|
|
|
|
sth r0,0(r6)
|
|
|
|
addi r6,r6,2
|
|
|
|
2:
|
|
|
|
bf cr7*4+3,1f
|
|
|
|
lbzx r0,r7,r6 /* copy 1 byte */
|
|
|
|
stb r0,0(r6)
|
|
|
|
1: blr
|
|
|
|
|
2017-04-11 17:18:35 +00:00
|
|
|
END_GEN_TB (MEMCPY,TB_TOCLESS)
|
2010-01-18 20:40:29 +00:00
|
|
|
libc_hidden_builtin_def (memcpy)
|