Skip to content

Commit

Permalink
RISC-V: Extract multi-letter extension names from "riscv, isa"
Browse files Browse the repository at this point in the history
Currently, there is no usage for version numbers in extensions as
any ratified non base ISA extension will always at v1.0.

Extract the extension names in place for future parsing.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com>
[Improved commit text and comments]
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
  • Loading branch information
Tsukasa OI authored and Palmer Dabbelt committed Mar 17, 2022
1 parent 2a31c54 commit 40a4d0d
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions arch/riscv/kernel/cpufeature.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,28 @@ void __init riscv_fill_hwcap(void)
ext_long = true;
/* Multi-letter extension must be delimited */
for (; *isa && *isa != '_'; ++isa)
if (!islower(*isa) && !isdigit(*isa))
if (unlikely(!islower(*isa)
&& !isdigit(*isa)))
ext_err = true;
/* Parse backwards */
ext_end = isa;
if (unlikely(ext_err))
break;
if (!isdigit(ext_end[-1]))
break;
/* Skip the minor version */
while (isdigit(*--ext_end))
;
if (ext_end[0] != 'p'
|| !isdigit(ext_end[-1])) {
/* Advance it to offset the pre-decrement */
++ext_end;
break;
}
/* Skip the major version */
while (isdigit(*--ext_end))
;
++ext_end;
break;
default:
if (unlikely(!islower(*ext))) {
Expand All @@ -151,14 +171,13 @@ void __init riscv_fill_hwcap(void)
}
if (*isa != '_')
--isa;
/*
* TODO: Full version-aware handling including
* multi-letter extensions will be added in-future.
*/
if (ext_err || ext_long)

if (unlikely(ext_err))
continue;
this_hwcap |= isa2hwcap[(unsigned char)(*ext)];
this_isa |= (1UL << (*ext - 'a'));
if (!ext_long) {
this_hwcap |= isa2hwcap[(unsigned char)(*ext)];
this_isa |= (1UL << (*ext - 'a'));
}
}

/*
Expand Down

0 comments on commit 40a4d0d

Please sign in to comment.