Skip to content

std_detect: RISC-V Linux: Ergonomic querying with riscv_hwprobe #1839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

a4lg
Copy link
Contributor

@a4lg a4lg commented Jun 29, 2025

Originally, we used an array of riscv_hwprobe directly and indexed using raw numbers, making correspondence between the index and the query key less obvious.

We also frequently used out[idx].key != -1 to test whether the key is supported by the riscv_hwprobe system call (on the Linux kernel version we are testing) but we'd better to integrate with an operation to retrieve the value.

This commit improves the ergonomics of feature querying by:

  1. Utilizing macros to
    1. enable indexing by identifier names and
    2. encapsulate accesses to the riscv_hwprobe array to query and
  2. New method riscv_hwprobe::get() returning Option<u64>, integrating availability checking and value retrieval.

It also removes has_ima for now because it's redundant if we only need to test for single base behavior.

Implementation

It (again) uses macro_rules! which is rare in architecture-specific portion of std_detect.

Due to hygiene requirements, outer init!{} macro generates inner data_mut!() and query![] macros that access inner variable. It makes sure that the inner variable t is only accessible through inner macros (data_mut!() provides effectively raw access but still controlled).

Originally, we used an array of `riscv_hwprobe` directly and indexed
using raw numbers, making correspondence between the index and the query
key less obvious.

We also frequently used `out[idx].key != -1` to test whether the key is
supported by the `riscv_hwprobe` system call (on the Linux kernel
version we are testing) but we'd better to integrate with an operation
to retrieve the value.

This commit improves the ergonomics of feature querying by:

1.  Utilizing macros to
    a.  enable indexing by identifier names and
    b.  encapsulate accesses to the `riscv_hwprobe` array to query and
2.  New method `riscv_hwprobe::get()` returning `Option<u64>`,
    integrating availability checking and value retrieval.

It also removes `has_ima` for now because it's redundant if we only need
to test for single base behavior.
@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2025

r? @Amanieu

rustbot has assigned @Amanieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants