aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-06-22 18:46:56 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-06-24 16:56:39 -0700
commitf26dda21171e26f44aeec8c59a75bbb3331eeb2e (patch)
treec935248861ae2693b314f2c8bc78fe38d9961b6d /src/codegen/spirv
parent447ca4e3fff021f471b748187b53f0a4744ad0bc (diff)
downloadzig-f26dda21171e26f44aeec8c59a75bbb3331eeb2e.tar.gz
zig-f26dda21171e26f44aeec8c59a75bbb3331eeb2e.zip
all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
Diffstat (limited to 'src/codegen/spirv')
-rw-r--r--src/codegen/spirv/Assembler.zig24
-rw-r--r--src/codegen/spirv/Cache.zig124
-rw-r--r--src/codegen/spirv/Module.zig14
-rw-r--r--src/codegen/spirv/Section.zig30
4 files changed, 96 insertions, 96 deletions
diff --git a/src/codegen/spirv/Assembler.zig b/src/codegen/spirv/Assembler.zig
index 73a842ebe9..8f466668ea 100644
--- a/src/codegen/spirv/Assembler.zig
+++ b/src/codegen/spirv/Assembler.zig
@@ -293,7 +293,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
return self.fail(0, "{} is not a valid bit count for floats (expected 16, 32 or 64)", .{bits});
},
}
- break :blk try self.spv.resolve(.{ .float_type = .{ .bits = @intCast(u16, bits) } });
+ break :blk try self.spv.resolve(.{ .float_type = .{ .bits = @as(u16, @intCast(bits)) } });
},
.OpTypeVector => try self.spv.resolve(.{ .vector_type = .{
.component_type = try self.resolveTypeRef(operands[1].ref_id),
@@ -306,7 +306,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
},
.OpTypePointer => try self.spv.ptrType(
try self.resolveTypeRef(operands[2].ref_id),
- @enumFromInt(spec.StorageClass, operands[1].value),
+ @as(spec.StorageClass, @enumFromInt(operands[1].value)),
),
.OpTypeFunction => blk: {
const param_operands = operands[2..];
@@ -340,7 +340,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
else => switch (self.inst.opcode) {
.OpEntryPoint => unreachable,
.OpExecutionMode, .OpExecutionModeId => &self.spv.sections.execution_modes,
- .OpVariable => switch (@enumFromInt(spec.StorageClass, operands[2].value)) {
+ .OpVariable => switch (@as(spec.StorageClass, @enumFromInt(operands[2].value))) {
.Function => &self.func.prologue,
else => {
// This is currently disabled because global variables are required to be
@@ -391,7 +391,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
}
const actual_word_count = section.instructions.items.len - first_word;
- section.instructions.items[first_word] |= @as(u32, @intCast(u16, actual_word_count)) << 16 | @intFromEnum(self.inst.opcode);
+ section.instructions.items[first_word] |= @as(u32, @as(u16, @intCast(actual_word_count))) << 16 | @intFromEnum(self.inst.opcode);
if (maybe_result_id) |result| {
return AsmValue{ .value = result };
@@ -458,7 +458,7 @@ fn parseInstruction(self: *Assembler) !void {
if (!entry.found_existing) {
entry.value_ptr.* = .just_declared;
}
- break :blk @intCast(AsmValue.Ref, entry.index);
+ break :blk @as(AsmValue.Ref, @intCast(entry.index));
} else null;
const opcode_tok = self.currentToken();
@@ -613,7 +613,7 @@ fn parseRefId(self: *Assembler) !void {
entry.value_ptr.* = .unresolved_forward_reference;
}
- const index = @intCast(AsmValue.Ref, entry.index);
+ const index = @as(AsmValue.Ref, @intCast(entry.index));
try self.inst.operands.append(self.gpa, .{ .ref_id = index });
}
@@ -645,7 +645,7 @@ fn parseString(self: *Assembler) !void {
else
text[1..];
- const string_offset = @intCast(u32, self.inst.string_bytes.items.len);
+ const string_offset = @as(u32, @intCast(self.inst.string_bytes.items.len));
try self.inst.string_bytes.ensureUnusedCapacity(self.gpa, literal.len + 1);
self.inst.string_bytes.appendSliceAssumeCapacity(literal);
self.inst.string_bytes.appendAssumeCapacity(0);
@@ -693,18 +693,18 @@ fn parseContextDependentInt(self: *Assembler, signedness: std.builtin.Signedness
const int = std.fmt.parseInt(i128, text, 0) catch break :invalid;
const min = switch (signedness) {
.unsigned => 0,
- .signed => -(@as(i128, 1) << (@intCast(u7, width) - 1)),
+ .signed => -(@as(i128, 1) << (@as(u7, @intCast(width)) - 1)),
};
- const max = (@as(i128, 1) << (@intCast(u7, width) - @intFromBool(signedness == .signed))) - 1;
+ const max = (@as(i128, 1) << (@as(u7, @intCast(width)) - @intFromBool(signedness == .signed))) - 1;
if (int < min or int > max) {
break :invalid;
}
// Note, we store the sign-extended version here.
if (width <= @bitSizeOf(spec.Word)) {
- try self.inst.operands.append(self.gpa, .{ .literal32 = @truncate(u32, @bitCast(u128, int)) });
+ try self.inst.operands.append(self.gpa, .{ .literal32 = @as(u32, @truncate(@as(u128, @bitCast(int)))) });
} else {
- try self.inst.operands.append(self.gpa, .{ .literal64 = @truncate(u64, @bitCast(u128, int)) });
+ try self.inst.operands.append(self.gpa, .{ .literal64 = @as(u64, @truncate(@as(u128, @bitCast(int)))) });
}
return;
}
@@ -725,7 +725,7 @@ fn parseContextDependentFloat(self: *Assembler, comptime width: u16) !void {
return self.fail(tok.start, "'{s}' is not a valid {}-bit float literal", .{ text, width });
};
- const float_bits = @bitCast(Int, value);
+ const float_bits = @as(Int, @bitCast(value));
if (width <= @bitSizeOf(spec.Word)) {
try self.inst.operands.append(self.gpa, .{ .literal32 = float_bits });
} else {
diff --git a/src/codegen/spirv/Cache.zig b/src/codegen/spirv/Cache.zig
index 7d7fc0fb0d..7a3b6f61f5 100644
--- a/src/codegen/spirv/Cache.zig
+++ b/src/codegen/spirv/Cache.zig
@@ -158,16 +158,16 @@ const Tag = enum {
high: u32,
fn encode(value: f64) Float64 {
- const bits = @bitCast(u64, value);
+ const bits = @as(u64, @bitCast(value));
return .{
- .low = @truncate(u32, bits),
- .high = @truncate(u32, bits >> 32),
+ .low = @as(u32, @truncate(bits)),
+ .high = @as(u32, @truncate(bits >> 32)),
};
}
fn decode(self: Float64) f64 {
const bits = @as(u64, self.low) | (@as(u64, self.high) << 32);
- return @bitCast(f64, bits);
+ return @as(f64, @bitCast(bits));
}
};
@@ -189,8 +189,8 @@ const Tag = enum {
fn encode(ty: Ref, value: u64) Int64 {
return .{
.ty = ty,
- .low = @truncate(u32, value),
- .high = @truncate(u32, value >> 32),
+ .low = @as(u32, @truncate(value)),
+ .high = @as(u32, @truncate(value >> 32)),
};
}
@@ -207,13 +207,13 @@ const Tag = enum {
fn encode(ty: Ref, value: i64) Int64 {
return .{
.ty = ty,
- .low = @truncate(u32, @bitCast(u64, value)),
- .high = @truncate(u32, @bitCast(u64, value) >> 32),
+ .low = @as(u32, @truncate(@as(u64, @bitCast(value)))),
+ .high = @as(u32, @truncate(@as(u64, @bitCast(value)) >> 32)),
};
}
fn decode(self: Int64) i64 {
- return @bitCast(i64, @as(u64, self.low) | (@as(u64, self.high) << 32));
+ return @as(i64, @bitCast(@as(u64, self.low) | (@as(u64, self.high) << 32)));
}
};
};
@@ -305,21 +305,21 @@ pub const Key = union(enum) {
/// Turns this value into the corresponding 32-bit literal, 2s complement signed.
fn toBits32(self: Int) u32 {
return switch (self.value) {
- .uint64 => |val| @intCast(u32, val),
- .int64 => |val| if (val < 0) @bitCast(u32, @intCast(i32, val)) else @intCast(u32, val),
+ .uint64 => |val| @as(u32, @intCast(val)),
+ .int64 => |val| if (val < 0) @as(u32, @bitCast(@as(i32, @intCast(val)))) else @as(u32, @intCast(val)),
};
}
fn toBits64(self: Int) u64 {
return switch (self.value) {
.uint64 => |val| val,
- .int64 => |val| @bitCast(u64, val),
+ .int64 => |val| @as(u64, @bitCast(val)),
};
}
fn to(self: Int, comptime T: type) T {
return switch (self.value) {
- inline else => |val| @intCast(T, val),
+ inline else => |val| @as(T, @intCast(val)),
};
}
};
@@ -357,9 +357,9 @@ pub const Key = union(enum) {
.float => |float| {
std.hash.autoHash(&hasher, float.ty);
switch (float.value) {
- .float16 => |value| std.hash.autoHash(&hasher, @bitCast(u16, value)),
- .float32 => |value| std.hash.autoHash(&hasher, @bitCast(u32, value)),
- .float64 => |value| std.hash.autoHash(&hasher, @bitCast(u64, value)),
+ .float16 => |value| std.hash.autoHash(&hasher, @as(u16, @bitCast(value))),
+ .float32 => |value| std.hash.autoHash(&hasher, @as(u32, @bitCast(value))),
+ .float64 => |value| std.hash.autoHash(&hasher, @as(u64, @bitCast(value))),
}
},
.function_type => |func| {
@@ -379,7 +379,7 @@ pub const Key = union(enum) {
},
inline else => |key| std.hash.autoHash(&hasher, key),
}
- return @truncate(u32, hasher.final());
+ return @as(u32, @truncate(hasher.final()));
}
fn eql(a: Key, b: Key) bool {
@@ -411,7 +411,7 @@ pub const Key = union(enum) {
pub fn eql(ctx: @This(), a: Key, b_void: void, b_index: usize) bool {
_ = b_void;
- return ctx.self.lookup(@enumFromInt(Ref, b_index)).eql(a);
+ return ctx.self.lookup(@as(Ref, @enumFromInt(b_index))).eql(a);
}
pub fn hash(ctx: @This(), a: Key) u32 {
@@ -445,7 +445,7 @@ pub fn materialize(self: *const Self, spv: *Module) !Section {
var section = Section{};
errdefer section.deinit(spv.gpa);
for (self.items.items(.result_id), 0..) |result_id, index| {
- try self.emit(spv, result_id, @enumFromInt(Ref, index), &section);
+ try self.emit(spv, result_id, @as(Ref, @enumFromInt(index)), &section);
}
return section;
}
@@ -534,7 +534,7 @@ fn emit(
}
for (struct_type.memberNames(), 0..) |member_name, i| {
if (self.getString(member_name)) |name| {
- try spv.memberDebugName(result_id, @intCast(u32, i), "{s}", .{name});
+ try spv.memberDebugName(result_id, @as(u32, @intCast(i)), "{s}", .{name});
}
}
// TODO: Decorations?
@@ -557,7 +557,7 @@ fn emit(
.float => |float| {
const ty_id = self.resultId(float.ty);
const lit: Lit = switch (float.value) {
- .float16 => |value| .{ .uint32 = @bitCast(u16, value) },
+ .float16 => |value| .{ .uint32 = @as(u16, @bitCast(value)) },
.float32 => |value| .{ .float32 = value },
.float64 => |value| .{ .float64 = value },
};
@@ -603,7 +603,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
const adapter: Key.Adapter = .{ .self = self };
const entry = try self.map.getOrPutAdapted(spv.gpa, key, adapter);
if (entry.found_existing) {
- return @enumFromInt(Ref, entry.index);
+ return @as(Ref, @enumFromInt(entry.index));
}
const result_id = spv.allocId();
const item: Item = switch (key) {
@@ -640,10 +640,10 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
},
.function_type => |function| blk: {
const extra = try self.addExtra(spv, Tag.FunctionType{
- .param_len = @intCast(u32, function.parameters.len),
+ .param_len = @as(u32, @intCast(function.parameters.len)),
.return_type = function.return_type,
});
- try self.extra.appendSlice(spv.gpa, @ptrCast([]const u32, function.parameters));
+ try self.extra.appendSlice(spv.gpa, @as([]const u32, @ptrCast(function.parameters)));
break :blk .{
.tag = .type_function,
.result_id = result_id,
@@ -678,12 +678,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
.struct_type => |struct_type| blk: {
const extra = try self.addExtra(spv, Tag.SimpleStructType{
.name = struct_type.name,
- .members_len = @intCast(u32, struct_type.member_types.len),
+ .members_len = @as(u32, @intCast(struct_type.member_types.len)),
});
- try self.extra.appendSlice(spv.gpa, @ptrCast([]const u32, struct_type.member_types));
+ try self.extra.appendSlice(spv.gpa, @as([]const u32, @ptrCast(struct_type.member_types)));
if (struct_type.member_names) |member_names| {
- try self.extra.appendSlice(spv.gpa, @ptrCast([]const u32, member_names));
+ try self.extra.appendSlice(spv.gpa, @as([]const u32, @ptrCast(member_names)));
break :blk Item{
.tag = .type_struct_simple_with_member_names,
.result_id = result_id,
@@ -721,7 +721,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
.result_id = result_id,
.data = try self.addExtra(spv, Tag.UInt32{
.ty = int.ty,
- .value = @intCast(u32, val),
+ .value = @as(u32, @intCast(val)),
}),
};
} else if (val >= std.math.minInt(i32) and val <= std.math.maxInt(i32)) {
@@ -730,20 +730,20 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
.result_id = result_id,
.data = try self.addExtra(spv, Tag.Int32{
.ty = int.ty,
- .value = @intCast(i32, val),
+ .value = @as(i32, @intCast(val)),
}),
};
} else if (val < 0) {
break :blk .{
.tag = .int_large,
.result_id = result_id,
- .data = try self.addExtra(spv, Tag.Int64.encode(int.ty, @intCast(i64, val))),
+ .data = try self.addExtra(spv, Tag.Int64.encode(int.ty, @as(i64, @intCast(val)))),
};
} else {
break :blk .{
.tag = .uint_large,
.result_id = result_id,
- .data = try self.addExtra(spv, Tag.UInt64.encode(int.ty, @intCast(u64, val))),
+ .data = try self.addExtra(spv, Tag.UInt64.encode(int.ty, @as(u64, @intCast(val)))),
};
}
},
@@ -753,12 +753,12 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
16 => .{
.tag = .float16,
.result_id = result_id,
- .data = @bitCast(u16, float.value.float16),
+ .data = @as(u16, @bitCast(float.value.float16)),
},
32 => .{
.tag = .float32,
.result_id = result_id,
- .data = @bitCast(u32, float.value.float32),
+ .data = @as(u32, @bitCast(float.value.float32)),
},
64 => .{
.tag = .float64,
@@ -788,7 +788,7 @@ pub fn resolve(self: *Self, spv: *Module, key: Key) !Ref {
};
try self.items.append(spv.gpa, item);
- return @enumFromInt(Ref, entry.index);
+ return @as(Ref, @enumFromInt(entry.index));
}
/// Turn a Ref back into a Key.
@@ -797,20 +797,20 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
const item = self.items.get(@intFromEnum(ref));
const data = item.data;
return switch (item.tag) {
- .type_simple => switch (@enumFromInt(Tag.SimpleType, data)) {
+ .type_simple => switch (@as(Tag.SimpleType, @enumFromInt(data))) {
.void => .void_type,
.bool => .bool_type,
},
.type_int_signed => .{ .int_type = .{
.signedness = .signed,
- .bits = @intCast(u16, data),
+ .bits = @as(u16, @intCast(data)),
} },
.type_int_unsigned => .{ .int_type = .{
.signedness = .unsigned,
- .bits = @intCast(u16, data),
+ .bits = @as(u16, @intCast(data)),
} },
.type_float => .{ .float_type = .{
- .bits = @intCast(u16, data),
+ .bits = @as(u16, @intCast(data)),
} },
.type_vector => .{ .vector_type = self.extraData(Tag.VectorType, data) },
.type_array => .{ .array_type = self.extraData(Tag.ArrayType, data) },
@@ -819,26 +819,26 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
return .{
.function_type = .{
.return_type = payload.data.return_type,
- .parameters = @ptrCast([]const Ref, self.extra.items[payload.trail..][0..payload.data.param_len]),
+ .parameters = @as([]const Ref, @ptrCast(self.extra.items[payload.trail..][0..payload.data.param_len])),
},
};
},
.type_ptr_generic => .{
.ptr_type = .{
.storage_class = .Generic,
- .child_type = @enumFromInt(Ref, data),
+ .child_type = @as(Ref, @enumFromInt(data)),
},
},
.type_ptr_crosswgp => .{
.ptr_type = .{
.storage_class = .CrossWorkgroup,
- .child_type = @enumFromInt(Ref, data),
+ .child_type = @as(Ref, @enumFromInt(data)),
},
},
.type_ptr_function => .{
.ptr_type = .{
.storage_class = .Function,
- .child_type = @enumFromInt(Ref, data),
+ .child_type = @as(Ref, @enumFromInt(data)),
},
},
.type_ptr_simple => {
@@ -852,7 +852,7 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
},
.type_struct_simple => {
const payload = self.extraDataTrail(Tag.SimpleStructType, data);
- const member_types = @ptrCast([]const Ref, self.extra.items[payload.trail..][0..payload.data.members_len]);
+ const member_types = @as([]const Ref, @ptrCast(self.extra.items[payload.trail..][0..payload.data.members_len]));
return .{
.struct_type = .{
.name = payload.data.name,
@@ -864,8 +864,8 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
.type_struct_simple_with_member_names => {
const payload = self.extraDataTrail(Tag.SimpleStructType, data);
const trailing = self.extra.items[payload.trail..];
- const member_types = @ptrCast([]const Ref, trailing[0..payload.data.members_len]);
- const member_names = @ptrCast([]const String, trailing[payload.data.members_len..][0..payload.data.members_len]);
+ const member_types = @as([]const Ref, @ptrCast(trailing[0..payload.data.members_len]));
+ const member_names = @as([]const String, @ptrCast(trailing[payload.data.members_len..][0..payload.data.members_len]));
return .{
.struct_type = .{
.name = payload.data.name,
@@ -876,11 +876,11 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
},
.float16 => .{ .float = .{
.ty = self.get(.{ .float_type = .{ .bits = 16 } }),
- .value = .{ .float16 = @bitCast(f16, @intCast(u16, data)) },
+ .value = .{ .float16 = @as(f16, @bitCast(@as(u16, @intCast(data)))) },
} },
.float32 => .{ .float = .{
.ty = self.get(.{ .float_type = .{ .bits = 32 } }),
- .value = .{ .float32 = @bitCast(f32, data) },
+ .value = .{ .float32 = @as(f32, @bitCast(data)) },
} },
.float64 => .{ .float = .{
.ty = self.get(.{ .float_type = .{ .bits = 64 } }),
@@ -923,17 +923,17 @@ pub fn lookup(self: *const Self, ref: Ref) Key {
} };
},
.undef => .{ .undef = .{
- .ty = @enumFromInt(Ref, data),
+ .ty = @as(Ref, @enumFromInt(data)),
} },
.null => .{ .null = .{
- .ty = @enumFromInt(Ref, data),
+ .ty = @as(Ref, @enumFromInt(data)),
} },
.bool_true => .{ .bool = .{
- .ty = @enumFromInt(Ref, data),
+ .ty = @as(Ref, @enumFromInt(data)),
.value = true,
} },
.bool_false => .{ .bool = .{
- .ty = @enumFromInt(Ref, data),
+ .ty = @as(Ref, @enumFromInt(data)),
.value = false,
} },
};
@@ -949,7 +949,7 @@ pub fn resultId(self: Self, ref: Ref) IdResult {
fn get(self: *const Self, key: Key) Ref {
const adapter: Key.Adapter = .{ .self = self };
const index = self.map.getIndexAdapted(key, adapter).?;
- return @enumFromInt(Ref, index);
+ return @as(Ref, @enumFromInt(index));
}
fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {
@@ -959,12 +959,12 @@ fn addExtra(self: *Self, spv: *Module, extra: anytype) !u32 {
}
fn addExtraAssumeCapacity(self: *Self, extra: anytype) !u32 {
- const payload_offset = @intCast(u32, self.extra.items.len);
+ const payload_offset = @as(u32, @intCast(self.extra.items.len));
inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
const field_val = @field(extra, field.name);
const word = switch (field.type) {
u32 => field_val,
- i32 => @bitCast(u32, field_val),
+ i32 => @as(u32, @bitCast(field_val)),
Ref => @intFromEnum(field_val),
StorageClass => @intFromEnum(field_val),
String => @intFromEnum(field_val),
@@ -986,16 +986,16 @@ fn extraDataTrail(self: Self, comptime T: type, offset: u32) struct { data: T, t
const word = self.extra.items[offset + i];
@field(result, field.name) = switch (field.type) {
u32 => word,
- i32 => @bitCast(i32, word),
- Ref => @enumFromInt(Ref, word),
- StorageClass => @enumFromInt(StorageClass, word),
- String => @enumFromInt(String, word),
+ i32 => @as(i32, @bitCast(word)),
+ Ref => @as(Ref, @enumFromInt(word)),
+ StorageClass => @as(StorageClass, @enumFromInt(word)),
+ String => @as(String, @enumFromInt(word)),
else => @compileError("Invalid type: " ++ @typeName(field.type)),
};
}
return .{
.data = result,
- .trail = offset + @intCast(u32, fields.len),
+ .trail = offset + @as(u32, @intCast(fields.len)),
};
}
@@ -1017,7 +1017,7 @@ pub const String = enum(u32) {
_ = ctx;
var hasher = std.hash.Wyhash.init(0);
hasher.update(a);
- return @truncate(u32, hasher.final());
+ return @as(u32, @truncate(hasher.final()));
}
};
};
@@ -1032,10 +1032,10 @@ pub fn addString(self: *Self, spv: *Module, str: []const u8) !String {
try self.string_bytes.ensureUnusedCapacity(spv.gpa, 1 + str.len);
self.string_bytes.appendSliceAssumeCapacity(str);
self.string_bytes.appendAssumeCapacity(0);
- entry.value_ptr.* = @intCast(u32, offset);
+ entry.value_ptr.* = @as(u32, @intCast(offset));
}
- return @enumFromInt(String, entry.index);
+ return @as(String, @enumFromInt(entry.index));
}
pub fn getString(self: *const Self, ref: String) ?[]const u8 {
diff --git a/src/codegen/spirv/Module.zig b/src/codegen/spirv/Module.zig
index 9d8cca9445..e61ac754ee 100644
--- a/src/codegen/spirv/Module.zig
+++ b/src/codegen/spirv/Module.zig
@@ -451,8 +451,8 @@ pub fn constInt(self: *Module, ty_ref: CacheRef, value: anytype) !IdRef {
return try self.resolveId(.{ .int = .{
.ty = ty_ref,
.value = switch (ty.signedness) {
- .signed => Value{ .int64 = @intCast(i64, value) },
- .unsigned => Value{ .uint64 = @intCast(u64, value) },
+ .signed => Value{ .int64 = @as(i64, @intCast(value)) },
+ .unsigned => Value{ .uint64 = @as(u64, @intCast(value)) },
},
} });
}
@@ -516,7 +516,7 @@ pub fn allocDecl(self: *Module, kind: DeclKind) !Decl.Index {
.begin_dep = undefined,
.end_dep = undefined,
});
- const index = @enumFromInt(Decl.Index, @intCast(u32, self.decls.items.len - 1));
+ const index = @as(Decl.Index, @enumFromInt(@as(u32, @intCast(self.decls.items.len - 1))));
switch (kind) {
.func => {},
// If the decl represents a global, also allocate a global node.
@@ -540,9 +540,9 @@ pub fn globalPtr(self: *Module, index: Decl.Index) ?*Global {
/// Declare ALL dependencies for a decl.
pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl.Index) !void {
- const begin_dep = @intCast(u32, self.decl_deps.items.len);
+ const begin_dep = @as(u32, @intCast(self.decl_deps.items.len));
try self.decl_deps.appendSlice(self.gpa, deps);
- const end_dep = @intCast(u32, self.decl_deps.items.len);
+ const end_dep = @as(u32, @intCast(self.decl_deps.items.len));
const decl = self.declPtr(decl_index);
decl.begin_dep = begin_dep;
@@ -550,13 +550,13 @@ pub fn declareDeclDeps(self: *Module, decl_index: Decl.Index, deps: []const Decl
}
pub fn beginGlobal(self: *Module) u32 {
- return @intCast(u32, self.globals.section.instructions.items.len);
+ return @as(u32, @intCast(self.globals.section.instructions.items.len));
}
pub fn endGlobal(self: *Module, global_index: Decl.Index, begin_inst: u32) void {
const global = self.globalPtr(global_index).?;
global.begin_inst = begin_inst;
- global.end_inst = @intCast(u32, self.globals.section.instructions.items.len);
+ global.end_inst = @as(u32, @intCast(self.globals.section.instructions.items.len));
}
pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8) !void {
diff --git a/src/codegen/spirv/Section.zig b/src/codegen/spirv/Section.zig
index b35dc489e4..ae88dc7c8a 100644
--- a/src/codegen/spirv/Section.zig
+++ b/src/codegen/spirv/Section.zig
@@ -50,7 +50,7 @@ pub fn emitRaw(
) !void {
const word_count = 1 + operand_words;
try section.instructions.ensureUnusedCapacity(allocator, word_count);
- section.writeWord((@intCast(Word, word_count << 16)) | @intFromEnum(opcode));
+ section.writeWord((@as(Word, @intCast(word_count << 16))) | @intFromEnum(opcode));
}
pub fn emit(
@@ -61,7 +61,7 @@ pub fn emit(
) !void {
const word_count = instructionSize(opcode, operands);
try section.instructions.ensureUnusedCapacity(allocator, word_count);
- section.writeWord(@intCast(Word, word_count << 16) | @intFromEnum(opcode));
+ section.writeWord(@as(Word, @intCast(word_count << 16)) | @intFromEnum(opcode));
section.writeOperands(opcode.Operands(), operands);
}
@@ -94,8 +94,8 @@ pub fn writeWords(section: *Section, words: []const Word) void {
pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {
section.writeWords(&.{
- @truncate(Word, dword),
- @truncate(Word, dword >> @bitSizeOf(Word)),
+ @as(Word, @truncate(dword)),
+ @as(Word, @truncate(dword >> @bitSizeOf(Word))),
});
}
@@ -145,7 +145,7 @@ pub fn writeOperand(section: *Section, comptime Operand: type, operand: Operand)
},
.Struct => |info| {
if (info.layout == .Packed) {
- section.writeWord(@bitCast(Word, operand));
+ section.writeWord(@as(Word, @bitCast(operand)));
} else {
section.writeExtendedMask(Operand, operand);
}
@@ -166,7 +166,7 @@ fn writeString(section: *Section, str: []const u8) void {
var j: usize = 0;
while (j < @sizeOf(Word) and i + j < str.len) : (j += 1) {
- word |= @as(Word, str[i + j]) << @intCast(Log2Word, j * @bitSizeOf(u8));
+ word |= @as(Word, str[i + j]) << @as(Log2Word, @intCast(j * @bitSizeOf(u8)));
}
section.instructions.appendAssumeCapacity(word);
@@ -175,12 +175,12 @@ fn writeString(section: *Section, str: []const u8) void {
fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDependentNumber) void {
switch (operand) {
- .int32 => |int| section.writeWord(@bitCast(Word, int)),
- .uint32 => |int| section.writeWord(@bitCast(Word, int)),
- .int64 => |int| section.writeDoubleWord(@bitCast(DoubleWord, int)),
- .uint64 => |int| section.writeDoubleWord(@bitCast(DoubleWord, int)),
- .float32 => |float| section.writeWord(@bitCast(Word, float)),
- .float64 => |float| section.writeDoubleWord(@bitCast(DoubleWord, float)),
+ .int32 => |int| section.writeWord(@as(Word, @bitCast(int))),
+ .uint32 => |int| section.writeWord(@as(Word, @bitCast(int))),
+ .int64 => |int| section.writeDoubleWord(@as(DoubleWord, @bitCast(int))),
+ .uint64 => |int| section.writeDoubleWord(@as(DoubleWord, @bitCast(int))),
+ .float32 => |float| section.writeWord(@as(Word, @bitCast(float))),
+ .float64 => |float| section.writeDoubleWord(@as(DoubleWord, @bitCast(float))),
}
}
@@ -189,10 +189,10 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
inline for (@typeInfo(Operand).Struct.fields, 0..) |field, bit| {
switch (@typeInfo(field.type)) {
.Optional => if (@field(operand, field.name) != null) {
- mask |= 1 << @intCast(u5, bit);
+ mask |= 1 << @as(u5, @intCast(bit));
},
.Bool => if (@field(operand, field.name)) {
- mask |= 1 << @intCast(u5, bit);
+ mask |= 1 << @as(u5, @intCast(bit));
},
else => unreachable,
}
@@ -392,7 +392,7 @@ test "SPIR-V Section emit() - extended mask" {
(@as(Word, 5) << 16) | @intFromEnum(Opcode.OpLoopMerge),
10,
20,
- @bitCast(Word, spec.LoopControl{ .Unroll = true, .DependencyLength = true }),
+ @as(Word, @bitCast(spec.LoopControl{ .Unroll = true, .DependencyLength = true })),
2,
}, section.instructions.items);
}