aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv/Cache.zig
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/Cache.zig
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/Cache.zig')
-rw-r--r--src/codegen/spirv/Cache.zig124
1 files changed, 62 insertions, 62 deletions
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 {