| ... | ... | @@ -11842,6 +11842,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 11842 | 11842 | const operand = sema.resolveInst(inst_data.operand); |
| 11843 | 11843 | const operand_ty = sema.typeOf(operand); |
| 11844 | 11844 | |
| 11845 | try sema.resolveTypeLayout(block, operand_src, operand_ty); |
| 11845 | 11846 | const enum_ty = switch (operand_ty.zigTypeTag()) { |
| 11846 | 11847 | .EnumLiteral => { |
| 11847 | 11848 | const val = try sema.resolveConstValue(block, operand_src, operand); |
| ... | ... | @@ -17113,30 +17114,41 @@ fn cmpNumeric( |
| 17113 | 17114 | if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| { |
| 17114 | 17115 | if (lhs_val.isUndef()) |
| 17115 | 17116 | return sema.addConstUndef(Type.bool); |
| 17116 | | const is_unsigned = if (lhs_is_float) x: { |
| 17117 | if (!rhs_is_signed) { |
| 17118 | switch (lhs_val.orderAgainstZero()) { |
| 17119 | .gt => {}, |
| 17120 | .eq => switch (op) { // LHS = 0, RHS is unsigned |
| 17121 | .lte => return Air.Inst.Ref.bool_true, |
| 17122 | .gt => return Air.Inst.Ref.bool_false, |
| 17123 | else => {}, |
| 17124 | }, |
| 17125 | .lt => switch (op) { // LHS < 0, RHS is unsigned |
| 17126 | .neq, .lt, .lte => return Air.Inst.Ref.bool_true, |
| 17127 | .eq, .gt, .gte => return Air.Inst.Ref.bool_false, |
| 17128 | }, |
| 17129 | } |
| 17130 | } |
| 17131 | if (lhs_is_float) { |
| 17117 | 17132 | var bigint_space: Value.BigIntSpace = undefined; |
| 17118 | 17133 | var bigint = try lhs_val.toBigInt(&bigint_space).toManaged(sema.gpa); |
| 17119 | 17134 | defer bigint.deinit(); |
| 17120 | | const zcmp = lhs_val.orderAgainstZero(); |
| 17121 | 17135 | if (lhs_val.floatHasFraction()) { |
| 17122 | 17136 | switch (op) { |
| 17123 | 17137 | .eq => return Air.Inst.Ref.bool_false, |
| 17124 | 17138 | .neq => return Air.Inst.Ref.bool_true, |
| 17125 | 17139 | else => {}, |
| 17126 | 17140 | } |
| 17127 | | if (zcmp == .lt) { |
| 17141 | if (lhs_is_signed) { |
| 17128 | 17142 | try bigint.addScalar(bigint.toConst(), -1); |
| 17129 | 17143 | } else { |
| 17130 | 17144 | try bigint.addScalar(bigint.toConst(), 1); |
| 17131 | 17145 | } |
| 17132 | 17146 | } |
| 17133 | 17147 | lhs_bits = bigint.toConst().bitCountTwosComp(); |
| 17134 | | break :x (zcmp != .lt); |
| 17135 | | } else x: { |
| 17148 | } else { |
| 17136 | 17149 | lhs_bits = lhs_val.intBitCountTwosComp(target); |
| 17137 | | break :x (lhs_val.orderAgainstZero() != .lt); |
| 17138 | | }; |
| 17139 | | lhs_bits += @boolToInt(is_unsigned and dest_int_is_signed); |
| 17150 | } |
| 17151 | lhs_bits += @boolToInt(!lhs_is_signed and dest_int_is_signed); |
| 17140 | 17152 | } else if (lhs_is_float) { |
| 17141 | 17153 | dest_float_type = lhs_ty; |
| 17142 | 17154 | } else { |
| ... | ... | @@ -17148,30 +17160,41 @@ fn cmpNumeric( |
| 17148 | 17160 | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { |
| 17149 | 17161 | if (rhs_val.isUndef()) |
| 17150 | 17162 | return sema.addConstUndef(Type.bool); |
| 17151 | | const is_unsigned = if (rhs_is_float) x: { |
| 17163 | if (!lhs_is_signed) { |
| 17164 | switch (rhs_val.orderAgainstZero()) { |
| 17165 | .gt => {}, |
| 17166 | .eq => switch (op) { // RHS = 0, LHS is unsigned |
| 17167 | .gte => return Air.Inst.Ref.bool_true, |
| 17168 | .lt => return Air.Inst.Ref.bool_false, |
| 17169 | else => {}, |
| 17170 | }, |
| 17171 | .lt => switch (op) { // RHS < 0, LHS is unsigned |
| 17172 | .neq, .gt, .gte => return Air.Inst.Ref.bool_true, |
| 17173 | .eq, .lt, .lte => return Air.Inst.Ref.bool_false, |
| 17174 | }, |
| 17175 | } |
| 17176 | } |
| 17177 | if (rhs_is_float) { |
| 17152 | 17178 | var bigint_space: Value.BigIntSpace = undefined; |
| 17153 | 17179 | var bigint = try rhs_val.toBigInt(&bigint_space).toManaged(sema.gpa); |
| 17154 | 17180 | defer bigint.deinit(); |
| 17155 | | const zcmp = rhs_val.orderAgainstZero(); |
| 17156 | 17181 | if (rhs_val.floatHasFraction()) { |
| 17157 | 17182 | switch (op) { |
| 17158 | 17183 | .eq => return Air.Inst.Ref.bool_false, |
| 17159 | 17184 | .neq => return Air.Inst.Ref.bool_true, |
| 17160 | 17185 | else => {}, |
| 17161 | 17186 | } |
| 17162 | | if (zcmp == .lt) { |
| 17187 | if (rhs_is_signed) { |
| 17163 | 17188 | try bigint.addScalar(bigint.toConst(), -1); |
| 17164 | 17189 | } else { |
| 17165 | 17190 | try bigint.addScalar(bigint.toConst(), 1); |
| 17166 | 17191 | } |
| 17167 | 17192 | } |
| 17168 | 17193 | rhs_bits = bigint.toConst().bitCountTwosComp(); |
| 17169 | | break :x (zcmp != .lt); |
| 17170 | | } else x: { |
| 17194 | } else { |
| 17171 | 17195 | rhs_bits = rhs_val.intBitCountTwosComp(target); |
| 17172 | | break :x (rhs_val.orderAgainstZero() != .lt); |
| 17173 | | }; |
| 17174 | | rhs_bits += @boolToInt(is_unsigned and dest_int_is_signed); |
| 17196 | } |
| 17197 | rhs_bits += @boolToInt(!rhs_is_signed and dest_int_is_signed); |
| 17175 | 17198 | } else if (rhs_is_float) { |
| 17176 | 17199 | dest_float_type = rhs_ty; |
| 17177 | 17200 | } else { |