Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ pub fn build(b: *std.Build) void {
b.installArtifact(wasm_cli);
wasm_cli_artifact = wasm_cli;
const run_cli = b.addRunArtifact(wasm_cli);
if (b.args) |a| run_cli.addArgs(a);
run_cli.addPassthruArgs();
const run_step = b.step("run-wasm", "Run the host Wasm CLI: -- <file.wasm> [export] [i32 args]");
run_step.dependOn(&run_cli.step);
}

// The GLSL -> SPIR-V shader compiler CLI runner (glsl_cli is declared above).
if (target.result.os.tag != .uefi) {
const run_glsl = b.addRunArtifact(glsl_cli);
if (b.args) |a| run_glsl.addArgs(a);
run_glsl.addPassthruArgs();
const run_glsl_step = b.step("run-glsl", "Run the GLSL->SPIR-V compiler: -- <input.glsl> [stage] [-o out.spv]");
run_glsl_step.dependOn(&run_glsl.step);

Expand All @@ -232,7 +232,7 @@ pub fn build(b: *std.Build) void {
}) });
b.installArtifact(disasm_cli);
const run_disasm = b.addRunArtifact(disasm_cli);
if (b.args) |a| run_disasm.addArgs(a);
run_disasm.addPassthruArgs();
const run_disasm_step = b.step("run-disasm", "Disassemble an ELF or SPIR-V binary to text assembly: -- <file>");
run_disasm_step.dependOn(&run_disasm.step);

Expand All @@ -252,7 +252,7 @@ pub fn build(b: *std.Build) void {
}) });
b.installArtifact(uarch_bench_cli);
const run_uarch_bench = b.addRunArtifact(uarch_bench_cli);
if (b.args) |a| run_uarch_bench.addArgs(a);
run_uarch_bench.addPassthruArgs();
const run_uarch_bench_step = b.step("run-uarch-bench", "Benchmark the microarch optimizer: -- [--model <tag> | --list | --custom]");
run_uarch_bench_step.dependOn(&run_uarch_bench.step);
}
Expand Down
10 changes: 5 additions & 5 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
.name = .vulcan,
.version = "0.0.0",
.fingerprint = 0xb0060bbb641fa177,
.minimum_zig_version = "0.16.0",
.minimum_zig_version = "0.17.0",
.dependencies = .{
.uefi = .{
.url = "git+https://git.lilithsemi.com/LilithSemi/uefi.zig#e5c9c30f847845c406da08dea2faf79964b0e793",
.hash = "uefi-0.1.0-1okz4b5QAAD-ImP4Q86o97td2DpQNfFhltlBjgnLdL8X",
.url = "git+https://git.lilithsemi.com/LilithSemi/uefi.zig#986da3d3257af14381194a9f6d3305b42ab5c200",
.hash = "uefi-0.1.0-1okz4W9QAABRgMd4j0-GeQLna8qyVgujEeAsasKoOP4O",
},
.nvidia = .{
.url = "git+https://git.lilithsemi.com/LilithSemi/nvidia.zig#c278df01ad3dcf3568a2ed530719eb7b8ac178de",
.hash = "nvidia-0.1.0-nX_095kyCwArp7mMdvRev_44U2oXxZXf7y8Q66L6PdhZ",
.url = "git+https://git.lilithsemi.com/LilithSemi/nvidia.zig#05e7ddedfc17c5d95d6c4d5435a467d5fc884a2c",
.hash = "nvidia-0.1.0-nX_09yYxCwBzixjrJ8xdHL3cUo3DBntoSWQHr2Mi_5Fn",
},
},
.paths = .{
Expand Down
30 changes: 15 additions & 15 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@

treefmt.programs = {
nixfmt.enable = true;
zig.enable = true;
zig = {
enable = true;
package = pkgs.zig_0_17;
};
};

overlayAttrs = {
flakever = flakeverConfig;
erbium-hal = pkgs.callPackage ./pkgs/erbium-hal { };
etsoc-sysemu = pkgs.callPackage ./pkgs/etsoc-sysemu { };
vulcan = pkgs.callPackage ./pkgs/vulcan { };
vulcan = pkgs.callPackage ./pkgs/vulcan { zig = pkgs.zig_0_17; };
};

packages = {
Expand Down
2 changes: 1 addition & 1 deletion libs/vulcan-cc/abi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn classifyX86_64(ty: ctype.CType, l: layout.TargetLayout) ClassResult {
if (size > 16 or hasUnalignedField(def, l)) {
return .{ .arg = .memory_stack, .ret = .sret };
}
var byte_class: [16]?Class = .{null} ** 16;
var byte_class: [16]?Class = @splat(null);
if (!def.is_union) collectLeavesX86_64(ty, 0, l, &byte_class);

var pieces: [4]Eightbyte = undefined;
Expand Down
2 changes: 1 addition & 1 deletion libs/vulcan-cc/consteval.zig
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ fn writeBitfieldLeaf(arena: std.mem.Allocator, bytes: []u8, unit_ty: ctype.CType
const clear_mask: u64 = (~shifted_mask) & type_mask;
// Read the current unit little-endian (zero-padded to 8 bytes), clear the field's bits, OR
// the new value's low `w` bits shifted up to `bit_off`, and write the unit back.
var buf: [8]u8 = [_]u8{0} ** 8;
var buf: [8]u8 = @splat(0);
@memcpy(buf[0..unit_size], bytes[off .. off + unit_size]);
const cur = std.mem.readInt(u64, &buf, .little);
const new_unit = (cur & clear_mask) | (((v & field_mask) << @intCast(bit_off)) & type_mask);
Expand Down
6 changes: 3 additions & 3 deletions libs/vulcan-cc/ctype.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub const IntType = struct {

/// Integer promotion: types of rank < int promote to (signed) int; else unchanged.
pub fn promote(self: IntType) IntType {
return if (@intFromEnum(self.rank) < @intFromEnum(Rank.int)) .{ .rank = .int, .signed = true } else self;
return if (@backingInt(self.rank) < @backingInt(Rank.int)) .{ .rank = .int, .signed = true } else self;
}

/// The usual arithmetic conversions over two already-promoted operand types (C89 6.2.1.5).
Expand All @@ -48,13 +48,13 @@ pub const IntType = struct {
if (a.rank == b.rank and a.signed == b.signed) return a;
// Same signedness: the higher rank wins.
if (a.signed == b.signed) {
return if (@intFromEnum(a.rank) >= @intFromEnum(b.rank)) a else b;
return if (@backingInt(a.rank) >= @backingInt(b.rank)) a else b;
}
// Mixed signedness. Find the unsigned operand and the signed operand.
const u = if (!a.signed) a else b;
const s = if (a.signed) a else b;
// If the unsigned operand's rank is at least the signed operand's rank, use the unsigned type.
if (@intFromEnum(u.rank) >= @intFromEnum(s.rank)) return u;
if (@backingInt(u.rank) >= @backingInt(s.rank)) return u;
// The signed operand has strictly higher rank. If it is strictly wider, it can
// represent every value of the unsigned type, so keep it signed. Otherwise use
// the unsigned version of the signed operand's higher rank.
Expand Down
2 changes: 1 addition & 1 deletion libs/vulcan-cc/lower.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,7 @@ fn lowerCallArgs(l: *L, args: []const *parser.Expr, params: anytype) Error!std.A
fn defaultArgPromote(ty: ctype.CType) ctype.CType {
if (ty.isFloat()) return .{ .float = .f64 };
if (ty.asInt()) |it| {
if (@intFromEnum(it.rank) < @intFromEnum(ctype.Rank.int)) return ctype.int_t;
if (@backingInt(it.rank) < @backingInt(ctype.Rank.int)) return ctype.int_t;
}
return ty;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/vulcan-cc/parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ fn intLitType(l: layout_mod.TargetLayout, value: u64, has_u: bool, long_count: u
const suffix_rank: ctype.Rank = if (long_count >= 2) .longlong else if (long_count == 1) .long else .int;
const ranks = [_]ctype.Rank{ .int, .long, .longlong };
for (ranks) |r| {
if (@intFromEnum(r) < @intFromEnum(suffix_rank)) continue;
if (@backingInt(r) < @backingInt(suffix_rank)) continue;
const it: ctype.IntType = .{ .rank = r, .signed = !has_u };
const bits = it.bits(l);
// `int`/`long long` are fixed at 32/64. Only `long` varies (32 on ILP32, 64 on
Expand Down
4 changes: 2 additions & 2 deletions libs/vulcan-cc/tests/external_linkage.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ test "x86 (i386): a struct-by-value arg decomposes into two 32-bit .memory_stack
for (mod.funcs) |*nf| {
if (!std.mem.eql(u8, nf.name, "take")) continue;
found = true;
const params = nf.func.blockParams(@enumFromInt(0));
const params = nf.func.blockParams(@fromBackingInt(@intCast(0)));
try std.testing.expectEqual(@as(usize, 2), params.len);
for (params) |p| {
const k = nf.func.types.type_kind(nf.func.valueType(p));
Expand Down Expand Up @@ -1547,7 +1547,7 @@ test "x86 (i386): an over-16-byte struct return threads a hidden result pointer
if (!std.mem.eql(u8, nf.name, "mk")) continue;
found = true;
try std.testing.expect(nf.func.sret);
const params = nf.func.blockParams(@enumFromInt(0));
const params = nf.func.blockParams(@fromBackingInt(@intCast(0)));
try std.testing.expectEqual(@as(usize, 1), params.len); // only the hidden pointer (mk is void-param)
try std.testing.expect(nf.func.types.type_kind(nf.func.valueType(params[0])) == .ptr);
}
Expand Down
6 changes: 3 additions & 3 deletions libs/vulcan-cc/tests/native.zig
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const ReturnKind = union(enum) { int: u16, f32, f64 };
fn returnKind(func: *const ir.function.Function) !ReturnKind {
var bi: usize = 0;
while (bi < func.blockCount()) : (bi += 1) {
const block: ir.function.Block = @enumFromInt(@as(u32, @intCast(bi)));
const block: ir.function.Block = @fromBackingInt(@intCast(@as(u32, @intCast(bi))));
if (func.terminator(block)) |term| switch (term) {
.ret => |r| if (r.count > 0) {
const v = r.values[0];
Expand Down Expand Up @@ -2314,7 +2314,7 @@ fn hasVolatileAccess(func: *const ir.function.Function, want_load: bool, want_st
var has_store = false;
var bi: usize = 0;
while (bi < func.blockCount()) : (bi += 1) {
const block: ir.function.Block = @enumFromInt(bi);
const block: ir.function.Block = @fromBackingInt(@intCast(bi));
for (func.blockInsts(block)) |inst| {
switch (func.opcode(inst)) {
.load => |l| if (l.@"volatile") {
Expand Down Expand Up @@ -2351,7 +2351,7 @@ fn countAllocaMemAccesses(func: *const ir.function.Function) usize {
var count: usize = 0;
var bi: usize = 0;
while (bi < func.blockCount()) : (bi += 1) {
const block: ir.function.Block = @enumFromInt(bi);
const block: ir.function.Block = @fromBackingInt(@intCast(bi));
for (func.blockInsts(block)) |inst| {
switch (func.opcode(inst)) {
.load => |l| if (func.definingInst(l.ptr) != null and func.opcode(func.definingInst(l.ptr).?) == .alloca) {
Expand Down
8 changes: 4 additions & 4 deletions libs/vulcan-cc/tests/variadic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ test "a variadic call default-arg-promotes its variadic args and sets num_fixed"
const func = module.find("f").?;
var found = false;
for (0..func.blockCount()) |bi| {
const block: ir.function.Block = @enumFromInt(bi);
const block: ir.function.Block = @fromBackingInt(@intCast(bi));
for (func.blockInsts(block)) |inst| {
const op = func.opcode(inst);
if (op != .call) continue;
Expand Down Expand Up @@ -168,7 +168,7 @@ test "a call to a same-TU variadic DEFINITION sets is_variadic and num_fixed" {
const func = module.find("f").?;
var found = false;
for (0..func.blockCount()) |bi| {
const block: ir.function.Block = @enumFromInt(bi);
const block: ir.function.Block = @fromBackingInt(@intCast(bi));
for (func.blockInsts(block)) |inst| {
const op = func.opcode(inst);
if (op != .call) continue;
Expand Down Expand Up @@ -202,7 +202,7 @@ test "an indirect call through a variadic function pointer sets is_variadic and
const func = module.find("f").?;
var found = false;
for (0..func.blockCount()) |bi| {
const block: ir.function.Block = @enumFromInt(bi);
const block: ir.function.Block = @fromBackingInt(@intCast(bi));
for (func.blockInsts(block)) |inst| {
const op = func.opcode(inst);
if (op != .call_indirect) continue;
Expand Down Expand Up @@ -244,7 +244,7 @@ test "a variadic DEFINITION lowers is_variadic/num_fixed_params and its stdarg o
var saw_arg = false;
var saw_end = false;
for (0..func.blockCount()) |bi| {
const block: ir.function.Block = @enumFromInt(bi);
const block: ir.function.Block = @fromBackingInt(@intCast(bi));
for (func.blockInsts(block)) |inst| {
switch (func.opcode(inst)) {
.va_start => saw_start = true,
Expand Down
10 changes: 5 additions & 5 deletions libs/vulcan-glsl/lower.zig
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ fn lowerStmt(l: *L, ret_ty: Type, stmt: parser.Stmt) Error!bool {
if (stmt.line != 0) {
var i = before;
while (i < l.func.instCount()) : (i += 1) {
const inst: ir.function.Inst = @enumFromInt(@as(u32, @intCast(i)));
const inst: ir.function.Inst = @fromBackingInt(@intCast(@as(u32, @intCast(i))));
if (!hasLineAttr(l.func, inst)) {
try l.func.addAttr(.{ .inst = inst }, .{ .custom = .{ .namespace = "debug", .key = "line", .value = .{ .int = stmt.line } } });
}
Expand Down Expand Up @@ -1151,8 +1151,8 @@ fn lowerFor(l: *L, ret_ty: Type, init: []const parser.Stmt, cond_e: ?*parser.Exp
try l.func.appendIf(header, cond.scalar.value, .{ .target = body_b, .args = &.{} }, .{ .target = exit_b, .args = exit_edge });
// Record the merge (exit) and the dedicated continue block for OpLoopMerge and
// structured block ordering.
try l.func.addAttr(.{ .block = header }, .{ .custom = .{ .namespace = "cf", .key = "merge", .value = .{ .int = @intFromEnum(exit_b) } } });
try l.func.addAttr(.{ .block = header }, .{ .custom = .{ .namespace = "cf", .key = "continue", .value = .{ .int = @intFromEnum(continue_b) } } });
try l.func.addAttr(.{ .block = header }, .{ .custom = .{ .namespace = "cf", .key = "merge", .value = .{ .int = @backingInt(exit_b) } } });
try l.func.addAttr(.{ .block = header }, .{ .custom = .{ .namespace = "cf", .key = "continue", .value = .{ .int = @backingInt(continue_b) } } });

try l.loops.append(l.allocator, .{ .exit = exit_b, .cont = continue_b, .len = len });

Expand Down Expand Up @@ -1357,7 +1357,7 @@ fn lowerIf(l: *L, ret_ty: Type, cond_e: *parser.Expr, then_body: []const parser.
try l.func.appendIf(head, cond.scalar.value, .{ .target = then_b, .args = &.{} }, .{ .target = else_b, .args = &.{} });
// Record the structured merge so the SPIR-V emitter can emit OpSelectionMerge and
// order blocks correctly even when branches contain nested control flow.
try l.func.addAttr(.{ .block = head }, .{ .custom = .{ .namespace = "cf", .key = "merge", .value = .{ .int = @intFromEnum(cont) } } });
try l.func.addAttr(.{ .block = head }, .{ .custom = .{ .namespace = "cf", .key = "merge", .value = .{ .int = @backingInt(cont) } } });

// then branch (a nested if/loop leaves l.block at the branch's actual end block)
l.block = then_b;
Expand Down Expand Up @@ -3341,7 +3341,7 @@ test "lowering tags instructions with their source line for debug info" {
var saw_line2 = false;
var saw_line3 = false;
for (0..func.instCount()) |i| {
var it = func.attributesOf(.{ .inst = @enumFromInt(@as(u32, @intCast(i))) });
var it = func.attributesOf(.{ .inst = @fromBackingInt(@intCast(@as(u32, @intCast(i)))) });
while (it.next()) |attr| switch (attr) {
.custom => |c| if (std.mem.eql(u8, c.namespace, "debug") and std.mem.eql(u8, c.key, "line")) {
if (c.value == .int and c.value.int == 2) saw_line2 = true;
Expand Down
4 changes: 2 additions & 2 deletions libs/vulcan-glsl/tests/native.zig
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ test "glsl->vectorize->NEON: a vec4 add fuses and runs to the right sum" {
try std.testing.expect(try opt.vectorize.run(allocator, f));
var has_vec = false;
for (0..f.instCount()) |i| {
if (f.opcodeMut(@enumFromInt(i)).* == .arith) {
const res = f.instResult(@enumFromInt(i)).?;
if (f.opcodeMut(@fromBackingInt(@intCast(i))).* == .arith) {
const res = f.instResult(@fromBackingInt(@intCast(i))).?;
if (f.types.type_kind(f.valueType(res)) == .vector) has_vec = true;
}
}
Expand Down
Loading
Loading