From 3c5c4cfa6bf4aa88bcd69e2688fdceea6a655165 Mon Sep 17 00:00:00 2001 From: Mark Hatle Date: Tue, 17 Jun 2025 18:39:38 -0500 Subject: riscv tunes: ISA Implementation of RISC-V tune features This implements the following base ISAs: * rv32i, rv64i * rv32e, rv64i The following ABIs: * ilp32, ilp32e, ilp32f, ilp32d * lp64, lp64e, lp64f, lp64d The following ISA extension are also implemented: * M - Integer Multiplication and Division Extension * A - Atomic Memory Extension * F - Single-Precision Floating-Point Extension * D - Double-Precision Floating-Point Extension * C - Compressed Extension * B - Bit Manipulation Extension (implies Zba, Zbb, Zbs) * V - Vector Operations Extension * Zicsr - Control and Status Register Access Extension * Zifencei - Instruction-Fetch Fence Extension * Zba - Address bit manipulation extension * Zbb - Basic bit manipulation extension * Zbc - Carry-less multiplication extension * Zbs - Single-bit manipulation extension * Zicbom - Cache-block management extension The existing processors tunes are preserved: * riscv64 (rv64gc) * riscv32 (rv32gc) * riscv64nf (rv64imac_zicsr_zifencei) * riscv32nf (rv32imac_zicsr_zifencei) * riscv64nc (rv64imafd_zicsr_zifencei) Previously defined feature 'big-endian' has been removed as it was not used. (From OE-Core rev: bcaf298a146dfd10e4c8f44223ea083bc4baf45c) Signed-off-by: Mark Hatle Signed-off-by: Richard Purdie --- meta/lib/oe/__init__.py | 2 +- meta/lib/oe/tune.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 meta/lib/oe/tune.py (limited to 'meta/lib') diff --git a/meta/lib/oe/__init__.py b/meta/lib/oe/__init__.py index dd094a874a..73de774266 100644 --- a/meta/lib/oe/__init__.py +++ b/meta/lib/oe/__init__.py @@ -12,4 +12,4 @@ __path__ = extend_path(__path__, __name__) BBIMPORTS = ["qa", "data", "path", "utils", "types", "package", "packagedata", \ "packagegroup", "sstatesig", "lsb", "cachedpath", "license", "qemu", \ "reproducible", "rust", "buildcfg", "go", "spdx30_tasks", "spdx_common", \ - "cve_check"] + "cve_check", "tune"] diff --git a/meta/lib/oe/tune.py b/meta/lib/oe/tune.py new file mode 100644 index 0000000000..7fda19430d --- /dev/null +++ b/meta/lib/oe/tune.py @@ -0,0 +1,81 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: GPL-2.0-only +# + +# riscv_isa_to_tune(isa) +# +# Automatically translate a RISC-V ISA string to TUNE_FEATURES +# +# Abbreviations, such as rv32g -> rv32imaffd_zicsr_zifencei are supported. +# +# Profiles, such as rva22u64, are NOT supported, you must use ISA strings. +# +def riscv_isa_to_tune(isa): + _isa = isa.lower() + + feature = [] + iter = 0 + + # rv or riscv + if _isa[iter:].startswith('rv'): + feature.append('rv') + iter = iter + 2 + elif _isa[iter:].startswith('riscv'): + feature.append('rv') + iter = iter + 5 + else: + # Not a risc-v ISA! + return _isa + + while (_isa[iter:]): + # Skip _ and whitespace + if _isa[iter] == '_' or _isa[iter].isspace(): + iter = iter + 1 + continue + + # Length, just capture numbers here + if _isa[iter].isdigit(): + iter_end = iter + while iter_end < len(_isa) and _isa[iter_end].isdigit(): + iter_end = iter_end + 1 + + feature.append(_isa[iter:iter_end]) + iter = iter_end + continue + + # Typically i, e or g is next, followed by extensions. + # Extensions are single character, except for Z, Ss, Sh, Sm, Sv, and X + + # If the extension starts with 'Z', 'S' or 'X' use the name until the next _, whitespace or end + if _isa[iter] in ['z', 's', 'x']: + ext_type = _isa[iter] + iter_end = iter + 1 + + # Multicharacter extension, these are supposed to have a _ before the next multicharacter extension + # See 37.4 and 37.5: + # 37.4: Underscores "_" may be used to separate ISA extensions... + # 37.5: All multi-letter extensions ... must be separated from other multi-letter extensions by an underscore... + # Some extensions permit only alphabetic characters, while others allow alphanumeric chartacters + while iter_end < len(_isa) and _isa[iter_end] != "_" and not _isa[iter_end].isspace(): + iter_end = iter_end + 1 + + feature.append(_isa[iter:iter_end]) + iter = iter_end + continue + + # 'g' is special, it's an abbreviation for imafd_zicsr_zifencei + # When expanding the abbreviation, any additional letters must appear before the _z* extensions + if _isa[iter] == 'g': + _isa = 'imafd' + _isa[iter+1:] + '_zicsr_zifencei' + iter = 0 + continue + + feature.append(_isa[iter]) + iter = iter + 1 + continue + + # Eliminate duplicates, but preserve the order + feature = list(dict.fromkeys(feature)) + return ' '.join(feature) -- cgit v1.2.3-54-g00ecf