Skip to contentSkip to conversation

powerpc: Remove assembly versions of strcpy, strcat, strlen and strcmp

PATCH Applied Anton Blanchard 4 participants 8 messages May 25, 2016 – Jun 15, 2016 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 powerpc: Remove assembly versions of strcpy, strcat, strlen and strcmp

A number of our assembly implementations of string functions do not align their hot loops. I was going to align them manually, but I realised that they are are almost instruction for instruction identical to what gcc produces, with the advantage that gcc does align them.

In light of that, let's just remove the assembly versions.

---

index e40010a..da3cdff 100644

arch/powerpc/include/asm/string.h +0 -4
Index: linux.junk/arch/powerpc/include/asm/string.h
===================================================================
@@ -3,12 +3,8 @@
 
 #ifdef __KERNEL__
 
-#define __HAVE_ARCH_STRCPY
 #define __HAVE_ARCH_STRNCPY
-#define __HAVE_ARCH_STRLEN
-#define __HAVE_ARCH_STRCMP
 #define __HAVE_ARCH_STRNCMP
-#define __HAVE_ARCH_STRCAT
 #define __HAVE_ARCH_MEMSET
 #define __HAVE_ARCH_MEMCPY
 #define __HAVE_ARCH_MEMMOVE
arch/powerpc/lib/ppc_ksyms.c +0 -4
Index: linux.junk/arch/powerpc/lib/ppc_ksyms.c
===================================================================
@@ -9,11 +9,7 @@ EXPORT_SYMBOL(memmove);
 EXPORT_SYMBOL(memcmp);
 EXPORT_SYMBOL(memchr);
 
-EXPORT_SYMBOL(strcpy);
 EXPORT_SYMBOL(strncpy);
-EXPORT_SYMBOL(strcat);
-EXPORT_SYMBOL(strlen);
-EXPORT_SYMBOL(strcmp);
 EXPORT_SYMBOL(strncmp);
 
 #ifndef CONFIG_GENERIC_CSUM
arch/powerpc/lib/string.S +0 -41

59 lines not on this page · raw message

#1 lore raw

PATCH 2/2 powerpc: Align hot loops of some string functions

Align the hot loops in our assembly implementation of strncpy(), strncmp() and memchr().

---

arch/powerpc/lib/string.S +3 -0
Index: linux.junk/arch/powerpc/lib/string.S
===================================================================
@@ -24,6 +24,7 @@ _GLOBAL(strncpy)
 	mtctr	r5
 	addi	r6,r3,-1
 	addi	r4,r4,-1
+	.balign 16
 1:	lbzu	r0,1(r4)
 	cmpwi	0,r0,0
 	stbu	r0,1(r6)
@@ -42,6 +43,7 @@ _GLOBAL(strncmp)
 	mtctr	r5
 	addi	r5,r3,-1
 	addi	r4,r4,-1
+	.balign 16
 1:	lbzu	r3,1(r5)
 	cmpwi	1,r3,0
 	lbzu	r0,1(r4)
@@ -73,6 +75,7 @@ _GLOBAL(memchr)
 	beq-	2f
 	mtctr	r5
 	addi	r3,r3,-1
+	.balign 16
 1:	lbzu	r0,1(r3)
 	cmpw	0,r0,r4
 	bdnzf	2,1b
#2 lore raw

Re: [PATCH 2/2] powerpc: Align hot loops of some string functions

Quoted 2 lines · Anton Blanchard via Linuxppc-dev

Align the hot loops in our assembly implementation of strncpy(), strncmp() and memchr().

Wouldn't it be better to add nops before the function entry in order to get the hot loop aligned, instead of adding nops in the middle of the function ?

Christophe

Quoted 36 lines

---

Index: linux.junk/arch/powerpc/lib/string.S
===================================================================

arch/powerpc/lib/string.S +3 -0
@@ -24,6 +24,7 @@ _GLOBAL(strncpy)
  	mtctr	r5
  	addi	r6,r3,-1
  	addi	r4,r4,-1
+	.balign 16
  1:	lbzu	r0,1(r4)
  	cmpwi	0,r0,0
  	stbu	r0,1(r6)
@@ -42,6 +43,7 @@ _GLOBAL(strncmp)
  	mtctr	r5
  	addi	r5,r3,-1
  	addi	r4,r4,-1
+	.balign 16
  1:	lbzu	r3,1(r5)
  	cmpwi	1,r3,0
  	lbzu	r0,1(r4)
@@ -73,6 +75,7 @@ _GLOBAL(memchr)
  	beq-	2f
  	mtctr	r5
  	addi	r3,r3,-1
+	.balign 16
  1:	lbzu	r0,1(r3)
  	cmpw	0,r0,r4
  	bdnzf	2,1b

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#3 lore raw

Re: [PATCH 2/2] powerpc: Align hot loops of some string functions

Quoted 3 lines · Christophe Leroy

Wouldn't it be better to add nops before the function entry in order to get the hot loop aligned, instead of adding nops in the middle of the function ?

Why would that be better? The nops are executed once per function call in either case, there are the same number of nops in either case, and on most CPUs nops aren't actually executed anyway (they are decoded and the thrown away).

Segher

#4 lore raw

Re: [PATCH 2/2] powerpc: Align hot loops of some string functions

Quoted 9 lines · Segher Boessenkool
Quoted 3 lines · Christophe Leroy

Wouldn't it be better to add nops before the function entry in order to get the hot loop aligned, instead of adding nops in the middle of the function ?

Why would that be better? The nops are executed once per function call in either case, there are the same number of nops in either case, and on most CPUs nops aren't actually executed anyway (they are decoded and the thrown away).

The idea was to not execute them:

|.balign 16 nop nop _GLOBAL(strcpy) addi r5,r3,-1 addi r4,r4,-1 1: lbzu r0,1(r4) cmpwi 0,r0,0 stbu r0,1(r5) bne 1b blr |

Christophe

#5 lore raw

Re: [PATCH 2/2] powerpc: Align hot loops of some string functions

Quoted 8 lines · Christophe Leroy
Quoted 8 lines
Quoted 3 lines

Wouldn't it be better to add nops before the function entry in order to get the hot loop aligned, instead of adding nops in the middle of the function ?

Why would that be better? The nops are executed once per function call in either case, there are the same number of nops in either case, and on most CPUs nops aren't actually executed anyway (they are decoded and the thrown away).

Quoted 4 lines

The idea was to not execute them:

|.balign 16 nop nop _GLOBAL(strcpy) addi r5,r3,-1 addi r4,r4,-1 1:
lbzu r0,1(r4) cmpwi 0,r0,0 stbu r0,1(r5) bne 1b blr |

That performs _worse_ on most modern CPUs (the first decode will decode less, so instructions are available for execution later). That's why functions are aligned in the first place!

Segher

reviewer Applied
#7 lore raw
In reply to Anton Blanchard
Quoted 9 lines · Unknown sender due to SPF

A number of our assembly implementations of string functions do not align their hot loops. I was going to align them manually, but I realised that they are are almost instruction for instruction identical to what gcc produces, with the advantage that gcc does align them.

In light of that, let's just remove the assembly versions.

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/3ece16632b64120df2ef566ce3

cheers