Skip to contentSkip to conversation

riscv: add new ISA extensions, profiles, and selftests

PATCH In review Trevor Gamblin 3 participants 15 messages Nov 18 – Nov 23 RISC-V

lore
Share & tools
lore
#0 lore raw

cover riscv: add new ISA extensions, profiles, and selftests

Note: This series is based on an earlier set of RFCs, of which v2 can be found at [1]. The changes here are also found in my contrib branch at [2]. I've been reviewing this myself and throwing an LLM at it for feedback, and I believe it's mature enough now compared to the initial versions that others ought to take another look, so please let me know what you think.

# Overview

Support for the RISC-V architecture and a basic set of extensions has been available in oe-core for a long time now, and as of late 2025, QEMU defaults to the RVA23S64 profile when booting qemuriscv64 images. However, at the userspace level, we currently support only the standard "riscv64gc" profile (behind a generic "riscv64" identifier), which is common across the wider open-source ecosystem, but lacks many of the features which are starting to become necessary for more advanced experimentation and testing on RISC-V platforms. This series aims to remedy that by introducing several changes across a handful of files.

Compared to the previous RFCs, the following changes were submitted and accepted separately:
1. tune-riscv: be explicit about riscv32gc, riscv64gc defaults
2. tune-riscv.inc: add 'riscv64gcv' tune

The patches here do the following, while trying to follow similar design decisions made for x86-64 and ARM in oe-core:

1. Adopt a new 'RISCVPKGARCH' variable (like 'ARMPKGARCH') which should be set for any new custom tune files, especially those that happen to have very complicated/non-standard extension sets
2. Add 'rva20u64', 'rva22u64', and 'rva23u64' tunes along with all extensions they mandate to arch-riscv.inc
3. Extend lib/oe/tune.py with a RISCV_PROFILES list, which is used to test and shorten extension strings for build paths
4. Add two new sets of selftests:
a. lib/oeqa/selftest/cases/oelib/tune.py, for testing the code in lib/oe/tune.py
b. lib/oeqa/selftest/cases/riscvtunes.py, for testing the various RISC-V tunings themselves. This includes an "unusual tunes" test where libgcc-initial is built for a handful of nonstandard extension combinations, so it's a bit heavier.
5. Allow 'superset' package archs to install packages built for subset tunings
6. Extend rust-target-config.bbclass so that it handles all of the extensions (avoiding a scenario where a build would target e.g. rva23u64 but Rust-based packages would still build against riscv64gc), and add a selftest for that
7. Report an error and provide a suggestion to the user when a tuning exceeds the allowable length of a package arch (i.e. set RISCVPKGARCH with a proper tune name, instead of letting the whole extension string hit the path)

The last entry is possibly the most significant one compared to earlier revisions of this work - it's now a much simpler and more 'strict' solution to the extension string length problem discussed in the RFC. Specifically, earlier attempts were made to try and support a very flexible "set any extension string you want" approach for users to experiment with, using a bitmask and/or hashing function to shorten the string for build/sstate paths. However, this required a lot of extra code to be maintained (including extra selftests) with essentially the only gain being to allow tunes to be set on-the-fly in local.conf, and it also meant that build paths became more obscure in order to keep their naming short. For example, a tuning for the SpacemiT X60 tune would have 'readable' and 'hashed' names like:

|readable: rva22u64_v_zbc_zfh_zicond_zifencei_zihpm_zvfh_zvkt |hashed: rva22u64_0x089e3d7dd8

After discussion in a recent technical call, this seems best suited to inclusion in the meta-riscv layer (if we feel it's needed at all). For now, This series (and a corresponding meta-riscv PR to add BSP-specific tunings) should be sufficient with its 'strict' tunes. The new profiles with explicit tunes get build paths in the TMPDIR like:

|rva20u64_zifencei
|rva22u64_zifencei
|rva23u64_zifencei

## Implementation, and Relation to meta-riscv

With this series in, oe-core will support all **mandated** extensions for all ratified profiles up to and including RVA23, according to the spec in [3], but not optional/development/expansion options. Some of these will be incorporated in the aforementioned companion PR [4], which will add 'spacemit-x60' and 'spacemit-x100' tunes along with corresponding selftests. Those extensions may be worth moving to oe-core as well eventually (especially if many future boards and/or profiles mandate them), but for now I think the mandated extension sets are enough to manage.

The selftests have been designed largely with Claude Code Opus 5.5, with the goal of helping us track any changes that may occur over time with toolchains or variable/logic changes in oe-core. That being said, I doubt the profiles themselves will change, so setting things like RISCV_PROFILES in tune.py should be stable. With riscvtunes.py, the objective is to ensure that the tune files themselves follow a consistent standard, which means that changes will need to be made there in the future if we alter the way different architectures' tunings are defined. Also worth noting that, compared to the RFC versions, the selftest suites have been expanded significantly - the initial versions were very 'thin' and often only covered a few cases at most, so I've made a point to increase the variety of asserts running in each test to handle more edge cases.

For now, the default tuning for qemuriscv64 remains 'riscv64gc', so there are still no explicit consumers of the new profiles in oe-core. They can be enabled easily by setting DEFAULTTUNE in local.conf when building for qemuriscv64, e.g. DEFAULTTUNE = 'rva23u64'. They **are** consumed by two new BSP-specific tunings added in [4]. qemuriscv32 and the 'riscv32gc' tuning have been mostly untouched by this series, other than to provide some selftests.

## Testing

### Selftests

oe-selftest -r oelib.tune:

|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_abbreviation: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_duplicates: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_explicit: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_multi_letter_prefixes: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_not_riscv: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_profile: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_profile_sizes: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_rva22u64_additions: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_rva23u64_additions: PASSED (0.00s)
|2026-11-18 15:25:02,172 - oe-selftest - INFO - RESULTS - oelib.tune.TestRiscvIsaToTune.test_separators: PASSED (0.00s)
|2026-11-18 15:25:02,173 - oe-selftest - INFO - SUMMARY:
|2026-11-18 15:25:02,173 - oe-selftest - INFO - oe-selftest () - Ran 10 tests in 5.167s
|2026-11-18 15:25:02,173 - oe-selftest - INFO - oe-selftest - OK - All required tests passed (successes=10, skipped=0, failures=0, errors=0)

oe-selftest -r riscvtunes:

|2026-11-18 15:30:51,286 - oe-selftest - INFO - RESULTS:
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_default_tunes: PASSED (12.07s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_pkgarch_fallback: PASSED (2.01s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_profile_ccargs: PASSED (3.16s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_rust_target_features: PASSED (32.90s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - RESULTS - riscvtunes.RiscvTunesTests.test_riscv_unusual_tunes: PASSED (84.92s)
|2026-11-18 15:30:51,287 - oe-selftest - INFO - SUMMARY:
|2026-11-18 15:30:51,287 - oe-selftest - INFO - oe-selftest () - Ran 5 tests in 147.710s
|2026-11-18 15:30:51,287 - oe-selftest - INFO - oe-selftest - OK - All required tests passed (successes=5, skipped=0, failures=0, errors=0)

### QEMU Tests

To showcase what the tuning differences look like in practice, below are some examples of how things look when core-image-ptest-coreutils (which I've used as a benchmark in the RFC) is built, booted (including a ptest run) for qemuriscv64 with each profile set for DEFAULTTUNE in turn. This was all performed on my local 12-core workstation and with QEMU's TCG emulation mode. The buildinfo data was set using:

|IMAGE_CLASSES += "image-buildinfo"
|IMAGE_BUILDINFO_VARS = "DISTRO DISTRO_VERSION MACHINE TUNE_FEATURES"

Also note that the 'rva23u64' coreutils ptest took significantly longer than the others. I suspect that some packages which make use of the new extensions will show similar differences. An example is ffmpeg, which needs 'zba' and 'zbb' (among others) - an upstream discussion [5] suggests that building it without those (which we'd do with the riscv64gc tune) could have performance implications.

riscv64gc:

|root@qemuriscv64:~# cat /etc/buildinfo
|-----------------------
|Build Configuration:  |
|-----------------------
|DISTRO = nodistro
|DISTRO_VERSION = nodistro.0
|MACHINE = qemuriscv64
|TUNE_FEATURES = rv 64 i m a f d c zicsr zifencei
|-----------------------
|Layer Revisions:      |
|-----------------------
|meta              = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|meta-selftest     = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|root@qemuriscv64:~#
|============================================================================
|Testsuite summary for GNU coreutils 9.12
|============================================================================
|# TOTAL: 759
|# PASS:  591
|# SKIP:  168
|# XFAIL: 0
|# FAIL:  0
|# XPASS: 0
|# ERROR: 0
|============================================================================
|make[1]: Leaving directory '/usr/lib/coreutils/ptest'
|DURATION: 758
|END: /usr/lib/coreutils/ptest
|2026-11-18T19:20
|STOP: ptest-runner
|TOTAL: 1 FAIL: 0

rva20u64:

|root@qemuriscv64:~# cat /etc/buildinfo
|-----------------------
|Build Configuration:  |
|-----------------------
|DISTRO = nodistro
|DISTRO_VERSION = nodistro.0
|MACHINE = qemuriscv64
|TUNE_FEATURES = rv 64 i m a f d c ziccamoa ziccif zicclsm ziccrse zicntr zicsr zmmul za128rs zaamo zalrsc zca zcd zifencei
|-----------------------
|Layer Revisions:      |
|-----------------------
|meta              = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|meta-selftest     = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|root@qemuriscv64:~#
|============================================================================
|Testsuite summary for GNU coreutils 9.12
|============================================================================
|# TOTAL: 759
|# PASS:  591
|# SKIP:  168
|# XFAIL: 0
|# FAIL:  0
|# XPASS: 0
|# ERROR: 0
|============================================================================
|make[1]: Leaving directory '/usr/lib/coreutils/ptest'
|DURATION: 760
|END: /usr/lib/coreutils/ptest
|2026-11-18T19:36
|STOP: ptest-runner
|TOTAL: 1 FAIL: 0
|root@qemuriscv64:~#

rva22u64:

|root@qemuriscv64:~# cat /etc/buildinfo
|-----------------------
|Build Configuration:  |
|-----------------------
|DISTRO = nodistro
|DISTRO_VERSION = nodistro.0
|MACHINE = qemuriscv64
|TUNE_FEATURES = rv 64 i m a f d c b zic64b zicbom zicbop zicboz ziccamoa ziccif zicclsm ziccrse zicntr zicsr zihintpause zihpm zmmul za64rs zaamo zalrsc zfhmin zca zcd zba zbb zbs zkt zifencei
|-----------------------
|Layer Revisions:      |
|-----------------------
|meta              = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|meta-selftest     = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|root@qemuriscv64:~#
|============================================================================
|Testsuite summary for GNU coreutils 9.12
|============================================================================
|# TOTAL: 759
|# PASS:  591
|# SKIP:  168
|# XFAIL: 0
|# FAIL:  0
|# XPASS: 0
|# ERROR: 0
|============================================================================
|make[1]: Leaving directory '/usr/lib/coreutils/ptest'
|DURATION: 730
|END: /usr/lib/coreutils/ptest
|2026-11-18T19:52
|STOP: ptest-runner
|TOTAL: 1 FAIL: 0
|root@qemuriscv64:~#

rva23u64:

|root@qemuriscv64:~# cat /etc/buildinfo
|-----------------------
|Build Configuration:  |
|-----------------------
|DISTRO = nodistro
|DISTRO_VERSION = nodistro.0
|MACHINE = qemuriscv64
|TUNE_FEATURES = rv 64 i m a f d c b v zic64b zicbom zicbop zicboz ziccamoa ziccif zicclsm ziccrse zicntr zicond zicsr zihintntl zihintpause zihpm zimop zmmul za64rs zaamo zalrsc zawrs zfa zfhmin zca zcb zcd zcmop zba zbb zbs zkt zvbb zve32f zve32x zve64d zve64f zve64x zvfhmin zvkb zvkt zvl128b zvl32b zvl64b supm zifencei
|-----------------------
|Layer Revisions:      |
|-----------------------
|meta              = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|meta-selftest     = tgamblin/riscv-tuning-strict:ead59b58fdda4df71f394e80c2fe451f5732b133
|root@qemuriscv64:~#
|============================================================================
|Testsuite summary for GNU coreutils 9.12
|============================================================================
|# TOTAL: 759
|# PASS:  591
|# SKIP:  168
|# XFAIL: 0
|# FAIL:  0
|# XPASS: 0
|# ERROR: 0
|============================================================================
|make[1]: Leaving directory '/usr/lib/coreutils/ptest'
|DURATION: 1102
|END: /usr/lib/coreutils/ptest
|2026-11-18T20:14
|STOP: ptest-runner
|TOTAL: 1 FAIL: 0
|root@qemuriscv64:~#

[1]: https://lore.kernel.org/openembedded-core/[email protected]/
[2]: https://git.openembedded.org/openembedded-core-contrib/log/?h=tgamblin/riscv-tuning-strict
[3]: https://docs.riscv.org/reference/rva23/v1.0/rva23-profiles.html
[4]: https://github.com/riscv/meta-riscv/pull/739
[5]: https://www.mail-archive.com/[email protected]/msg69408.html

Trevor Gamblin (12):
arch-riscv.inc, tune-riscv.inc: add RISCVPKGARCH arch-riscv.inc: add zmmul, zaamo, zalrsc, zca, zcd lib/oe/tune.py: support RISC-V profiles in riscv_isa_to_tune() lib/oeqa/selftest/cases/oelib/tune.py: add selftests for
lib/oe/tune.py
arch-riscv.inc, tune-riscv.inc: add rva20u64 tune arch-riscv.inc, tune-riscv.inc: add rva22u64 tune arch-riscv.inc, tune-riscv.inc: add rva23u64 tune tune-riscv.inc: set PACKAGE_EXTRA_ARCHS for supersets meta/conf/machine/include/riscv/arch-riscv.inc: error on very long
package archs
lib/oeqa/selftest/cases/riscvtunes.py: add RISC-V tune selftests rust-target-config.bbclass: pass on all RISC-V extensions to LLVM lib/oeqa/selftest/cases/riscvtunes.py: test Rust target features

 .../classes-recipe/rust-target-config.bbclass |  34 +---
 meta/conf/machine/include/riscv/README        |  14 +-
 .../conf/machine/include/riscv/arch-riscv.inc | 189 +++++++++++++++++-
 .../conf/machine/include/riscv/tune-riscv.inc |  40 +++-
 meta/lib/oe/tune.py                           |  26 ++-
 meta/lib/oeqa/selftest/cases/oelib/tune.py    |  81 ++++++++
 meta/lib/oeqa/selftest/cases/riscvtunes.py    | 174 ++++++++++++++++
 7 files changed, 519 insertions(+), 39 deletions(-)
 create mode 100644 meta/lib/oeqa/selftest/cases/oelib/tune.py
 create mode 100644 meta/lib/oeqa/selftest/cases/riscvtunes.py
Signature · 1 line
2.56.0
#1 lore raw

PATCH 1/12 arch-riscv.inc, tune-riscv.inc: add RISCVPKGARCH

Set each generic RISC-V tune's package arch as a literal in RISCVPKGARCH:tune-<name>, matching how we do so for ARM and ARMPKGARCH. Include a fallback to TUNE_RISCV_PKGARCH for tunes that don't set RISCVPKGARCH:tune-<name>.

No package arch changes.

---
 meta/conf/machine/include/riscv/README        | 10 ++++++++--
 .../conf/machine/include/riscv/arch-riscv.inc |  8 ++++++--
 .../conf/machine/include/riscv/tune-riscv.inc | 20 +++++++++++++------
 3 files changed, 28 insertions(+), 10 deletions(-)
meta/conf/machine/include/riscv/README +8 -2
index beef68f523..b17c86c814 100644
@@ -87,7 +87,13 @@ TUNE_RISCV_ABI - This is the generated ABI that corresponds to the ARCH and
                  ISA variation.  The ISA affects the ABI when the 'e', 'f'
                  and 'd' extension are used.
 
-TUNE_RISCV_PKGARCH - This is the generated PKGARCH value.
+TUNE_RISCV_PKGARCH - This is the PKGARCH value generated from TUNE_FEATURES.
+
+RISCVPKGARCH - This is the package arch actually used.  As with ARMPKGARCH
+               on arm, each tune sets it as a literal in
+               RISCVPKGARCH:tune-<name>, so that it only changes when
+               deliberately changed.  Tunes that don't set it fall back to
+               TUNE_RISCV_PKGARCH.
 
 The standard variables are defined as:
 
@@ -99,7 +105,7 @@ not adequate for some reason.  It is expected that most, if not all,
 implementations will use the default behavior.
 
 TUNE_ARCH = "${TUNE_RISCV_ARCH}"
-TUNE_PKGARCH = "${TUNE_RISCV_PKGARCH}"
+TUNE_PKGARCH = "${RISCVPKGARCH}"
 
 The above two will always base their setting off the standard TUNE_FEATURES.
 
meta/conf/machine/include/riscv/arch-riscv.inc +6 -2
index 6f9b74974d..b2a9aa8952 100644
@@ -121,9 +121,13 @@ TUNE_CCARGS = "${@ '-march=${TUNE_RISCV_MARCH} -mabi=${TUNE_RISCV_ABI}' if not d
 TUNE_ARCH = "${TUNE_RISCV_ARCH}"
 
 # Construct TUNE_PKGARCH
-# This should result in a package are like:
+# As with ARMPKGARCH on arm, each tune sets its package arch as a literal in
+# RISCVPKGARCH:tune-<name>, so that it only changes when deliberately changed.
+# Tunes that don't set it fall back to TUNE_RISCV_PKGARCH, which is built from
+# TUNE_FEATURES above, e.g.:
 #    riscv32imac
-TUNE_PKGARCH = "${TUNE_RISCV_PKGARCH}"
+RISCVPKGARCH = "${@d.getVar('RISCVPKGARCH:tune-${DEFAULTTUNE}') or d.getVar('TUNE_RISCV_PKGARCH')}"
+TUNE_PKGARCH = "${RISCVPKGARCH}"
 
 # Misc settings
 # Fix: ld: unrecognized option '--hash-style=sysv'
meta/conf/machine/include/riscv/tune-riscv.inc +14 -6
index ed71dc06ba..88c9184c8b 100644
@@ -6,27 +6,35 @@ AVAILTUNES += "riscv64gcv riscv64gc riscv32gc riscv64 riscv32 riscv64nc riscv64n
 
 # Default
 TUNE_FEATURES:tune-riscv64gc := "${@oe.tune.riscv_isa_to_tune("rv64gc")}"
-PACKAGE_EXTRA_ARCHS:tune-riscv64gc = "${TUNE_RISCV_PKGARCH}"
+RISCVPKGARCH:tune-riscv64gc ?= "riscv64imafdc_zicsr_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-riscv64gc = "${RISCVPKGARCH:tune-riscv64gc}"
 
 TUNE_FEATURES:tune-riscv64gcv := "${@oe.tune.riscv_isa_to_tune("rv64gcv")}"
-PACKAGE_EXTRA_ARCHS:tune-riscv64gcv = "${TUNE_RISCV_PKGARCH}"
+RISCVPKGARCH:tune-riscv64gcv ?= "riscv64imafdcv_zicsr_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-riscv64gcv = "${RISCVPKGARCH:tune-riscv64gcv}"
 
 TUNE_FEATURES:tune-riscv32gc := "${@oe.tune.riscv_isa_to_tune("rv32gc")}"
-PACKAGE_EXTRA_ARCHS:tune-riscv32gc = "${TUNE_RISCV_PKGARCH}"
+RISCVPKGARCH:tune-riscv32gc ?= "riscv32imafdc_zicsr_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-riscv32gc = "${RISCVPKGARCH:tune-riscv32gc}"
 
 # Compatibility aliases so that layers using old tunes don't break
 TUNE_FEATURES:tune-riscv64 := "${TUNE_FEATURES:tune-riscv64gc}"
+RISCVPKGARCH:tune-riscv64 ?= "${RISCVPKGARCH:tune-riscv64gc}"
 PACKAGE_EXTRA_ARCHS:tune-riscv64 = "${PACKAGE_EXTRA_ARCHS:tune-riscv64gc}"
 TUNE_FEATURES:tune-riscv32 := "${TUNE_FEATURES:tune-riscv32gc}"
+RISCVPKGARCH:tune-riscv32 ?= "${RISCVPKGARCH:tune-riscv32gc}"
 PACKAGE_EXTRA_ARCHS:tune-riscv32 = "${PACKAGE_EXTRA_ARCHS:tune-riscv32gc}"
 
 # No float
 TUNE_FEATURES:tune-riscv64nf := "${@oe.tune.riscv_isa_to_tune("rv64imac_zicsr_zifencei")}"
-PACKAGE_EXTRA_ARCHS:tune-riscv64nf = "${TUNE_RISCV_PKGARCH}"
+RISCVPKGARCH:tune-riscv64nf ?= "riscv64imac_zicsr_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-riscv64nf = "${RISCVPKGARCH:tune-riscv64nf}"
 
 TUNE_FEATURES:tune-riscv32nf := "${@oe.tune.riscv_isa_to_tune("rv32imac_zicsr_zifencei")}"
-PACKAGE_EXTRA_ARCHS:tune-riscv32nf = "${TUNE_RISCV_PKGARCH}"
+RISCVPKGARCH:tune-riscv32nf ?= "riscv32imac_zicsr_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-riscv32nf = "${RISCVPKGARCH:tune-riscv32nf}"
 
 # no compressed
 TUNE_FEATURES:tune-riscv64nc := "${@oe.tune.riscv_isa_to_tune("rv64imafd_zicsr_zifencei")}"
-PACKAGE_EXTRA_ARCHS:tune-riscv64nc = "${TUNE_RISCV_PKGARCH}"
+RISCVPKGARCH:tune-riscv64nc ?= "riscv64imafd_zicsr_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-riscv64nc = "${RISCVPKGARCH:tune-riscv64nc}"
Signature · 1 line
2.56.0
#2 lore raw

PATCH 2/12 arch-riscv.inc: add zmmul, zaamo, zalrsc, zca, zcd

In reply to Trevor Gamblin

Add TUNE_FEATURES for the zmmul, zaamo, zalrsc, zca, and zcd extensions, which are enabled by compilers with m, a, c, and c with d:

|tgamblin@megalith ~/workspace/git/linux (master)$ riscv64-linux-gnu-gcc -march=rv64gc -mabi=lp64d -Q --help=target | grep march
|  --print-supported-extensions          -march=help
|  -march=                               rv64imafdc_zicsr_zifencei_zmmul_zaamo_zalrsc_zca_zcd
|  -march=help                           [disabled]
|  -print-supported-extensions           -march=help

Only pass them to '-march' when TUNE_FEATURES lists them, so that '-march' doesn't change for existing tunes. Also add them to the generated package arch, so that e.g. 'rv64ia_zmmul' doesn't share a package arch with 'rv64ia', but only when the extension that they're a subset of isn't enabled, so that e.g. 'rv64ima_zmmul' still shares one with 'rv64ima', as the code is the same.

---
 .../conf/machine/include/riscv/arch-riscv.inc | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)
meta/conf/machine/include/riscv/arch-riscv.inc +25 -0
index b2a9aa8952..6883e39a5f 100644
@@ -94,6 +94,31 @@ TUNEVALID[zifencei] = "Instruction-fetch fence extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
 
+# zmmul, zaamo, zalrsc, zca and zcd are subsets of single-letter extensions
+# above (m, a, c and c with d), which compilers enable along with them. They
+# are only passed on when listed in TUNE_FEATURES, so that -march doesn't
+# change for existing tunes, and only added to the package arch when the
+# extension they're part of isn't enabled.
+TUNEVALID[zmmul] = "Integer multiplication (without division) extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zmmul", "_zmmul", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zmmul", bb.utils.contains("TUNE_FEATURES", "m", "", "_zmmul", d), "", d)}"
+
+TUNEVALID[zaamo] = "Atomic memory operations extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zaamo", "_zaamo", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zaamo", bb.utils.contains("TUNE_FEATURES", "a", "", "_zaamo", d), "", d)}"
+
+TUNEVALID[zalrsc] = "Load-reserved/store-conditional extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zalrsc", "_zalrsc", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zalrsc", bb.utils.contains("TUNE_FEATURES", "a", "", "_zalrsc", d), "", d)}"
+
+TUNEVALID[zca] = "Compressed integer instructions extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zca", "_zca", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zca", bb.utils.contains("TUNE_FEATURES", "c", "", "_zca", d), "", d)}"
+
+TUNEVALID[zcd] = "Compressed double-precision floating-point instructions extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zcd", "_zcd", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zcd", bb.utils.contains("TUNE_FEATURES", "c d", "", "_zcd", d), "", d)}"
+
 TUNEVALID[zba] = "Address bit manipulation extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "b zba", "_zba", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "b zba", "_zba", "", d)}"
Signature · 1 line
2.56.0
#3 lore raw

PATCH 3/12 lib/oe/tune.py: support RISC-V profiles in riscv_isa_to_tune()

In reply to Trevor Gamblin

Add RISCV_PROFILES for mapping the rva20u64, rva22u64, and rva23u64 profile names to their extension sets according to the RISC-V Profiles specification. riscv_isa_to_tune() now accepts them in addition to ISA strings, for tunes based on a profile.

---
 meta/conf/machine/include/riscv/README |  3 +++
 meta/lib/oe/tune.py                    | 21 +++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
meta/conf/machine/include/riscv/README +3 -0
index b17c86c814..ef7a484f25 100644
@@ -126,3 +126,6 @@ rv32g -> rv 32 i m a f d zicsr zifencei
 The helper can be called using oe.tune.riscv_isa_to_tune("<ISA>") such as
 oe.tune.riscv_isa_to_tune("rv64gc") which would return:
  rv 64 i m a f d c zicsr zifencei
+
+The RISC-V profile names listed in RISCV_PROFILES in lib/oe/tune.py, such as
+rva22u64, are also accepted, and return the profile's mandatory extensions.
meta/lib/oe/tune.py +19 -2
index 7fda19430d..580c84d4fa 100644
@@ -4,16 +4,33 @@
 # SPDX-License-Identifier: GPL-2.0-only
 #
 
+# RISC-V profile name -> equivalent ISA string, i.e. the mandatory extensions of
+# each profile as ratified in the RISC-V Profiles specification
+# (https://github.com/riscv/riscv-profiles):
+#   RVA20U64, RVA22U64: RVA20/RVA22 Profiles, version 1.0
+#   RVA23U64: RVA23 Profiles, version 1.0
+# plus the extensions those imply (e.g. zmmul, zaamo, zca, zve*).
+#
+# Do not regenerate these from compiler output (e.g. gcc's -march expansion);
+# a newer compiler, or clang, may expand a profile differently. For example,
+# gcc's rva22u64 leaves out zihpm, which the specification makes mandatory.
+RISCV_PROFILES = {
+    'rva20u64': 'rv64imafdc_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicsr_zmmul_za128rs_zaamo_zalrsc_zca_zcd',
+    'rva22u64': 'rv64imafdcb_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicsr_zihintpause_zihpm_zmmul_za64rs_zaamo_zalrsc_zfhmin_zca_zcd_zba_zbb_zbs_zkt',
+    'rva23u64': 'rv64imafdcbv_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zicond_zicsr_zihintntl_zihintpause_zihpm_zimop_zmmul_za64rs_zaamo_zalrsc_zawrs_zfa_zfhmin_zca_zcb_zcd_zcmop_zba_zbb_zbs_zkt_zvbb_zve32f_zve32x_zve64d_zve64f_zve64x_zvfhmin_zvkb_zvkt_zvl128b_zvl32b_zvl64b_supm',
+}
+
 # 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.
+# The profile names in RISCV_PROFILES, such as rva22u64, are also supported,
+# and are translated to the profile's mandatory extensions.
 #
 def riscv_isa_to_tune(isa):
-    _isa = isa.lower()
+    _isa = RISCV_PROFILES.get(isa.lower(), isa).lower()
 
     feature = []
     iter = 0
Signature · 1 line
2.56.0
#4 lore raw

Patchtest results for [OE-core][PATCH 03/12] lib/oe/tune.py: support RISC-V profiles in riscv_isa_to_tune()

Thank you for your submission. Patchtest identified one or more issues with the patch. Please see the log below for more information:

---
Testing patch /home/patchtest/share/mboxes/03-12-lib-oe-tune.py-support-RISC-V-profiles-in-riscv_isa_to_tune.patch

FAIL: test max line length: Patch line too long (current length 307, maximum is 200) (test_metadata.TestMetadata.test_max_line_length)

PASS: pretest pylint (test_python_pylint.PyLint.pretest_pylint)
PASS: test Signed-off-by presence (test_mbox.TestMbox.test_signed_off_by_presence)
PASS: test auh changelog truncation notice (test_mbox.TestMbox.test_auh_changelog_truncation_notice)
PASS: test author valid (test_mbox.TestMbox.test_author_valid)
PASS: test commit message presence (test_mbox.TestMbox.test_commit_message_presence)
PASS: test commit message user tags (test_mbox.TestMbox.test_commit_message_user_tags)
PASS: test mbox format (test_mbox.TestMbox.test_mbox_format)
PASS: test non-AUH upgrade (test_mbox.TestMbox.test_non_auh_upgrade)
PASS: test pylint (test_python_pylint.PyLint.test_pylint)
PASS: test shortlog format (test_mbox.TestMbox.test_shortlog_format)
PASS: test shortlog length (test_mbox.TestMbox.test_shortlog_length)
PASS: test target mailing list (test_mbox.TestMbox.test_target_mailing_list)

SKIP: pretest src uri left files: No modified recipes, skipping pretest (test_metadata.TestMetadata.pretest_src_uri_left_files)
SKIP: test CVE check ignore: No modified recipes or older target branch, skipping test (test_metadata.TestMetadata.test_cve_check_ignore)
SKIP: test CVE tag format: No new source patches introduced (test_patch.TestPatch.test_cve_tag_format)
SKIP: test Signed-off-by presence: No new source patches introduced (test_patch.TestPatch.test_signed_off_by_presence)
SKIP: test Upstream-Status presence: No new source patches introduced (test_patch.TestPatch.test_upstream_status_presence_format)
SKIP: test bugzilla entry format: No bug ID found (test_mbox.TestMbox.test_bugzilla_entry_format)
SKIP: test lic files chksum modified not mentioned: No modified recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_modified_not_mentioned)
SKIP: test lic files chksum presence: No added recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_presence)
SKIP: test license presence: No added recipes, skipping test (test_metadata.TestMetadata.test_license_presence)
SKIP: test series merge on head: Merge test is disabled for now (test_mbox.TestMbox.test_series_merge_on_head)
SKIP: test src uri left files: No modified recipes, skipping test (test_metadata.TestMetadata.test_src_uri_left_files)
SKIP: test summary presence: No added recipes, skipping test (test_metadata.TestMetadata.test_summary_presence)

---

Please address the issues identified and
submit a new revision of the patch, or alternatively, reply to this email with an explanation of why the patch should be accepted. If you believe these results are due to an error in patchtest, please submit a bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category under 'Yocto Project Subprojects'). For more information on specific failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank you!

#5 lore raw

PATCH 4/12 lib/oeqa/selftest/cases/oelib/tune.py: add selftests for lib/oe/tune.py

In reply to Trevor Gamblin

Add basic selftests for tune.py's riscv_isa_to_tune() function, covering:

- Abbreviations of tune feature lists
- Explicit tuning mappings
- Whitespace as valid separators in tuning lists
- Duplicate extensions only appear once
- Extensions starting with z, s, or x are not shortened
- Non-RISC-V architecture strings don't result in valid RISC-V tunings
- Profile names and ISA strings are parsed the same
- Expected profile ISA string lengths
- Deltas between successive profiles' extension sets (e.g. RVA22 vs RVA20, RVA23 vs RVA22)

AI-Generated: Uses Claude Opus 5.5

---
 meta/lib/oeqa/selftest/cases/oelib/tune.py | 81 ++++++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/oelib/tune.py
meta/lib/oeqa/selftest/cases/oelib/tune.py new file +81 -0
new file mode 100644
index 0000000000..e851876588
@@ -0,0 +1,81 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+from unittest.case import TestCase
+from oe.tune import RISCV_PROFILES, riscv_isa_to_tune
+
+def _features(isa):
+    return set(riscv_isa_to_tune(isa).split())
+
+class TestRiscvIsaToTune(TestCase):
+    def test_abbreviation(self):
+        self.assertEqual(riscv_isa_to_tune('rv32g'), 'rv 32 i m a f d zicsr zifencei')
+        self.assertEqual(riscv_isa_to_tune('rv64g'), 'rv 64 i m a f d zicsr zifencei')
+        self.assertEqual(riscv_isa_to_tune('rv64gc'), 'rv 64 i m a f d c zicsr zifencei')
+        self.assertEqual(riscv_isa_to_tune('rv32gcv'), 'rv 32 i m a f d c v zicsr zifencei')
+        # Single-letter extensions after g stay ahead of the multi-letter ones
+        self.assertEqual(riscv_isa_to_tune('rv64gcv_zba'), 'rv 64 i m a f d c v zba zicsr zifencei')
+
+    def test_explicit(self):
+        self.assertEqual(riscv_isa_to_tune('rv32imac_zicsr_zifencei'), 'rv 32 i m a c zicsr zifencei')
+        self.assertEqual(riscv_isa_to_tune('rv32ec'), 'rv 32 e c')
+        self.assertEqual(riscv_isa_to_tune('RV64IMAFD_Zicsr'), 'rv 64 i m a f d zicsr')
+        # riscv as well as rv
+        self.assertEqual(riscv_isa_to_tune('riscv64gc'), riscv_isa_to_tune('rv64gc'))
+
+    def test_separators(self):
+        self.assertEqual(riscv_isa_to_tune('rv64imac zicsr'), 'rv 64 i m a c zicsr')
+
+    def test_duplicates(self):
+        self.assertEqual(riscv_isa_to_tune('rv64imac_zicsr_zicsr'), 'rv 64 i m a c zicsr')
+
+    def test_multi_letter_prefixes(self):
+        # z, s and x extensions are all kept whole
+        self.assertEqual(riscv_isa_to_tune('rv64gc_xtheadba_svpbmt'),
+                         'rv 64 i m a f d c xtheadba svpbmt zicsr zifencei')
+
+    def test_not_riscv(self):
+        self.assertEqual(riscv_isa_to_tune('x86_64'), 'x86_64')
+        self.assertEqual(riscv_isa_to_tune('aarch64'), 'aarch64')
+        self.assertEqual(riscv_isa_to_tune(''), '')
+
+    def test_profile(self):
+        self.assertEqual(riscv_isa_to_tune('rva20u64'),
+                         'rv 64 i m a f d c ziccamoa ziccif zicclsm ziccrse zicntr zicsr zmmul za128rs zaamo zalrsc zca zcd')
+        for name, isa in RISCV_PROFILES.items():
+            with self.subTest(profile=name):
+                tune = riscv_isa_to_tune(name).split()
+                self.assertEqual(tune, riscv_isa_to_tune(isa).split())
+                self.assertEqual(riscv_isa_to_tune(name.upper()).split(), tune)
+                self.assertEqual(tune[:3], ['rv', '64', 'i'])
+                self.assertEqual(len(tune), len(set(tune)))
+                # Required by Linux, but not by the profiles
+                self.assertNotIn('zifencei', tune)
+
+    def test_profile_sizes(self):
+        self.assertEqual(len(_features('rva20u64')), 20)
+        self.assertEqual(len(_features('rva22u64')), 32)
+        self.assertEqual(len(_features('rva23u64')), 53)
+
+    def test_rva22u64_additions(self):
+        # Everything in RVA20U64 is in RVA22U64, except that the latter's za64rs
+        # (a reservation set of at most 64 bytes) replaces za128rs
+        rva20 = _features('rva20u64')
+        rva22 = _features('rva22u64')
+        self.assertEqual(rva20 - rva22, {'za128rs'})
+        self.assertEqual(rva22 - rva20,
+                         {'b', 'za64rs', 'zba', 'zbb', 'zbs', 'zfhmin', 'zic64b',
+                          'zicbom', 'zicbop', 'zicboz', 'zihintpause', 'zihpm', 'zkt'})
+
+    def test_rva23u64_additions(self):
+        rva22 = _features('rva22u64')
+        rva23 = _features('rva23u64')
+        self.assertLessEqual(rva22, rva23)
+        self.assertEqual(rva23 - rva22,
+                         {'supm', 'v', 'zawrs', 'zcb', 'zcmop', 'zfa', 'zicond',
+                          'zihintntl', 'zimop', 'zvbb', 'zve32f', 'zve32x',
+                          'zve64d', 'zve64f', 'zve64x', 'zvfhmin', 'zvkb', 'zvkt',
+                          'zvl128b', 'zvl32b', 'zvl64b'})
Signature · 1 line
2.56.0
#6 lore raw

PATCH 5/12 arch-riscv.inc, tune-riscv.inc: add rva20u64 tune

In reply to Trevor Gamblin

Add TUNE_FEATURES for the extensions mandated by the RVA20U64 profile which weren't yet in arch-riscv.inc:

- ziccamoa
- ziccif
- zicclsm
- ziccrse
- zicntr
- za128rs

Then, add an 'rva20u64' tune which uses them. Zifencei isn't mandatory in the profile, but it is added on top of the profile's extensions since it's required by Linux, making the package arch 'rva20u64_zifencei'.

Also update the tune.py notes to be clear about the ABI claim being made, since the profiles there are now being used by package archs.

---
 .../conf/machine/include/riscv/arch-riscv.inc | 26 +++++++++++++++++++
 .../conf/machine/include/riscv/tune-riscv.inc |  8 +++++-
 meta/lib/oe/tune.py                           |  5 ++++
 3 files changed, 38 insertions(+), 1 deletion(-)
meta/conf/machine/include/riscv/arch-riscv.inc +26 -0
index 6883e39a5f..26b8940f15 100644
@@ -86,6 +86,27 @@ TUNEVALID[zicbom] = "Cache-block management extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicbom", "_zicbom", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicbom", "_zicbom", "", d)}"
 
+# The following are mandatory in the RVA20U64 and later profiles
+TUNEVALID[ziccamoa] = "Main memory supports all atomics in A extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "ziccamoa", "_ziccamoa", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "ziccamoa", "_ziccamoa", "", d)}"
+
+TUNEVALID[ziccif] = "Main memory supports instruction fetch with atomicity requirement extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "ziccif", "_ziccif", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "ziccif", "_ziccif", "", d)}"
+
+TUNEVALID[zicclsm] = "Main memory supports misaligned loads/stores extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicclsm", "_zicclsm", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicclsm", "_zicclsm", "", d)}"
+
+TUNEVALID[ziccrse] = "Main memory supports forward progress on LR/SC sequences extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "ziccrse", "_ziccrse", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "ziccrse", "_ziccrse", "", d)}"
+
+TUNEVALID[zicntr] = "Base counters and timers extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicntr", "_zicntr", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicntr", "_zicntr", "", d)}"
+
 TUNEVALID[zicsr] = "Control and status register access extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicsr f d", "_zicsr", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicsr f d", "_zicsr", "", d)}"
@@ -103,6 +124,11 @@ TUNEVALID[zmmul] = "Integer multiplication (without division) extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zmmul", "_zmmul", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zmmul", bb.utils.contains("TUNE_FEATURES", "m", "", "_zmmul", d), "", d)}"
 
+# Mandatory in the RVA20U64 profile
+TUNEVALID[za128rs] = "Reservation set size of at most 128 bytes extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "za128rs", "_za128rs", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "za128rs", "_za128rs", "", d)}"
+
 TUNEVALID[zaamo] = "Atomic memory operations extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zaamo", "_zaamo", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zaamo", bb.utils.contains("TUNE_FEATURES", "a", "", "_zaamo", d), "", d)}"
meta/conf/machine/include/riscv/tune-riscv.inc +7 -1
index 88c9184c8b..bce345f684 100644
@@ -2,7 +2,7 @@ require conf/machine/include/riscv/arch-riscv.inc
 
 DEFAULTTUNE ?= "riscv64gc"
 
-AVAILTUNES += "riscv64gcv riscv64gc riscv32gc riscv64 riscv32 riscv64nc riscv64nf riscv32nf"
+AVAILTUNES += "riscv64gcv riscv64gc riscv32gc riscv64 riscv32 riscv64nc riscv64nf riscv32nf rva20u64"
 
 # Default
 TUNE_FEATURES:tune-riscv64gc := "${@oe.tune.riscv_isa_to_tune("rv64gc")}"
@@ -38,3 +38,9 @@ PACKAGE_EXTRA_ARCHS:tune-riscv32nf = "${RISCVPKGARCH:tune-riscv32nf}"
 TUNE_FEATURES:tune-riscv64nc := "${@oe.tune.riscv_isa_to_tune("rv64imafd_zicsr_zifencei")}"
 RISCVPKGARCH:tune-riscv64nc ?= "riscv64imafd_zicsr_zifencei"
 PACKAGE_EXTRA_ARCHS:tune-riscv64nc = "${RISCVPKGARCH:tune-riscv64nc}"
+
+# RISC-V profiles. zifencei isn't mandatory in them, but Linux requires it, so
+# it's added on top of each profile's mandatory extensions.
+TUNE_FEATURES:tune-rva20u64 := "${@oe.tune.riscv_isa_to_tune("rva20u64")} zifencei"
+RISCVPKGARCH:tune-rva20u64 ?= "rva20u64_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-rva20u64 = "${RISCVPKGARCH:tune-rva20u64}"
meta/lib/oe/tune.py +5 -0
index 580c84d4fa..f44043c605 100644
@@ -11,6 +11,11 @@
 #   RVA23U64: RVA23 Profiles, version 1.0
 # plus the extensions those imply (e.g. zmmul, zaamo, zca, zve*).
 #
+# The profile names are also used in package archs, so each entry here is an
+# ABI claim: packages built for e.g. "rva22u64_zifencei" must keep meaning
+# exactly this extension set. Changing an entry changes what existing package
+# feeds mean.
+#
 # Do not regenerate these from compiler output (e.g. gcc's -march expansion);
 # a newer compiler, or clang, may expand a profile differently. For example,
 # gcc's rva22u64 leaves out zihpm, which the specification makes mandatory.
Signature · 1 line
2.56.0
#7 lore raw

PATCH 6/12 arch-riscv.inc, tune-riscv.inc: add rva22u64 tune

In reply to Trevor Gamblin

Add TUNE_FEATURES for extensions mandated by the RVA22U64 profile but not yet included in arch-riscv.inc:

- zic64b
- zicbop
- zicboz
- zihintpause
- zihpm
- za64rs
- zfhmin
- zkt

It also mandates the following, which were already in oe-core:

- b
- zicbom
- zba
- zbb
- zbs

Then, add an 'rva22u64' tune using them. Zifencei isn't mandatory in the profile, but it is added on top of the profile's extensions since Linux requires it, making the package arch 'rva22u64_zifencei'.

---
 .../conf/machine/include/riscv/arch-riscv.inc | 37 ++++++++++++++++++-
 .../conf/machine/include/riscv/tune-riscv.inc |  6 ++-
 2 files changed, 41 insertions(+), 2 deletions(-)
meta/conf/machine/include/riscv/arch-riscv.inc +36 -1
index 26b8940f15..0661c24e8e 100644
@@ -82,10 +82,24 @@ TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "v", "v", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "v", "v", "", d)}"
 
 # Now the special Z extensions
+# zic64b, zicbop, zicboz, zihintpause, zihpm, za64rs, zfhmin and zkt are
+# mandatory in the RVA22U64 and later profiles
+TUNEVALID[zic64b] = "Cache blocks are 64 bytes extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zic64b", "_zic64b", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zic64b", "_zic64b", "", d)}"
+
 TUNEVALID[zicbom] = "Cache-block management extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicbom", "_zicbom", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicbom", "_zicbom", "", d)}"
 
+TUNEVALID[zicbop] = "Cache-block prefetch extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicbop", "_zicbop", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicbop", "_zicbop", "", d)}"
+
+TUNEVALID[zicboz] = "Cache-block zero extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicboz", "_zicboz", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicboz", "_zicboz", "", d)}"
+
 # The following are mandatory in the RVA20U64 and later profiles
 TUNEVALID[ziccamoa] = "Main memory supports all atomics in A extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "ziccamoa", "_ziccamoa", "", d)}"
@@ -115,6 +129,14 @@ TUNEVALID[zifencei] = "Instruction-fetch fence extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
 
+TUNEVALID[zihintpause] = "Pause hint extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihintpause", "_zihintpause", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihintpause", "_zihintpause", "", d)}"
+
+TUNEVALID[zihpm] = "Hardware performance counters extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihpm", "_zihpm", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihpm", "_zihpm", "", d)}"
+
 # zmmul, zaamo, zalrsc, zca and zcd are subsets of single-letter extensions
 # above (m, a, c and c with d), which compilers enable along with them. They
 # are only passed on when listed in TUNE_FEATURES, so that -march doesn't
@@ -124,11 +146,16 @@ TUNEVALID[zmmul] = "Integer multiplication (without division) extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zmmul", "_zmmul", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zmmul", bb.utils.contains("TUNE_FEATURES", "m", "", "_zmmul", d), "", d)}"
 
-# Mandatory in the RVA20U64 profile
+# Mandatory in the RVA20U64 profile. Later profiles require za64rs (below),
+# which is stricter, instead.
 TUNEVALID[za128rs] = "Reservation set size of at most 128 bytes extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "za128rs", "_za128rs", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "za128rs", "_za128rs", "", d)}"
 
+TUNEVALID[za64rs] = "Reservation set size of at most 64 bytes extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "za64rs", "_za64rs", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "za64rs", "_za64rs", "", d)}"
+
 TUNEVALID[zaamo] = "Atomic memory operations extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zaamo", "_zaamo", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zaamo", bb.utils.contains("TUNE_FEATURES", "a", "", "_zaamo", d), "", d)}"
@@ -137,6 +164,10 @@ TUNEVALID[zalrsc] = "Load-reserved/store-conditional extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zalrsc", "_zalrsc", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zalrsc", bb.utils.contains("TUNE_FEATURES", "a", "", "_zalrsc", d), "", d)}"
 
+TUNEVALID[zfhmin] = "Minimal half-precision floating-point extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zfhmin", "_zfhmin", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zfhmin", "_zfhmin", "", d)}"
+
 TUNEVALID[zca] = "Compressed integer instructions extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zca", "_zca", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zca", bb.utils.contains("TUNE_FEATURES", "c", "", "_zca", d), "", d)}"
@@ -161,6 +192,10 @@ TUNEVALID[zbs] = "Single-bit manipulation extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "b zbs", "_zbs", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "b zbs", "_zbs", "", d)}"
 
+TUNEVALID[zkt] = "Data-independent execution latency extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zkt", "_zkt", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zkt", "_zkt", "", d)}"
+
 # Construct TUNE_CCARGS
 # This should result in a CCARG similar to:
 #   -march=rv32imac -mabi=ilp32
meta/conf/machine/include/riscv/tune-riscv.inc +5 -1
index bce345f684..6aad54ae97 100644
@@ -2,7 +2,7 @@ require conf/machine/include/riscv/arch-riscv.inc
 
 DEFAULTTUNE ?= "riscv64gc"
 
-AVAILTUNES += "riscv64gcv riscv64gc riscv32gc riscv64 riscv32 riscv64nc riscv64nf riscv32nf rva20u64"
+AVAILTUNES += "riscv64gcv riscv64gc riscv32gc riscv64 riscv32 riscv64nc riscv64nf riscv32nf rva20u64 rva22u64"
 
 # Default
 TUNE_FEATURES:tune-riscv64gc := "${@oe.tune.riscv_isa_to_tune("rv64gc")}"
@@ -44,3 +44,7 @@ PACKAGE_EXTRA_ARCHS:tune-riscv64nc = "${RISCVPKGARCH:tune-riscv64nc}"
 TUNE_FEATURES:tune-rva20u64 := "${@oe.tune.riscv_isa_to_tune("rva20u64")} zifencei"
 RISCVPKGARCH:tune-rva20u64 ?= "rva20u64_zifencei"
 PACKAGE_EXTRA_ARCHS:tune-rva20u64 = "${RISCVPKGARCH:tune-rva20u64}"
+
+TUNE_FEATURES:tune-rva22u64 := "${@oe.tune.riscv_isa_to_tune("rva22u64")} zifencei"
+RISCVPKGARCH:tune-rva22u64 ?= "rva22u64_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-rva22u64 = "${RISCVPKGARCH:tune-rva22u64}"
Signature · 1 line
2.56.0
#8 lore raw

PATCH 7/12 arch-riscv.inc, tune-riscv.inc: add rva23u64 tune

In reply to Trevor Gamblin

Add TUNE_FEATURES for the extensions mandated by the RVA23U64 profile, which weren't yet in arch-riscv.inc:

- zicond
- zihintntl
- zimop
- zawrs
- zfa
- zcb
- zcmop
- zvbb
- zvfhmin
- zvkb
- zvkt
- supm
- zve* and zvl* vector extensions

The zve*/zvl* extensions are only added to the package arch when v isn't enabled, and zvkb, when zvbb isn't. As with other profiles, zifencei is added to the extension set since it's required by Linux, making the package arch 'rva23u64_zifencei'.

---
 .../conf/machine/include/riscv/arch-riscv.inc | 89 +++++++++++++++++++
 .../conf/machine/include/riscv/tune-riscv.inc |  6 +-
 2 files changed, 94 insertions(+), 1 deletion(-)
meta/conf/machine/include/riscv/arch-riscv.inc +89 -0
index 0661c24e8e..ff14f94deb 100644
@@ -84,6 +84,8 @@ TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "v", "v", "", d)}"
 # Now the special Z extensions
 # zic64b, zicbop, zicboz, zihintpause, zihpm, za64rs, zfhmin and zkt are
 # mandatory in the RVA22U64 and later profiles
+# zicond, zihintntl, zimop, zawrs, zfa, zcb, zcmop, zvbb, zvfhmin, zvkb, zvkt
+# and supm, as well as v, are mandatory in the RVA23U64 and later profiles
 TUNEVALID[zic64b] = "Cache blocks are 64 bytes extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zic64b", "_zic64b", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zic64b", "_zic64b", "", d)}"
@@ -121,6 +123,10 @@ TUNEVALID[zicntr] = "Base counters and timers extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicntr", "_zicntr", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicntr", "_zicntr", "", d)}"
 
+TUNEVALID[zicond] = "Integer conditional operations extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicond", "_zicond", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zicond", "_zicond", "", d)}"
+
 TUNEVALID[zicsr] = "Control and status register access extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicsr f d", "_zicsr", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "zicsr f d", "_zicsr", "", d)}"
@@ -129,6 +135,10 @@ TUNEVALID[zifencei] = "Instruction-fetch fence extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zifencei", "_zifencei", "", d)}"
 
+TUNEVALID[zihintntl] = "Non-temporal locality hints extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihintntl", "_zihintntl", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihintntl", "_zihintntl", "", d)}"
+
 TUNEVALID[zihintpause] = "Pause hint extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihintpause", "_zihintpause", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihintpause", "_zihintpause", "", d)}"
@@ -137,6 +147,10 @@ TUNEVALID[zihpm] = "Hardware performance counters extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihpm", "_zihpm", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zihpm", "_zihpm", "", d)}"
 
+TUNEVALID[zimop] = "May-be-operations extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zimop", "_zimop", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zimop", "_zimop", "", d)}"
+
 # zmmul, zaamo, zalrsc, zca and zcd are subsets of single-letter extensions
 # above (m, a, c and c with d), which compilers enable along with them. They
 # are only passed on when listed in TUNE_FEATURES, so that -march doesn't
@@ -164,6 +178,14 @@ TUNEVALID[zalrsc] = "Load-reserved/store-conditional extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zalrsc", "_zalrsc", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zalrsc", bb.utils.contains("TUNE_FEATURES", "a", "", "_zalrsc", d), "", d)}"
 
+TUNEVALID[zawrs] = "Wait-on-reservation-set instructions extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zawrs", "_zawrs", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zawrs", "_zawrs", "", d)}"
+
+TUNEVALID[zfa] = "Additional floating-point instructions extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zfa", "_zfa", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zfa", "_zfa", "", d)}"
+
 TUNEVALID[zfhmin] = "Minimal half-precision floating-point extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zfhmin", "_zfhmin", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zfhmin", "_zfhmin", "", d)}"
@@ -172,10 +194,18 @@ TUNEVALID[zca] = "Compressed integer instructions extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zca", "_zca", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zca", bb.utils.contains("TUNE_FEATURES", "c", "", "_zca", d), "", d)}"
 
+TUNEVALID[zcb] = "Additional compressed instructions extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zcb", "_zcb", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zcb", "_zcb", "", d)}"
+
 TUNEVALID[zcd] = "Compressed double-precision floating-point instructions extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zcd", "_zcd", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zcd", bb.utils.contains("TUNE_FEATURES", "c d", "", "_zcd", d), "", d)}"
 
+TUNEVALID[zcmop] = "Compressed may-be-operations extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zcmop", "_zcmop", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zcmop", "_zcmop", "", d)}"
+
 TUNEVALID[zba] = "Address bit manipulation extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "b zba", "_zba", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains_any("TUNE_FEATURES", "b zba", "_zba", "", d)}"
@@ -196,6 +226,65 @@ TUNEVALID[zkt] = "Data-independent execution latency extension"
 TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zkt", "_zkt", "", d)}"
 TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zkt", "_zkt", "", d)}"
 
+TUNEVALID[zvbb] = "Vector basic bit-manipulation extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvbb", "_zvbb", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvbb", "_zvbb", "", d)}"
+
+# The zve* and zvl* extensions are subsets of v, like zmmul is of m above, so
+# they are only added to the package arch when v isn't enabled. Other extensions
+# also imply them (e.g. zvbb implies zvkb, zve32x, and zvl32b), which the
+# compilers handle but the package arch doesn't. Tunes using them without v
+# should set RISCVPKGARCH:tune-<name>.
+TUNEVALID[zve32f] = "Embedded vector (32-bit integer and floating-point) extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve32f", "_zve32f", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve32f", bb.utils.contains("TUNE_FEATURES", "v", "", "_zve32f", d), "", d)}"
+
+TUNEVALID[zve32x] = "Embedded vector (32-bit integer) extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve32x", "_zve32x", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve32x", bb.utils.contains("TUNE_FEATURES", "v", "", "_zve32x", d), "", d)}"
+
+TUNEVALID[zve64d] = "Embedded vector (64-bit integer, 64-bit floating-point) extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve64d", "_zve64d", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve64d", bb.utils.contains("TUNE_FEATURES", "v", "", "_zve64d", d), "", d)}"
+
+TUNEVALID[zve64f] = "Embedded vector (64-bit integer, 32-bit floating-point) extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve64f", "_zve64f", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve64f", bb.utils.contains("TUNE_FEATURES", "v", "", "_zve64f", d), "", d)}"
+
+TUNEVALID[zve64x] = "Embedded vector (64-bit integer) extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve64x", "_zve64x", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zve64x", bb.utils.contains("TUNE_FEATURES", "v", "", "_zve64x", d), "", d)}"
+
+TUNEVALID[zvfhmin] = "Vector minimal half-precision floating-point extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvfhmin", "_zvfhmin", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvfhmin", "_zvfhmin", "", d)}"
+
+# zvkb is a subset of zvbb
+TUNEVALID[zvkb] = "Vector cryptography bit-manipulation extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvkb", "_zvkb", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvkb", bb.utils.contains("TUNE_FEATURES", "zvbb", "", "_zvkb", d), "", d)}"
+
+TUNEVALID[zvkt] = "Vector data-independent execution latency extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvkt", "_zvkt", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvkt", "_zvkt", "", d)}"
+
+TUNEVALID[zvl128b] = "Minimum vector length of 128 bits extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvl128b", "_zvl128b", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvl128b", bb.utils.contains("TUNE_FEATURES", "v", "", "_zvl128b", d), "", d)}"
+
+TUNEVALID[zvl32b] = "Minimum vector length of 32 bits extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvl32b", "_zvl32b", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvl32b", bb.utils.contains("TUNE_FEATURES", "v", "", "_zvl32b", d), "", d)}"
+
+TUNEVALID[zvl64b] = "Minimum vector length of 64 bits extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvl64b", "_zvl64b", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "zvl64b", bb.utils.contains("TUNE_FEATURES", "v", "", "_zvl64b", d), "", d)}"
+
+# Supervisor-level extensions, which come after all of the Z extensions
+TUNEVALID[supm] = "User-mode pointer masking extension"
+TUNE_RISCV_MARCH .= "${@bb.utils.contains("TUNE_FEATURES", "supm", "_supm", "", d)}"
+TUNE_RISCV_PKGARCH .= "${@bb.utils.contains("TUNE_FEATURES", "supm", "_supm", "", d)}"
+
 # Construct TUNE_CCARGS
 # This should result in a CCARG similar to:
 #   -march=rv32imac -mabi=ilp32
meta/conf/machine/include/riscv/tune-riscv.inc +5 -1
index 6aad54ae97..d2657d8dad 100644
@@ -2,7 +2,7 @@ require conf/machine/include/riscv/arch-riscv.inc
 
 DEFAULTTUNE ?= "riscv64gc"
 
-AVAILTUNES += "riscv64gcv riscv64gc riscv32gc riscv64 riscv32 riscv64nc riscv64nf riscv32nf rva20u64 rva22u64"
+AVAILTUNES += "riscv64gcv riscv64gc riscv32gc riscv64 riscv32 riscv64nc riscv64nf riscv32nf rva20u64 rva22u64 rva23u64"
 
 # Default
 TUNE_FEATURES:tune-riscv64gc := "${@oe.tune.riscv_isa_to_tune("rv64gc")}"
@@ -48,3 +48,7 @@ PACKAGE_EXTRA_ARCHS:tune-rva20u64 = "${RISCVPKGARCH:tune-rva20u64}"
 TUNE_FEATURES:tune-rva22u64 := "${@oe.tune.riscv_isa_to_tune("rva22u64")} zifencei"
 RISCVPKGARCH:tune-rva22u64 ?= "rva22u64_zifencei"
 PACKAGE_EXTRA_ARCHS:tune-rva22u64 = "${RISCVPKGARCH:tune-rva22u64}"
+
+TUNE_FEATURES:tune-rva23u64 := "${@oe.tune.riscv_isa_to_tune("rva23u64")} zifencei"
+RISCVPKGARCH:tune-rva23u64 ?= "rva23u64_zifencei"
+PACKAGE_EXTRA_ARCHS:tune-rva23u64 = "${RISCVPKGARCH:tune-rva23u64}"
Signature · 1 line
2.56.0
#9 lore raw

PATCH 8/12 tune-riscv.inc: set PACKAGE_EXTRA_ARCHS for supersets

In reply to Trevor Gamblin

For each tune, list the package archs it is a superset of in PACKAGE_EXTRA_ARCHS, with the lowest priority tunes first (like ARM tunings). This allows (for example) a 'riscv64gcv' machine to install 'riscv64gc' packages, and an 'rva23u64' machine to install packages built for:

- riscv64gc
- riscv64gcv
- rva20u64
- rva22u64

---
 meta/conf/machine/include/riscv/tune-riscv.inc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
meta/conf/machine/include/riscv/tune-riscv.inc +8 -4
index d2657d8dad..496dbdd722 100644
@@ -11,7 +11,7 @@ PACKAGE_EXTRA_ARCHS:tune-riscv64gc = "${RISCVPKGARCH:tune-riscv64gc}"
 
 TUNE_FEATURES:tune-riscv64gcv := "${@oe.tune.riscv_isa_to_tune("rv64gcv")}"
 RISCVPKGARCH:tune-riscv64gcv ?= "riscv64imafdcv_zicsr_zifencei"
-PACKAGE_EXTRA_ARCHS:tune-riscv64gcv = "${RISCVPKGARCH:tune-riscv64gcv}"
+PACKAGE_EXTRA_ARCHS:tune-riscv64gcv = "${PACKAGE_EXTRA_ARCHS:tune-riscv64gc} ${RISCVPKGARCH:tune-riscv64gcv}"
 
 TUNE_FEATURES:tune-riscv32gc := "${@oe.tune.riscv_isa_to_tune("rv32gc")}"
 RISCVPKGARCH:tune-riscv32gc ?= "riscv32imafdc_zicsr_zifencei"
@@ -41,14 +41,18 @@ PACKAGE_EXTRA_ARCHS:tune-riscv64nc = "${RISCVPKGARCH:tune-riscv64nc}"
 
 # RISC-V profiles. zifencei isn't mandatory in them, but Linux requires it, so
 # it's added on top of each profile's mandatory extensions.
+#
+# Each profile tune's PACKAGE_EXTRA_ARCHS lists the package archs of the tunes
+# that it's a superset of (with the same lp64d ABI), lowest priority first.
 TUNE_FEATURES:tune-rva20u64 := "${@oe.tune.riscv_isa_to_tune("rva20u64")} zifencei"
 RISCVPKGARCH:tune-rva20u64 ?= "rva20u64_zifencei"
-PACKAGE_EXTRA_ARCHS:tune-rva20u64 = "${RISCVPKGARCH:tune-rva20u64}"
+PACKAGE_EXTRA_ARCHS:tune-rva20u64 = "${PACKAGE_EXTRA_ARCHS:tune-riscv64gc} ${RISCVPKGARCH:tune-rva20u64}"
 
 TUNE_FEATURES:tune-rva22u64 := "${@oe.tune.riscv_isa_to_tune("rva22u64")} zifencei"
 RISCVPKGARCH:tune-rva22u64 ?= "rva22u64_zifencei"
-PACKAGE_EXTRA_ARCHS:tune-rva22u64 = "${RISCVPKGARCH:tune-rva22u64}"
+PACKAGE_EXTRA_ARCHS:tune-rva22u64 = "${PACKAGE_EXTRA_ARCHS:tune-rva20u64} ${RISCVPKGARCH:tune-rva22u64}"
 
 TUNE_FEATURES:tune-rva23u64 := "${@oe.tune.riscv_isa_to_tune("rva23u64")} zifencei"
 RISCVPKGARCH:tune-rva23u64 ?= "rva23u64_zifencei"
-PACKAGE_EXTRA_ARCHS:tune-rva23u64 = "${RISCVPKGARCH:tune-rva23u64}"
+# Unlike rva20u64 and rva22u64, rva23u64 is a superset of riscv64gcv
+PACKAGE_EXTRA_ARCHS:tune-rva23u64 = "${PACKAGE_EXTRA_ARCHS:tune-riscv64gcv} ${RISCVPKGARCH:tune-rva20u64} ${RISCVPKGARCH:tune-rva22u64} ${RISCVPKGARCH:tune-rva23u64}"
Signature · 1 line
2.56.0
#10 lore raw

PATCH 9/12 meta/conf/machine/include/riscv/arch-riscv.inc: error on very long package archs

In reply to Trevor Gamblin

Tunes that don't set RISCVPKGARCH:tune-<name> fall back to TUNE_RISCV_PKGARCH, which grows with every extension enabled. This can easily exceed allowable maximums for build and sstate paths, so make it a fatal error when it's longer than 64 characters and inform the user to set RISCVPKGARCH:tune-<name> instead.

Existing tunes already set RISCVPKGARCH:tune-<name>, so they are unaffected. The longest known fallback is currently Microblaze-V's riscv64imafdc_zicsr_zifencei_zba_zbb_zbs at 41 characters, which is well under the set limit.

---
 meta/conf/machine/include/riscv/README         | 3 ++-
 meta/conf/machine/include/riscv/arch-riscv.inc | 8 +++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
meta/conf/machine/include/riscv/README +2 -1
index ef7a484f25..c66925eb83 100644
@@ -93,7 +93,8 @@ RISCVPKGARCH - This is the package arch actually used.  As with ARMPKGARCH
                on arm, each tune sets it as a literal in
                RISCVPKGARCH:tune-<name>, so that it only changes when
                deliberately changed.  Tunes that don't set it fall back to
-               TUNE_RISCV_PKGARCH.
+               TUNE_RISCV_PKGARCH, which is an error if that is longer
+               than 64 characters.
 
 The standard variables are defined as:
 
meta/conf/machine/include/riscv/arch-riscv.inc +7 -1
index ff14f94deb..cde35ce56d 100644
@@ -301,7 +301,13 @@ TUNE_ARCH = "${TUNE_RISCV_ARCH}"
 # Tunes that don't set it fall back to TUNE_RISCV_PKGARCH, which is built from
 # TUNE_FEATURES above, e.g.:
 #    riscv32imac
-RISCVPKGARCH = "${@d.getVar('RISCVPKGARCH:tune-${DEFAULTTUNE}') or d.getVar('TUNE_RISCV_PKGARCH')}"
+# However, TUNE_RISCV_PKGARCH grows with every extension the tune enables, so to
+# keep build and sstate paths manageable, RISCVPKGARCH:tune-<name> should be set
+# for a custom tune. For TUNE_RISCV_PKGARCH longer than 64 characters, throw an
+# error.
+RISCVPKGARCH = "${@d.getVar('RISCVPKGARCH:tune-${DEFAULTTUNE}') or \
+    ('${TUNE_RISCV_PKGARCH}' if len('${TUNE_RISCV_PKGARCH}') <= 64 else \
+     bb.fatal('The package arch for tune ${DEFAULTTUNE} would be ${TUNE_RISCV_PKGARCH}, which is longer than 64 characters. Set RISCVPKGARCH:tune-${DEFAULTTUNE} to a shorter name.'))}"
 TUNE_PKGARCH = "${RISCVPKGARCH}"
 
 # Misc settings
Signature · 1 line
2.56.0
#11 lore raw

Re: [OE-core][PATCH 09/12] meta/conf/machine/include/riscv/arch-riscv.inc: error on very long package archs

Quoted 47 lines · Trevor Gamblin via openembedded-core

Tunes that don't set RISCVPKGARCH:tune-<name> fall back to TUNE_RISCV_PKGARCH, which grows with every extension enabled. This can easily exceed allowable maximums for build and sstate paths, so make it a fatal error when it's longer than 64 characters and inform the user to set RISCVPKGARCH:tune-<name> instead.

Existing tunes already set RISCVPKGARCH:tune-<name>, so they are unaffected. The longest known fallback is currently Microblaze-V's riscv64imafdc_zicsr_zifencei_zba_zbb_zbs at 41 characters, which is well under the set limit.

---
 meta/conf/machine/include/riscv/README         | 3 ++- meta/conf/machine/include/riscv/arch-riscv.inc | 8 +++++++-

 2 files changed, 9 insertions(+), 2 deletions(-)
meta/conf/machine/include/riscv/README +0 -0
index ef7a484f25..c66925eb83 100644
@@ -93,7 +93,8 @@ RISCVPKGARCH - This is the package arch actually used.  As with ARMPKGARCH

                on arm, each tune sets it as a literal in RISCVPKGARCH:tune-<name>, so that it only changes when deliberately changed.  Tunes that don't set it fall back to -               TUNE_RISCV_PKGARCH.
+               TUNE_RISCV_PKGARCH, which is an error if that is longer +               than 64 characters.

 The standard variables are defined as:

meta/conf/machine/include/riscv/arch-riscv.inc +7 -1
index ff14f94deb..cde35ce56d 100644
@@ -301,7 +301,13 @@ TUNE_ARCH = "${TUNE_RISCV_ARCH}"
  # Tunes that don't set it fall back to TUNE_RISCV_PKGARCH, which is built from
  # TUNE_FEATURES above, e.g.:
  #    riscv32imac
-RISCVPKGARCH = "${@d.getVar('RISCVPKGARCH:tune-${DEFAULTTUNE}') or d.getVar('TUNE_RISCV_PKGARCH')}"
+# However, TUNE_RISCV_PKGARCH grows with every extension the tune enables, so to
+# keep build and sstate paths manageable, RISCVPKGARCH:tune-<name> should be set
+# for a custom tune. For TUNE_RISCV_PKGARCH longer than 64 characters, throw an
+# error.
+RISCVPKGARCH = "${@d.getVar('RISCVPKGARCH:tune-${DEFAULTTUNE}') or \
+    ('${TUNE_RISCV_PKGARCH}' if len('${TUNE_RISCV_PKGARCH}') <= 64 else \
+     bb.fatal('The package arch for tune ${DEFAULTTUNE} would be ${TUNE_RISCV_PKGARCH}, which is longer than 64 characters. Set RISCVPKGARCH:tune-${DEFAULTTUNE} to a shorter name.'))}"
Quoted 3 lines

 TUNE_PKGARCH = "${RISCVPKGARCH}"

 # Misc settings

I think I'd rather have that check somewhere end where it isn't going to be run again and again ever time the variable is used/expanded. Inline python is ok to a point but I think it is getting too unreadable.

Cheers,

Richard

#12 lore raw

PATCH 10/12 lib/oeqa/selftest/cases/riscvtunes.py: add RISC-V tune selftests

In reply to Trevor Gamblin

Add selftests for the RISC-V tunes in oe-core, covering:

- Every tune in tune-riscv.inc has a package arch that's in PACKAGE_ARCHS
- PACKAGE_EXTRA_ARCHS only lists package archs for tunes that each tune is a superset of, with its own coming last
- Package archs for profile tunes and their '-march' and '-mabi' options
- Existing tunes' package archs don't change
- The 'riscv64' and 'riscv32' aliases match 'riscv64gc' and 'riscv32gc' respectively
- Custom tunes that don't set RISCVPKGARCH:tune-<name> fall back to TUNE_RISCV_PKGARCH, and error if they're too long
- Custom tunes with unusual extension sets build, i.e. the compiler accepts their respective '-march', and the package arch works for build/sstate paths

AI-Generated: Uses Claude Opus 5.5

---
 meta/lib/oeqa/selftest/cases/riscvtunes.py | 148 +++++++++++++++++++++
 1 file changed, 148 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/riscvtunes.py
meta/lib/oeqa/selftest/cases/riscvtunes.py new file +148 -0
new file mode 100644
index 0000000000..daee22a51e
@@ -0,0 +1,148 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+from oe.tune import riscv_isa_to_tune
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars
+
+class RiscvTunesTests(OESelftestTestCase):
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls.orig_machine = get_bb_var('MACHINE')
+
+    def _machine_config(self, machine='qemuriscv64'):
+        # Builds set up by bitbake-setup select the machine with a builtin
+        # fragment, which is fatal alongside a MACHINE assignment, so drop it
+        return 'OE_FRAGMENTS:remove = "machine/%s"\nMACHINE = "%s"\n' % (self.orig_machine, machine)
+
+    def test_riscv_default_tunes(self):
+        """
+        Parse every RISC-V tune and check it yields a usable package arch, and
+        that PACKAGE_EXTRA_ARCHS only lists archs of other tunes whose
+        extensions are all available in this one.
+        """
+        # Only variables are checked here, so the riscv32 tunes can use the same
+        # machine
+        self.write_config(self._machine_config())
+        tunes = get_bb_var('AVAILTUNES').split()
+
+        vars = {}
+        for tune in tunes:
+            self.write_config(self._machine_config() + 'DEFAULTTUNE = "%s"\n' % tune)
+            vars[tune] = get_bb_vars(['TUNE_FEATURES', 'TUNE_PKGARCH', 'PACKAGE_EXTRA_ARCHS', 'PACKAGE_ARCHS'])
+
+        pkgarch_features = {v['TUNE_PKGARCH']: set(v['TUNE_FEATURES'].split()) for v in vars.values()}
+
+        for tune, v in vars.items():
+            with self.subTest(tune=tune):
+                self.assertTrue(v['TUNE_FEATURES'], 'empty TUNE_FEATURES')
+                self.assertTrue(v['TUNE_PKGARCH'], 'empty TUNE_PKGARCH')
+                self.assertIn(v['TUNE_PKGARCH'], v['PACKAGE_ARCHS'].split())
+
+                features = set(v['TUNE_FEATURES'].split())
+                # za64rs is a stricter za128rs, which RVA20U64 requires
+                if 'za64rs' in features:
+                    features.add('za128rs')
+                for arch in v['PACKAGE_EXTRA_ARCHS'].split():
+                    self.assertIn(arch, pkgarch_features, '%s is not the package arch of any tune' % arch)
+                    self.assertLessEqual(pkgarch_features[arch], features, '%s needs extensions %s lacks' % (arch, tune))
+                # The tune's own package arch has the highest priority
+                self.assertEqual(v['PACKAGE_EXTRA_ARCHS'].split()[-1], v['TUNE_PKGARCH'])
+
+        # Profile tunes are named after the profile
+        for profile in ['rva20u64', 'rva22u64', 'rva23u64']:
+            with self.subTest(profile=profile):
+                self.assertEqual(vars[profile]['TUNE_PKGARCH'], profile + '_zifencei')
+                self.assertEqual(vars[profile]['TUNE_FEATURES'], riscv_isa_to_tune(profile) + ' zifencei')
+
+        # The package archs of the existing tunes must not change
+        self.assertEqual(vars['riscv64gc']['TUNE_PKGARCH'], 'riscv64imafdc_zicsr_zifencei')
+        self.assertEqual(vars['riscv32gc']['TUNE_PKGARCH'], 'riscv32imafdc_zicsr_zifencei')
+
+        # Legacy tune names behave exactly like the tunes they alias
+        for alias, target in [('riscv64', 'riscv64gc'), ('riscv32', 'riscv32gc')]:
+            with self.subTest(alias=alias):
+                self.assertIn(alias, tunes)
+                self.assertEqual(vars[alias], vars[target])
+
+    def test_riscv_profile_ccargs(self):
+        """
+        Check the -march and -mabi options of the profile tunes.
+        """
+        for profile in ['rva20u64', 'rva22u64', 'rva23u64']:
+            with self.subTest(profile=profile):
+                self.write_config(self._machine_config() + 'DEFAULTTUNE = "%s"\n' % profile)
+                ccargs = get_bb_var('TUNE_CCARGS').split()
+                self.assertIn('-mabi=lp64d', ccargs)
+                march = [a for a in ccargs if a.startswith('-march=')]
+                self.assertEqual(len(march), 1, ccargs)
+                exts = march[0][len('-march='):].split('_')
+                self.assertTrue(exts[0].startswith('rv64imafdc'), exts[0])
+                # Every multi-letter extension of the profile is passed on
+                for f in riscv_isa_to_tune(profile).split() + ['zifencei']:
+                    if len(f) > 1 and f not in ('rv', '64'):
+                        self.assertIn(f, exts)
+
+    def test_riscv_pkgarch_fallback(self):
+        """
+        Check that custom tunes which don't set RISCVPKGARCH:tune-<name> get
+        TUNE_RISCV_PKGARCH as their package arch, and that it's an error if
+        that is too long.
+        """
+        def config(tune, features):
+            return self._machine_config() + \
+                   'AVAILTUNES += "%s"\n' \
+                   'TUNE_FEATURES:tune-%s = "%s"\n' \
+                   'DEFAULTTUNE = "%s"\n' % (tune, tune, features, tune)
+
+        self.write_config(config('rv64imac-zicond', riscv_isa_to_tune('rv64imac_zicond')))
+        self.assertEqual(get_bb_var('TUNE_PKGARCH'), 'riscv64imac_zicond')
+
+        self.write_config(config('rva22-zicond', riscv_isa_to_tune('rva22u64') + ' zicond'))
+        result = bitbake('-e', ignore_status=True)
+        self.assertNotEqual(result.status, 0)
+        self.assertIn('Set RISCVPKGARCH:tune-rva22-zicond to a shorter name', result.output)
+
+    def test_riscv_unusual_tunes(self):
+        """
+        Define custom tunes with unusual extension combinations, as a BSP
+        might, and check each one builds: the sanity checks accept the
+        package arch, gcc and binutils accept the -march string, and the
+        package arch works in the build and sstate paths.
+        """
+        def profile(name, drop=None):
+            return ' '.join(f for f in riscv_isa_to_tune(name).split() if f != drop) + ' zifencei'
+        tunes = {
+            # no float (lp64 ABI), with bitmanip. Short enough to use the
+            # fallback package arch.
+            'rv64-nofloat-bitmanip': riscv_isa_to_tune('rv64imac_zicsr_zifencei_zba_zbb_zbs'),
+            # no profile, scalar extensions on top of gc
+            'rv64gc-scalar-extras': riscv_isa_to_tune('rv64gc_zicbom_zicboz_zicond_zfa_zfhmin'),
+            # profile plus vector crypto extensions
+            'rva20-vector-crypto': profile('rva20u64') + ' v zvbb zvkt',
+            # a profile missing one extension
+            'rva22-no-zkt': profile('rva22u64', 'zkt'),
+            # rva23u64 without the full vector extension
+            'rva23-no-v': profile('rva23u64', 'v'),
+        }
+
+        config = self._machine_config()
+        for tune, features in tunes.items():
+            config += 'AVAILTUNES += "%s"\n' % tune
+            config += 'TUNE_FEATURES:tune-%s = "%s"\n' % (tune, features)
+            # The rest are too long for the fallback, so name them as a BSP
+            # would have to
+            if tune != 'rv64-nofloat-bitmanip':
+                config += 'RISCVPKGARCH:tune-%s = "%s"\n' % (tune, tune.replace('-', '_'))
+            config += 'PACKAGE_EXTRA_ARCHS:tune-%s = "${RISCVPKGARCH}"\n' % tune
+
+        for tune in tunes:
+            with self.subTest(tune=tune):
+                self.write_config(config + 'DEFAULTTUNE = "%s"\n' % tune)
+                # small, and compiled with TUNE_CCARGS. It has no do_build, and
+                # populate_sysroot also writes an sstate object.
+                bitbake('libgcc-initial -c populate_sysroot')
Signature · 1 line
2.56.0
#13 lore raw

PATCH 11/12 rust-target-config.bbclass: pass on all RISC-V extensions to LLVM

In reply to Trevor Gamblin

llvm_features_from_tune() doesn't pass on all RISC-V extensions listed in TUNE_FEATURES, but rather has a fixed subset listed, and ignores others. This means that with new profiles and custom tunes, Rust code still gets compiled for riscv64gc plus a handful of extras.

LLVM's RISC-V extension names match those we use for TUNE_FEATURES, so we can instead pass on each extension in the same order.

---
 .../classes-recipe/rust-target-config.bbclass | 34 +++++--------------
 1 file changed, 8 insertions(+), 26 deletions(-)
meta/classes-recipe/rust-target-config.bbclass +8 -26
index 2faecd55f9..89fbd19374 100644
@@ -83,32 +83,14 @@ def llvm_features_from_tune(d):
     if 'cortexa57' in feat:
         f.append("+v8a")
     if 'rv' in feat:
-        if 'm' in feat:
-            f.append("+m")
-        if 'a' in feat:
-            f.append("+a")
-        if 'f' in feat:
-            f.append("+f")
-        if 'd' in feat:
-            f.append("+d")
-        if 'c' in feat:
-            f.append("+c")
-        if 'v' in feat:
-            f.append("+v")
-        if 'zicbom' in feat:
-            f.append("+zicbom")
-        if 'zicsr' in feat:
-            f.append("+zicsr")
-        if 'zifencei' in feat:
-            f.append("+zifencei")
-        if 'zba' in feat:
-            f.append("+zba")
-        if 'zbb' in feat:
-            f.append("+zbb")
-        if 'zbc' in feat:
-            f.append("+zbc")
-        if 'zbs' in feat:
-            f.append("+zbs")
+        # LLVM uses the same names as TUNE_FEATURES for RISC-V extensions, so
+        # pass on every single-letter (except the base i) and z, s or x
+        # extension, in TUNE_FEATURES order to keep the result stable. Other
+        # tune flags (e.g. "rv", "64" or core names) aren't extensions.
+        for e in dict.fromkeys(d.getVar('TUNE_FEATURES').split()):
+            if (len(e) == 1 and e.isalpha() and e != 'i') or \
+                    (len(e) > 1 and e[0] in 'zsx' and e.isalnum()):
+                f.append("+" + e)
     return f
 llvm_features_from_tune[vardepvalue] = "${@llvm_features_from_tune(d)}"
 
Signature · 1 line
2.56.0
#14 lore raw

PATCH 12/12 lib/oeqa/selftest/cases/riscvtunes.py: test Rust target features

In reply to Trevor Gamblin

Add test_riscv_rust_target_features(), which generates the Rust target spec for hello-rs with the 'riscv64gc' and 'rva23u64' tunes, then checks that its 'features' pass each extension in TUNE_FEATURES to LLVM in order. Also check that riscv64gc's feature set remains unchanged.

AI-Generated: Uses Claude Opus 5.5

---
 meta/lib/oeqa/selftest/cases/riscvtunes.py | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
meta/lib/oeqa/selftest/cases/riscvtunes.py +26 -0
index daee22a51e..b2ff2cc739 100644
@@ -4,6 +4,9 @@
 # SPDX-License-Identifier: MIT
 #
 
+import json
+import os
+
 from oe.tune import riscv_isa_to_tune
 from oeqa.selftest.case import OESelftestTestCase
 from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars
@@ -146,3 +149,26 @@ class RiscvTunesTests(OESelftestTestCase):
                 # small, and compiled with TUNE_CCARGS. It has no do_build, and
                 # populate_sysroot also writes an sstate object.
                 bitbake('libgcc-initial -c populate_sysroot')
+
+    def test_riscv_rust_target_features(self):
+        """
+        Check that the Rust target spec passes every extension in the tune's
+        TUNE_FEATURES on to LLVM, in TUNE_FEATURES order.
+        """
+        for tune in ['riscv64gc', 'rva23u64']:
+            with self.subTest(tune=tune):
+                self.write_config(self._machine_config() + 'DEFAULTTUNE = "%s"\n' % tune)
+                # hello-rs is a small cargo recipe in meta-selftest, and
+                # do_rust_gen_targets runs right after do_patch, so neither
+                # the toolchain nor Rust has to be built
+                bitbake('hello-rs -c rust_gen_targets')
+                v = get_bb_vars(['WORKDIR', 'RUST_TARGET_SYS', 'TUNE_FEATURES'], 'hello-rs')
+                with open(os.path.join(v['WORKDIR'], 'rust-targets', v['RUST_TARGET_SYS'] + '.json')) as f:
+                    features = json.load(f)['features'].split(',')
+
+                # Everything but the base ISA and its width
+                expected = ['+' + e for e in v['TUNE_FEATURES'].split() if e not in ('rv', '64', 'i')]
+                self.assertEqual(features, expected)
+                if tune == 'riscv64gc':
+                    # The features of the existing tunes must not change
+                    self.assertEqual(features, ['+m', '+a', '+f', '+d', '+c', '+zicsr', '+zifencei'])
Signature · 1 line
2.56.0