authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-13 00:11:42+01:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-02-25 11:22:10+01:00
logab6f9e3d10a6fdcbfca6d079645bfcb063b376bb
tree8237d43808c6b8ddda1d1a49bea72193ed3989df
parent55f437b92bb394f7df558bb3209f057f9f46274f

x86_64: fix incorrect mnemonic selection


3 files changed, 21 insertions(+), 20 deletions(-)

lib/std/crypto/aes.zig+1-1
...@@ -6,7 +6,7 @@ const has_aesni = std.Target.x86.featureSetHas(builtin.cpu.features, .aes);...@@ -6,7 +6,7 @@ const has_aesni = std.Target.x86.featureSetHas(builtin.cpu.features, .aes);
6const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx);6const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx);
7const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes);7const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes);
8// C backend doesn't currently support passing vectors to inline asm.8// C backend doesn't currently support passing vectors to inline asm.
9const impl = if (builtin.cpu.arch == .x86_64 and builtin.zig_backend != .stage2_c and builtin.zig_backend != .stage2_x86_64 and has_aesni and has_avx) impl: {9const impl = if (builtin.cpu.arch == .x86_64 and builtin.zig_backend != .stage2_c and has_aesni and has_avx) impl: {
10 break :impl @import("aes/aesni.zig");10 break :impl @import("aes/aesni.zig");
11} else if (builtin.cpu.arch == .aarch64 and builtin.zig_backend != .stage2_c and has_armaes)11} else if (builtin.cpu.arch == .aarch64 and builtin.zig_backend != .stage2_c and has_armaes)
12impl: {12impl: {
lib/std/crypto/sha2.zig+1-1
...@@ -238,7 +238,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {...@@ -238,7 +238,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
238 return;238 return;
239 },239 },
240 // C backend doesn't currently support passing vectors to inline asm.240 // C backend doesn't currently support passing vectors to inline asm.
241 .x86_64 => if (builtin.zig_backend != .stage2_c and builtin.zig_backend != .stage2_x86_64 and comptime std.Target.x86.featureSetHasAll(builtin.cpu.features, .{ .sha, .avx2 })) {241 .x86_64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.x86.featureSetHasAll(builtin.cpu.features, .{ .sha, .avx2 })) {
242 var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] };242 var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] };
243 var y: v4u32 = [_]u32{ d.s[7], d.s[6], d.s[3], d.s[2] };243 var y: v4u32 = [_]u32{ d.s[7], d.s[6], d.s[3], d.s[2] };
244 const s_v = @as(*[16]v4u32, @ptrCast(&s));244 const s_v = @as(*[16]v4u32, @ptrCast(&s));
src/arch/x86_64/CodeGen.zig+19-18
...@@ -13619,25 +13619,26 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -13619,25 +13619,26 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
13619 label_gop.value_ptr.target = @intCast(self.mir_instructions.len);13619 label_gop.value_ptr.target = @intCast(self.mir_instructions.len);
13620 } else continue;13620 } else continue;
1362113621
13622 var mnem_size: ?Memory.Size = null;13622 var mnem_size: ?Memory.Size = if (mem.endsWith(u8, mnem_str, "b"))
13623 const mnem_tag = mnem: {13623 .byte
13624 mnem_size = if (mem.endsWith(u8, mnem_str, "b"))13624 else if (mem.endsWith(u8, mnem_str, "w"))
13625 .byte13625 .word
13626 else if (mem.endsWith(u8, mnem_str, "w"))13626 else if (mem.endsWith(u8, mnem_str, "l"))
13627 .word13627 .dword
13628 else if (mem.endsWith(u8, mnem_str, "l"))13628 else if (mem.endsWith(u8, mnem_str, "q") and
13629 .dword13629 (std.mem.indexOfScalar(u8, "vp", mnem_str[0]) == null or !mem.endsWith(u8, mnem_str, "dq")))
13630 else if (mem.endsWith(u8, mnem_str, "q"))13630 .qword
13631 .qword13631 else if (mem.endsWith(u8, mnem_str, "t"))
13632 else if (mem.endsWith(u8, mnem_str, "t"))13632 .tbyte
13633 .tbyte13633 else
13634 else13634 null;
13635 break :mnem null;13635 const mnem_tag = while (true) break std.meta.stringToEnum(
13636 break :mnem std.meta.stringToEnum(Instruction.Mnemonic, mnem_str[0 .. mnem_str.len - 1]);13636 Instruction.Mnemonic,
13637 } orelse mnem: {13637 mnem_str[0 .. mnem_str.len - @intFromBool(mnem_size != null)],
13638 ) orelse if (mnem_size) |_| {
13638 mnem_size = null;13639 mnem_size = null;
13639 break :mnem std.meta.stringToEnum(Instruction.Mnemonic, mnem_str);13640 continue;
13640 } orelse return self.fail("invalid mnemonic: '{s}'", .{mnem_str});13641 } else return self.fail("invalid mnemonic: '{s}'", .{mnem_str});
13641 if (@as(?Memory.Size, switch (mnem_tag) {13642 if (@as(?Memory.Size, switch (mnem_tag) {
13642 .clflush => .byte,13643 .clflush => .byte,
13643 .fldenv, .fnstenv, .fstenv => .none,13644 .fldenv, .fnstenv, .fstenv => .none,