nx_cpu_features_test.nx source
↩ module page · 21 lines · 778 B
1// nx_cpu_features_test.nx -- KAT for the cpuid feature gate. Asserts the results
2// are valid booleans, prints them, and (for the deploy target -- a modern x86 box)
3// requires BMI2 + ADX present. Cross-checked against /proc/cpuinfo. license_tier: ORIGINAL
4
5import "nx_syscalls.nx"
6import "nx_cpu_features.nx"
7
8func main() -> i64 {
9 let bmi2: i64 = nx_cpu_has_bmi2()
10 let adx: i64 = nx_cpu_has_adx()
11
12 // must be valid booleans (not garbage from a mis-encoded cpuid)
13 if bmi2 != 0 { if bmi2 != 1 { return 1 } }
14 if adx != 0 { if adx != 1 { return 2 } }
15
16 // deploy-target expectation (this box has bmi2+adx per /proc/cpuinfo).
17 // If cpuid mis-extracted the bits, these fail.
18 if bmi2 != 1 { return 10 }
19 if adx != 1 { return 11 }
20 return 0
21}