| ... | ... | @@ -155,6 +155,8 @@ pub const MCValue = union(enum) { |
| 155 | 155 | .memory, |
| 156 | 156 | .stack_offset, |
| 157 | 157 | .ptr_stack_offset, |
| 158 | .direct_load, |
| 159 | .got_load, |
| 158 | 160 | => true, |
| 159 | 161 | else => false, |
| 160 | 162 | }; |
| ... | ... | @@ -3131,20 +3133,19 @@ fn genBinMathOp(self: *Self, inst: Air.Inst.Index, op_lhs: Air.Inst.Ref, op_rhs: |
| 3131 | 3133 | } |
| 3132 | 3134 | |
| 3133 | 3135 | fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void { |
| 3134 | | const abi_size = dst_ty.abiSize(self.target.*); |
| 3136 | const abi_size = @intCast(u32, dst_ty.abiSize(self.target.*)); |
| 3135 | 3137 | switch (dst_mcv) { |
| 3136 | 3138 | .none => unreachable, |
| 3137 | 3139 | .undef => unreachable, |
| 3138 | 3140 | .dead, .unreach, .immediate => unreachable, |
| 3139 | 3141 | .compare_flags_unsigned => unreachable, |
| 3140 | 3142 | .compare_flags_signed => unreachable, |
| 3141 | | .ptr_stack_offset => unreachable, |
| 3142 | 3143 | .register_overflow_unsigned => unreachable, |
| 3143 | 3144 | .register_overflow_signed => unreachable, |
| 3144 | 3145 | .register => |dst_reg| { |
| 3145 | 3146 | switch (src_mcv) { |
| 3146 | 3147 | .none => unreachable, |
| 3147 | | .undef => try self.genSetReg(dst_ty, dst_reg, .undef), |
| 3148 | .undef => unreachable, |
| 3148 | 3149 | .dead, .unreach => unreachable, |
| 3149 | 3150 | .register_overflow_unsigned => unreachable, |
| 3150 | 3151 | .register_overflow_signed => unreachable, |
| ... | ... | @@ -3168,7 +3169,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC |
| 3168 | 3169 | _ = try self.addInst(.{ |
| 3169 | 3170 | .tag = mir_tag, |
| 3170 | 3171 | .ops = (Mir.Ops{ |
| 3171 | | .reg1 = registerAlias(dst_reg, @intCast(u32, abi_size)), |
| 3172 | .reg1 = registerAlias(dst_reg, abi_size), |
| 3172 | 3173 | }).encode(), |
| 3173 | 3174 | .data = .{ .imm = @truncate(u32, imm) }, |
| 3174 | 3175 | }); |
| ... | ... | @@ -3192,7 +3193,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC |
| 3192 | 3193 | _ = try self.addInst(.{ |
| 3193 | 3194 | .tag = mir_tag, |
| 3194 | 3195 | .ops = (Mir.Ops{ |
| 3195 | | .reg1 = registerAlias(dst_reg, @intCast(u32, abi_size)), |
| 3196 | .reg1 = registerAlias(dst_reg, abi_size), |
| 3196 | 3197 | .reg2 = .rbp, |
| 3197 | 3198 | .flags = 0b01, |
| 3198 | 3199 | }).encode(), |
| ... | ... | @@ -3201,19 +3202,18 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC |
| 3201 | 3202 | }, |
| 3202 | 3203 | } |
| 3203 | 3204 | }, |
| 3204 | | .stack_offset => |off| { |
| 3205 | .ptr_stack_offset, .stack_offset => |off| { |
| 3205 | 3206 | if (off > math.maxInt(i32)) { |
| 3206 | 3207 | return self.fail("stack offset too large", .{}); |
| 3207 | 3208 | } |
| 3208 | 3209 | if (abi_size > 8) { |
| 3209 | | return self.fail("TODO implement ADD/SUB/CMP for stack dst with large ABI", .{}); |
| 3210 | return self.fail("TODO implement {} for stack dst with large ABI", .{mir_tag}); |
| 3210 | 3211 | } |
| 3211 | 3212 | |
| 3212 | 3213 | switch (src_mcv) { |
| 3213 | 3214 | .none => unreachable, |
| 3214 | | .undef => return self.genSetStack(dst_ty, off, .undef, .{}), |
| 3215 | .undef => unreachable, |
| 3215 | 3216 | .dead, .unreach => unreachable, |
| 3216 | | .ptr_stack_offset => unreachable, |
| 3217 | 3217 | .register_overflow_unsigned => unreachable, |
| 3218 | 3218 | .register_overflow_signed => unreachable, |
| 3219 | 3219 | .register => |src_reg| { |
| ... | ... | @@ -3221,7 +3221,7 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC |
| 3221 | 3221 | .tag = mir_tag, |
| 3222 | 3222 | .ops = (Mir.Ops{ |
| 3223 | 3223 | .reg1 = .rbp, |
| 3224 | | .reg2 = registerAlias(src_reg, @intCast(u32, abi_size)), |
| 3224 | .reg2 = registerAlias(src_reg, abi_size), |
| 3225 | 3225 | .flags = 0b10, |
| 3226 | 3226 | }).encode(), |
| 3227 | 3227 | .data = .{ .imm = @bitCast(u32, -off) }, |
| ... | ... | @@ -3257,7 +3257,10 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC |
| 3257 | 3257 | .data = .{ .payload = payload }, |
| 3258 | 3258 | }); |
| 3259 | 3259 | }, |
| 3260 | | .memory, .stack_offset => { |
| 3260 | .memory, |
| 3261 | .stack_offset, |
| 3262 | .ptr_stack_offset, |
| 3263 | => { |
| 3261 | 3264 | return self.fail("TODO implement x86 ADD/SUB/CMP source memory", .{}); |
| 3262 | 3265 | }, |
| 3263 | 3266 | .got_load, .direct_load => { |