|
1 | 1 | /*
|
2 |
| - * Copyright (C) 2021-2022 Intel Corporation |
| 2 | + * Copyright (C) 2021-2023 Intel Corporation |
3 | 3 | *
|
4 | 4 | * SPDX-License-Identifier: MIT
|
5 | 5 | *
|
|
13 | 13 |
|
14 | 14 | namespace NEO {
|
15 | 15 | void CpuInfo::detect() const {
|
| 16 | + constexpr uint32_t processorInfo = 1; |
| 17 | + constexpr uint32_t extendedFeatures = 0x7; |
| 18 | + constexpr uint32_t extendedFunctionId = 0x80000000; |
| 19 | + constexpr uint32_t addressSize = 0x80000008; |
| 20 | + constexpr size_t eax = 0; |
| 21 | + constexpr size_t ebx = 1; |
| 22 | + constexpr size_t ecx = 2; |
| 23 | + constexpr size_t edx = 3; |
| 24 | + |
16 | 25 | uint32_t cpuInfo[4] = {};
|
17 | 26 |
|
18 | 27 | cpuid(cpuInfo, 0u);
|
19 |
| - auto numFunctionIds = cpuInfo[0]; |
20 |
| - if (numFunctionIds >= 1u) { |
21 |
| - cpuid(cpuInfo, 1u); |
| 28 | + auto numFunctionIds = cpuInfo[eax]; |
| 29 | + if (numFunctionIds >= processorInfo) { |
| 30 | + cpuid(cpuInfo, processorInfo); |
22 | 31 | {
|
23 |
| - features |= cpuInfo[3] & BIT(19) ? featureClflush : featureNone; |
| 32 | + features |= cpuInfo[edx] & BIT(19) ? featureClflush : featureNone; |
24 | 33 | }
|
25 | 34 | }
|
26 | 35 |
|
27 |
| - if (numFunctionIds >= 7u) { |
28 |
| - cpuid(cpuInfo, 7u); |
| 36 | + if (numFunctionIds >= extendedFeatures) { |
| 37 | + cpuid(cpuInfo, extendedFeatures); |
29 | 38 | {
|
30 | 39 | auto mask = BIT(5) | BIT(3) | BIT(8);
|
31 |
| - features |= (cpuInfo[1] & mask) == mask ? featureAvX2 : featureNone; |
| 40 | + features |= (cpuInfo[ebx] & mask) == mask ? featureAvX2 : featureNone; |
| 41 | + |
| 42 | + features |= (cpuInfo[ecx] & BIT(5)) ? featureWaitPkg : featureNone; |
32 | 43 | }
|
33 | 44 | }
|
34 | 45 |
|
35 |
| - cpuid(cpuInfo, 0x80000000); |
36 |
| - auto maxExtendedId = cpuInfo[0]; |
37 |
| - if (maxExtendedId >= 0x80000008) { |
38 |
| - cpuid(cpuInfo, 0x80000008); |
| 46 | + cpuid(cpuInfo, extendedFunctionId); |
| 47 | + auto maxExtendedId = cpuInfo[eax]; |
| 48 | + if (maxExtendedId >= addressSize) { |
| 49 | + cpuid(cpuInfo, addressSize); |
39 | 50 | {
|
40 |
| - virtualAddressSize = (cpuInfo[0] >> 8) & 0xFF; |
| 51 | + virtualAddressSize = (cpuInfo[eax] >> 8) & 0xFF; |
41 | 52 | }
|
42 | 53 | }
|
43 | 54 | }
|
|
0 commit comments