diff options
| author | 2022-02-23 10:43:41 -0800 | |
|---|---|---|
| committer | 2022-03-09 13:57:47 -0800 | |
| commit | 86e9e60f07d59d6e3bf5d3a9cabf7db3fedb40c7 (patch) | |
| tree | 9da8ad92482fb5b31dee53511b89631ac7a4df88 /src/common/x64/cpu_detect.cpp | |
| parent | cpu_detect: Utilize `Bit<N>` utility function (diff) | |
| download | yuzu-86e9e60f07d59d6e3bf5d3a9cabf7db3fedb40c7.tar.gz yuzu-86e9e60f07d59d6e3bf5d3a9cabf7db3fedb40c7.tar.xz yuzu-86e9e60f07d59d6e3bf5d3a9cabf7db3fedb40c7.zip | |
cpu_detect: Update array-types to `span` and `array`
Update some uses of `int` into some more explicitly sized types as well
Diffstat (limited to 'src/common/x64/cpu_detect.cpp')
| -rw-r--r-- | src/common/x64/cpu_detect.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/common/x64/cpu_detect.cpp b/src/common/x64/cpu_detect.cpp index fee00914a..23adc5c75 100644 --- a/src/common/x64/cpu_detect.cpp +++ b/src/common/x64/cpu_detect.cpp | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project / 2015 Citra Emulator Project / 2022 Yuzu Emulator | 1 | // Copyright 2013 Dolphin Emulator Project / 2015 Citra Emulator Project / 2022 Yuzu Emulator |
| 2 | // Project Licensed under GPLv2 or any later version Refer to the license.txt file included. | 2 | // Project Licensed under GPLv2 or any later version Refer to the license.txt file included. |
| 3 | 3 | ||
| 4 | #include <array> | ||
| 4 | #include <cstring> | 5 | #include <cstring> |
| 6 | #include <span> | ||
| 5 | #include "common/bit_util.h" | 7 | #include "common/bit_util.h" |
| 6 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 7 | #include "common/x64/cpu_detect.h" | 9 | #include "common/x64/cpu_detect.h" |
| @@ -17,7 +19,7 @@ | |||
| 17 | // clang-format on | 19 | // clang-format on |
| 18 | #endif | 20 | #endif |
| 19 | 21 | ||
| 20 | static inline void __cpuidex(int info[4], int function_id, int subfunction_id) { | 22 | static inline void __cpuidex(const std::span<u32, 4> info, u32 function_id, u32 subfunction_id) { |
| 21 | #if defined(__DragonFly__) || defined(__FreeBSD__) | 23 | #if defined(__DragonFly__) || defined(__FreeBSD__) |
| 22 | // Despite the name, this is just do_cpuid() with ECX as second input. | 24 | // Despite the name, this is just do_cpuid() with ECX as second input. |
| 23 | cpuid_count((u_int)function_id, (u_int)subfunction_id, (u_int*)info); | 25 | cpuid_count((u_int)function_id, (u_int)subfunction_id, (u_int*)info); |
| @@ -30,7 +32,7 @@ static inline void __cpuidex(int info[4], int function_id, int subfunction_id) { | |||
| 30 | #endif | 32 | #endif |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | static inline void __cpuid(int info[4], int function_id) { | 35 | static inline void __cpuid(const std::span<u32, 4> info, u32 function_id) { |
| 34 | return __cpuidex(info, function_id, 0); | 36 | return __cpuidex(info, function_id, 0); |
| 35 | } | 37 | } |
| 36 | 38 | ||
| @@ -52,16 +54,16 @@ static CPUCaps Detect() { | |||
| 52 | // Assumes the CPU supports the CPUID instruction. Those that don't would likely not support | 54 | // Assumes the CPU supports the CPUID instruction. Those that don't would likely not support |
| 53 | // yuzu at all anyway | 55 | // yuzu at all anyway |
| 54 | 56 | ||
| 55 | int cpu_id[4]; | 57 | std::array<u32, 4> cpu_id; |
| 56 | memset(caps.brand_string, 0, sizeof(caps.brand_string)); | 58 | std::memset(caps.brand_string, 0, sizeof(caps.brand_string)); |
| 57 | 59 | ||
| 58 | // Detect CPU's CPUID capabilities and grab CPU string | 60 | // Detect CPU's CPUID capabilities and grab CPU string |
| 59 | __cpuid(cpu_id, 0x00000000); | 61 | __cpuid(cpu_id, 0x00000000); |
| 60 | u32 max_std_fn = cpu_id[0]; // EAX | 62 | u32 max_std_fn = cpu_id[0]; // EAX |
| 61 | 63 | ||
| 62 | std::memcpy(&caps.brand_string[0], &cpu_id[1], sizeof(int)); | 64 | std::memcpy(&caps.brand_string[0], &cpu_id[1], sizeof(u32)); |
| 63 | std::memcpy(&caps.brand_string[4], &cpu_id[3], sizeof(int)); | 65 | std::memcpy(&caps.brand_string[4], &cpu_id[3], sizeof(u32)); |
| 64 | std::memcpy(&caps.brand_string[8], &cpu_id[2], sizeof(int)); | 66 | std::memcpy(&caps.brand_string[8], &cpu_id[2], sizeof(u32)); |
| 65 | if (cpu_id[1] == 0x756e6547 && cpu_id[2] == 0x6c65746e && cpu_id[3] == 0x49656e69) | 67 | if (cpu_id[1] == 0x756e6547 && cpu_id[2] == 0x6c65746e && cpu_id[3] == 0x49656e69) |
| 66 | caps.manufacturer = Manufacturer::Intel; | 68 | caps.manufacturer = Manufacturer::Intel; |
| 67 | else if (cpu_id[1] == 0x68747541 && cpu_id[2] == 0x444d4163 && cpu_id[3] == 0x69746e65) | 69 | else if (cpu_id[1] == 0x68747541 && cpu_id[2] == 0x444d4163 && cpu_id[3] == 0x69746e65) |
| @@ -76,7 +78,7 @@ static CPUCaps Detect() { | |||
| 76 | u32 max_ex_fn = cpu_id[0]; | 78 | u32 max_ex_fn = cpu_id[0]; |
| 77 | 79 | ||
| 78 | // Set reasonable default brand string even if brand string not available | 80 | // Set reasonable default brand string even if brand string not available |
| 79 | strcpy(caps.cpu_string, caps.brand_string); | 81 | std::strcpy(caps.cpu_string, caps.brand_string); |
| 80 | 82 | ||
| 81 | // Detect family and other miscellaneous features | 83 | // Detect family and other miscellaneous features |
| 82 | if (max_std_fn >= 1) { | 84 | if (max_std_fn >= 1) { |
| @@ -119,11 +121,11 @@ static CPUCaps Detect() { | |||
| 119 | if (max_ex_fn >= 0x80000004) { | 121 | if (max_ex_fn >= 0x80000004) { |
| 120 | // Extract CPU model string | 122 | // Extract CPU model string |
| 121 | __cpuid(cpu_id, 0x80000002); | 123 | __cpuid(cpu_id, 0x80000002); |
| 122 | std::memcpy(caps.cpu_string, cpu_id, sizeof(cpu_id)); | 124 | std::memcpy(caps.cpu_string, cpu_id.data(), sizeof(cpu_id)); |
| 123 | __cpuid(cpu_id, 0x80000003); | 125 | __cpuid(cpu_id, 0x80000003); |
| 124 | std::memcpy(caps.cpu_string + 16, cpu_id, sizeof(cpu_id)); | 126 | std::memcpy(caps.cpu_string + 16, cpu_id.data(), sizeof(cpu_id)); |
| 125 | __cpuid(cpu_id, 0x80000004); | 127 | __cpuid(cpu_id, 0x80000004); |
| 126 | std::memcpy(caps.cpu_string + 32, cpu_id, sizeof(cpu_id)); | 128 | std::memcpy(caps.cpu_string + 32, cpu_id.data(), sizeof(cpu_id)); |
| 127 | } | 129 | } |
| 128 | 130 | ||
| 129 | if (max_ex_fn >= 0x80000001) { | 131 | if (max_ex_fn >= 0x80000001) { |