2020-01-20 19:21:45 -08:00
|
|
|
const std = @import("../std.zig");
|
2020-02-19 18:30:36 -08:00
|
|
|
const CpuFeature = std.Target.Cpu.Feature;
|
|
|
|
const CpuModel = std.Target.Cpu.Model;
|
2019-12-20 16:27:13 -08:00
|
|
|
|
2020-01-20 19:21:45 -08:00
|
|
|
pub const Feature = enum {
|
|
|
|
@"64bit",
|
|
|
|
a,
|
|
|
|
c,
|
|
|
|
d,
|
|
|
|
e,
|
|
|
|
f,
|
|
|
|
m,
|
|
|
|
relax,
|
2020-01-30 08:31:41 -08:00
|
|
|
reserve_x1,
|
|
|
|
reserve_x10,
|
|
|
|
reserve_x11,
|
|
|
|
reserve_x12,
|
|
|
|
reserve_x13,
|
|
|
|
reserve_x14,
|
|
|
|
reserve_x15,
|
|
|
|
reserve_x16,
|
|
|
|
reserve_x17,
|
|
|
|
reserve_x18,
|
|
|
|
reserve_x19,
|
|
|
|
reserve_x2,
|
|
|
|
reserve_x20,
|
|
|
|
reserve_x21,
|
|
|
|
reserve_x22,
|
|
|
|
reserve_x23,
|
|
|
|
reserve_x24,
|
|
|
|
reserve_x25,
|
|
|
|
reserve_x26,
|
|
|
|
reserve_x27,
|
|
|
|
reserve_x28,
|
|
|
|
reserve_x29,
|
|
|
|
reserve_x3,
|
|
|
|
reserve_x30,
|
|
|
|
reserve_x31,
|
|
|
|
reserve_x4,
|
|
|
|
reserve_x5,
|
|
|
|
reserve_x6,
|
|
|
|
reserve_x7,
|
|
|
|
reserve_x8,
|
|
|
|
reserve_x9,
|
|
|
|
rvc_hints,
|
2019-12-20 16:27:13 -08:00
|
|
|
};
|
|
|
|
|
2020-02-19 18:30:36 -08:00
|
|
|
pub usingnamespace CpuFeature.feature_set_fns(Feature);
|
2019-12-20 16:27:13 -08:00
|
|
|
|
2020-01-20 19:21:45 -08:00
|
|
|
pub const all_features = blk: {
|
|
|
|
const len = @typeInfo(Feature).Enum.fields.len;
|
2020-02-19 18:30:36 -08:00
|
|
|
std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
|
|
|
|
var result: [len]CpuFeature = undefined;
|
2020-01-20 19:21:45 -08:00
|
|
|
result[@enumToInt(Feature.@"64bit")] = .{
|
|
|
|
.llvm_name = "64bit",
|
|
|
|
.description = "Implements RV64",
|
2020-01-21 17:11:36 -08:00
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.a)] = .{
|
|
|
|
.llvm_name = "a",
|
|
|
|
.description = "'A' (Atomic Instructions)",
|
2020-01-21 17:11:36 -08:00
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.c)] = .{
|
|
|
|
.llvm_name = "c",
|
|
|
|
.description = "'C' (Compressed Instructions)",
|
2020-01-21 17:11:36 -08:00
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.d)] = .{
|
|
|
|
.llvm_name = "d",
|
|
|
|
.description = "'D' (Double-Precision Floating-Point)",
|
2020-01-21 17:11:36 -08:00
|
|
|
.dependencies = featureSet(&[_]Feature{
|
2020-01-20 19:21:45 -08:00
|
|
|
.f,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.e)] = .{
|
|
|
|
.llvm_name = "e",
|
|
|
|
.description = "Implements RV32E (provides 16 rather than 32 GPRs)",
|
2020-01-21 17:11:36 -08:00
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.f)] = .{
|
|
|
|
.llvm_name = "f",
|
|
|
|
.description = "'F' (Single-Precision Floating-Point)",
|
2020-01-21 17:11:36 -08:00
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.m)] = .{
|
|
|
|
.llvm_name = "m",
|
|
|
|
.description = "'M' (Integer Multiplication and Division)",
|
2020-01-21 17:11:36 -08:00
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.relax)] = .{
|
|
|
|
.llvm_name = "relax",
|
|
|
|
.description = "Enable Linker relaxation.",
|
2020-01-21 17:11:36 -08:00
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
2020-01-30 08:31:41 -08:00
|
|
|
result[@enumToInt(Feature.reserve_x1)] = .{
|
|
|
|
.llvm_name = "reserve-x1",
|
|
|
|
.description = "Reserve X1",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x10)] = .{
|
|
|
|
.llvm_name = "reserve-x10",
|
|
|
|
.description = "Reserve X10",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x11)] = .{
|
|
|
|
.llvm_name = "reserve-x11",
|
|
|
|
.description = "Reserve X11",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x12)] = .{
|
|
|
|
.llvm_name = "reserve-x12",
|
|
|
|
.description = "Reserve X12",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x13)] = .{
|
|
|
|
.llvm_name = "reserve-x13",
|
|
|
|
.description = "Reserve X13",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x14)] = .{
|
|
|
|
.llvm_name = "reserve-x14",
|
|
|
|
.description = "Reserve X14",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x15)] = .{
|
|
|
|
.llvm_name = "reserve-x15",
|
|
|
|
.description = "Reserve X15",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x16)] = .{
|
|
|
|
.llvm_name = "reserve-x16",
|
|
|
|
.description = "Reserve X16",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x17)] = .{
|
|
|
|
.llvm_name = "reserve-x17",
|
|
|
|
.description = "Reserve X17",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x18)] = .{
|
|
|
|
.llvm_name = "reserve-x18",
|
|
|
|
.description = "Reserve X18",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x19)] = .{
|
|
|
|
.llvm_name = "reserve-x19",
|
|
|
|
.description = "Reserve X19",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x2)] = .{
|
|
|
|
.llvm_name = "reserve-x2",
|
|
|
|
.description = "Reserve X2",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x20)] = .{
|
|
|
|
.llvm_name = "reserve-x20",
|
|
|
|
.description = "Reserve X20",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x21)] = .{
|
|
|
|
.llvm_name = "reserve-x21",
|
|
|
|
.description = "Reserve X21",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x22)] = .{
|
|
|
|
.llvm_name = "reserve-x22",
|
|
|
|
.description = "Reserve X22",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x23)] = .{
|
|
|
|
.llvm_name = "reserve-x23",
|
|
|
|
.description = "Reserve X23",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x24)] = .{
|
|
|
|
.llvm_name = "reserve-x24",
|
|
|
|
.description = "Reserve X24",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x25)] = .{
|
|
|
|
.llvm_name = "reserve-x25",
|
|
|
|
.description = "Reserve X25",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x26)] = .{
|
|
|
|
.llvm_name = "reserve-x26",
|
|
|
|
.description = "Reserve X26",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x27)] = .{
|
|
|
|
.llvm_name = "reserve-x27",
|
|
|
|
.description = "Reserve X27",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x28)] = .{
|
|
|
|
.llvm_name = "reserve-x28",
|
|
|
|
.description = "Reserve X28",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x29)] = .{
|
|
|
|
.llvm_name = "reserve-x29",
|
|
|
|
.description = "Reserve X29",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x3)] = .{
|
|
|
|
.llvm_name = "reserve-x3",
|
|
|
|
.description = "Reserve X3",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x30)] = .{
|
|
|
|
.llvm_name = "reserve-x30",
|
|
|
|
.description = "Reserve X30",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x31)] = .{
|
|
|
|
.llvm_name = "reserve-x31",
|
|
|
|
.description = "Reserve X31",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x4)] = .{
|
|
|
|
.llvm_name = "reserve-x4",
|
|
|
|
.description = "Reserve X4",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x5)] = .{
|
|
|
|
.llvm_name = "reserve-x5",
|
|
|
|
.description = "Reserve X5",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x6)] = .{
|
|
|
|
.llvm_name = "reserve-x6",
|
|
|
|
.description = "Reserve X6",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x7)] = .{
|
|
|
|
.llvm_name = "reserve-x7",
|
|
|
|
.description = "Reserve X7",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x8)] = .{
|
|
|
|
.llvm_name = "reserve-x8",
|
|
|
|
.description = "Reserve X8",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.reserve_x9)] = .{
|
|
|
|
.llvm_name = "reserve-x9",
|
|
|
|
.description = "Reserve X9",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
|
|
|
result[@enumToInt(Feature.rvc_hints)] = .{
|
|
|
|
.llvm_name = "rvc-hints",
|
|
|
|
.description = "Enable RVC Hint Instructions.",
|
|
|
|
.dependencies = featureSet(&[_]Feature{}),
|
|
|
|
};
|
2020-01-21 16:40:44 -08:00
|
|
|
const ti = @typeInfo(Feature);
|
|
|
|
for (result) |*elem, i| {
|
|
|
|
elem.index = i;
|
|
|
|
elem.name = ti.Enum.fields[i].name;
|
|
|
|
}
|
2020-01-20 19:21:45 -08:00
|
|
|
break :blk result;
|
2019-12-20 16:27:13 -08:00
|
|
|
};
|
|
|
|
|
2020-01-20 19:21:45 -08:00
|
|
|
pub const cpu = struct {
|
2020-02-19 18:30:36 -08:00
|
|
|
pub const baseline_rv32 = CpuModel{
|
2020-01-22 14:13:31 -08:00
|
|
|
.name = "baseline_rv32",
|
2020-02-16 21:06:19 -08:00
|
|
|
.llvm_name = null,
|
2020-01-22 14:13:31 -08:00
|
|
|
.features = featureSet(&[_]Feature{
|
|
|
|
.a,
|
|
|
|
.c,
|
|
|
|
.d,
|
|
|
|
.f,
|
|
|
|
.m,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
2020-02-19 18:30:36 -08:00
|
|
|
pub const baseline_rv64 = CpuModel{
|
2020-01-22 14:13:31 -08:00
|
|
|
.name = "baseline_rv64",
|
2020-02-16 21:06:19 -08:00
|
|
|
.llvm_name = null,
|
2020-01-22 14:13:31 -08:00
|
|
|
.features = featureSet(&[_]Feature{
|
|
|
|
.@"64bit",
|
|
|
|
.a,
|
|
|
|
.c,
|
|
|
|
.d,
|
|
|
|
.f,
|
|
|
|
.m,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
2020-02-19 18:30:36 -08:00
|
|
|
pub const generic_rv32 = CpuModel{
|
2020-01-20 19:21:45 -08:00
|
|
|
.name = "generic_rv32",
|
2020-02-16 21:06:19 -08:00
|
|
|
.llvm_name = null,
|
2020-01-30 08:31:41 -08:00
|
|
|
.features = featureSet(&[_]Feature{
|
|
|
|
.rvc_hints,
|
|
|
|
}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
2020-02-19 18:30:36 -08:00
|
|
|
pub const generic_rv64 = CpuModel{
|
2020-01-20 19:21:45 -08:00
|
|
|
.name = "generic_rv64",
|
2020-02-16 21:06:19 -08:00
|
|
|
.llvm_name = null,
|
2020-01-21 17:11:36 -08:00
|
|
|
.features = featureSet(&[_]Feature{
|
2020-01-20 19:21:45 -08:00
|
|
|
.@"64bit",
|
2020-01-30 08:31:41 -08:00
|
|
|
.rvc_hints,
|
2020-01-20 19:21:45 -08:00
|
|
|
}),
|
|
|
|
};
|
2019-12-20 16:27:13 -08:00
|
|
|
};
|
|
|
|
|
2020-01-20 19:21:45 -08:00
|
|
|
/// All riscv CPUs, sorted alphabetically by name.
|
|
|
|
/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
|
|
|
|
/// compiler has inefficient memory and CPU usage, affecting build times.
|
2020-02-19 18:30:36 -08:00
|
|
|
pub const all_cpus = &[_]*const CpuModel{
|
2020-01-22 14:13:31 -08:00
|
|
|
&cpu.baseline_rv32,
|
|
|
|
&cpu.baseline_rv64,
|
2020-01-20 19:21:45 -08:00
|
|
|
&cpu.generic_rv32,
|
|
|
|
&cpu.generic_rv64,
|
2019-12-20 16:27:13 -08:00
|
|
|
};
|