mirror of
https://github.com/ziglang/zig.git
synced 2026-02-11 12:01:18 +00:00
stage2 RISCV64: implement move register to register
This commit is contained in:
parent
956d9f4ce0
commit
7cdc47a4e0
@ -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.
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user