Skip to content

Commit 00f554f

Browse files
Philippe Bergheaudozbenh
authored andcommitted
powerpc: memcpy optimization for 64bit LE
Unaligned stores take alignment exceptions on POWER7 running in little-endian. This is a dumb little-endian base memcpy that prevents unaligned stores. Once booted the feature fixup code switches over to the VMX copy loops (which are already endian safe). The question is what we do before that switch over. The base 64bit memcpy takes alignment exceptions on POWER7 so we can't use it as is. Fixing the causes of alignment exception would slow it down, because we'd need to ensure all loads and stores are aligned either through rotate tricks or bytewise loads and stores. Either would be bad for all other 64bit platforms. [ I simplified the loop a bit - Anton ] Signed-off-by: Philippe Bergheaud <felix@linux.vnet.ibm.com> Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 48ce3b7 commit 00f554f

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎arch/powerpc/include/asm/string.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
#define __HAVE_ARCH_STRNCMP
1111
#define __HAVE_ARCH_STRCAT
1212
#define __HAVE_ARCH_MEMSET
13-
#ifdef __BIG_ENDIAN__
1413
#define __HAVE_ARCH_MEMCPY
15-
#endif
1614
#define __HAVE_ARCH_MEMMOVE
1715
#define __HAVE_ARCH_MEMCMP
1816
#define __HAVE_ARCH_MEMCHR
@@ -24,9 +22,7 @@ extern int strcmp(const char *,const char *);
2422
extern int strncmp(const char *, const char *, __kernel_size_t);
2523
extern char * strcat(char *, const char *);
2624
extern void * memset(void *,int,__kernel_size_t);
27-
#ifdef __BIG_ENDIAN__
2825
extern void * memcpy(void *,const void *,__kernel_size_t);
29-
#endif
3026
extern void * memmove(void *,const void *,__kernel_size_t);
3127
extern int memcmp(const void *,const void *,__kernel_size_t);
3228
extern void * memchr(const void *,int,__kernel_size_t);

‎arch/powerpc/kernel/ppc_ksyms.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ EXPORT_SYMBOL(__cmpdi2);
155155
#endif
156156
long long __bswapdi2(long long);
157157
EXPORT_SYMBOL(__bswapdi2);
158-
#ifdef __BIG_ENDIAN__
159158
EXPORT_SYMBOL(memcpy);
160-
#endif
161159
EXPORT_SYMBOL(memset);
162160
EXPORT_SYMBOL(memmove);
163161
EXPORT_SYMBOL(memcmp);

‎arch/powerpc/lib/Makefile‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ obj-y += checksum_$(CONFIG_WORD_SIZE).o
2323
obj-$(CONFIG_PPC64) += checksum_wrappers_64.o
2424
endif
2525

26-
ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),)
2726
obj-$(CONFIG_PPC64) += memcpy_power7.o memcpy_64.o
28-
endif
2927

3028
obj-$(CONFIG_PPC_EMULATE_SSTEP) += sstep.o ldstfp.o
3129

‎arch/powerpc/lib/memcpy_64.S‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,27 @@
1212
.align 7
1313
_GLOBAL(memcpy)
1414
BEGIN_FTR_SECTION
15+
#ifdef __LITTLE_ENDIAN__
16+
cmpdi cr7,r5,0
17+
#else
1518
std r3,48(r1) /* save destination pointer for return value */
19+
#endif
1620
FTR_SECTION_ELSE
1721
#ifndef SELFTEST
1822
b memcpy_power7
1923
#endif
2024
ALT_FTR_SECTION_END_IFCLR(CPU_FTR_VMX_COPY)
25+
#ifdef __LITTLE_ENDIAN__
26+
/* dumb little-endian memcpy that will get replaced at runtime */
27+
addi r9,r3,-1
28+
addi r4,r4,-1
29+
beqlr cr7
30+
mtctr r5
31+
1: lbzu r10,1(r4)
32+
stbu r10,1(r9)
33+
bdnz 1b
34+
blr
35+
#else
2136
PPC_MTOCRF(0x01,r5)
2237
cmpldi cr1,r5,16
2338
neg r6,r3 # LS 3 bits = # bytes to 8-byte dest bdry
@@ -203,3 +218,4 @@ END_FTR_SECTION_IFCLR(CPU_FTR_UNALIGNED_LD_STD)
203218
stb r0,0(r3)
204219
4: ld r3,48(r1) /* return dest pointer */
205220
blr
221+
#endif

0 commit comments

Comments
 (0)