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
This commit is contained in:
mlugg
2023-06-22 18:46:56 +01:00
committed by Andrew Kelley
parent 447ca4e3ff
commit f26dda2117
651 changed files with 8967 additions and 9039 deletions

View File

@@ -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);
}