| 57 | namespace { |
| 58 | |
| 59 | void OsRetrieveCpuInfo(int64_t* hardware_flags, CpuInfo::Vendor* vendor) { |
| 60 | const auto cpu = xsimd::cpu_features(); |
| 61 | |
| 62 | *hardware_flags |= cpu.popcnt() ? CpuInfo::POPCNT : 0; |
| 63 | *hardware_flags |= cpu.bmi1() ? CpuInfo::BMI1 : 0; |
| 64 | *hardware_flags |= cpu.bmi2() ? CpuInfo::BMI2 : 0; |
| 65 | |
| 66 | // SSE |
| 67 | *hardware_flags |= cpu.ssse3() ? CpuInfo::SSSE3 : 0; |
| 68 | *hardware_flags |= cpu.sse4_1() ? CpuInfo::SSE4_1 : 0; |
| 69 | *hardware_flags |= cpu.sse4_2() ? CpuInfo::SSE4_2 : 0; |
| 70 | // AVX |
| 71 | *hardware_flags |= cpu.avx() ? CpuInfo::AVX : 0; |
| 72 | *hardware_flags |= cpu.avx2() ? CpuInfo::AVX2 : 0; |
| 73 | // AVX 512 |
| 74 | const bool avx512f = cpu.avx512f(); |
| 75 | *hardware_flags |= cpu.avx512f() ? CpuInfo::AVX512F : 0; |
| 76 | *hardware_flags |= cpu.avx512cd() ? CpuInfo::AVX512CD : 0; |
| 77 | *hardware_flags |= cpu.avx512dq() ? CpuInfo::AVX512DQ : 0; |
| 78 | *hardware_flags |= cpu.avx512bw() ? CpuInfo::AVX512BW : 0; |
| 79 | // TODO(xsimd): Missing in xsimd 14.2.0 but fixed afterwards. |
| 80 | // Can be replaced with the following (no `if(avx512f)` required). |
| 81 | // *hardware_flags |= cpu.avx512vl() ? CpuInfo::AVX512VL : 0; |
| 82 | if (avx512f) { |
| 83 | const auto cpu_x86 = xsimd::x86_cpu_features_backend_default(); |
| 84 | auto constexpr avx512vl = static_cast<xsimd::x86_cpuid_leaf7::ebx>(31); |
| 85 | *hardware_flags |= cpu_x86.leaf7().all_bits_set<avx512vl>() ? CpuInfo::AVX512VL : 0; |
| 86 | } |
| 87 | |
| 88 | // Neon |
| 89 | *hardware_flags |= cpu.neon64() ? CpuInfo::ASIMD : 0; |
| 90 | // SVE and length |
| 91 | // Running SVE128 on a SVE256 machine is more tricky than the x86 equivalent of |
| 92 | // running SSE code on an AVX machine and requires to explicitly change the |
| 93 | // vector length using `prctl` (per thread setting). |
| 94 | const bool sve = cpu.sve(); |
| 95 | const auto sve_size = cpu.sve_size_bytes(); |
| 96 | *hardware_flags |= sve ? CpuInfo::SVE : 0; |
| 97 | *hardware_flags |= (sve && sve_size == 16) ? CpuInfo::SVE128 : 0; |
| 98 | *hardware_flags |= (sve && sve_size == 32) ? CpuInfo::SVE256 : 0; |
| 99 | *hardware_flags |= (sve && sve_size == 64) ? CpuInfo::SVE512 : 0; |
| 100 | |
| 101 | // x86 only |
| 102 | switch (cpu.known_manufacturer()) { |
| 103 | case (xsimd::x86_manufacturer::intel): |
| 104 | *vendor = CpuInfo::Vendor::Intel; |
| 105 | break; |
| 106 | case (xsimd::x86_manufacturer::amd): |
| 107 | *vendor = CpuInfo::Vendor::AMD; |
| 108 | break; |
| 109 | default: { |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | //============================== OS Dependent ==============================// |
| 115 | |