authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2020-11-22 22:13:17+01:00
committergravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2020-11-28 18:19:22+01:00
logf06f0ebcda57c65f481e5da41fb3949b9863744c
tree818500fb56d6cb5216f99d1031955ccb3897ee7f
parent85a3991a4392cee42acf0ed5fed185afdc2b133c
signaturelock-open Commit is signed but in an unrecognized format.

stage2 ARM: Implement genNot


1 files changed, 29 insertions(+), 14 deletions(-)

src/codegen.zig+29-14
......@@ -975,6 +975,18 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
975975 };
976976 return try self.genX8664BinMath(&inst.base, inst.operand, &imm.base, 6, 0x30);
977977 },
978 .arm, .armeb => {
979 var imm = ir.Inst.Constant{
980 .base = .{
981 .tag = .constant,
982 .deaths = 0,
983 .ty = inst.operand.ty,
984 .src = inst.operand.src,
985 },
986 .val = Value.initTag(.bool_true),
987 };
988 return try self.genArmBinOp(&inst.base, inst.operand, &imm.base, .not);
989 },
978990 else => return self.fail(inst.base.src, "TODO implement NOT for {}", .{self.target.cpu.arch}),
979991 }
980992 }
......@@ -987,7 +999,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
987999 .x86_64 => {
9881000 return try self.genX8664BinMath(&inst.base, inst.lhs, inst.rhs, 0, 0x00);
9891001 },
990 .arm, .armeb => return try self.genArmBinArith(inst, .add),
1002 .arm, .armeb => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .add),
9911003 else => return self.fail(inst.base.src, "TODO implement add for {}", .{self.target.cpu.arch}),
9921004 }
9931005 }
......@@ -1145,14 +1157,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
11451157 .x86_64 => {
11461158 return try self.genX8664BinMath(&inst.base, inst.lhs, inst.rhs, 5, 0x28);
11471159 },
1148 .arm, .armeb => return try self.genArmBinArith(inst, .sub),
1160 .arm, .armeb => return try self.genArmBinOp(&inst.base, inst.lhs, inst.rhs, .sub),
11491161 else => return self.fail(inst.base.src, "TODO implement sub for {}", .{self.target.cpu.arch}),
11501162 }
11511163 }
11521164
1153 fn genArmBinArith(self: *Self, inst: *ir.Inst.BinOp, op: ir.Inst.Tag) !MCValue {
1154 const lhs = try self.resolveInst(inst.lhs);
1155 const rhs = try self.resolveInst(inst.rhs);
1165 fn genArmBinOp(self: *Self, inst: *ir.Inst, op_lhs: *ir.Inst, op_rhs: *ir.Inst, op: ir.Inst.Tag) !MCValue {
1166 const lhs = try self.resolveInst(op_lhs);
1167 const rhs = try self.resolveInst(op_rhs);
11561168
11571169 // Destination must be a register
11581170 // Source may be register, memory or an immediate
......@@ -1160,9 +1172,9 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
11601172 // So there are two options: (lhs is src and rhs is dest)
11611173 // or (rhs is src and lhs is dest)
11621174 const lhs_is_dest = blk: {
1163 if (self.reuseOperand(&inst.base, 0, lhs)) {
1175 if (self.reuseOperand(inst, 0, lhs)) {
11641176 break :blk true;
1165 } else if (self.reuseOperand(&inst.base, 1, rhs)) {
1177 } else if (self.reuseOperand(inst, 1, rhs)) {
11661178 break :blk false;
11671179 } else {
11681180 break :blk lhs == .register;
......@@ -1175,22 +1187,22 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
11751187 if (lhs_is_dest) {
11761188 // LHS is the destination
11771189 // RHS is the source
1178 src_inst = inst.rhs;
1190 src_inst = op_rhs;
11791191 src_mcv = rhs;
1180 dst_mcv = if (lhs != .register) try self.copyToNewRegister(&inst.base, lhs) else lhs;
1192 dst_mcv = if (lhs != .register) try self.copyToNewRegister(inst, lhs) else lhs;
11811193 } else {
11821194 // RHS is the destination
11831195 // LHS is the source
1184 src_inst = inst.lhs;
1196 src_inst = op_lhs;
11851197 src_mcv = lhs;
1186 dst_mcv = if (rhs != .register) try self.copyToNewRegister(&inst.base, rhs) else rhs;
1198 dst_mcv = if (rhs != .register) try self.copyToNewRegister(inst, rhs) else rhs;
11871199 }
11881200
1189 try self.genArmBinArithCode(inst.base.src, dst_mcv.register, src_mcv, lhs_is_dest, op);
1201 try self.genArmBinOpCode(inst.src, dst_mcv.register, src_mcv, lhs_is_dest, op);
11901202 return dst_mcv;
11911203 }
11921204
1193 fn genArmBinArithCode(
1205 fn genArmBinOpCode(
11941206 self: *Self,
11951207 src: usize,
11961208 dst_reg: Register,
......@@ -1234,7 +1246,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
12341246 writeInt(u32, try self.code.addManyAsArray(4), Instruction.rsb(.al, dst_reg, dst_reg, operand).toU32());
12351247 }
12361248 },
1237 else => unreachable, // not a binary arithmetic instruction
1249 .not => {
1250 writeInt(u32, try self.code.addManyAsArray(4), Instruction.eor(.al, dst_reg, dst_reg, operand).toU32());
1251 },
1252 else => unreachable, // not a binary instruction
12381253 }
12391254 }
12401255