| ... | ... | @@ -658,6 +658,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 658 | 658 | |
| 659 | 659 | const mcv = try self.genFuncInst(inst); |
| 660 | 660 | if (!inst.isUnused()) { |
| 661 | log.debug("{*} => {}", .{ inst, mcv }); |
| 661 | 662 | const branch = &self.branch_stack.items[self.branch_stack.items.len - 1]; |
| 662 | 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 | 2040 | const condition: Condition = switch (cond) { |
| 2040 | 2041 | .compare_flags_signed => |cmp_op| blk: { |
| 2041 | 2042 | // Here we map to the opposite condition because the jump is to the false branch. |
| 2042 | | const condition: Condition = switch (cmp_op) { |
| 2043 | | .gte => .lt, |
| 2044 | | .gt => .le, |
| 2045 | | .neq => .eq, |
| 2046 | | .lt => .ge, |
| 2047 | | .lte => .gt, |
| 2048 | | .eq => .ne, |
| 2049 | | }; |
| 2050 | | break :blk condition; |
| 2043 | const condition = Condition.fromCompareOperatorSigned(cmp_op); |
| 2044 | break :blk condition.negate(); |
| 2051 | 2045 | }, |
| 2052 | 2046 | .compare_flags_unsigned => |cmp_op| blk: { |
| 2053 | 2047 | // Here we map to the opposite condition because the jump is to the false branch. |
| 2054 | | const condition: Condition = switch (cmp_op) { |
| 2055 | | .gte => .cc, |
| 2056 | | .gt => .ls, |
| 2057 | | .neq => .eq, |
| 2058 | | .lt => .cs, |
| 2059 | | .lte => .hi, |
| 2060 | | .eq => .ne, |
| 2061 | | }; |
| 2062 | | break :blk condition; |
| 2048 | const condition = Condition.fromCompareOperatorUnsigned(cmp_op); |
| 2049 | break :blk condition.negate(); |
| 2063 | 2050 | }, |
| 2064 | 2051 | .register => |reg| blk: { |
| 2065 | 2052 | // cmp reg, 1 |
| ... | ... | @@ -2239,7 +2226,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2239 | 2226 | } |
| 2240 | 2227 | }, |
| 2241 | 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 | 2230 | writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(.al, delta).toU32()); |
| 2244 | 2231 | } else |err| { |
| 2245 | 2232 | return self.fail(src, "TODO: enable larger branch offset", .{}); |
| ... | ... | @@ -2736,6 +2723,22 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2736 | 2723 | // Write the debug undefined value. |
| 2737 | 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 | 2742 | .immediate => |x| { |
| 2740 | 2743 | if (x > math.maxInt(u32)) return self.fail(src, "ARM registers are 32-bit wide", .{}); |
| 2741 | 2744 | |