| ... | @@ -758,8 +758,8 @@ fn analyzeBodyInner( | ... | @@ -758,8 +758,8 @@ fn analyzeBodyInner( |
| 758 | .is_non_null => try sema.zirIsNonNull(block, inst), | 758 | .is_non_null => try sema.zirIsNonNull(block, inst), |
| 759 | .is_non_null_ptr => try sema.zirIsNonNullPtr(block, inst), | 759 | .is_non_null_ptr => try sema.zirIsNonNullPtr(block, inst), |
| 760 | .merge_error_sets => try sema.zirMergeErrorSets(block, inst), | 760 | .merge_error_sets => try sema.zirMergeErrorSets(block, inst), |
| 761 | .negate => try sema.zirNegate(block, inst, .sub), | 761 | .negate => try sema.zirNegate(block, inst), |
| 762 | .negate_wrap => try sema.zirNegate(block, inst, .subwrap), | 762 | .negate_wrap => try sema.zirNegateWrap(block, inst), |
| 763 | .optional_payload_safe => try sema.zirOptionalPayload(block, inst, true), | 763 | .optional_payload_safe => try sema.zirOptionalPayload(block, inst, true), |
| 764 | .optional_payload_safe_ptr => try sema.zirOptionalPayloadPtr(block, inst, true), | 764 | .optional_payload_safe_ptr => try sema.zirOptionalPayloadPtr(block, inst, true), |
| 765 | .optional_payload_unsafe => try sema.zirOptionalPayload(block, inst, false), | 765 | .optional_payload_unsafe => try sema.zirOptionalPayload(block, inst, false), |
| ... | @@ -9328,15 +9328,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -9328,15 +9328,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9328 | return sema.fail(block, lhs_src, "TODO runtime array_mul", .{}); | 9328 | return sema.fail(block, lhs_src, "TODO runtime array_mul", .{}); |
| 9329 | } | 9329 | } |
| 9330 | | 9330 | |
| 9331 | fn zirNegate( | 9331 | fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9332 | sema: *Sema, | | |
| 9333 | block: *Block, | | |
| 9334 | inst: Zir.Inst.Index, | | |
| 9335 | tag_override: Zir.Inst.Tag, | | |
| 9336 | ) CompileError!Air.Inst.Ref { | | |
| 9337 | const tracy = trace(@src()); | | |
| 9338 | defer tracy.end(); | | |
| 9339 | | | |
| 9340 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9332 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 9341 | const src = inst_data.src(); | 9333 | const src = inst_data.src(); |
| 9342 | const lhs_src = src; | 9334 | const lhs_src = src; |
| ... | @@ -9346,16 +9338,42 @@ fn zirNegate( | ... | @@ -9346,16 +9338,42 @@ fn zirNegate( |
| 9346 | const rhs_ty = sema.typeOf(rhs); | 9338 | const rhs_ty = sema.typeOf(rhs); |
| 9347 | const rhs_scalar_ty = rhs_ty.scalarType(); | 9339 | const rhs_scalar_ty = rhs_ty.scalarType(); |
| 9348 | | 9340 | |
| 9349 | if (tag_override == .sub and rhs_scalar_ty.isUnsignedInt()) { | 9341 | if (rhs_scalar_ty.isUnsignedInt()) { |
| 9350 | return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(sema.mod)}); | 9342 | return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(sema.mod)}); |
| 9351 | } | 9343 | } |
| 9352 | | 9344 | |
| | 9345 | if (rhs_scalar_ty.isAnyFloat()) { |
| | 9346 | // We handle comptime negation here to ensure negative zero is represented in the bits. |
| | 9347 | if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| { |
| | 9348 | if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty); |
| | 9349 | const target = sema.mod.getTarget(); |
| | 9350 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target)); |
| | 9351 | } |
| | 9352 | } |
| | 9353 | |
| | 9354 | const lhs = if (rhs_ty.zigTypeTag() == .Vector) |
| | 9355 | try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero)) |
| | 9356 | else |
| | 9357 | sema.resolveInst(.zero); |
| | 9358 | |
| | 9359 | return sema.analyzeArithmetic(block, .sub, lhs, rhs, src, lhs_src, rhs_src); |
| | 9360 | } |
| | 9361 | |
| | 9362 | fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| | 9363 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| | 9364 | const src = inst_data.src(); |
| | 9365 | const lhs_src = src; |
| | 9366 | const rhs_src = src; // TODO better source location |
| | 9367 | |
| | 9368 | const rhs = sema.resolveInst(inst_data.operand); |
| | 9369 | const rhs_ty = sema.typeOf(rhs); |
| | 9370 | |
| 9353 | const lhs = if (rhs_ty.zigTypeTag() == .Vector) | 9371 | const lhs = if (rhs_ty.zigTypeTag() == .Vector) |
| 9354 | try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero)) | 9372 | try sema.addConstant(rhs_ty, try Value.Tag.repeated.create(sema.arena, Value.zero)) |
| 9355 | else | 9373 | else |
| 9356 | sema.resolveInst(.zero); | 9374 | sema.resolveInst(.zero); |
| 9357 | | 9375 | |
| 9358 | return sema.analyzeArithmetic(block, tag_override, lhs, rhs, src, lhs_src, rhs_src); | 9376 | return sema.analyzeArithmetic(block, .subwrap, lhs, rhs, src, lhs_src, rhs_src); |
| 9359 | } | 9377 | } |
| 9360 | | 9378 | |
| 9361 | fn zirArithmetic( | 9379 | fn zirArithmetic( |