authorgravatar for xtex@astrafall.orgxtex <xtex@astrafall.org> 2025-10-25 14:00:04+08:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-11-01 15:11:35+01:00
loga8fea09cd59601bf2eb84643291be196c4ef2a2f
treee9acf19d564aa25850d6f07be50c257d2929f589
parent95c76b1b4aa7302966281c6b9b7f6cadea3cf7a6

cbe: fix more MIPS register names in inline assembly


1 files changed, 17 insertions(+), 13 deletions(-)

src/codegen/c.zig+17-13
...@@ -5768,21 +5768,25 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5768,21 +5768,25 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5768 switch (aggregate.storage) {5768 switch (aggregate.storage) {
5769 .elems => |elems| for (elems, 0..) |elem, i| switch (elem) {5769 .elems => |elems| for (elems, 0..) |elem, i| switch (elem) {
5770 .bool_true => {5770 .bool_true => {
5771 const name = struct_type.structFieldName(i, zcu).toSlice(ip).?;5771 const field_name = struct_type.structFieldName(i, zcu).toSlice(ip).?;
5772 assert(name.len != 0);5772 assert(field_name.len != 0);
57735773
5774 const target = &f.object.dg.mod.resolved_target.result;5774 const target = &f.object.dg.mod.resolved_target.result;
5775 if (target.cpu.arch.isMIPS() and name[0] == 'r') {5775 var c_name_buf: [16]u8 = undefined;
5776 // GCC uses "$N" for register names instead of "rN" used by Zig.5776 const name =
5777 var c_name_buf: [4]u8 = undefined;5777 if ((target.cpu.arch.isMIPS() or target.cpu.arch == .alpha) and field_name[0] == 'r') name: {
5778 const c_name = (&c_name_buf)[0..name.len];5778 // Convert "rN" to "$N"
5779 @memcpy(c_name, name);5779 const c_name = (&c_name_buf)[0..field_name.len];
5780 c_name_buf[0] = '$';5780 @memcpy(c_name, field_name);
57815781 c_name_buf[0] = '$';
5782 try w.print(" {f}", .{fmtStringLiteral(c_name, null)});5782 break :name c_name;
5783 (try w.writableArray(1))[0] = ',';5783 } else if ((target.cpu.arch.isMIPS() and (mem.startsWith(u8, field_name, "fcc") or field_name[0] == 'w')) or
5784 continue;5784 ((target.cpu.arch.isMIPS() or target.cpu.arch == .alpha) and field_name[0] == 'f')) name: {
5785 }5785 // "$" prefix for FCC, W and F registers
5786 c_name_buf[0] = '$';
5787 @memcpy((&c_name_buf)[1..][0..field_name.len], field_name);
5788 break :name (&c_name_buf)[0 .. 1 + field_name.len];
5789 } else field_name;
57865790
5787 try w.print(" {f}", .{fmtStringLiteral(name, null)});5791 try w.print(" {f}", .{fmtStringLiteral(name, null)});
5788 (try w.writableArray(1))[0] = ',';5792 (try w.writableArray(1))[0] = ',';