sparc64: Optimize fls and __fls
Subsystems (2)
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
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
@@ -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
@@ -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
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
@@ -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
@@ -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
PATCH v4 3/5 sparc64: SPARC optimized fls function
In reply to Vijay KumarDefined 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
@@ -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
@@ -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
PATCH v4 4/5 sparc64: SPARC optimized __fls function
In reply to Vijay KumarDefined 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
@@ -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
PATCH v4 5/5 sparc64: Use sparc optimized fls and __fls for T4 and above
In reply to Vijay KumarFor 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
@@ -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
@@ -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
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,
__flsand fls64 functions. For the systems that supports lzcnt instruction, we now do boot time patching to use sparc optimized fls,__flsand 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__flsfunction
sparc64: SPARC optimized fls function
sparc64: SPARC optimized__flsfunction
sparc64: Use sparc optimized fls and__flsfor T4 and abovearch/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 100644arch/sparc/lib/fls.S
create mode 100644arch/sparc/lib/fls64.S
David Miller
maintainerFrom: 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,
__flsand fls64 functions. For the systems that supports lzcnt instruction, we now do boot time patching to use sparc optimized fls,__flsand 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.