stage2 RISCV64: implement move register to register

This commit is contained in:
joachimschmidt557 2022-03-19 19:48:27 +01:00
parent 956d9f4ce0
commit 7cdc47a4e0
No known key found for this signature in database
GPG Key ID: E0B575BE2884ACC5
3 changed files with 33 additions and 0 deletions

View File

@ -2074,6 +2074,20 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
return self.fail("TODO genSetReg 33-64 bit immediates for riscv64", .{}); // glhf
}
},
.register => |src_reg| {
// If the registers are the same, nothing to do.
if (src_reg.id() == reg.id())
return;
// mov reg, src_reg
_ = try self.addInst(.{
.tag = .mv,
.data = .{ .rr = .{
.rd = reg,
.rs = src_reg,
} },
});
},
.memory => |addr| {
// The value is in memory at a hard-coded address.
// If the type is a pointer, it means the pointer address is at this memory location.

View File

@ -56,6 +56,8 @@ pub fn emitMir(
.dbg_prologue_end => try emit.mirDebugPrologueEnd(),
.dbg_epilogue_begin => try emit.mirDebugEpilogueBegin(),
.mv => try emit.mirRR(inst),
.nop => try emit.mirNop(inst),
.ret => try emit.mirNop(inst),
@ -186,6 +188,15 @@ fn mirDebugEpilogueBegin(self: *Emit) !void {
}
}
fn mirRR(emit: *Emit, inst: Mir.Inst.Index) !void {
const tag = emit.mir.instructions.items(.tag)[inst];
const rr = emit.mir.instructions.items(.data)[inst].rr;
switch (tag) {
.mv => try emit.writeInstruction(Instruction.addi(rr.rd, rr.rs, 0)),
else => unreachable,
}
}
fn mirUType(emit: *Emit, inst: Mir.Inst.Index) !void {
const tag = emit.mir.instructions.items(.tag)[inst];
const u_type = emit.mir.instructions.items(.data)[inst].u_type;

View File

@ -36,6 +36,7 @@ pub const Inst = struct {
jalr,
ld,
lui,
mv,
nop,
ret,
sd,
@ -68,6 +69,13 @@ pub const Inst = struct {
///
/// Used by e.g. blr
reg: Register,
/// Two registers
///
/// Used by e.g. mv
rr: struct {
rd: Register,
rs: Register,
},
/// I-Type
///
/// Used by e.g. jalr