| ... | @@ -658,6 +658,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -658,6 +658,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 658 | | 658 | |
| 659 | const mcv = try self.genFuncInst(inst); | 659 | const mcv = try self.genFuncInst(inst); |
| 660 | if (!inst.isUnused()) { | 660 | if (!inst.isUnused()) { |
| | 661 | log.debug("{*} => {}", .{ inst, mcv }); |
| 661 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; | 662 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 662 | try branch.inst_table.putNoClobber(self.gpa, inst, mcv); | 663 | try branch.inst_table.putNoClobber(self.gpa, inst, mcv); |
| 663 | } | 664 | } |
| ... | @@ -2039,27 +2040,13 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2039,27 +2040,13 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2039 | const condition: Condition = switch (cond) { | 2040 | const condition: Condition = switch (cond) { |
| 2040 | .compare_flags_signed => |cmp_op| blk: { | 2041 | .compare_flags_signed => |cmp_op| blk: { |
| 2041 | // Here we map to the opposite condition because the jump is to the false branch. | 2042 | // Here we map to the opposite condition because the jump is to the false branch. |
| 2042 | const condition: Condition = switch (cmp_op) { | 2043 | const condition = Condition.fromCompareOperatorSigned(cmp_op); |
| 2043 | .gte => .lt, | 2044 | break :blk condition.negate(); |
| 2044 | .gt => .le, | | |
| 2045 | .neq => .eq, | | |
| 2046 | .lt => .ge, | | |
| 2047 | .lte => .gt, | | |
| 2048 | .eq => .ne, | | |
| 2049 | }; | | |
| 2050 | break :blk condition; | | |
| 2051 | }, | 2045 | }, |
| 2052 | .compare_flags_unsigned => |cmp_op| blk: { | 2046 | .compare_flags_unsigned => |cmp_op| blk: { |
| 2053 | // Here we map to the opposite condition because the jump is to the false branch. | 2047 | // Here we map to the opposite condition because the jump is to the false branch. |
| 2054 | const condition: Condition = switch (cmp_op) { | 2048 | const condition = Condition.fromCompareOperatorUnsigned(cmp_op); |
| 2055 | .gte => .cc, | 2049 | break :blk condition.negate(); |
| 2056 | .gt => .ls, | | |
| 2057 | .neq => .eq, | | |
| 2058 | .lt => .cs, | | |
| 2059 | .lte => .hi, | | |
| 2060 | .eq => .ne, | | |
| 2061 | }; | | |
| 2062 | break :blk condition; | | |
| 2063 | }, | 2050 | }, |
| 2064 | .register => |reg| blk: { | 2051 | .register => |reg| blk: { |
| 2065 | // cmp reg, 1 | 2052 | // cmp reg, 1 |
| ... | @@ -2239,7 +2226,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2239,7 +2226,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2239 | } | 2226 | } |
| 2240 | }, | 2227 | }, |
| 2241 | .arm, .armeb => { | 2228 | .arm, .armeb => { |
| 2242 | if (math.cast(i26, @intCast(i32, index) - @intCast(i32, self.code.items.len))) |delta| { | 2229 | if (math.cast(i26, @intCast(i32, index) - @intCast(i32, self.code.items.len + 8))) |delta| { |
| 2243 | writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(.al, delta).toU32()); | 2230 | writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(.al, delta).toU32()); |
| 2244 | } else |err| { | 2231 | } else |err| { |
| 2245 | return self.fail(src, "TODO: enable larger branch offset", .{}); | 2232 | return self.fail(src, "TODO: enable larger branch offset", .{}); |
| ... | @@ -2736,6 +2723,22 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2736,6 +2723,22 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2736 | // Write the debug undefined value. | 2723 | // Write the debug undefined value. |
| 2737 | return self.genSetReg(src, reg, .{ .immediate = 0xaaaaaaaa }); | 2724 | return self.genSetReg(src, reg, .{ .immediate = 0xaaaaaaaa }); |
| 2738 | }, | 2725 | }, |
| | 2726 | .compare_flags_unsigned, |
| | 2727 | .compare_flags_signed, |
| | 2728 | => |op| { |
| | 2729 | const condition = switch (mcv) { |
| | 2730 | .compare_flags_unsigned => Condition.fromCompareOperatorUnsigned(op), |
| | 2731 | .compare_flags_signed => Condition.fromCompareOperatorSigned(op), |
| | 2732 | else => unreachable, |
| | 2733 | }; |
| | 2734 | |
| | 2735 | // mov reg, 0 |
| | 2736 | // moveq reg, 1 |
| | 2737 | const zero = Instruction.Operand.imm(0, 0); |
| | 2738 | const one = Instruction.Operand.imm(1, 0); |
| | 2739 | writeInt(u32, try self.code.addManyAsArray(4), Instruction.mov(.al, reg, zero).toU32()); |
| | 2740 | writeInt(u32, try self.code.addManyAsArray(4), Instruction.mov(condition, reg, one).toU32()); |
| | 2741 | }, |
| 2739 | .immediate => |x| { | 2742 | .immediate => |x| { |
| 2740 | if (x > math.maxInt(u32)) return self.fail(src, "ARM registers are 32-bit wide", .{}); | 2743 | if (x > math.maxInt(u32)) return self.fail(src, "ARM registers are 32-bit wide", .{}); |
| 2741 | | 2744 | |