| ... | @@ -1,6 +1,10 @@ | ... | @@ -1,6 +1,10 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| | 2 | const builtin = @import("builtin"); |
| | 3 | const Target = std.Target; |
| 2 | | 4 | |
| 3 | pub const WindowsVersion = std.Target.Os.WindowsVersion; | 5 | pub const WindowsVersion = std.Target.Os.WindowsVersion; |
| | 6 | pub const PF = std.os.windows.PF; |
| | 7 | pub const IsProcessorFeaturePresent = std.os.windows.IsProcessorFeaturePresent; |
| 4 | | 8 | |
| 5 | /// Returns the highest known WindowsVersion deduced from reported runtime information. | 9 | /// Returns the highest known WindowsVersion deduced from reported runtime information. |
| 6 | /// Discards information about in-between versions we don't differentiate. | 10 | /// Discards information about in-between versions we don't differentiate. |
| ... | @@ -38,3 +42,40 @@ pub fn detectRuntimeVersion() WindowsVersion { | ... | @@ -38,3 +42,40 @@ pub fn detectRuntimeVersion() WindowsVersion { |
| 38 | | 42 | |
| 39 | return @intToEnum(WindowsVersion, version); | 43 | return @intToEnum(WindowsVersion, version); |
| 40 | } | 44 | } |
| | 45 | |
| | 46 | fn detectNativeCpuAndFeaturesArm64() Target.Cpu { |
| | 47 | const Feature = Target.aarch64.Feature; |
| | 48 | |
| | 49 | var cpu = Target.Cpu{ |
| | 50 | .arch = .aarch64, |
| | 51 | .model = Target.Cpu.Model.generic(.aarch64), |
| | 52 | .features = Target.Cpu.Feature.Set.empty, |
| | 53 | }; |
| | 54 | |
| | 55 | if (IsProcessorFeaturePresent(PF.ARM_NEON_INSTRUCTIONS_AVAILABLE)) { |
| | 56 | cpu.features.addFeature(@enumToInt(Feature.neon)); |
| | 57 | } |
| | 58 | if (IsProcessorFeaturePresent(PF.ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)) { |
| | 59 | cpu.features.addFeature(@enumToInt(Feature.crc)); |
| | 60 | } |
| | 61 | if (IsProcessorFeaturePresent(PF.ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) { |
| | 62 | cpu.features.addFeature(@enumToInt(Feature.crypto)); |
| | 63 | } |
| | 64 | |
| | 65 | return cpu; |
| | 66 | } |
| | 67 | |
| | 68 | fn getCpuCount() usize { |
| | 69 | return std.os.windows.peb().NumberOfProcessors; |
| | 70 | } |
| | 71 | |
| | 72 | pub fn detectNativeCpuAndFeatures() ?Target.Cpu { |
| | 73 | switch (builtin.cpu.arch) { |
| | 74 | .aarch64 => return detectNativeCpuAndFeaturesArm64(), |
| | 75 | else => |arch| return .{ |
| | 76 | .arch = arch, |
| | 77 | .model = Target.Cpu.Model.generic(arch), |
| | 78 | .features = Target.Cpu.Feature.Set.empty, |
| | 79 | }, |
| | 80 | } |
| | 81 | } |