std_detect: RISC-V Linux: Ergonomic querying with riscv_hwprobe
#1839
+42
−41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theriscv_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:
riscv_hwprobe
array to query andriscv_hwprobe::get()
returningOption<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 ofstd_detect
.Due to hygiene requirements, outer
init!{}
macro generates innerdata_mut!()
andquery![]
macros that access inner variable. It makes sure that the inner variablet
is only accessible through inner macros (data_mut!()
provides effectively raw access but still controlled).