authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2023-02-20 22:40:08+07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-28 16:46:04-07:00
log75a1360cdd1745ac267c9a25b84ec7ee765d9262
tree4971860efa034a9e34942b225274a9bd67202452
parent83e6223192acd635275e67614e55b7a4c579a969

stage2: sparc64: Implement ASI load/store ops


3 files changed, 66 insertions(+), 11 deletions(-)

src/arch/sparc64/CodeGen.zig+3-3
......@@ -1254,7 +1254,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12541254
12551255 try self.genStoreASI(reg, .sp, off_reg, abi_size, opposite_endian_asi);
12561256 try self.genLoad(reg, .sp, Register, off_reg, abi_size);
1257 break :result reg;
1257 break :result .{ .register = reg };
12581258 },
12591259 .memory => {
12601260 if (int_info.bits > 64 or @popCount(int_info.bits) != 1)
......@@ -1264,7 +1264,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12641264 const dst_reg = try self.register_manager.allocReg(null, gp);
12651265
12661266 try self.genLoadASI(dst_reg, addr_reg, .g0, abi_size, opposite_endian_asi);
1267 break :result dst_reg;
1267 break :result .{ .register = dst_reg };
12681268 },
12691269 .stack_offset => |off| {
12701270 if (int_info.bits > 64 or @popCount(int_info.bits) != 1)
......@@ -1274,7 +1274,7 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12741274 const dst_reg = try self.register_manager.allocReg(null, gp);
12751275
12761276 try self.genLoadASI(dst_reg, .sp, off_reg, abi_size, opposite_endian_asi);
1277 break :result dst_reg;
1277 break :result .{ .register = dst_reg };
12781278 },
12791279 else => unreachable,
12801280 }
src/arch/sparc64/Emit.zig+31-8
......@@ -91,10 +91,10 @@ pub fn emitMir(
9191 .lduw => try emit.mirArithmetic3Op(inst),
9292 .ldx => try emit.mirArithmetic3Op(inst),
9393
94 .lduba => unreachable,
95 .lduha => unreachable,
96 .lduwa => unreachable,
97 .ldxa => unreachable,
94 .lduba => try emit.mirMemASI(inst),
95 .lduha => try emit.mirMemASI(inst),
96 .lduwa => try emit.mirMemASI(inst),
97 .ldxa => try emit.mirMemASI(inst),
9898
9999 .@"and" => try emit.mirArithmetic3Op(inst),
100100 .@"or" => try emit.mirArithmetic3Op(inst),
......@@ -132,10 +132,10 @@ pub fn emitMir(
132132 .stw => try emit.mirArithmetic3Op(inst),
133133 .stx => try emit.mirArithmetic3Op(inst),
134134
135 .stba => unreachable,
136 .stha => unreachable,
137 .stwa => unreachable,
138 .stxa => unreachable,
135 .stba => try emit.mirMemASI(inst),
136 .stha => try emit.mirMemASI(inst),
137 .stwa => try emit.mirMemASI(inst),
138 .stxa => try emit.mirMemASI(inst),
139139
140140 .sub => try emit.mirArithmetic3Op(inst),
141141 .subcc => try emit.mirArithmetic3Op(inst),
......@@ -378,6 +378,29 @@ fn mirConditionalMove(emit: *Emit, inst: Mir.Inst.Index) !void {
378378 }
379379}
380380
381fn mirMemASI(emit: *Emit, inst: Mir.Inst.Index) !void {
382 const tag = emit.mir.instructions.items(.tag)[inst];
383 const data = emit.mir.instructions.items(.data)[inst].mem_asi;
384
385 const rd = data.rd;
386 const rs1 = data.rs1;
387 const rs2 = data.rs2;
388 const asi = data.asi;
389
390 switch (tag) {
391 .lduba => try emit.writeInstruction(Instruction.lduba(rs1, rs2, asi, rd)),
392 .lduha => try emit.writeInstruction(Instruction.lduha(rs1, rs2, asi, rd)),
393 .lduwa => try emit.writeInstruction(Instruction.lduwa(rs1, rs2, asi, rd)),
394 .ldxa => try emit.writeInstruction(Instruction.ldxa(rs1, rs2, asi, rd)),
395
396 .stba => try emit.writeInstruction(Instruction.stba(rs1, rs2, asi, rd)),
397 .stha => try emit.writeInstruction(Instruction.stha(rs1, rs2, asi, rd)),
398 .stwa => try emit.writeInstruction(Instruction.stwa(rs1, rs2, asi, rd)),
399 .stxa => try emit.writeInstruction(Instruction.stxa(rs1, rs2, asi, rd)),
400 else => unreachable,
401 }
402}
403
381404fn mirMembar(emit: *Emit, inst: Mir.Inst.Index) !void {
382405 const tag = emit.mir.instructions.items(.tag)[inst];
383406 const mask = emit.mir.instructions.items(.data)[inst].membar_mask;
src/arch/sparc64/bits.zig+32
......@@ -1229,6 +1229,22 @@ pub const Instruction = union(enum) {
12291229 };
12301230 }
12311231
1232 pub fn lduba(rs1: Register, rs2: Register, asi: ASI, rd: Register) Instruction {
1233 return format3i(0b11, 0b01_0001, rs1, rs2, rd, asi);
1234 }
1235
1236 pub fn lduha(rs1: Register, rs2: Register, asi: ASI, rd: Register) Instruction {
1237 return format3i(0b11, 0b01_0010, rs1, rs2, rd, asi);
1238 }
1239
1240 pub fn lduwa(rs1: Register, rs2: Register, asi: ASI, rd: Register) Instruction {
1241 return format3i(0b11, 0b01_0000, rs1, rs2, rd, asi);
1242 }
1243
1244 pub fn ldxa(rs1: Register, rs2: Register, asi: ASI, rd: Register) Instruction {
1245 return format3i(0b11, 0b01_1011, rs1, rs2, rd, asi);
1246 }
1247
12321248 pub fn @"and"(comptime s2: type, rs1: Register, rs2: s2, rd: Register) Instruction {
12331249 return switch (s2) {
12341250 Register => format3a(0b10, 0b00_0001, rs1, rs2, rd),
......@@ -1417,6 +1433,22 @@ pub const Instruction = union(enum) {
14171433 };
14181434 }
14191435
1436 pub fn stba(rs1: Register, rs2: Register, asi: ASI, rd: Register) Instruction {
1437 return format3i(0b11, 0b01_0101, rs1, rs2, rd, asi);
1438 }
1439
1440 pub fn stha(rs1: Register, rs2: Register, asi: ASI, rd: Register) Instruction {
1441 return format3i(0b11, 0b01_0110, rs1, rs2, rd, asi);
1442 }
1443
1444 pub fn stwa(rs1: Register, rs2: Register, asi: ASI, rd: Register) Instruction {
1445 return format3i(0b11, 0b01_0100, rs1, rs2, rd, asi);
1446 }
1447
1448 pub fn stxa(rs1: Register, rs2: Register, asi: ASI, rd: Register) Instruction {
1449 return format3i(0b11, 0b01_1110, rs1, rs2, rd, asi);
1450 }
1451
14201452 pub fn sub(comptime s2: type, rs1: Register, rs2: s2, rd: Register) Instruction {
14211453 return switch (s2) {
14221454 Register => format3a(0b10, 0b00_0100, rs1, rs2, rd),