code wiki / (root) / nx_cpu_features.nx

nx_cpu_features.nx source

↩ module page · 22 lines · 785 B

1// nx_cpu_features.nx -- sovereign x86-64 CPU feature detection via cpuid. 2// The BMI2/ADX gate for G3 Phase-2 maax (MULX needs BMI2, ADCX/ADOX need ADX) and 3// for any future feature-gated codegen. cpuid(7,0):EBX holds the structured 4// extended-feature flags: bit 8 = BMI2, bit 19 = ADX. The EBX value is returned 5// zero-extended (positive < 2^32), so >> is unambiguous. 6 7func nx_cpu_has_bmi2() -> i64 { 8 let ebx: i64 = __cpuid_ebx(7, 0) 9 return (ebx >> 8) & 1 10} 11 12func nx_cpu_has_adx() -> i64 { 13 let ebx: i64 = __cpuid_ebx(7, 0) 14 return (ebx >> 19) & 1 15} 16 17// Both MULX (BMI2) and ADCX/ADOX (ADX) -- the maax multiply's prerequisites. 18func nx_cpu_has_adx_mulx() -> i64 { 19 if nx_cpu_has_bmi2() == 0 { return 0 } 20 if nx_cpu_has_adx() == 0 { return 0 } 21 return 1 22}