@@ -6,70 +6,38 @@ use crate::detect::{Feature, bit, cache};
6
6
/// Read list of supported features from the auxiliary vector.
7
7
pub ( crate ) fn detect_features ( ) -> cache:: Initializer {
8
8
let mut value = cache:: Initializer :: default ( ) ;
9
- let enable_feature = |value : & mut cache :: Initializer , feature, enable| {
9
+ let mut enable_feature = |feature, enable| {
10
10
if enable {
11
11
value. set ( feature as u32 ) ;
12
12
}
13
13
} ;
14
- let enable_features = |value : & mut cache:: Initializer , feature_slice : & [ Feature ] , enable| {
15
- if enable {
16
- for feature in feature_slice {
17
- value. set ( * feature as u32 ) ;
18
- }
19
- }
20
- } ;
21
14
22
15
// Use auxiliary vector to enable single-letter ISA extensions and Zicsr.
23
16
// The values are part of the platform-specific [asm/hwcap.h][hwcap]
24
17
//
25
18
// [hwcap]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/uapi/asm/hwcap.h?h=v6.14
26
19
let auxv = auxvec:: auxv ( ) . expect ( "read auxvec" ) ; // should not fail on RISC-V platform
27
20
#[ allow( clippy:: eq_op) ]
28
- enable_feature (
29
- & mut value,
30
- Feature :: a,
31
- bit:: test ( auxv. hwcap , ( b'a' - b'a' ) . into ( ) ) ,
32
- ) ;
33
- enable_feature (
34
- & mut value,
35
- Feature :: c,
36
- bit:: test ( auxv. hwcap , ( b'c' - b'a' ) . into ( ) ) ,
37
- ) ;
38
- enable_features (
39
- & mut value,
40
- & [ Feature :: d, Feature :: f, Feature :: zicsr] ,
41
- bit:: test ( auxv. hwcap , ( b'd' - b'a' ) . into ( ) ) ,
42
- ) ;
43
- enable_features (
44
- & mut value,
45
- & [ Feature :: f, Feature :: zicsr] ,
46
- bit:: test ( auxv. hwcap , ( b'f' - b'a' ) . into ( ) ) ,
47
- ) ;
48
- enable_feature (
49
- & mut value,
50
- Feature :: h,
51
- bit:: test ( auxv. hwcap , ( b'h' - b'a' ) . into ( ) ) ,
52
- ) ;
53
- enable_feature (
54
- & mut value,
55
- Feature :: m,
56
- bit:: test ( auxv. hwcap , ( b'm' - b'a' ) . into ( ) ) ,
57
- ) ;
21
+ enable_feature ( Feature :: a, bit:: test ( auxv. hwcap , ( b'a' - b'a' ) . into ( ) ) ) ;
22
+ enable_feature ( Feature :: c, bit:: test ( auxv. hwcap , ( b'c' - b'a' ) . into ( ) ) ) ;
23
+ let has_d = bit:: test ( auxv. hwcap , ( b'd' - b'a' ) . into ( ) ) ;
24
+ let has_f = bit:: test ( auxv. hwcap , ( b'f' - b'a' ) . into ( ) ) ;
25
+ enable_feature ( Feature :: d, has_d) ;
26
+ enable_feature ( Feature :: f, has_d | has_f) ;
27
+ enable_feature ( Feature :: zicsr, has_d | has_f) ;
28
+ enable_feature ( Feature :: h, bit:: test ( auxv. hwcap , ( b'h' - b'a' ) . into ( ) ) ) ;
29
+ enable_feature ( Feature :: m, bit:: test ( auxv. hwcap , ( b'm' - b'a' ) . into ( ) ) ) ;
58
30
59
31
// Handle base ISA.
60
32
let has_i = bit:: test ( auxv. hwcap , ( b'i' - b'a' ) . into ( ) ) ;
61
33
// If future RV128I is supported, implement with `enable_feature` here
62
34
#[ cfg( target_pointer_width = "64" ) ]
63
- enable_feature ( & mut value , Feature :: rv64i, has_i) ;
35
+ enable_feature ( Feature :: rv64i, has_i) ;
64
36
#[ cfg( target_pointer_width = "32" ) ]
65
- enable_feature ( & mut value , Feature :: rv32i, has_i) ;
37
+ enable_feature ( Feature :: rv32i, has_i) ;
66
38
// FIXME: e is not exposed in any of asm/hwcap.h, uapi/asm/hwcap.h, uapi/asm/hwprobe.h
67
39
#[ cfg( target_pointer_width = "32" ) ]
68
- enable_feature (
69
- & mut value,
70
- Feature :: rv32e,
71
- bit:: test ( auxv. hwcap , ( b'e' - b'a' ) . into ( ) ) ,
72
- ) ;
40
+ enable_feature ( Feature :: rv32e, bit:: test ( auxv. hwcap , ( b'e' - b'a' ) . into ( ) ) ) ;
73
41
74
42
// FIXME: Auxvec does not show supervisor feature support, but this mode may be useful
75
43
// to detect when Rust is used to write Linux kernel modules.
0 commit comments