22
33use super :: auxvec;
44use crate :: detect:: { bit, cache, Feature } ;
5+ use core:: arch:: asm;
56
67/// Try to read the features from the auxiliary vector.
78pub ( crate ) fn detect_features ( ) -> cache:: Initializer {
@@ -12,14 +13,42 @@ pub(crate) fn detect_features() -> cache::Initializer {
1213 }
1314 } ;
1415
16+ // The values are part of the platform-specific [cpucfg]
17+ //
18+ // [cpucfg]: LoongArch Reference Manual Volume 1: Basic Architecture v1.1
19+ let cpucfg2: usize ;
20+ unsafe {
21+ asm ! (
22+ "cpucfg {}, {}" ,
23+ out( reg) cpucfg2, in( reg) 2 ,
24+ options( pure, nomem, preserves_flags, nostack)
25+ ) ;
26+ }
27+ enable_feature ( & mut value, Feature :: frecipe, bit:: test ( cpucfg2, 25 ) ) ;
28+
1529 // The values are part of the platform-specific [asm/hwcap.h][hwcap]
1630 //
1731 // [hwcap]: https://github.com/torvalds/linux/blob/master/arch/loongarch/include/uapi/asm/hwcap.h
1832 if let Ok ( auxv) = auxvec:: auxv ( ) {
19- enable_feature ( & mut value, Feature :: ual, bit:: test ( auxv. hwcap , 2 ) ) ;
33+ enable_feature (
34+ & mut value,
35+ Feature :: f,
36+ bit:: test ( cpucfg2, 1 ) && bit:: test ( auxv. hwcap , 3 ) ,
37+ ) ;
38+ enable_feature (
39+ & mut value,
40+ Feature :: d,
41+ bit:: test ( cpucfg2, 2 ) && bit:: test ( auxv. hwcap , 3 ) ,
42+ ) ;
2043 enable_feature ( & mut value, Feature :: lsx, bit:: test ( auxv. hwcap , 4 ) ) ;
2144 enable_feature ( & mut value, Feature :: lasx, bit:: test ( auxv. hwcap , 5 ) ) ;
45+ enable_feature (
46+ & mut value,
47+ Feature :: lbt,
48+ bit:: test ( auxv. hwcap , 10 ) && bit:: test ( auxv. hwcap , 11 ) && bit:: test ( auxv. hwcap , 12 ) ,
49+ ) ;
2250 enable_feature ( & mut value, Feature :: lvz, bit:: test ( auxv. hwcap , 9 ) ) ;
51+ enable_feature ( & mut value, Feature :: ual, bit:: test ( auxv. hwcap , 2 ) ) ;
2352 return value;
2453 }
2554 value
0 commit comments