| ... | ... | @@ -1,6 +1,13 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | const Variant = enum(u2) { |
| 5 | la32r = 0b00, |
| 6 | la32 = 0b01, |
| 7 | la64 = 0b10, |
| 8 | reserved = 0b11, |
| 9 | }; |
| 10 | |
| 4 | 11 | inline fn bit(input: u32, offset: u5) bool { |
| 5 | 12 | return (input >> offset) & 1 != 0; |
| 6 | 13 | } |
| ... | ... | @@ -19,10 +26,16 @@ pub fn detectNativeCpuAndFeatures( |
| 19 | 26 | _ = os; |
| 20 | 27 | _ = query; |
| 21 | 28 | |
| 29 | const variant: Variant = @enumFromInt(cpucfg(1) & 0b11); |
| 30 | |
| 22 | 31 | var cpu: std.Target.Cpu = .{ |
| 23 | 32 | .arch = arch, |
| 24 | | .model = switch (cpucfg(0) & 0xf000) { |
| 25 | | else => return null, |
| 33 | .model = switch (cpucfg(0) & 0b1111000000000000) { |
| 34 | else => switch (variant) { |
| 35 | .la32r, .la32 => &std.Target.loongarch.cpu.generic_la32, |
| 36 | .la64 => &std.Target.loongarch.cpu.generic_la64, |
| 37 | .reserved => unreachable, |
| 38 | }, |
| 26 | 39 | 0xc000 => &std.Target.loongarch.cpu.la464, |
| 27 | 40 | 0xd000 => &std.Target.loongarch.cpu.la664, |
| 28 | 41 | }, |
| ... | ... | @@ -31,6 +44,8 @@ pub fn detectNativeCpuAndFeatures( |
| 31 | 44 | |
| 32 | 45 | cpu.features.addFeatureSet(cpu.model.features); |
| 33 | 46 | |
| 47 | setFeature(&cpu, .@"32s", variant != .la32r); |
| 48 | |
| 34 | 49 | const cfg2 = cpucfg(2); |
| 35 | 50 | const cfg3 = cpucfg(3); |
| 36 | 51 | |