Skip to contentSkip to conversation

sparc64: Optimize fls and __fls

PATCH Superseded Vijay Kumar 3 participants 9 messages Oct 6, 2017 – Oct 9, 2017

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover sparc64: Optimize fls and __fls

SPARC provides lzcnt instruction (with VIS3) which can be used to optimize fls, __fls and fls64 functions. For the systems that supports lzcnt instruction, we now do boot time patching to use sparc optimized fls, __fls and fls64 functions.

v2->v3:

 -  Using ENTRY(), ENDPROC() for assembler functions.
 -  Removed BITS_PER_LONG from __fls.
 -  Using generic fls64().
 -  Replaced lzcnt instruction with .word directive.

v1->v2:
- Fixed delay slot issue.

Vijay Kumar (2):
sparc64: Define SPARC default fls and __fls
sparc64: Use lzcnt instruction for fls and __fls

 arch/sparc/Makefile                |    1 +
 arch/sparc/include/asm/bitops_64.h |    7 +-
 arch/sparc/kernel/head_64.S        |    2 +
 arch/sparc/lib/Makefile            |    4 +
 arch/sparc/lib/NG4fls.S            |   31 +++++++++
 arch/sparc/lib/NG4patch.S          |    9 +++
 arch/sparc/lib/fls.S               |  126 ++++++++++++++++++++++++++++++++++++
 7 files changed, 177 insertions(+), 3 deletions(-)
 create mode 100644 arch/sparc/lib/NG4fls.S
 create mode 100644 arch/sparc/lib/fls.S
#1 lore raw

PATCH v3 1/5 sparc64: Define SPARC default fls function

fls will now require a boot time patching on T4 and above. Redefining it under arch/sparc/lib.

---
 arch/sparc/include/asm/bitops_64.h |    3 +-
 arch/sparc/lib/Makefile            |    1 +
 arch/sparc/lib/fls.S               |   67 ++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletions(-)
arch/sparc/include/asm/bitops_64.h +2 -1
index 2d52240..30aea56 100644
@@ -22,9 +22,10 @@
 void clear_bit(unsigned long nr, volatile unsigned long *addr);
 void change_bit(unsigned long nr, volatile unsigned long *addr);
 
+int fls(unsigned int word);
+
 #include <asm-generic/bitops/non-atomic.h>
 
-#include <asm-generic/bitops/fls.h>
 #include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
 
arch/sparc/lib/Makefile +1 -0
index a1a2d39..3b9f5e0 100644
@@ -16,6 +16,7 @@ lib-$(CONFIG_SPARC64) += atomic_64.o
 lib-$(CONFIG_SPARC32) += lshrdi3.o ashldi3.o
 lib-$(CONFIG_SPARC32) += muldi3.o bitext.o cmpdi2.o
 lib-$(CONFIG_SPARC64) += multi3.o
+lib-$(CONFIG_SPARC64) += fls.o
 
 lib-$(CONFIG_SPARC64) += copy_page.o clear_page.o bzero.o
 lib-$(CONFIG_SPARC64) += csum_copy.o csum_copy_from_user.o csum_copy_to_user.o
arch/sparc/lib/fls.S new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

PATCH v3 2/5 sparc64: Define SPARC default __fls function

In reply to Vijay Kumar

__fls will now require a boot time patching on T4 and above. Redefining it under arch/sparc/lib.

---
 arch/sparc/include/asm/bitops_64.h |    2 +-
 arch/sparc/lib/Makefile            |    1 +
 arch/sparc/lib/fls64.S             |   61 ++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 1 deletions(-)
arch/sparc/include/asm/bitops_64.h +1 -1
index 30aea56..d7a46e2 100644
@@ -23,10 +23,10 @@
 void change_bit(unsigned long nr, volatile unsigned long *addr);
 
 int fls(unsigned int word);
+int __fls(unsigned long word);
 
 #include <asm-generic/bitops/non-atomic.h>
 
-#include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
 
 #ifdef __KERNEL__
arch/sparc/lib/Makefile +1 -0
index 3b9f5e0..5380c59 100644
@@ -17,6 +17,7 @@ lib-$(CONFIG_SPARC32) += lshrdi3.o ashldi3.o
 lib-$(CONFIG_SPARC32) += muldi3.o bitext.o cmpdi2.o
 lib-$(CONFIG_SPARC64) += multi3.o
 lib-$(CONFIG_SPARC64) += fls.o
+lib-$(CONFIG_SPARC64) += fls64.o
 
 lib-$(CONFIG_SPARC64) += copy_page.o clear_page.o bzero.o
 lib-$(CONFIG_SPARC64) += csum_copy.o csum_copy_from_user.o csum_copy_to_user.o
arch/sparc/lib/fls64.S new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
1.7.1
#3 lore raw

PATCH v3 3/5 sparc64: SPARC optimised fls function

In reply to Vijay Kumar

Defined SPARC optimised fls using lzcnt opcode.

---
 arch/sparc/lib/Makefile |    1 +
 arch/sparc/lib/NG4fls.S |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
arch/sparc/lib/Makefile +1 -0
index 5380c59..2823b8e 100644
@@ -18,6 +18,7 @@ lib-$(CONFIG_SPARC32) += muldi3.o bitext.o cmpdi2.o
 lib-$(CONFIG_SPARC64) += multi3.o
 lib-$(CONFIG_SPARC64) += fls.o
 lib-$(CONFIG_SPARC64) += fls64.o
+obj-$(CONFIG_SPARC64) += NG4fls.o
 
 lib-$(CONFIG_SPARC64) += copy_page.o clear_page.o bzero.o
 lib-$(CONFIG_SPARC64) += csum_copy.o csum_copy_from_user.o csum_copy_to_user.o
arch/sparc/lib/NG4fls.S new file +20 -0
new file mode 100644
index 0000000..5ed7da9
@@ -0,0 +1,20 @@
+/* NG4fls.S: SPARC optimized fls and __fls for T4 and above.
+ *
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ */
+
+#include <linux/linkage.h>
+
+#define LXCNT_O0_G2	\
+	.word	0x85b002e8
+
+	.text
+	.register	%g2, #scratch
+	.register	%g3, #scratch
+
+ENTRY(NG4fls)
+	LXCNT_O0_G2	!lzcnt	%o0, %g2
+	mov	64, %g3
+	retl
+	 sub	%g3, %g2, %o0
+ENDPROC(NG4fls)
Signature · 1 line
1.7.1
#4 lore raw

Re: [PATCH v3 3/5] sparc64: SPARC optimised fls function

Quoted 29 lines · Vijay Kumar

Defined SPARC optimised fls using lzcnt opcode.

---
arch/sparc/lib/Makefile | 1 +
arch/sparc/lib/NG4fls.S | 20 ++++++++++++++++++++

2 files changed, 21 insertions(+), 0 deletions(-)
arch/sparc/lib/Makefile +0 -0
index 5380c59..2823b8e 100644
@@ -18,6 +18,7 @@ lib-$(CONFIG_SPARC32) += muldi3.o bitext.o cmpdi2.o

lib-$(CONFIG_SPARC64) += multi3.o
lib-$(CONFIG_SPARC64) += fls.o
lib-$(CONFIG_SPARC64) += fls64.o
+obj-$(CONFIG_SPARC64) += NG4fls.o

lib-$(CONFIG_SPARC64) += copy_page.o clear_page.o bzero.o lib-$(CONFIG_SPARC64) += csum_copy.o csum_copy_from_user.o csum_copy_to_user.o

arch/sparc/lib/NG4fls.S new file +0 -0
new file mode 100644
index 0000000..5ed7da9

arch/sparc/lib/NG4fls.S line 8

Quoted 8 lines
arch/sparc/lib/NG4fls.S new file +8 -0
@@ -0,0 +1,20 @@
+/* NG4fls.S: SPARC optimized fls and __fls for T4 and above.
+ *
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ */
+
+#include <linux/linkage.h>
+
+#define LXCNT_O0_G2	\

Typo? Should be LZCNT_O0_G2.

Anthony

Quoted 19 lines
arch/sparc/lib/NG4fls.S new file +12 -0
+	.word	0x85b002e8
+
+	.text
+	.register	%g2, #scratch
+	.register	%g3, #scratch
+
+ENTRY(NG4fls)
+	LXCNT_O0_G2	!lzcnt	%o0, %g2
+	mov	64, %g3
+	retl
+	 sub	%g3, %g2, %o0
+ENDPROC(NG4fls)
Signature · 6 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#5 lore raw

Re: [PATCH v3 3/5] sparc64: SPARC optimised fls function

In reply to Vijay Kumar

From: Vijay Kumar <[email protected]>
Date: Fri, 6 Oct 2017 10:54:51 -0600

arch/sparc/lib/NG4fls.S line 16

Quoted 9 lines
arch/sparc/lib/NG4fls.S new file +9 -0
+#define LXCNT_O0_G2	\
+	.word	0x85b002e8
+
+	.text
+	.register	%g2, #scratch
+	.register	%g3, #scratch
+
+ENTRY(NG4fls)
+	LXCNT_O0_G2	!lzcnt	%o0, %g2

Agreed with others that you should name this LZCNT_* instead of LXCNT_*.

#6 lore raw

Re: [PATCH v3 3/5] sparc64: SPARC optimised fls function

Quoted 15 lines · David Miller

From: Vijay Kumar <[email protected]>
Date: Fri, 6 Oct 2017 10:54:51 -0600

arch/sparc/lib/NG4fls.S line 16

Quoted 9 lines
arch/sparc/lib/NG4fls.S new file +9 -0
+#define LXCNT_O0_G2	\
+	.word	0x85b002e8
+
+	.text
+	.register	%g2, #scratch
+	.register	%g3, #scratch
+
+ENTRY(NG4fls)
+	LXCNT_O0_G2	!lzcnt	%o0, %g2

Agreed with others that you should name this LZCNT_* instead of LXCNT_*.

Yes, That's typo. I will fix it.

Vijay

#7 lore raw

PATCH v3 4/5 sparc64: SPARC optimised __fls function

In reply to Vijay Kumar

Defined SPARC optimised __fls using lzcnt opcode.

---
 arch/sparc/lib/NG4fls.S |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
arch/sparc/lib/NG4fls.S +10 -0
index 5ed7da9..34ad371 100644
@@ -18,3 +18,13 @@ ENTRY(NG4fls)
 	retl
 	 sub	%g3, %g2, %o0
 ENDPROC(NG4fls)
+
+ENTRY(__NG4fls)
+	brz,pn	%o0, 1f
+	LXCNT_O0_G2	!lzcnt	%o0, %g2
+	mov	63, %g3
+	sub	%g3, %g2, %o0
+1:
+	retl
+	 nop
+ENDPROC(__NG4fls)
Signature · 1 line
1.7.1
#8 lore raw

PATCH v3 5/5 sparc64: Use sparc optimised fls and __fls for T4 and above

In reply to Vijay Kumar

For T4 and above, patch fls and __fls functions
at the boot time to use lzcnt instruction.

---
 arch/sparc/kernel/head_64.S |    2 ++
 arch/sparc/lib/NG4patch.S   |    9 +++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)
arch/sparc/kernel/head_64.S +2 -0
index 4de9fbd..f362ecb 100644
@@ -640,6 +640,8 @@ niagara4_patch:
 	 nop
 	call	niagara4_patch_pageops
 	 nop
+	call	niagara4_patch_fls
+	 nop
 
 	ba,a,pt	%xcc, 80f
 	 nop
arch/sparc/lib/NG4patch.S +9 -0
index 3cc0f8c..da65a3e 100644
@@ -3,6 +3,8 @@
  * Copyright (C) 2012 David S. Miller <[email protected]>
  */
 
+#include <linux/linkage.h>
+
 #define BRANCH_ALWAYS	0x10680000
 #define NOP		0x01000000
 #define NG_DO_PATCH(OLD, NEW)	\
@@ -52,3 +54,10 @@ niagara4_patch_pageops:
 	retl
 	 nop
 	.size	niagara4_patch_pageops,.-niagara4_patch_pageops
+
+ENTRY(niagara4_patch_fls)
+	NG_DO_PATCH(fls, NG4fls)
+	NG_DO_PATCH(__fls, __NG4fls)
+	retl
+	 nop
+ENDPROC(niagara4_patch_fls)
Signature · 1 line
1.7.1