2020-01-20 19:21:45 -08:00
|
|
|
const std = @import("../std.zig");
|
|
|
|
const Cpu = std.Target.Cpu;
|
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,
|
2019-12-20 16:27:13 -08:00
|
|
|
};
|
|
|
|
|
2020-01-20 19:21:45 -08:00
|
|
|
pub usingnamespace Cpu.Feature.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-01-21 16:40:44 -08:00
|
|
|
std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
|
2020-01-20 19:21:45 -08:00
|
|
|
var result: [len]Cpu.Feature = undefined;
|
|
|
|
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-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-01-22 14:13:31 -08:00
|
|
|
pub const baseline_rv32 = Cpu{
|
|
|
|
.name = "baseline_rv32",
|
|
|
|
.llvm_name = "generic-rv32",
|
|
|
|
.features = featureSet(&[_]Feature{
|
|
|
|
.a,
|
|
|
|
.c,
|
|
|
|
.d,
|
|
|
|
.f,
|
|
|
|
.m,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const baseline_rv64 = Cpu{
|
|
|
|
.name = "baseline_rv64",
|
|
|
|
.llvm_name = "generic-rv64",
|
|
|
|
.features = featureSet(&[_]Feature{
|
|
|
|
.@"64bit",
|
|
|
|
.a,
|
|
|
|
.c,
|
|
|
|
.d,
|
|
|
|
.f,
|
|
|
|
.m,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
2020-01-20 19:21:45 -08:00
|
|
|
pub const generic_rv32 = Cpu{
|
|
|
|
.name = "generic_rv32",
|
|
|
|
.llvm_name = "generic-rv32",
|
2020-01-21 17:11:36 -08:00
|
|
|
.features = featureSet(&[_]Feature{}),
|
2020-01-20 19:21:45 -08:00
|
|
|
};
|
2020-01-22 14:13:31 -08:00
|
|
|
|
2020-01-20 19:21:45 -08:00
|
|
|
pub const generic_rv64 = Cpu{
|
|
|
|
.name = "generic_rv64",
|
|
|
|
.llvm_name = "generic-rv64",
|
2020-01-21 17:11:36 -08:00
|
|
|
.features = featureSet(&[_]Feature{
|
2020-01-20 19:21:45 -08:00
|
|
|
.@"64bit",
|
|
|
|
}),
|
|
|
|
};
|
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.
|
|
|
|
pub const all_cpus = &[_]*const Cpu{
|
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
|
|
|
};
|