|
1 | 1 | using JSON
|
| 2 | +using Base.BinaryPlatforms: arch_march_isa_mapping |
| 3 | +using Base.BinaryPlatforms.CPUID |
2 | 4 |
|
3 | 5 | ## We start with definitions of instruction mnemonics, broken down by category:
|
4 | 6 | const instruction_categories = JSON.parsefile(joinpath(@__DIR__, "instructions.json");
|
@@ -168,3 +170,34 @@ function analyze_instruction_set(oh::ObjectHandle, platform::AbstractPlatform; v
|
168 | 170 | # Otherwise, return `min_march` and let 'em know!
|
169 | 171 | return min_march
|
170 | 172 | end
|
| 173 | + |
| 174 | +function augment_microarchitecture!(platform::Platform) |
| 175 | + haskey(platform, "march") && return platform |
| 176 | + |
| 177 | + host_arch = arch(HostPlatform()) |
| 178 | + host_isas = arch_march_isa_mapping[host_arch] |
| 179 | + idx = findlast(((name, isa),) -> isa <= CPUID.cpu_isa(), host_isas) |
| 180 | + platform["march"] = first(host_isas[idx]) |
| 181 | + return platform |
| 182 | +end |
| 183 | + |
| 184 | +function march_comparison_strategy(a::String, b::String, a_requested::Bool, b_requested::Bool) |
| 185 | + function get_arch_isa(isa_name::String) |
| 186 | + for (arch, isas) in arch_march_isa_mapping |
| 187 | + for (name, isa) in isas |
| 188 | + name == isa_name && return arch, isa |
| 189 | + end |
| 190 | + end |
| 191 | + return nothing, nothing |
| 192 | + end |
| 193 | + |
| 194 | + a_arch, a_isa = get_arch_isa(a) |
| 195 | + b_arch, b_isa = get_arch_isa(b) |
| 196 | + if any(isnothing, (a_arch, b_arch)) || a_arch != b_arch |
| 197 | + # Architectures are definitely not compatible, exit early |
| 198 | + return false |
| 199 | + end |
| 200 | + |
| 201 | + # ISA `a` is compatible with ISA `b` only if it's a subset of `b` |
| 202 | + return a_isa ≤ b_isa |
| 203 | +end |
0 commit comments