| ... | @@ -3889,27 +3889,26 @@ fn airMaxMin(self: *Self, inst: Air.Inst.Index, op: enum { max, min }) InnerErro | ... | @@ -3889,27 +3889,26 @@ fn airMaxMin(self: *Self, inst: Air.Inst.Index, op: enum { max, min }) InnerErro |
| 3889 | const lhs = try self.resolveInst(bin_op.lhs); | 3889 | const lhs = try self.resolveInst(bin_op.lhs); |
| 3890 | const rhs = try self.resolveInst(bin_op.rhs); | 3890 | const rhs = try self.resolveInst(bin_op.rhs); |
| 3891 | | 3891 | |
| 3892 | const result = try self.allocLocal(ty); | 3892 | // operands to select from |
| 3893 | | 3893 | try self.emitWValue(lhs); |
| 3894 | try self.startBlock(.block, wasm.block_empty); | | |
| 3895 | try self.startBlock(.block, wasm.block_empty); | | |
| 3896 | | | |
| 3897 | // check if LHS is greater/lesser than RHS | | |
| 3898 | const cmp_result = try self.cmp(lhs, rhs, ty, if (op == .max) .gt else .lt); | | |
| 3899 | try self.addLabel(.local_get, cmp_result.local); | | |
| 3900 | try self.addLabel(.br_if, 0); // break to outer loop if LHS is greater/lesser than RHS | | |
| 3901 | | | |
| 3902 | // set RHS as max/min | | |
| 3903 | try self.emitWValue(rhs); | 3894 | try self.emitWValue(rhs); |
| 3904 | try self.addLabel(.local_set, result.local); | | |
| 3905 | try self.addLabel(.br, 1); // break out of all blocks | | |
| 3906 | try self.endBlock(); | | |
| 3907 | | 3895 | |
| 3908 | // set LHS as max/min | 3896 | // operands to compare |
| 3909 | try self.emitWValue(lhs); | 3897 | try self.emitWValue(lhs); |
| 3910 | try self.addLabel(.local_set, result.local); | 3898 | try self.emitWValue(rhs); |
| 3911 | try self.endBlock(); | 3899 | const opcode = buildOpcode(.{ |
| | 3900 | .op = if (op == .max) .gt else .lt, |
| | 3901 | .signedness = if (ty.isSignedInt()) .signed else .unsigned, |
| | 3902 | .valtype1 = typeToValtype(ty, self.target), |
| | 3903 | }); |
| | 3904 | try self.addTag(Mir.Inst.Tag.fromOpcode(opcode)); |
| | 3905 | |
| | 3906 | // based on the result from comparison, return operand 0 or 1. |
| | 3907 | try self.addTag(.select); |
| 3912 | | 3908 | |
| | 3909 | // store result in local |
| | 3910 | const result = try self.allocLocal(ty); |
| | 3911 | try self.addLabel(.local_set, result.local); |
| 3913 | return result; | 3912 | return result; |
| 3914 | } | 3913 | } |
| 3915 | | 3914 | |