authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-11 00:38:49+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-11 14:34:53+01:00
log993eb22a772323bfeef87cf783672c33b6a2cfa2
tree075b7edd4c487f0faa20792c1a01c0471eb8635d
parentf512676d0b4220a5f771110982657140c363a146

stage2 aarch64: add .memory prong in genSetReg


1 files changed, 11 insertions(+), 5 deletions(-)

src/codegen.zig+11-5
...@@ -2572,17 +2572,23 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2572,17 +2572,23 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2572 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movz(reg, @truncate(u16, x), 0).toU32());2572 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movz(reg, @truncate(u16, x), 0).toU32());
2573 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 16), 16).toU32());2573 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 16), 16).toU32());
2574 } else if (x <= math.maxInt(u32)) {2574 } else if (x <= math.maxInt(u32)) {
2575 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movz(reg, @intCast(u16, x), 0).toU32());2575 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movz(reg, @truncate(u16, x), 0).toU32());
2576 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 16), 16).toU32());2576 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @truncate(u16, x >> 16), 16).toU32());
2577 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 32), 32).toU32());2577 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 32), 32).toU32());
2578 } else {2578 } else {
2579 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movz(reg, @intCast(u16, x), 0).toU32());2579 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movz(reg, @truncate(u16, x), 0).toU32());
2580 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 16), 16).toU32());2580 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @truncate(u16, x >> 16), 16).toU32());
2581 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 32), 32).toU32());2581 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @truncate(u16, x >> 32), 32).toU32());
2582 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 48), 48).toU32());2582 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.movk(reg, @intCast(u16, x >> 48), 48).toU32());
2583 }2583 }
2584 },2584 },
2585 .register => return self.fail(src, "TODO implement genSetReg for aarch64 {}", .{mcv}),2585 .register => return self.fail(src, "TODO implement genSetReg for aarch64 {}", .{mcv}),
2586 .memory => |addr| {
2587 // The value is in memory at a hard-coded address.
2588 // If the type is a pointer, it means the pointer address is at this memory location.
2589 try self.genSetReg(src, reg, .{ .immediate = addr });
2590 mem.writeIntLittle(u32, try self.code.addManyAsArray(4), Instruction.ldr(reg, .{ .rn = reg }).toU32());
2591 },
2586 else => return self.fail(src, "TODO implement genSetReg for aarch64 {}", .{mcv}),2592 else => return self.fail(src, "TODO implement genSetReg for aarch64 {}", .{mcv}),
2587 },2593 },
2588 .riscv64 => switch (mcv) {2594 .riscv64 => switch (mcv) {