Skip to contentSkip to conversation

sparc64: Optimize fls and __fls

PATCH In review Vijay Kumar 3 participants 8 messages Oct 11, 2017 – Nov 15, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 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.

v3->v4:
- Fixed a typo.
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 (5):
sparc64: Define SPARC default fls function
sparc64: Define SPARC default __fls function
sparc64: SPARC optimized fls function
sparc64: SPARC optimized __fls function
sparc64: Use sparc optimized fls and __fls for T4 and above

 arch/sparc/include/asm/bitops_64.h |    5 ++-
 arch/sparc/kernel/head_64.S        |    2 +
 arch/sparc/lib/Makefile            |    3 ++
 arch/sparc/lib/NG4fls.S            |   30 ++++++++++++++++
 arch/sparc/lib/NG4patch.S          |    9 +++++
 arch/sparc/lib/fls.S               |   67 ++++++++++++++++++++++++++++++++++++
 arch/sparc/lib/fls64.S             |   61 ++++++++++++++++++++++++++++++++
 7 files changed, 175 insertions(+), 2 deletions(-)
 create mode 100644 arch/sparc/lib/NG4fls.S
 create mode 100644 arch/sparc/lib/fls.S
 create mode 100644 arch/sparc/lib/fls64.S
#1 lore raw

PATCH v4 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 v4 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 v4 3/5 sparc64: SPARC optimized fls function

In reply to Vijay Kumar

Defined SPARC optimized 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..bc17b65
@@ -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 LZCNT_O0_G2	\
+	.word	0x85b002e8
+
+	.text
+	.register	%g2, #scratch
+	.register	%g3, #scratch
+
+ENTRY(NG4fls)
+	LZCNT_O0_G2	!lzcnt	%o0, %g2
+	mov	64, %g3
+	retl
+	 sub	%g3, %g2, %o0
+ENDPROC(NG4fls)
Signature · 1 line
1.7.1
#4 lore raw

PATCH v4 4/5 sparc64: SPARC optimized __fls function

In reply to Vijay Kumar

Defined SPARC optimized __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 bc17b65..2d0991e 100644
@@ -18,3 +18,13 @@ ENTRY(NG4fls)
 	retl
 	 sub	%g3, %g2, %o0
 ENDPROC(NG4fls)
+
+ENTRY(__NG4fls)
+	brz,pn	%o0, 1f
+	LZCNT_O0_G2	!lzcnt	%o0, %g2
+	mov	63, %g3
+	sub	%g3, %g2, %o0
+1:
+	retl
+	 nop
+ENDPROC(__NG4fls)
Signature · 1 line
1.7.1
#5 lore raw

PATCH v4 5/5 sparc64: Use sparc optimized 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
Reviewed-by on the v4 series
#6 lore raw
In reply to Vijay Kumar

Looked at all the patches. Looks good to me.

Quoted 34 lines · Vijay Kumar

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.

v3->v4:
- Fixed a typo.
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 (5):
sparc64: Define SPARC default fls function
sparc64: Define SPARC default __fls function
sparc64: SPARC optimized fls function
sparc64: SPARC optimized __fls function
sparc64: Use sparc optimized fls and __fls for T4 and above

  arch/sparc/include/asm/bitops_64.h |    5 ++-
  arch/sparc/kernel/head_64.S        |    2 +
  arch/sparc/lib/Makefile            |    3 ++
  arch/sparc/lib/NG4fls.S            |   30 ++++++++++++++++
  arch/sparc/lib/NG4patch.S          |    9 +++++
  arch/sparc/lib/fls.S               |   67 ++++++++++++++++++++++++++++++++++++
  arch/sparc/lib/fls64.S             |   61 ++++++++++++++++++++++++++++++++
  7 files changed, 175 insertions(+), 2 deletions(-)

create mode 100644 arch/sparc/lib/NG4fls.S
create mode 100644 arch/sparc/lib/fls.S
create mode 100644 arch/sparc/lib/fls64.S

maintainer
#7 lore raw
In reply to Vijay Kumar

From: Vijay Kumar <[email protected]>
Date: Wed, 11 Oct 2017 12:50:01 -0600

Quoted 8 lines

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.

v3->v4:
- Fixed a typo.
v2->v3:

Quoted 6 lines
 -  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.

Series applied, thank you.