authorgravatar for mathieusuen@yahoo.frMathieu Suen <mathieusuen@yahoo.fr> 2026-02-16 10:29:26+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-04-10 23:23:33+02:00
log2c88821c568f5d66296f571390716f4e91552841
tree70a6fd37e0b3e19fe0be5b8efe65fadab79e1bc9
parent998b714708bd7f750a3a076e5afd47c80786e72c

x64_86 fix: RMI can accept imm16 only for imul r16,r/m16


1 files changed, 23 insertions(+), 1 deletions(-)

src/codegen/x86_64/CodeGen.zig+23-1
......@@ -1850,11 +1850,33 @@ fn asmRegisterMemoryImmediate(
18501850 m: Memory,
18511851 imm: Immediate,
18521852) !void {
1853 if (switch (imm) {
1853 if (reg.size() == .qword and tag[1] == .mul) {
1854 // imul does not support imm16 for RMI r64, r/m64
1855 const payload = try self.addExtra(Mir.Imm32{ .imm = switch (imm) {
1856 .signed => |s| @bitCast(s),
1857 .unsigned => |u| @as(u32, @intCast(u)),
1858 .nav, .uav, .lazy_sym, .extern_func => unreachable,
1859 } });
1860 assert(payload + 1 == try self.addExtra(Mir.Memory.encode(m)));
1861 _ = try self.addInst(.{
1862 .tag = tag[1],
1863 .ops = switch (imm) {
1864 .signed => .rmi_s,
1865 .unsigned => .rmi_u,
1866 .nav, .uav, .lazy_sym, .extern_func => unreachable,
1867 },
1868 .data = .{ .rx = .{
1869 .fixes = tag[0],
1870 .r1 = reg,
1871 .payload = payload,
1872 } },
1873 });
1874 } else if (switch (imm) {
18541875 .signed => |s| if (std.math.cast(i16, s)) |x| @as(u16, @bitCast(x)) else null,
18551876 .unsigned => |u| std.math.cast(u16, u),
18561877 .nav, .uav, .lazy_sym, .extern_func => unreachable,
18571878 }) |small_imm| {
1879 // This is only valid for imul RMI r16, r/m16
18581880 _ = try self.addInst(.{
18591881 .tag = tag[1],
18601882 .ops = .rmi,