Skip to content

Commit 7268555

Browse files
jones-drewpalmer-dabbelt
authored andcommitted
RISC-V: Improve use of isa2hwcap[]
Improve isa2hwcap[] by removing it from static storage, as riscv_fill_hwcap() is only called once, and by reducing its size from 256 bytes to 26. The latter improvement is possible because isa2hwcap[] will never be indexed with capital letters and we can precompute the offsets from 'a'. No functional change intended. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Reviewed-by: Heiko Stuebner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 5c20a3a commit 7268555

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

arch/riscv/kernel/cpufeature.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ void __init riscv_fill_hwcap(void)
7474
const char *isa;
7575
char print_str[NUM_ALPHA_EXTS + 1];
7676
int i, j, rc;
77-
static unsigned long isa2hwcap[256] = {0};
77+
unsigned long isa2hwcap[26] = {0};
7878
unsigned long hartid;
7979

80-
isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I;
81-
isa2hwcap['m'] = isa2hwcap['M'] = COMPAT_HWCAP_ISA_M;
82-
isa2hwcap['a'] = isa2hwcap['A'] = COMPAT_HWCAP_ISA_A;
83-
isa2hwcap['f'] = isa2hwcap['F'] = COMPAT_HWCAP_ISA_F;
84-
isa2hwcap['d'] = isa2hwcap['D'] = COMPAT_HWCAP_ISA_D;
85-
isa2hwcap['c'] = isa2hwcap['C'] = COMPAT_HWCAP_ISA_C;
80+
isa2hwcap['i' - 'a'] = COMPAT_HWCAP_ISA_I;
81+
isa2hwcap['m' - 'a'] = COMPAT_HWCAP_ISA_M;
82+
isa2hwcap['a' - 'a'] = COMPAT_HWCAP_ISA_A;
83+
isa2hwcap['f' - 'a'] = COMPAT_HWCAP_ISA_F;
84+
isa2hwcap['d' - 'a'] = COMPAT_HWCAP_ISA_D;
85+
isa2hwcap['c' - 'a'] = COMPAT_HWCAP_ISA_C;
8686

8787
elf_hwcap = 0;
8888

@@ -196,8 +196,10 @@ void __init riscv_fill_hwcap(void)
196196
if (unlikely(ext_err))
197197
continue;
198198
if (!ext_long) {
199-
this_hwcap |= isa2hwcap[(unsigned char)(*ext)];
200-
set_bit(*ext - 'a', this_isa);
199+
int nr = *ext - 'a';
200+
201+
this_hwcap |= isa2hwcap[nr];
202+
set_bit(nr, this_isa);
201203
} else {
202204
SET_ISA_EXT_MAP("sscofpmf", RISCV_ISA_EXT_SSCOFPMF);
203205
SET_ISA_EXT_MAP("svpbmt", RISCV_ISA_EXT_SVPBMT);

0 commit comments

Comments
 (0)