Skip to contentSkip to conversation

sparc64: Optimize fls, fls64 and __fls

PATCH Superseded Vijay Kumar 1 participant 3 messages Sep 27, 2017

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover sparc64: Optimize fls, fls64 and __fls

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

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 1/2 sparc64: Define SPARC default fls and __fls

fls and __fls will now require boot time patching on T4 and above. Redefining these functions under arc/sparc/lib.

---
 arch/sparc/include/asm/bitops_64.h |    7 +-
 arch/sparc/lib/Makefile            |    1 +
 arch/sparc/lib/fls.S               |  126 ++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+), 3 deletions(-)
arch/sparc/include/asm/bitops_64.h +4 -3
index 2d52240..946c236 100644
@@ -22,11 +22,12 @@
 void clear_bit(unsigned long nr, volatile unsigned long *addr);
 void change_bit(unsigned long nr, volatile unsigned long *addr);
 
+#define fls64(word)  (((word)?(__fls(word) + 1):0))
+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/__fls.h>
-#include <asm-generic/bitops/fls64.h>
 
 #ifdef __KERNEL__
 
arch/sparc/lib/Makefile +1 -0
index 07c03e7..eefbb9c 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 +126 -0

126 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/2 sparc64: Use lzcnt instruction for fls and __fls

In reply to Vijay Kumar

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

---
 arch/sparc/Makefile         |    1 +
 arch/sparc/kernel/head_64.S |    2 ++
 arch/sparc/lib/Makefile     |    3 +++
 arch/sparc/lib/NG4fls.S     |   31 +++++++++++++++++++++++++++++++
 arch/sparc/lib/NG4patch.S   |    9 +++++++++
 5 files changed, 46 insertions(+), 0 deletions(-)
arch/sparc/Makefile +1 -0
index 8496a07..0763cd8 100644
@@ -48,6 +48,7 @@ KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare
 KBUILD_CFLAGS += -Wa,--undeclared-regs
 KBUILD_CFLAGS += $(call cc-option,-mtune=ultrasparc3)
 KBUILD_AFLAGS += -m64 -mcpu=ultrasparc -Wa,--undeclared-regs
+KBUILD_AFLAGS += -Wa,-Asparc4
 
 ifeq ($(CONFIG_MCOUNT),y)
   KBUILD_CFLAGS += -pg
arch/sparc/kernel/head_64.S +2 -0
index 78e0211..1165254 100644
@@ -628,6 +628,8 @@ niagara4_patch:
 	 nop
 	call	niagara4_patch_pageops
 	 nop
+	call	niagara4_patch_fls
+	 nop
 
 	ba,a,pt	%xcc, 80f
 	 nop
arch/sparc/lib/Makefile +3 -0
index eefbb9c..72d2d8c 100644
@@ -46,3 +46,6 @@ lib-$(CONFIG_SPARC64) += mcount.o ipcsum.o xor.o hweight.o ffs.o
 obj-$(CONFIG_SPARC64) += iomap.o
 obj-$(CONFIG_SPARC32) += atomic32.o ucmpdi2.o
 obj-$(CONFIG_SPARC64) += PeeCeeI.o
+
+obj-$(CONFIG_SPARC64) += fls.o
+obj-$(CONFIG_SPARC64) += NG4fls.o
arch/sparc/lib/NG4fls.S new file +31 -0
new file mode 100644
index 0000000..7c2cfb3
@@ -0,0 +1,31 @@
+/* NG4fls.S: SPARC optimized fls and __fls for T4 and above.
+ *
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ */
+
+	.text
+	.align 32
+
+	.globl NG4fls
+	.globl __NG4fls
+	.type  NG4fls, #function
+	.type  __NG4fls, #function
+
+NG4fls:
+	lzcnt   %o0, %o1
+	mov     64, %o2
+	sub     %o2, %o1, %o0
+	retl
+	.size   NG4fls, .-NG4fls
+
+__NG4fls:
+	brz,pn  %o0, 1f
+        mov	%o0, %o1
+	lzcnt	%o1, %o0
+	mov     63, %o2
+	sub     %o2, %o0, %o0
+1:
+	retl
+	nop
+	nop
+	.size   __NG4fls, .-__NG4fls
arch/sparc/lib/NG4patch.S +9 -0
index 3cc0f8c..1010d53 100644
@@ -52,3 +52,12 @@ niagara4_patch_pageops:
 	retl
 	 nop
 	.size	niagara4_patch_pageops,.-niagara4_patch_pageops
+
+	.globl	niagara4_patch_fls
+	.type	niagara4_patch_fls,#function
+niagara4_patch_fls:
+	NG_DO_PATCH(fls, NG4fls)
+	NG_DO_PATCH(__fls, __NG4fls)
+	retl
+	 nop
+	.size	niagara4_patch_fls,.-niagara4_patch_fls
Signature · 1 line
1.7.1