Skip to content

Commit 9343aab

Browse files
ConchuODAlexandre Ghiti
authored andcommitted
RISC-V: separate Zbb optimisations requiring and not requiring toolchain support
It seems a bit ridiculous to require toolchain support for BPF to assemble Zbb instructions, so move the dependency on toolchain support for Zbb optimisations out of the Kconfig option and to the callsites. Zbb support has always depended on alternatives, so while adjusting the config options guarding optimisations, remove any checks for whether or not alternatives are enabled. Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Conor Dooley <[email protected]> Reviewed-by: Charlie Jenkins <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Link: https://lore.kernel.org/r/20241024-chump-freebase-d26b6d81af33@spud Signed-off-by: Alexandre Ghiti <[email protected]>
1 parent 6216182 commit 9343aab

File tree

8 files changed

+20
-33
lines changed

8 files changed

+20
-33
lines changed

arch/riscv/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,12 @@ config RISCV_ISA_ZBA
664664

665665
config RISCV_ISA_ZBB
666666
bool "Zbb extension support for bit manipulation instructions"
667-
depends on TOOLCHAIN_HAS_ZBB
668667
depends on RISCV_ALTERNATIVE
669668
default y
670669
help
671670
Add support for enabling optimisations in the kernel when the
672-
Zbb extension is detected at boot.
671+
Zbb extension is detected at boot. Some optimisations may
672+
additionally depend on toolchain support for Zbb.
673673

674674
The Zbb extension provides instructions to accelerate a number
675675
of bit-specific operations (count bit population, sign extending,

arch/riscv/include/asm/arch_hweight.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
static __always_inline unsigned int __arch_hweight32(unsigned int w)
2121
{
22-
#ifdef CONFIG_RISCV_ISA_ZBB
22+
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
2323
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
2424
RISCV_ISA_EXT_ZBB, 1)
2525
: : : : legacy);
@@ -50,7 +50,7 @@ static inline unsigned int __arch_hweight8(unsigned int w)
5050
#if BITS_PER_LONG == 64
5151
static __always_inline unsigned long __arch_hweight64(__u64 w)
5252
{
53-
# ifdef CONFIG_RISCV_ISA_ZBB
53+
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
5454
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
5555
RISCV_ISA_EXT_ZBB, 1)
5656
: : : : legacy);
@@ -64,7 +64,7 @@ static __always_inline unsigned long __arch_hweight64(__u64 w)
6464
return w;
6565

6666
legacy:
67-
# endif
67+
#endif
6868
return __sw_hweight64(w);
6969
}
7070
#else /* BITS_PER_LONG == 64 */

arch/riscv/include/asm/bitops.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <asm/barrier.h>
1616
#include <asm/bitsperlong.h>
1717

18-
#if !defined(CONFIG_RISCV_ISA_ZBB) || defined(NO_ALTERNATIVE)
18+
#if !(defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)) || defined(NO_ALTERNATIVE)
1919
#include <asm-generic/bitops/__ffs.h>
2020
#include <asm-generic/bitops/__fls.h>
2121
#include <asm-generic/bitops/ffs.h>
@@ -175,7 +175,7 @@ static __always_inline int variable_fls(unsigned int x)
175175
variable_fls(x_); \
176176
})
177177

178-
#endif /* !defined(CONFIG_RISCV_ISA_ZBB) || defined(NO_ALTERNATIVE) */
178+
#endif /* !(defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)) || defined(NO_ALTERNATIVE) */
179179

180180
#include <asm-generic/bitops/ffz.h>
181181
#include <asm-generic/bitops/fls64.h>

arch/riscv/include/asm/checksum.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
4949
* ZBB only saves three instructions on 32-bit and five on 64-bit so not
5050
* worth checking if supported without Alternatives.
5151
*/
52-
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
53-
IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
52+
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) {
5453
unsigned long fold_temp;
5554

5655
asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0,

arch/riscv/lib/csum.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
4040
uproto = (__force unsigned int)htonl(proto);
4141
sum += uproto;
4242

43-
/*
44-
* Zbb support saves 4 instructions, so not worth checking without
45-
* alternatives if supported
46-
*/
47-
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
48-
IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
43+
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) {
4944
unsigned long fold_temp;
5045

5146
/*
@@ -157,12 +152,7 @@ do_csum_with_alignment(const unsigned char *buff, int len)
157152
csum = do_csum_common(ptr, end, data);
158153

159154
#ifdef CC_HAS_ASM_GOTO_TIED_OUTPUT
160-
/*
161-
* Zbb support saves 6 instructions, so not worth checking without
162-
* alternatives if supported
163-
*/
164-
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
165-
IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
155+
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) {
166156
unsigned long fold_temp;
167157

168158
/*
@@ -244,12 +234,7 @@ do_csum_no_alignment(const unsigned char *buff, int len)
244234
end = (const unsigned long *)(buff + len);
245235
csum = do_csum_common(ptr, end, data);
246236

247-
/*
248-
* Zbb support saves 6 instructions, so not worth checking without
249-
* alternatives if supported
250-
*/
251-
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
252-
IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) {
237+
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) {
253238
unsigned long fold_temp;
254239

255240
/*

arch/riscv/lib/strcmp.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
/* int strcmp(const char *cs, const char *ct) */
99
SYM_FUNC_START(strcmp)
1010

11-
ALTERNATIVE("nop", "j strcmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
11+
__ALTERNATIVE_CFG("nop", "j strcmp_zbb", 0, RISCV_ISA_EXT_ZBB,
12+
IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB))
1213

1314
/*
1415
* Returns
@@ -43,7 +44,7 @@ SYM_FUNC_START(strcmp)
4344
* The code was published as part of the bitmanip manual
4445
* in Appendix A.
4546
*/
46-
#ifdef CONFIG_RISCV_ISA_ZBB
47+
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
4748
strcmp_zbb:
4849

4950
.option push

arch/riscv/lib/strlen.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
/* int strlen(const char *s) */
99
SYM_FUNC_START(strlen)
1010

11-
ALTERNATIVE("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
11+
__ALTERNATIVE_CFG("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB,
12+
IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB))
1213

1314
/*
1415
* Returns
@@ -33,7 +34,7 @@ SYM_FUNC_START(strlen)
3334
/*
3435
* Variant of strlen using the ZBB extension if available
3536
*/
36-
#ifdef CONFIG_RISCV_ISA_ZBB
37+
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
3738
strlen_zbb:
3839

3940
#ifdef CONFIG_CPU_BIG_ENDIAN

arch/riscv/lib/strncmp.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
/* int strncmp(const char *cs, const char *ct, size_t count) */
99
SYM_FUNC_START(strncmp)
1010

11-
ALTERNATIVE("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
11+
__ALTERNATIVE_CFG("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB,
12+
IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB))
1213

1314
/*
1415
* Returns
@@ -46,7 +47,7 @@ SYM_FUNC_START(strncmp)
4647
/*
4748
* Variant of strncmp using the ZBB extension if available
4849
*/
49-
#ifdef CONFIG_RISCV_ISA_ZBB
50+
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
5051
strncmp_zbb:
5152

5253
.option push

0 commit comments

Comments
 (0)