authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-11-10 06:52:12+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-11-10 08:20:21+01:00
log2c470d24b3c3c939a0ec20292b5d28d92c16b431
treece332a6d8d2e529cb187faae5d848c7791fa8ba2
parent5358af7ba4cf16bef1734729646b99842e439916
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Target: add Arch tag and info for kvx


8 files changed, 139 insertions(+), 1 deletions(-)

lib/compiler/aro/aro/target.zig+4-1
......@@ -477,6 +477,7 @@ pub fn get32BitArchVariant(target: std.Target) ?std.Target {
477477 .ve,
478478 .bpfel,
479479 .bpfeb,
480 .kvx,
480481 .s390x,
481482 => return null,
482483
......@@ -551,6 +552,7 @@ pub fn get64BitArchVariant(target: std.Target) ?std.Target {
551552 .nvptx64,
552553 .wasm64,
553554 .spirv64,
555 .kvx,
554556 .loongarch64,
555557 .mips64,
556558 .mips64el,
......@@ -636,8 +638,9 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
636638 .wasm32 => "wasm32",
637639 .wasm64 => "wasm64",
638640 .ve => "ve",
639 // Note: propeller1, kalimba and or1k are not supported in LLVM; this is the Zig arch name
641 // Note: propeller1, kalimba, kvx, and or1k are not supported in LLVM; this is the Zig arch name
640642 .kalimba => "kalimba",
643 .kvx => "kvx",
641644 .propeller => "propeller",
642645 .or1k => "or1k",
643646 };
lib/std/Target.zig+22
......@@ -710,6 +710,7 @@ pub const csky = @import("Target/csky.zig");
710710pub const hexagon = @import("Target/hexagon.zig");
711711pub const hppa = @import("Target/generic.zig");
712712pub const kalimba = @import("Target/generic.zig");
713pub const kvx = @import("Target/kvx.zig");
713714pub const lanai = @import("Target/lanai.zig");
714715pub const loongarch = @import("Target/loongarch.zig");
715716pub const m68k = @import("Target/m68k.zig");
......@@ -1043,6 +1044,7 @@ pub fn toElfMachine(target: *const Target) std.elf.EM {
10431044 .hexagon => .QDSP6,
10441045 .hppa, .hppa64 => .PARISC,
10451046 .kalimba => .CSR_KALIMBA,
1047 .kvx => .KVX,
10461048 .lanai => .LANAI,
10471049 .loongarch32, .loongarch64 => .LOONGARCH,
10481050 .m68k => .@"68K",
......@@ -1105,6 +1107,7 @@ pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {
11051107 .hppa,
11061108 .hppa64,
11071109 .kalimba,
1110 .kvx,
11081111 .lanai,
11091112 .m68k,
11101113 .microblaze,
......@@ -1310,6 +1313,7 @@ pub const Cpu = struct {
13101313 hppa,
13111314 hppa64,
13121315 kalimba,
1316 kvx,
13131317 lanai,
13141318 loongarch32,
13151319 loongarch64,
......@@ -1385,6 +1389,7 @@ pub const Cpu = struct {
13851389 hexagon,
13861390 hppa,
13871391 kalimba,
1392 kvx,
13881393 lanai,
13891394 loongarch,
13901395 m68k,
......@@ -1420,6 +1425,7 @@ pub const Cpu = struct {
14201425 .hexagon => .hexagon,
14211426 .hppa, .hppa64 => .hppa,
14221427 .kalimba => .kalimba,
1428 .kvx => .kvx,
14231429 .lanai => .lanai,
14241430 .loongarch32, .loongarch64 => .loongarch,
14251431 .m68k => .m68k,
......@@ -1623,6 +1629,7 @@ pub const Cpu = struct {
16231629 .csky,
16241630 .hexagon,
16251631 .kalimba,
1632 .kvx,
16261633 .loongarch32,
16271634 .loongarch64,
16281635 .microblazeel,
......@@ -1847,6 +1854,10 @@ pub const Cpu = struct {
18471854 .hppa64_elf,
18481855 => &.{.hppa64},
18491856
1857 .kvx_lp64,
1858 .kvx_ilp32,
1859 => &.{.kvx},
1860
18501861 .lanai_sysv,
18511862 => &.{.lanai},
18521863
......@@ -1936,6 +1947,7 @@ pub const Cpu = struct {
19361947 return switch (arch) {
19371948 .amdgcn => &amdgcn.cpu.gfx600,
19381949 .avr => &avr.cpu.avr1,
1950 .kvx => &kvx.cpu.coolidge_v1,
19391951 .loongarch32 => &loongarch.cpu.generic_la32,
19401952 .loongarch64 => &loongarch.cpu.generic_la64,
19411953 .mips, .mipsel => &mips.cpu.mips32,
......@@ -1987,6 +1999,7 @@ pub const Cpu = struct {
19871999 .bpfel, .bpfeb => &bpf.cpu.v3,
19882000 .csky => &csky.cpu.ck810, // gcc/clang do not have a generic csky model.
19892001 .hexagon => &hexagon.cpu.hexagonv68, // gcc/clang do not have a generic hexagon model.
2002 .kvx => &kvx.cpu.coolidge_v2,
19902003 .lanai => &lanai.cpu.v11, // clang does not have a generic lanai model.
19912004 .loongarch64 => &loongarch.cpu.la64v1_0,
19922005 .m68k => &m68k.cpu.M68000,
......@@ -2440,6 +2453,7 @@ pub const DynamicLinker = struct {
24402453 .aarch64,
24412454 .aarch64_be,
24422455 .hexagon,
2456 .kvx,
24432457 .m68k,
24442458 .microblaze,
24452459 .microblazeel,
......@@ -2817,6 +2831,7 @@ pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {
28172831 .bpfeb,
28182832 .bpfel,
28192833 .hppa64,
2834 .kvx,
28202835 .loongarch64,
28212836 .mips64,
28222837 .mips64el,
......@@ -3375,6 +3390,7 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
33753390 .aarch64_be,
33763391 .alpha,
33773392 .hppa64,
3393 .kvx,
33783394 .loongarch32,
33793395 .loongarch64,
33803396 .mips64,
......@@ -3482,6 +3498,7 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
34823498 .aarch64_be,
34833499 .alpha,
34843500 .hppa64,
3501 .kvx,
34853502 .loongarch32,
34863503 .loongarch64,
34873504 .mips64,
......@@ -3557,6 +3574,7 @@ pub fn cMaxIntAlignment(target: *const Target) u16 {
35573574 .bpfel,
35583575 .bpfeb,
35593576 .hppa64,
3577 .kvx,
35603578 .loongarch64,
35613579 .mips64,
35623580 .mips64el,
......@@ -3626,6 +3644,10 @@ pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention
36263644 .hppa => .{ .hppa_elf = .{} },
36273645 .hppa64 => .{ .hppa64_elf = .{} },
36283646 .kalimba => null,
3647 .kvx => switch (target.abi) {
3648 .ilp32 => .{ .kvx_ilp32 = .{} },
3649 else => .{ .kvx_lp64 = .{} },
3650 },
36293651 .lanai => .{ .lanai_sysv = .{} },
36303652 .loongarch64 => .{ .loongarch64_lp64 = .{} },
36313653 .loongarch32 => .{ .loongarch32_ilp32 = .{} },
lib/std/Target/kvx.zig created+64
......@@ -0,0 +1,64 @@
1//! This file is auto-generated by tools/update_cpu_features.zig.
2
3const std = @import("../std.zig");
4const CpuFeature = std.Target.Cpu.Feature;
5const CpuModel = std.Target.Cpu.Model;
6
7pub const Feature = enum {
8 v3_1,
9 v3_2,
10 v4_1,
11};
12
13pub const featureSet = CpuFeature.FeatureSetFns(Feature).featureSet;
14pub const featureSetHas = CpuFeature.FeatureSetFns(Feature).featureSetHas;
15pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
16pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
17
18pub const all_features = blk: {
19 const len = @typeInfo(Feature).@"enum".fields.len;
20 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
21 var result: [len]CpuFeature = undefined;
22 result[@intFromEnum(Feature.v3_1)] = .{
23 .llvm_name = null,
24 .description = "Enable ISA v3.1",
25 .dependencies = featureSet(&[_]Feature{}),
26 };
27 result[@intFromEnum(Feature.v3_2)] = .{
28 .llvm_name = null,
29 .description = "Enable ISA v3.2",
30 .dependencies = featureSet(&[_]Feature{
31 .v3_1,
32 }),
33 };
34 result[@intFromEnum(Feature.v4_1)] = .{
35 .llvm_name = null,
36 .description = "Enable ISA v4.1",
37 .dependencies = featureSet(&[_]Feature{
38 .v3_2,
39 }),
40 };
41 const ti = @typeInfo(Feature);
42 for (&result, 0..) |*elem, i| {
43 elem.index = i;
44 elem.name = ti.@"enum".fields[i].name;
45 }
46 break :blk result;
47};
48
49pub const cpu = struct {
50 pub const coolidge_v1: CpuModel = .{
51 .name = "coolidge_v1",
52 .llvm_name = null,
53 .features = featureSet(&[_]Feature{
54 .v3_1,
55 }),
56 };
57 pub const coolidge_v2: CpuModel = .{
58 .name = "coolidge_v2",
59 .llvm_name = null,
60 .features = featureSet(&[_]Feature{
61 .v3_2,
62 }),
63 };
64};
lib/std/builtin.zig+4
......@@ -274,6 +274,9 @@ pub const CallingConvention = union(enum(u8)) {
274274 /// The standard `hppa64` calling convention.
275275 hppa64_elf: CommonOptions,
276276
277 kvx_lp64: CommonOptions,
278 kvx_ilp32: CommonOptions,
279
277280 /// The standard `lanai` calling convention.
278281 lanai_sysv: CommonOptions,
279282
......@@ -959,6 +962,7 @@ pub const VaList = switch (builtin.cpu.arch) {
959962 .csky,
960963 .hppa,
961964 .hppa64,
965 .kvx,
962966 .lanai,
963967 .loongarch32,
964968 .loongarch64,
src/Sema.zig+2
......@@ -9074,6 +9074,8 @@ const calling_conventions_supporting_var_args = [_]std.builtin.CallingConvention
90749074 .hexagon_sysv_hvx,
90759075 .hppa_elf,
90769076 .hppa64_elf,
9077 .kvx_lp64,
9078 .kvx_ilp32,
90779079 .lanai_sysv,
90789080 .loongarch64_lp64,
90799081 .loongarch32_ilp32,
src/codegen/llvm.zig+5
......@@ -111,6 +111,7 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
111111 .hppa,
112112 .hppa64,
113113 .kalimba,
114 .kvx,
114115 .microblaze,
115116 .microblazeel,
116117 .or1k,
......@@ -476,6 +477,7 @@ pub fn dataLayout(target: *const std.Target) []const u8 {
476477 .hppa,
477478 .hppa64,
478479 .kalimba,
480 .kvx,
479481 .microblaze,
480482 .microblazeel,
481483 .or1k,
......@@ -11930,6 +11932,8 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s
1193011932 .hexagon_sysv_hvx,
1193111933 .hppa_elf,
1193211934 .hppa64_elf,
11935 .kvx_lp64,
11936 .kvx_ilp32,
1193311937 .lanai_sysv,
1193411938 .loongarch64_lp64,
1193511939 .loongarch32_ilp32,
......@@ -13113,6 +13117,7 @@ pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
1311313117 .hppa,
1311413118 .hppa64,
1311513119 .kalimba,
13120 .kvx,
1311613121 .microblaze,
1311713122 .microblazeel,
1311813123 .or1k,
src/target.zig+1
......@@ -219,6 +219,7 @@ pub fn hasLlvmSupport(target: *const std.Target, ofmt: std.Target.ObjectFormat)
219219 .hppa,
220220 .hppa64,
221221 .kalimba,
222 .kvx,
222223 .microblaze,
223224 .microblazeel,
224225 .or1k,
tools/update_cpu_features.zig+37
......@@ -973,6 +973,43 @@ const targets = [_]ArchTarget{
973973 .td_name = "Hexagon",
974974 },
975975 },
976 .{
977 .zig_name = "kvx",
978 .llvm = null,
979 .extra_features = &.{
980 .{
981 .zig_name = "v3_1",
982 .desc = "Enable ISA v3.1",
983 .deps = &.{},
984 },
985 .{
986 .zig_name = "v3_2",
987 .desc = "Enable ISA v3.2",
988 .deps = &.{"v3_1"},
989 },
990 .{
991 .zig_name = "v4_1",
992 .desc = "Enable ISA v4.1",
993 .deps = &.{"v3_2"},
994 },
995 },
996 .extra_cpus = &.{
997 .{
998 .llvm_name = null,
999 .zig_name = "coolidge_v1",
1000 .features = &.{
1001 "v3_1",
1002 },
1003 },
1004 .{
1005 .llvm_name = null,
1006 .zig_name = "coolidge_v2",
1007 .features = &.{
1008 "v3_2",
1009 },
1010 },
1011 },
1012 },
9761013 .{
9771014 .zig_name = "lanai",
9781015 .llvm = .{