authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-19 16:13:12+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-19 17:01:44+02:00
logee334aea801c71cbcc567b1d19be9c04d911beda
tree4134fa8f51d359fd638e7c2c92563b9d482ec718
parent22d46e1d7753ea2a9accc180e8613206120739c5

value: remove `indexVectorlike`

Vectors can represented in all the same values as arrays so this was never a valid shortcut.

2 files changed, 434 insertions(+), 227 deletions(-)

src/Sema.zig+129-91
...@@ -9225,7 +9225,7 @@ fn intCast(...@@ -9225,7 +9225,7 @@ fn intCast(
9225 // If the destination type is signed, then we need to double its9225 // If the destination type is signed, then we need to double its
9226 // range to account for negative values.9226 // range to account for negative values.
9227 const dest_range_val = if (wanted_info.signedness == .signed) range_val: {9227 const dest_range_val = if (wanted_info.signedness == .signed) range_val: {
9228 const range_minus_one = try dest_max_val.shl(Value.one, unsigned_operand_ty, sema.arena, target);9228 const range_minus_one = try dest_max_val.shl(Value.one, unsigned_operand_ty, sema.arena, sema.mod);
9229 break :range_val try sema.intAdd(range_minus_one, Value.one, unsigned_operand_ty);9229 break :range_val try sema.intAdd(range_minus_one, Value.one, unsigned_operand_ty);
9230 } else dest_max_val;9230 } else dest_max_val;
9231 const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val);9231 const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val);
...@@ -11683,9 +11683,11 @@ fn zirShl(...@@ -11683,9 +11683,11 @@ fn zirShl(
11683 if (rhs_ty.zigTypeTag() == .Vector) {11683 if (rhs_ty.zigTypeTag() == .Vector) {
11684 var i: usize = 0;11684 var i: usize = 0;
11685 while (i < rhs_ty.vectorLen()) : (i += 1) {11685 while (i < rhs_ty.vectorLen()) : (i += 1) {
11686 if (rhs_val.indexVectorlike(i).compareHetero(.gte, bit_value, target)) {11686 var elem_value_buf: Value.ElemValueBuffer = undefined;
11687 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
11688 if (rhs_elem.compareHetero(.gte, bit_value, target)) {
11687 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{11689 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
11688 rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),11690 rhs_elem.fmtValue(scalar_ty, sema.mod),
11689 i,11691 i,
11690 scalar_ty.fmt(sema.mod),11692 scalar_ty.fmt(sema.mod),
11691 });11693 });
...@@ -11701,9 +11703,11 @@ fn zirShl(...@@ -11701,9 +11703,11 @@ fn zirShl(
11701 if (rhs_ty.zigTypeTag() == .Vector) {11703 if (rhs_ty.zigTypeTag() == .Vector) {
11702 var i: usize = 0;11704 var i: usize = 0;
11703 while (i < rhs_ty.vectorLen()) : (i += 1) {11705 while (i < rhs_ty.vectorLen()) : (i += 1) {
11704 if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) {11706 var elem_value_buf: Value.ElemValueBuffer = undefined;
11707 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
11708 if (rhs_elem.compareHetero(.lt, Value.zero, target)) {
11705 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{11709 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
11706 rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),11710 rhs_elem.fmtValue(scalar_ty, sema.mod),
11707 i,11711 i,
11708 });11712 });
11709 }11713 }
...@@ -11726,7 +11730,7 @@ fn zirShl(...@@ -11726,7 +11730,7 @@ fn zirShl(
1172611730
11727 const val = switch (air_tag) {11731 const val = switch (air_tag) {
11728 .shl_exact => val: {11732 .shl_exact => val: {
11729 const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, target);11733 const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, sema.mod);
11730 if (scalar_ty.zigTypeTag() == .ComptimeInt) {11734 if (scalar_ty.zigTypeTag() == .ComptimeInt) {
11731 break :val shifted.wrapped_result;11735 break :val shifted.wrapped_result;
11732 }11736 }
...@@ -11737,14 +11741,14 @@ fn zirShl(...@@ -11737,14 +11741,14 @@ fn zirShl(
11737 },11741 },
1173811742
11739 .shl_sat => if (scalar_ty.zigTypeTag() == .ComptimeInt)11743 .shl_sat => if (scalar_ty.zigTypeTag() == .ComptimeInt)
11740 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, target)11744 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, sema.mod)
11741 else11745 else
11742 try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, target),11746 try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, sema.mod),
1174311747
11744 .shl => if (scalar_ty.zigTypeTag() == .ComptimeInt)11748 .shl => if (scalar_ty.zigTypeTag() == .ComptimeInt)
11745 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, target)11749 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, sema.mod)
11746 else11750 else
11747 try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, target),11751 try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, sema.mod),
1174811752
11749 else => unreachable,11753 else => unreachable,
11750 };11754 };
...@@ -11867,9 +11871,11 @@ fn zirShr(...@@ -11867,9 +11871,11 @@ fn zirShr(
11867 if (rhs_ty.zigTypeTag() == .Vector) {11871 if (rhs_ty.zigTypeTag() == .Vector) {
11868 var i: usize = 0;11872 var i: usize = 0;
11869 while (i < rhs_ty.vectorLen()) : (i += 1) {11873 while (i < rhs_ty.vectorLen()) : (i += 1) {
11870 if (rhs_val.indexVectorlike(i).compareHetero(.gte, bit_value, target)) {11874 var elem_value_buf: Value.ElemValueBuffer = undefined;
11875 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
11876 if (rhs_elem.compareHetero(.gte, bit_value, target)) {
11871 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{11877 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
11872 rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),11878 rhs_elem.fmtValue(scalar_ty, sema.mod),
11873 i,11879 i,
11874 scalar_ty.fmt(sema.mod),11880 scalar_ty.fmt(sema.mod),
11875 });11881 });
...@@ -11885,9 +11891,11 @@ fn zirShr(...@@ -11885,9 +11891,11 @@ fn zirShr(
11885 if (rhs_ty.zigTypeTag() == .Vector) {11891 if (rhs_ty.zigTypeTag() == .Vector) {
11886 var i: usize = 0;11892 var i: usize = 0;
11887 while (i < rhs_ty.vectorLen()) : (i += 1) {11893 while (i < rhs_ty.vectorLen()) : (i += 1) {
11888 if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) {11894 var elem_value_buf: Value.ElemValueBuffer = undefined;
11895 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
11896 if (rhs_elem.compareHetero(.lt, Value.zero, target)) {
11889 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{11897 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
11890 rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),11898 rhs_elem.fmtValue(scalar_ty, sema.mod),
11891 i,11899 i,
11892 });11900 });
11893 }11901 }
...@@ -11903,12 +11911,12 @@ fn zirShr(...@@ -11903,12 +11911,12 @@ fn zirShr(
11903 }11911 }
11904 if (air_tag == .shr_exact) {11912 if (air_tag == .shr_exact) {
11905 // Detect if any ones would be shifted out.11913 // Detect if any ones would be shifted out.
11906 const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, target);11914 const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, sema.mod);
11907 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) {11915 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) {
11908 return sema.fail(block, src, "exact shift shifted out 1 bits", .{});11916 return sema.fail(block, src, "exact shift shifted out 1 bits", .{});
11909 }11917 }
11910 }11918 }
11911 const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, target);11919 const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, sema.mod);
11912 return sema.addConstant(lhs_ty, val);11920 return sema.addConstant(lhs_ty, val);
11913 } else {11921 } else {
11914 break :rs lhs_src;11922 break :rs lhs_src;
...@@ -11992,7 +12000,6 @@ fn zirBitwise(...@@ -11992,7 +12000,6 @@ fn zirBitwise(
11992 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);12000 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1199312001
11994 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;12002 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
11995 const target = sema.mod.getTarget();
1199612003
11997 if (!is_int) {12004 if (!is_int) {
11998 return sema.fail(block, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) });12005 return sema.fail(block, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) });
...@@ -12004,9 +12011,9 @@ fn zirBitwise(...@@ -12004,9 +12011,9 @@ fn zirBitwise(
12004 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {12011 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {
12005 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {12012 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {
12006 const result_val = switch (air_tag) {12013 const result_val = switch (air_tag) {
12007 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, target),12014 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, sema.mod),
12008 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, target),12015 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, sema.mod),
12009 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, target),12016 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, sema.mod),
12010 else => unreachable,12017 else => unreachable,
12011 };12018 };
12012 return sema.addConstant(resolved_type, result_val);12019 return sema.addConstant(resolved_type, result_val);
...@@ -12033,7 +12040,6 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -12033,7 +12040,6 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
12033 const operand = try sema.resolveInst(inst_data.operand);12040 const operand = try sema.resolveInst(inst_data.operand);
12034 const operand_type = sema.typeOf(operand);12041 const operand_type = sema.typeOf(operand);
12035 const scalar_type = operand_type.scalarType();12042 const scalar_type = operand_type.scalarType();
12036 const target = sema.mod.getTarget();
1203712043
12038 if (scalar_type.zigTypeTag() != .Int) {12044 if (scalar_type.zigTypeTag() != .Int) {
12039 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{12045 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{
...@@ -12050,14 +12056,14 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -12050,14 +12056,14 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
12050 const elems = try sema.arena.alloc(Value, vec_len);12056 const elems = try sema.arena.alloc(Value, vec_len);
12051 for (elems) |*elem, i| {12057 for (elems) |*elem, i| {
12052 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_val_buf);12058 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_val_buf);
12053 elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, target);12059 elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod);
12054 }12060 }
12055 return sema.addConstant(12061 return sema.addConstant(
12056 operand_type,12062 operand_type,
12057 try Value.Tag.aggregate.create(sema.arena, elems),12063 try Value.Tag.aggregate.create(sema.arena, elems),
12058 );12064 );
12059 } else {12065 } else {
12060 const result_val = try val.bitwiseNot(operand_type, sema.arena, target);12066 const result_val = try val.bitwiseNot(operand_type, sema.arena, sema.mod);
12061 return sema.addConstant(operand_type, result_val);12067 return sema.addConstant(operand_type, result_val);
12062 }12068 }
12063 }12069 }
...@@ -12586,8 +12592,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -12586,8 +12592,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
12586 // We handle float negation here to ensure negative zero is represented in the bits.12592 // We handle float negation here to ensure negative zero is represented in the bits.
12587 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {12593 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
12588 if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty);12594 if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty);
12589 const target = sema.mod.getTarget();12595 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, sema.mod));
12590 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target));
12591 }12596 }
12592 try sema.requireRuntimeBlock(block, src, null);12597 try sema.requireRuntimeBlock(block, src, null);
12593 return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs);12598 return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs);
...@@ -12679,7 +12684,6 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -12679,7 +12684,6 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
12679 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div);12684 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div);
1268012685
12681 const mod = sema.mod;12686 const mod = sema.mod;
12682 const target = mod.getTarget();
12683 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);12687 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
12684 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);12688 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1268512689
...@@ -12690,7 +12694,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -12690,7 +12694,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
12690 // If lhs % rhs is 0, it doesn't matter.12694 // If lhs % rhs is 0, it doesn't matter.
12691 const lhs_val = maybe_lhs_val orelse unreachable;12695 const lhs_val = maybe_lhs_val orelse unreachable;
12692 const rhs_val = maybe_rhs_val orelse unreachable;12696 const rhs_val = maybe_rhs_val orelse unreachable;
12693 const rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, target) catch unreachable;12697 const rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod) catch unreachable;
12694 if (!rem.compareAllWithZero(.eq)) {12698 if (!rem.compareAllWithZero(.eq)) {
12695 return sema.fail(block, src, "ambiguous coercion of division operands '{s}' and '{s}'; non-zero remainder '{}'", .{12699 return sema.fail(block, src, "ambiguous coercion of division operands '{s}' and '{s}'; non-zero remainder '{}'", .{
12696 @tagName(lhs_ty.tag()), @tagName(rhs_ty.tag()), rem.fmtValue(resolved_type, sema.mod),12700 @tagName(lhs_ty.tag()), @tagName(rhs_ty.tag()), rem.fmtValue(resolved_type, sema.mod),
...@@ -12766,7 +12770,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -12766,7 +12770,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1276612770
12767 if (maybe_rhs_val) |rhs_val| {12771 if (maybe_rhs_val) |rhs_val| {
12768 if (is_int) {12772 if (is_int) {
12769 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);12773 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, mod);
12770 var vector_index: usize = undefined;12774 var vector_index: usize = undefined;
12771 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {12775 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
12772 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);12776 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
...@@ -12775,7 +12779,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -12775,7 +12779,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
12775 } else {12779 } else {
12776 return sema.addConstant(12780 return sema.addConstant(
12777 resolved_type,12781 resolved_type,
12778 try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, target),12782 try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, mod),
12779 );12783 );
12780 }12784 }
12781 } else {12785 } else {
...@@ -12839,7 +12843,6 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12839,7 +12843,6 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12839 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_exact);12843 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_exact);
1284012844
12841 const mod = sema.mod;12845 const mod = sema.mod;
12842 const target = mod.getTarget();
12843 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);12846 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
12844 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);12847 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1284512848
...@@ -12884,24 +12887,24 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12884,24 +12887,24 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12884 if (maybe_lhs_val) |lhs_val| {12887 if (maybe_lhs_val) |lhs_val| {
12885 if (maybe_rhs_val) |rhs_val| {12888 if (maybe_rhs_val) |rhs_val| {
12886 if (is_int) {12889 if (is_int) {
12887 const modulus_val = try lhs_val.intMod(rhs_val, resolved_type, sema.arena, target);12890 const modulus_val = try lhs_val.intMod(rhs_val, resolved_type, sema.arena, mod);
12888 if (!(modulus_val.compareAllWithZero(.eq))) {12891 if (!(modulus_val.compareAllWithZero(.eq))) {
12889 return sema.fail(block, src, "exact division produced remainder", .{});12892 return sema.fail(block, src, "exact division produced remainder", .{});
12890 }12893 }
12891 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);12894 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, mod);
12892 var vector_index: usize = undefined;12895 var vector_index: usize = undefined;
12893 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {12896 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
12894 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);12897 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
12895 }12898 }
12896 return sema.addConstant(resolved_type, res);12899 return sema.addConstant(resolved_type, res);
12897 } else {12900 } else {
12898 const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, target);12901 const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod);
12899 if (!(modulus_val.compareAllWithZero(.eq))) {12902 if (!(modulus_val.compareAllWithZero(.eq))) {
12900 return sema.fail(block, src, "exact division produced remainder", .{});12903 return sema.fail(block, src, "exact division produced remainder", .{});
12901 }12904 }
12902 return sema.addConstant(12905 return sema.addConstant(
12903 resolved_type,12906 resolved_type,
12904 try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, target),12907 try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, mod),
12905 );12908 );
12906 }12909 }
12907 } else break :rs rhs_src;12910 } else break :rs rhs_src;
...@@ -13004,7 +13007,6 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13004,7 +13007,6 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13004 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_floor);13007 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_floor);
1300513008
13006 const mod = sema.mod;13009 const mod = sema.mod;
13007 const target = mod.getTarget();
13008 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);13010 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13009 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);13011 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1301013012
...@@ -13064,12 +13066,12 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13064,12 +13066,12 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13064 if (is_int) {13066 if (is_int) {
13065 return sema.addConstant(13067 return sema.addConstant(
13066 resolved_type,13068 resolved_type,
13067 try lhs_val.intDivFloor(rhs_val, resolved_type, sema.arena, target),13069 try lhs_val.intDivFloor(rhs_val, resolved_type, sema.arena, mod),
13068 );13070 );
13069 } else {13071 } else {
13070 return sema.addConstant(13072 return sema.addConstant(
13071 resolved_type,13073 resolved_type,
13072 try lhs_val.floatDivFloor(rhs_val, resolved_type, sema.arena, target),13074 try lhs_val.floatDivFloor(rhs_val, resolved_type, sema.arena, mod),
13073 );13075 );
13074 }13076 }
13075 } else break :rs rhs_src;13077 } else break :rs rhs_src;
...@@ -13121,7 +13123,6 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13121,7 +13123,6 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13121 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_trunc);13123 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_trunc);
1312213124
13123 const mod = sema.mod;13125 const mod = sema.mod;
13124 const target = mod.getTarget();
13125 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);13126 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13126 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);13127 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1312713128
...@@ -13178,7 +13179,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13178,7 +13179,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1317813179
13179 if (maybe_rhs_val) |rhs_val| {13180 if (maybe_rhs_val) |rhs_val| {
13180 if (is_int) {13181 if (is_int) {
13181 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);13182 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, mod);
13182 var vector_index: usize = undefined;13183 var vector_index: usize = undefined;
13183 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {13184 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
13184 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);13185 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
...@@ -13187,7 +13188,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13187,7 +13188,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13187 } else {13188 } else {
13188 return sema.addConstant(13189 return sema.addConstant(
13189 resolved_type,13190 resolved_type,
13190 try lhs_val.floatDivTrunc(rhs_val, resolved_type, sema.arena, target),13191 try lhs_val.floatDivTrunc(rhs_val, resolved_type, sema.arena, mod),
13191 );13192 );
13192 }13193 }
13193 } else break :rs rhs_src;13194 } else break :rs rhs_src;
...@@ -13365,7 +13366,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -13365,7 +13366,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
13365 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod_rem);13366 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod_rem);
1336613367
13367 const mod = sema.mod;13368 const mod = sema.mod;
13368 const target = mod.getTarget();
13369 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);13369 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13370 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);13370 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1337113371
...@@ -13442,7 +13442,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -13442,7 +13442,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
13442 }13442 }
13443 return sema.addConstant(13443 return sema.addConstant(
13444 resolved_type,13444 resolved_type,
13445 try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, target),13445 try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod),
13446 );13446 );
13447 } else {13447 } else {
13448 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);13448 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
...@@ -13471,7 +13471,11 @@ fn intRem(...@@ -13471,7 +13471,11 @@ fn intRem(
13471 if (ty.zigTypeTag() == .Vector) {13471 if (ty.zigTypeTag() == .Vector) {
13472 const result_data = try sema.arena.alloc(Value, ty.vectorLen());13472 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
13473 for (result_data) |*scalar, i| {13473 for (result_data) |*scalar, i| {
13474 scalar.* = try sema.intRemScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));13474 var lhs_buf: Value.ElemValueBuffer = undefined;
13475 var rhs_buf: Value.ElemValueBuffer = undefined;
13476 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
13477 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
13478 scalar.* = try sema.intRemScalar(lhs_elem, rhs_elem);
13475 }13479 }
13476 return Value.Tag.aggregate.create(sema.arena, result_data);13480 return Value.Tag.aggregate.create(sema.arena, result_data);
13477 }13481 }
...@@ -13541,7 +13545,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -13541,7 +13545,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
13541 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod);13545 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod);
1354213546
13543 const mod = sema.mod;13547 const mod = sema.mod;
13544 const target = mod.getTarget();
13545 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);13548 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13546 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);13549 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1354713550
...@@ -13573,7 +13576,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -13573,7 +13576,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
13573 if (maybe_lhs_val) |lhs_val| {13576 if (maybe_lhs_val) |lhs_val| {
13574 return sema.addConstant(13577 return sema.addConstant(
13575 resolved_type,13578 resolved_type,
13576 try lhs_val.intMod(rhs_val, resolved_type, sema.arena, target),13579 try lhs_val.intMod(rhs_val, resolved_type, sema.arena, mod),
13577 );13580 );
13578 }13581 }
13579 break :rs lhs_src;13582 break :rs lhs_src;
...@@ -13597,7 +13600,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -13597,7 +13600,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
13597 if (maybe_rhs_val) |rhs_val| {13600 if (maybe_rhs_val) |rhs_val| {
13598 return sema.addConstant(13601 return sema.addConstant(
13599 resolved_type,13602 resolved_type,
13600 try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, target),13603 try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod),
13601 );13604 );
13602 } else break :rs rhs_src;13605 } else break :rs rhs_src;
13603 } else break :rs lhs_src;13606 } else break :rs lhs_src;
...@@ -13644,7 +13647,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -13644,7 +13647,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
13644 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .rem);13647 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .rem);
1364513648
13646 const mod = sema.mod;13649 const mod = sema.mod;
13647 const target = mod.getTarget();
13648 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);13650 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13649 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);13651 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1365013652
...@@ -13700,7 +13702,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -13700,7 +13702,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
13700 if (maybe_rhs_val) |rhs_val| {13702 if (maybe_rhs_val) |rhs_val| {
13701 return sema.addConstant(13703 return sema.addConstant(
13702 resolved_type,13704 resolved_type,
13703 try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, target),13705 try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod),
13704 );13706 );
13705 } else break :rs rhs_src;13707 } else break :rs rhs_src;
13706 } else break :rs lhs_src;13708 } else break :rs lhs_src;
...@@ -13739,7 +13741,6 @@ fn zirOverflowArithmetic(...@@ -13739,7 +13741,6 @@ fn zirOverflowArithmetic(
13739 const lhs_ty = sema.typeOf(lhs);13741 const lhs_ty = sema.typeOf(lhs);
13740 const rhs_ty = sema.typeOf(rhs);13742 const rhs_ty = sema.typeOf(rhs);
13741 const mod = sema.mod;13743 const mod = sema.mod;
13742 const target = mod.getTarget();
1374313744
13744 // Note, the types of lhs/rhs (also for shifting)/ptr are already correct as ensured by astgen.13745 // Note, the types of lhs/rhs (also for shifting)/ptr are already correct as ensured by astgen.
13745 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);13746 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
...@@ -13839,7 +13840,7 @@ fn zirOverflowArithmetic(...@@ -13839,7 +13840,7 @@ fn zirOverflowArithmetic(
13839 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };13840 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
13840 }13841 }
1384113842
13842 const result = try lhs_val.intMulWithOverflow(rhs_val, dest_ty, sema.arena, target);13843 const result = try lhs_val.intMulWithOverflow(rhs_val, dest_ty, sema.arena, mod);
13843 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);13844 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);
13844 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);13845 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);
13845 break :result .{ .overflowed = overflowed, .wrapped = wrapped };13846 break :result .{ .overflowed = overflowed, .wrapped = wrapped };
...@@ -13866,7 +13867,7 @@ fn zirOverflowArithmetic(...@@ -13866,7 +13867,7 @@ fn zirOverflowArithmetic(
13866 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };13867 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
13867 }13868 }
1386813869
13869 const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, target);13870 const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, sema.mod);
13870 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);13871 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);
13871 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);13872 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);
13872 break :result .{ .overflowed = overflowed, .wrapped = wrapped };13873 break :result .{ .overflowed = overflowed, .wrapped = wrapped };
...@@ -13979,13 +13980,12 @@ fn analyzeArithmetic(...@@ -13979,13 +13980,12 @@ fn analyzeArithmetic(
13979 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, zir_tag);13980 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, zir_tag);
1398013981
13981 const mod = sema.mod;13982 const mod = sema.mod;
13982 const target = mod.getTarget();
13983 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);13983 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13984 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);13984 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
13985 const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: {13985 const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: {
13986 switch (zir_tag) {13986 switch (zir_tag) {
13987 .add => {13987 .add => {
13988 // For integers:13988 // For integers:intAddSat
13989 // If either of the operands are zero, then the other operand is13989 // If either of the operands are zero, then the other operand is
13990 // returned, even if it is undefined.13990 // returned, even if it is undefined.
13991 // If either of the operands are undefined, it's a compile error13991 // If either of the operands are undefined, it's a compile error
...@@ -14080,7 +14080,7 @@ fn analyzeArithmetic(...@@ -14080,7 +14080,7 @@ fn analyzeArithmetic(
14080 const val = if (scalar_tag == .ComptimeInt)14080 const val = if (scalar_tag == .ComptimeInt)
14081 try sema.intAdd(lhs_val, rhs_val, resolved_type)14081 try sema.intAdd(lhs_val, rhs_val, resolved_type)
14082 else14082 else
14083 try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, target);14083 try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, mod);
1408414084
14085 return sema.addConstant(resolved_type, val);14085 return sema.addConstant(resolved_type, val);
14086 } else break :rs .{ .src = lhs_src, .air_tag = .add_sat };14086 } else break :rs .{ .src = lhs_src, .air_tag = .add_sat };
...@@ -14177,7 +14177,7 @@ fn analyzeArithmetic(...@@ -14177,7 +14177,7 @@ fn analyzeArithmetic(
14177 const val = if (scalar_tag == .ComptimeInt)14177 const val = if (scalar_tag == .ComptimeInt)
14178 try sema.intSub(lhs_val, rhs_val, resolved_type)14178 try sema.intSub(lhs_val, rhs_val, resolved_type)
14179 else14179 else
14180 try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, target);14180 try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, mod);
1418114181
14182 return sema.addConstant(resolved_type, val);14182 return sema.addConstant(resolved_type, val);
14183 } else break :rs .{ .src = rhs_src, .air_tag = .sub_sat };14183 } else break :rs .{ .src = rhs_src, .air_tag = .sub_sat };
...@@ -14258,7 +14258,7 @@ fn analyzeArithmetic(...@@ -14258,7 +14258,7 @@ fn analyzeArithmetic(
14258 }14258 }
14259 }14259 }
14260 if (is_int) {14260 if (is_int) {
14261 const product = try lhs_val.intMul(rhs_val, resolved_type, sema.arena, target);14261 const product = try lhs_val.intMul(rhs_val, resolved_type, sema.arena, sema.mod);
14262 var vector_index: usize = undefined;14262 var vector_index: usize = undefined;
14263 if (!(try sema.intFitsInType(product, resolved_type, &vector_index))) {14263 if (!(try sema.intFitsInType(product, resolved_type, &vector_index))) {
14264 return sema.failWithIntegerOverflow(block, src, resolved_type, product, vector_index);14264 return sema.failWithIntegerOverflow(block, src, resolved_type, product, vector_index);
...@@ -14267,7 +14267,7 @@ fn analyzeArithmetic(...@@ -14267,7 +14267,7 @@ fn analyzeArithmetic(
14267 } else {14267 } else {
14268 return sema.addConstant(14268 return sema.addConstant(
14269 resolved_type,14269 resolved_type,
14270 try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, target),14270 try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, sema.mod),
14271 );14271 );
14272 }14272 }
14273 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };14273 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
...@@ -14311,7 +14311,7 @@ fn analyzeArithmetic(...@@ -14311,7 +14311,7 @@ fn analyzeArithmetic(
14311 }14311 }
14312 return sema.addConstant(14312 return sema.addConstant(
14313 resolved_type,14313 resolved_type,
14314 try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, target),14314 try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, sema.mod),
14315 );14315 );
14316 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };14316 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
14317 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };14317 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
...@@ -14353,9 +14353,9 @@ fn analyzeArithmetic(...@@ -14353,9 +14353,9 @@ fn analyzeArithmetic(
14353 }14353 }
1435414354
14355 const val = if (scalar_tag == .ComptimeInt)14355 const val = if (scalar_tag == .ComptimeInt)
14356 try lhs_val.intMul(rhs_val, resolved_type, sema.arena, target)14356 try lhs_val.intMul(rhs_val, resolved_type, sema.arena, sema.mod)
14357 else14357 else
14358 try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, target);14358 try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, sema.mod);
1435914359
14360 return sema.addConstant(resolved_type, val);14360 return sema.addConstant(resolved_type, val);
14361 } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat };14361 } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat };
...@@ -17947,7 +17947,7 @@ fn zirUnaryMath(...@@ -17947,7 +17947,7 @@ fn zirUnaryMath(
17947 block: *Block,17947 block: *Block,
17948 inst: Zir.Inst.Index,17948 inst: Zir.Inst.Index,
17949 air_tag: Air.Inst.Tag,17949 air_tag: Air.Inst.Tag,
17950 comptime eval: fn (Value, Type, Allocator, std.Target) Allocator.Error!Value,17950 comptime eval: fn (Value, Type, Allocator, *Module) Allocator.Error!Value,
17951) CompileError!Air.Inst.Ref {17951) CompileError!Air.Inst.Ref {
17952 const tracy = trace(@src());17952 const tracy = trace(@src());
17953 defer tracy.end();17953 defer tracy.end();
...@@ -17956,7 +17956,6 @@ fn zirUnaryMath(...@@ -17956,7 +17956,6 @@ fn zirUnaryMath(
17956 const operand = try sema.resolveInst(inst_data.operand);17956 const operand = try sema.resolveInst(inst_data.operand);
17957 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };17957 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
17958 const operand_ty = sema.typeOf(operand);17958 const operand_ty = sema.typeOf(operand);
17959 const target = sema.mod.getTarget();
1796017959
17961 switch (operand_ty.zigTypeTag()) {17960 switch (operand_ty.zigTypeTag()) {
17962 .ComptimeFloat, .Float => {},17961 .ComptimeFloat, .Float => {},
...@@ -17983,7 +17982,7 @@ fn zirUnaryMath(...@@ -17983,7 +17982,7 @@ fn zirUnaryMath(
17983 const elems = try sema.arena.alloc(Value, vec_len);17982 const elems = try sema.arena.alloc(Value, vec_len);
17984 for (elems) |*elem, i| {17983 for (elems) |*elem, i| {
17985 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);17984 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
17986 elem.* = try eval(elem_val, scalar_ty, sema.arena, target);17985 elem.* = try eval(elem_val, scalar_ty, sema.arena, sema.mod);
17987 }17986 }
17988 return sema.addConstant(17987 return sema.addConstant(
17989 result_ty,17988 result_ty,
...@@ -17998,7 +17997,7 @@ fn zirUnaryMath(...@@ -17998,7 +17997,7 @@ fn zirUnaryMath(
17998 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {17997 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
17999 if (operand_val.isUndef())17998 if (operand_val.isUndef())
18000 return sema.addConstUndef(operand_ty);17999 return sema.addConstUndef(operand_ty);
18001 const result_val = try eval(operand_val, operand_ty, sema.arena, target);18000 const result_val = try eval(operand_val, operand_ty, sema.arena, sema.mod);
18002 return sema.addConstant(operand_ty, result_val);18001 return sema.addConstant(operand_ty, result_val);
18003 }18002 }
1800418003
...@@ -19220,8 +19219,7 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -19220,8 +19219,7 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
19220 _ = try sema.checkIntType(block, operand_src, operand_ty);19219 _ = try sema.checkIntType(block, operand_src, operand_ty);
1922119220
19222 if (try sema.resolveMaybeUndefVal(operand)) |val| {19221 if (try sema.resolveMaybeUndefVal(operand)) |val| {
19223 const target = sema.mod.getTarget();19222 const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, sema.mod, sema);
19224 const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, target, sema);
19225 return sema.addConstant(dest_ty, result_val);19223 return sema.addConstant(dest_ty, result_val);
19226 } else if (dest_ty.zigTypeTag() == .ComptimeFloat) {19224 } else if (dest_ty.zigTypeTag() == .ComptimeFloat) {
19227 return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known");19225 return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known");
...@@ -19547,14 +19545,14 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -19547,14 +19545,14 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
19547 if (!is_vector) {19545 if (!is_vector) {
19548 return sema.addConstant(19546 return sema.addConstant(
19549 dest_ty,19547 dest_ty,
19550 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, target),19548 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod),
19551 );19549 );
19552 }19550 }
19553 var elem_buf: Value.ElemValueBuffer = undefined;19551 var elem_buf: Value.ElemValueBuffer = undefined;
19554 const elems = try sema.arena.alloc(Value, operand_ty.vectorLen());19552 const elems = try sema.arena.alloc(Value, operand_ty.vectorLen());
19555 for (elems) |*elem, i| {19553 for (elems) |*elem, i| {
19556 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);19554 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
19557 elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, target);19555 elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod);
19558 }19556 }
19559 return sema.addConstant(19557 return sema.addConstant(
19560 dest_ty,19558 dest_ty,
...@@ -20523,13 +20521,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -20523,13 +20521,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
20523 while (i < vec_len) : (i += 1) {20521 while (i < vec_len) : (i += 1) {
20524 const elem_val = operand_val.elemValueBuffer(sema.mod, i, &elem_buf);20522 const elem_val = operand_val.elemValueBuffer(sema.mod, i, &elem_buf);
20525 switch (operation) {20523 switch (operation) {
20526 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, target),20524 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, sema.mod),
20527 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, target),20525 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, sema.mod),
20528 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, target),20526 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, sema.mod),
20529 .Min => accum = accum.numberMin(elem_val, target),20527 .Min => accum = accum.numberMin(elem_val, target),
20530 .Max => accum = accum.numberMax(elem_val, target),20528 .Max => accum = accum.numberMax(elem_val, target),
20531 .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty),20529 .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty),
20532 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, target),20530 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, sema.mod),
20533 }20531 }
20534 }20532 }
20535 return sema.addConstant(scalar_ty, accum);20533 return sema.addConstant(scalar_ty, accum);
...@@ -20925,10 +20923,10 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -20925,10 +20923,10 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
20925 .Xchg => operand_val,20923 .Xchg => operand_val,
20926 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),20924 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),
20927 .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty),20925 .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty),
20928 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, target),20926 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, sema.mod),
20929 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, target),20927 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, sema.mod),
20930 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, target),20928 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, sema.mod),
20931 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, target),20929 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, sema.mod),
20932 .Max => stored_val.numberMax (operand_val, target),20930 .Max => stored_val.numberMax (operand_val, target),
20933 .Min => stored_val.numberMin (operand_val, target),20931 .Min => stored_val.numberMin (operand_val, target),
20934 // zig fmt: on20932 // zig fmt: on
...@@ -21001,8 +20999,6 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -21001,8 +20999,6 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
21001 const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src);20999 const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src);
21002 const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src);21000 const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src);
2100321001
21004 const target = sema.mod.getTarget();
21005
21006 const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1);21002 const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1);
21007 const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2);21003 const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2);
21008 const maybe_addend = try sema.resolveMaybeUndefVal(addend);21004 const maybe_addend = try sema.resolveMaybeUndefVal(addend);
...@@ -21018,7 +21014,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -21018,7 +21014,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2101821014
21019 if (maybe_addend) |addend_val| {21015 if (maybe_addend) |addend_val| {
21020 if (addend_val.isUndef()) return sema.addConstUndef(ty);21016 if (addend_val.isUndef()) return sema.addConstUndef(ty);
21021 const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, target);21017 const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, sema.mod);
21022 return sema.addConstant(ty, result_val);21018 return sema.addConstant(ty, result_val);
21023 } else {21019 } else {
21024 break :rs addend_src;21020 break :rs addend_src;
...@@ -24830,7 +24826,7 @@ fn coerceExtra(...@@ -24830,7 +24826,7 @@ fn coerceExtra(
24830 }24826 }
24831 break :int;24827 break :int;
24832 };24828 };
24833 const result_val = try val.intToFloatAdvanced(sema.arena, inst_ty, dest_ty, target, sema);24829 const result_val = try val.intToFloatAdvanced(sema.arena, inst_ty, dest_ty, sema.mod, sema);
24834 // TODO implement this compile error24830 // TODO implement this compile error
24835 //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty);24831 //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty);
24836 //if (!int_again_val.eql(val, inst_ty, mod)) {24832 //if (!int_again_val.eql(val, inst_ty, mod)) {
...@@ -32263,7 +32259,11 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {...@@ -32263,7 +32259,11 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
32263 if (ty.zigTypeTag() == .Vector) {32259 if (ty.zigTypeTag() == .Vector) {
32264 const result_data = try sema.arena.alloc(Value, ty.vectorLen());32260 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
32265 for (result_data) |*scalar, i| {32261 for (result_data) |*scalar, i| {
32266 scalar.* = try sema.intAddScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));32262 var lhs_buf: Value.ElemValueBuffer = undefined;
32263 var rhs_buf: Value.ElemValueBuffer = undefined;
32264 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32265 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32266 scalar.* = try sema.intAddScalar(lhs_elem, rhs_elem);
32267 }32267 }
32268 return Value.Tag.aggregate.create(sema.arena, result_data);32268 return Value.Tag.aggregate.create(sema.arena, result_data);
32269 }32269 }
...@@ -32297,7 +32297,11 @@ fn numberAddWrap(...@@ -32297,7 +32297,11 @@ fn numberAddWrap(
32297 if (ty.zigTypeTag() == .Vector) {32297 if (ty.zigTypeTag() == .Vector) {
32298 const result_data = try sema.arena.alloc(Value, ty.vectorLen());32298 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
32299 for (result_data) |*scalar, i| {32299 for (result_data) |*scalar, i| {
32300 scalar.* = try sema.numberAddWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());32300 var lhs_buf: Value.ElemValueBuffer = undefined;
32301 var rhs_buf: Value.ElemValueBuffer = undefined;
32302 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32303 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32304 scalar.* = try sema.numberAddWrapScalar(lhs_elem, rhs_elem, ty.scalarType());
32301 }32305 }
32302 return Value.Tag.aggregate.create(sema.arena, result_data);32306 return Value.Tag.aggregate.create(sema.arena, result_data);
32303 }32307 }
...@@ -32334,7 +32338,11 @@ fn intSub(...@@ -32334,7 +32338,11 @@ fn intSub(
32334 if (ty.zigTypeTag() == .Vector) {32338 if (ty.zigTypeTag() == .Vector) {
32335 const result_data = try sema.arena.alloc(Value, ty.vectorLen());32339 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
32336 for (result_data) |*scalar, i| {32340 for (result_data) |*scalar, i| {
32337 scalar.* = try sema.intSubScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));32341 var lhs_buf: Value.ElemValueBuffer = undefined;
32342 var rhs_buf: Value.ElemValueBuffer = undefined;
32343 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32344 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32345 scalar.* = try sema.intSubScalar(lhs_elem, rhs_elem);
32338 }32346 }
32339 return Value.Tag.aggregate.create(sema.arena, result_data);32347 return Value.Tag.aggregate.create(sema.arena, result_data);
32340 }32348 }
...@@ -32368,7 +32376,11 @@ fn numberSubWrap(...@@ -32368,7 +32376,11 @@ fn numberSubWrap(
32368 if (ty.zigTypeTag() == .Vector) {32376 if (ty.zigTypeTag() == .Vector) {
32369 const result_data = try sema.arena.alloc(Value, ty.vectorLen());32377 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
32370 for (result_data) |*scalar, i| {32378 for (result_data) |*scalar, i| {
32371 scalar.* = try sema.numberSubWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());32379 var lhs_buf: Value.ElemValueBuffer = undefined;
32380 var rhs_buf: Value.ElemValueBuffer = undefined;
32381 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32382 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32383 scalar.* = try sema.numberSubWrapScalar(lhs_elem, rhs_elem, ty.scalarType());
32372 }32384 }
32373 return Value.Tag.aggregate.create(sema.arena, result_data);32385 return Value.Tag.aggregate.create(sema.arena, result_data);
32374 }32386 }
...@@ -32405,7 +32417,11 @@ fn floatAdd(...@@ -32405,7 +32417,11 @@ fn floatAdd(
32405 if (float_type.zigTypeTag() == .Vector) {32417 if (float_type.zigTypeTag() == .Vector) {
32406 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());32418 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());
32407 for (result_data) |*scalar, i| {32419 for (result_data) |*scalar, i| {
32408 scalar.* = try sema.floatAddScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType());32420 var lhs_buf: Value.ElemValueBuffer = undefined;
32421 var rhs_buf: Value.ElemValueBuffer = undefined;
32422 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32423 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32424 scalar.* = try sema.floatAddScalar(lhs_elem, rhs_elem, float_type.scalarType());
32409 }32425 }
32410 return Value.Tag.aggregate.create(sema.arena, result_data);32426 return Value.Tag.aggregate.create(sema.arena, result_data);
32411 }32427 }
...@@ -32458,7 +32474,11 @@ fn floatSub(...@@ -32458,7 +32474,11 @@ fn floatSub(
32458 if (float_type.zigTypeTag() == .Vector) {32474 if (float_type.zigTypeTag() == .Vector) {
32459 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());32475 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());
32460 for (result_data) |*scalar, i| {32476 for (result_data) |*scalar, i| {
32461 scalar.* = try sema.floatSubScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType());32477 var lhs_buf: Value.ElemValueBuffer = undefined;
32478 var rhs_buf: Value.ElemValueBuffer = undefined;
32479 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32480 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32481 scalar.* = try sema.floatSubScalar(lhs_elem, rhs_elem, float_type.scalarType());
32462 }32482 }
32463 return Value.Tag.aggregate.create(sema.arena, result_data);32483 return Value.Tag.aggregate.create(sema.arena, result_data);
32464 }32484 }
...@@ -32512,7 +32532,11 @@ fn intSubWithOverflow(...@@ -32512,7 +32532,11 @@ fn intSubWithOverflow(
32512 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());32532 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
32513 const result_data = try sema.arena.alloc(Value, ty.vectorLen());32533 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
32514 for (result_data) |*scalar, i| {32534 for (result_data) |*scalar, i| {
32515 const of_math_result = try sema.intSubWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());32535 var lhs_buf: Value.ElemValueBuffer = undefined;
32536 var rhs_buf: Value.ElemValueBuffer = undefined;
32537 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32538 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32539 const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType());
32516 overflowed_data[i] = of_math_result.overflowed;32540 overflowed_data[i] = of_math_result.overflowed;
32517 scalar.* = of_math_result.wrapped_result;32541 scalar.* = of_math_result.wrapped_result;
32518 }32542 }
...@@ -32562,7 +32586,9 @@ fn floatToInt(...@@ -32562,7 +32586,9 @@ fn floatToInt(
32562 const elem_ty = float_ty.childType();32586 const elem_ty = float_ty.childType();
32563 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen());32587 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen());
32564 for (result_data) |*scalar, i| {32588 for (result_data) |*scalar, i| {
32565 scalar.* = try sema.floatToIntScalar(block, src, val.indexVectorlike(i), elem_ty, int_ty.scalarType());32589 var buf: Value.ElemValueBuffer = undefined;
32590 const elem_val = val.elemValueBuffer(sema.mod, i, &buf);
32591 scalar.* = try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType());
32566 }32592 }
32567 return Value.Tag.aggregate.create(sema.arena, result_data);32593 return Value.Tag.aggregate.create(sema.arena, result_data);
32568 }32594 }
...@@ -32857,7 +32883,11 @@ fn intAddWithOverflow(...@@ -32857,7 +32883,11 @@ fn intAddWithOverflow(
32857 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());32883 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
32858 const result_data = try sema.arena.alloc(Value, ty.vectorLen());32884 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
32859 for (result_data) |*scalar, i| {32885 for (result_data) |*scalar, i| {
32860 const of_math_result = try sema.intAddWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());32886 var lhs_buf: Value.ElemValueBuffer = undefined;
32887 var rhs_buf: Value.ElemValueBuffer = undefined;
32888 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32889 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32890 const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType());
32861 overflowed_data[i] = of_math_result.overflowed;32891 overflowed_data[i] = of_math_result.overflowed;
32862 scalar.* = of_math_result.wrapped_result;32892 scalar.* = of_math_result.wrapped_result;
32863 }32893 }
...@@ -32909,7 +32939,11 @@ fn compareAll(...@@ -32909,7 +32939,11 @@ fn compareAll(
32909 if (ty.zigTypeTag() == .Vector) {32939 if (ty.zigTypeTag() == .Vector) {
32910 var i: usize = 0;32940 var i: usize = 0;
32911 while (i < ty.vectorLen()) : (i += 1) {32941 while (i < ty.vectorLen()) : (i += 1) {
32912 if (!(try sema.compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType()))) {32942 var lhs_buf: Value.ElemValueBuffer = undefined;
32943 var rhs_buf: Value.ElemValueBuffer = undefined;
32944 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32945 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32946 if (!(try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType()))) {
32913 return false;32947 return false;
32914 }32948 }
32915 }32949 }
...@@ -32953,7 +32987,11 @@ fn compareVector(...@@ -32953,7 +32987,11 @@ fn compareVector(
32953 assert(ty.zigTypeTag() == .Vector);32987 assert(ty.zigTypeTag() == .Vector);
32954 const result_data = try sema.arena.alloc(Value, ty.vectorLen());32988 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
32955 for (result_data) |*scalar, i| {32989 for (result_data) |*scalar, i| {
32956 const res_bool = try sema.compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType());32990 var lhs_buf: Value.ElemValueBuffer = undefined;
32991 var rhs_buf: Value.ElemValueBuffer = undefined;
32992 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32993 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32994 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType());
32957 scalar.* = Value.makeBool(res_bool);32995 scalar.* = Value.makeBool(res_bool);
32958 }32996 }
32959 return Value.Tag.aggregate.create(sema.arena, result_data);32997 return Value.Tag.aggregate.create(sema.arena, result_data);
src/value.zig+305-136
...@@ -2044,7 +2044,11 @@ pub const Value = extern union {...@@ -2044,7 +2044,11 @@ pub const Value = extern union {
2044 if (ty.zigTypeTag() == .Vector) {2044 if (ty.zigTypeTag() == .Vector) {
2045 var i: usize = 0;2045 var i: usize = 0;
2046 while (i < ty.vectorLen()) : (i += 1) {2046 while (i < ty.vectorLen()) : (i += 1) {
2047 if (!compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType(), mod)) {2047 var lhs_buf: Value.ElemValueBuffer = undefined;
2048 var rhs_buf: Value.ElemValueBuffer = undefined;
2049 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
2050 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
2051 if (!compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(), mod)) {
2048 return false;2052 return false;
2049 }2053 }
2050 }2054 }
...@@ -2793,27 +2797,6 @@ pub const Value = extern union {...@@ -2793,27 +2797,6 @@ pub const Value = extern union {
2793 };2797 };
2794 }2798 }
27952799
2796 /// Index into a vector-like `Value`. Asserts `index` is a valid index for `val`.
2797 /// Some scalar values are considered vector-like to avoid needing to allocate
2798 /// a new `repeated` each time a constant is used.
2799 pub fn indexVectorlike(val: Value, index: usize) Value {
2800 return switch (val.tag()) {
2801 .aggregate => val.castTag(.aggregate).?.data[index],
2802
2803 .repeated => val.castTag(.repeated).?.data,
2804 // These values will implicitly be treated as `repeated`.
2805 .zero,
2806 .one,
2807 .bool_false,
2808 .bool_true,
2809 .int_i64,
2810 .int_u64,
2811 => val,
2812
2813 else => unreachable,
2814 };
2815 }
2816
2817 /// Asserts the value is a single-item pointer to an array, or an array,2800 /// Asserts the value is a single-item pointer to an array, or an array,
2818 /// or an unknown-length pointer, and returns the element value at the index.2801 /// or an unknown-length pointer, and returns the element value at the index.
2819 pub fn elemValue(val: Value, mod: *Module, arena: Allocator, index: usize) !Value {2802 pub fn elemValue(val: Value, mod: *Module, arena: Allocator, index: usize) !Value {
...@@ -2889,18 +2872,21 @@ pub const Value = extern union {...@@ -2889,18 +2872,21 @@ pub const Value = extern union {
2889 // to have only one possible value itself.2872 // to have only one possible value itself.
2890 .the_only_possible_value => return val,2873 .the_only_possible_value => return val,
28912874
2892 // pointer to integer casted to pointer of array
2893 .int_u64, .int_i64 => {
2894 assert(index == 0);
2895 return val;
2896 },
2897
2898 .opt_payload_ptr => return val.castTag(.opt_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),2875 .opt_payload_ptr => return val.castTag(.opt_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),
2899 .eu_payload_ptr => return val.castTag(.eu_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),2876 .eu_payload_ptr => return val.castTag(.eu_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),
29002877
2901 .opt_payload => return val.castTag(.opt_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),2878 .opt_payload => return val.castTag(.opt_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),
2902 .eu_payload => return val.castTag(.eu_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),2879 .eu_payload => return val.castTag(.eu_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),
29032880
2881 // These values will implicitly be treated as `repeated`.
2882 .zero,
2883 .one,
2884 .bool_false,
2885 .bool_true,
2886 .int_i64,
2887 .int_u64,
2888 => return val,
2889
2904 else => unreachable,2890 else => unreachable,
2905 }2891 }
2906 }2892 }
...@@ -3172,18 +3158,21 @@ pub const Value = extern union {...@@ -3172,18 +3158,21 @@ pub const Value = extern union {
3172 };3158 };
3173 }3159 }
31743160
3175 pub fn intToFloat(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, target: Target) !Value {3161 pub fn intToFloat(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module) !Value {
3176 return intToFloatAdvanced(val, arena, int_ty, float_ty, target, null) catch |err| switch (err) {3162 return intToFloatAdvanced(val, arena, int_ty, float_ty, mod, null) catch |err| switch (err) {
3177 error.OutOfMemory => return error.OutOfMemory,3163 error.OutOfMemory => return error.OutOfMemory,
3178 else => unreachable,3164 else => unreachable,
3179 };3165 };
3180 }3166 }
31813167
3182 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, target: Target, opt_sema: ?*Sema) !Value {3168 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
3169 const target = mod.getTarget();
3183 if (int_ty.zigTypeTag() == .Vector) {3170 if (int_ty.zigTypeTag() == .Vector) {
3184 const result_data = try arena.alloc(Value, int_ty.vectorLen());3171 const result_data = try arena.alloc(Value, int_ty.vectorLen());
3185 for (result_data) |*scalar, i| {3172 for (result_data) |*scalar, i| {
3186 scalar.* = try intToFloatScalar(val.indexVectorlike(i), arena, float_ty.scalarType(), target, opt_sema);3173 var buf: Value.ElemValueBuffer = undefined;
3174 const elem_val = val.elemValueBuffer(mod, i, &buf);
3175 scalar.* = try intToFloatScalar(elem_val, arena, float_ty.scalarType(), target, opt_sema);
3187 }3176 }
3188 return Value.Tag.aggregate.create(arena, result_data);3177 return Value.Tag.aggregate.create(arena, result_data);
3189 }3178 }
...@@ -3289,12 +3278,17 @@ pub const Value = extern union {...@@ -3289,12 +3278,17 @@ pub const Value = extern union {
3289 rhs: Value,3278 rhs: Value,
3290 ty: Type,3279 ty: Type,
3291 arena: Allocator,3280 arena: Allocator,
3292 target: Target,3281 mod: *Module,
3293 ) !Value {3282 ) !Value {
3283 const target = mod.getTarget();
3294 if (ty.zigTypeTag() == .Vector) {3284 if (ty.zigTypeTag() == .Vector) {
3295 const result_data = try arena.alloc(Value, ty.vectorLen());3285 const result_data = try arena.alloc(Value, ty.vectorLen());
3296 for (result_data) |*scalar, i| {3286 for (result_data) |*scalar, i| {
3297 scalar.* = try intAddSatScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);3287 var lhs_buf: Value.ElemValueBuffer = undefined;
3288 var rhs_buf: Value.ElemValueBuffer = undefined;
3289 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3290 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3291 scalar.* = try intAddSatScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
3298 }3292 }
3299 return Value.Tag.aggregate.create(arena, result_data);3293 return Value.Tag.aggregate.create(arena, result_data);
3300 }3294 }
...@@ -3333,12 +3327,17 @@ pub const Value = extern union {...@@ -3333,12 +3327,17 @@ pub const Value = extern union {
3333 rhs: Value,3327 rhs: Value,
3334 ty: Type,3328 ty: Type,
3335 arena: Allocator,3329 arena: Allocator,
3336 target: Target,3330 mod: *Module,
3337 ) !Value {3331 ) !Value {
3332 const target = mod.getTarget();
3338 if (ty.zigTypeTag() == .Vector) {3333 if (ty.zigTypeTag() == .Vector) {
3339 const result_data = try arena.alloc(Value, ty.vectorLen());3334 const result_data = try arena.alloc(Value, ty.vectorLen());
3340 for (result_data) |*scalar, i| {3335 for (result_data) |*scalar, i| {
3341 scalar.* = try intSubSatScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);3336 var lhs_buf: Value.ElemValueBuffer = undefined;
3337 var rhs_buf: Value.ElemValueBuffer = undefined;
3338 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3339 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3340 scalar.* = try intSubSatScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
3342 }3341 }
3343 return Value.Tag.aggregate.create(arena, result_data);3342 return Value.Tag.aggregate.create(arena, result_data);
3344 }3343 }
...@@ -3376,13 +3375,18 @@ pub const Value = extern union {...@@ -3376,13 +3375,18 @@ pub const Value = extern union {
3376 rhs: Value,3375 rhs: Value,
3377 ty: Type,3376 ty: Type,
3378 arena: Allocator,3377 arena: Allocator,
3379 target: Target,3378 mod: *Module,
3380 ) !OverflowArithmeticResult {3379 ) !OverflowArithmeticResult {
3380 const target = mod.getTarget();
3381 if (ty.zigTypeTag() == .Vector) {3381 if (ty.zigTypeTag() == .Vector) {
3382 const overflowed_data = try arena.alloc(Value, ty.vectorLen());3382 const overflowed_data = try arena.alloc(Value, ty.vectorLen());
3383 const result_data = try arena.alloc(Value, ty.vectorLen());3383 const result_data = try arena.alloc(Value, ty.vectorLen());
3384 for (result_data) |*scalar, i| {3384 for (result_data) |*scalar, i| {
3385 const of_math_result = try intMulWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);3385 var lhs_buf: Value.ElemValueBuffer = undefined;
3386 var rhs_buf: Value.ElemValueBuffer = undefined;
3387 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3388 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3389 const of_math_result = try intMulWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
3386 overflowed_data[i] = of_math_result.overflowed;3390 overflowed_data[i] = of_math_result.overflowed;
3387 scalar.* = of_math_result.wrapped_result;3391 scalar.* = of_math_result.wrapped_result;
3388 }3392 }
...@@ -3435,16 +3439,20 @@ pub const Value = extern union {...@@ -3435,16 +3439,20 @@ pub const Value = extern union {
3435 rhs: Value,3439 rhs: Value,
3436 ty: Type,3440 ty: Type,
3437 arena: Allocator,3441 arena: Allocator,
3438 target: Target,3442 mod: *Module,
3439 ) !Value {3443 ) !Value {
3440 if (ty.zigTypeTag() == .Vector) {3444 if (ty.zigTypeTag() == .Vector) {
3441 const result_data = try arena.alloc(Value, ty.vectorLen());3445 const result_data = try arena.alloc(Value, ty.vectorLen());
3442 for (result_data) |*scalar, i| {3446 for (result_data) |*scalar, i| {
3443 scalar.* = try numberMulWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);3447 var lhs_buf: Value.ElemValueBuffer = undefined;
3448 var rhs_buf: Value.ElemValueBuffer = undefined;
3449 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3450 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3451 scalar.* = try numberMulWrapScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, mod);
3444 }3452 }
3445 return Value.Tag.aggregate.create(arena, result_data);3453 return Value.Tag.aggregate.create(arena, result_data);
3446 }3454 }
3447 return numberMulWrapScalar(lhs, rhs, ty, arena, target);3455 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);
3448 }3456 }
34493457
3450 /// Supports both floats and ints; handles undefined.3458 /// Supports both floats and ints; handles undefined.
...@@ -3453,19 +3461,19 @@ pub const Value = extern union {...@@ -3453,19 +3461,19 @@ pub const Value = extern union {
3453 rhs: Value,3461 rhs: Value,
3454 ty: Type,3462 ty: Type,
3455 arena: Allocator,3463 arena: Allocator,
3456 target: Target,3464 mod: *Module,
3457 ) !Value {3465 ) !Value {
3458 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);3466 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);
34593467
3460 if (ty.zigTypeTag() == .ComptimeInt) {3468 if (ty.zigTypeTag() == .ComptimeInt) {
3461 return intMul(lhs, rhs, ty, arena, target);3469 return intMul(lhs, rhs, ty, arena, mod);
3462 }3470 }
34633471
3464 if (ty.isAnyFloat()) {3472 if (ty.isAnyFloat()) {
3465 return floatMul(lhs, rhs, ty, arena, target);3473 return floatMul(lhs, rhs, ty, arena, mod);
3466 }3474 }
34673475
3468 const overflow_result = try intMulWithOverflow(lhs, rhs, ty, arena, target);3476 const overflow_result = try intMulWithOverflow(lhs, rhs, ty, arena, mod);
3469 return overflow_result.wrapped_result;3477 return overflow_result.wrapped_result;
3470 }3478 }
34713479
...@@ -3475,12 +3483,17 @@ pub const Value = extern union {...@@ -3475,12 +3483,17 @@ pub const Value = extern union {
3475 rhs: Value,3483 rhs: Value,
3476 ty: Type,3484 ty: Type,
3477 arena: Allocator,3485 arena: Allocator,
3478 target: Target,3486 mod: *Module,
3479 ) !Value {3487 ) !Value {
3488 const target = mod.getTarget();
3480 if (ty.zigTypeTag() == .Vector) {3489 if (ty.zigTypeTag() == .Vector) {
3481 const result_data = try arena.alloc(Value, ty.vectorLen());3490 const result_data = try arena.alloc(Value, ty.vectorLen());
3482 for (result_data) |*scalar, i| {3491 for (result_data) |*scalar, i| {
3483 scalar.* = try intMulSatScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);3492 var lhs_buf: Value.ElemValueBuffer = undefined;
3493 var rhs_buf: Value.ElemValueBuffer = undefined;
3494 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3495 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3496 scalar.* = try intMulSatScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
3484 }3497 }
3485 return Value.Tag.aggregate.create(arena, result_data);3498 return Value.Tag.aggregate.create(arena, result_data);
3486 }3499 }
...@@ -3547,11 +3560,14 @@ pub const Value = extern union {...@@ -3547,11 +3560,14 @@ pub const Value = extern union {
3547 }3560 }
35483561
3549 /// operands must be (vectors of) integers; handles undefined scalars.3562 /// operands must be (vectors of) integers; handles undefined scalars.
3550 pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, target: Target) !Value {3563 pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
3564 const target = mod.getTarget();
3551 if (ty.zigTypeTag() == .Vector) {3565 if (ty.zigTypeTag() == .Vector) {
3552 const result_data = try arena.alloc(Value, ty.vectorLen());3566 const result_data = try arena.alloc(Value, ty.vectorLen());
3553 for (result_data) |*scalar, i| {3567 for (result_data) |*scalar, i| {
3554 scalar.* = try bitwiseNotScalar(val.indexVectorlike(i), ty.scalarType(), arena, target);3568 var buf: Value.ElemValueBuffer = undefined;
3569 const elem_val = val.elemValueBuffer(mod, i, &buf);
3570 scalar.* = try bitwiseNotScalar(elem_val, ty.scalarType(), arena, target);
3555 }3571 }
3556 return Value.Tag.aggregate.create(arena, result_data);3572 return Value.Tag.aggregate.create(arena, result_data);
3557 }3573 }
...@@ -3583,11 +3599,16 @@ pub const Value = extern union {...@@ -3583,11 +3599,16 @@ pub const Value = extern union {
3583 }3599 }
35843600
3585 /// operands must be (vectors of) integers; handles undefined scalars.3601 /// operands must be (vectors of) integers; handles undefined scalars.
3586 pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {3602 pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3603 const target = mod.getTarget();
3587 if (ty.zigTypeTag() == .Vector) {3604 if (ty.zigTypeTag() == .Vector) {
3588 const result_data = try allocator.alloc(Value, ty.vectorLen());3605 const result_data = try allocator.alloc(Value, ty.vectorLen());
3589 for (result_data) |*scalar, i| {3606 for (result_data) |*scalar, i| {
3590 scalar.* = try bitwiseAndScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);3607 var lhs_buf: Value.ElemValueBuffer = undefined;
3608 var rhs_buf: Value.ElemValueBuffer = undefined;
3609 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3610 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3611 scalar.* = try bitwiseAndScalar(lhs_elem, rhs_elem, allocator, target);
3591 }3612 }
3592 return Value.Tag.aggregate.create(allocator, result_data);3613 return Value.Tag.aggregate.create(allocator, result_data);
3593 }3614 }
...@@ -3615,37 +3636,46 @@ pub const Value = extern union {...@@ -3615,37 +3636,46 @@ pub const Value = extern union {
3615 }3636 }
36163637
3617 /// operands must be (vectors of) integers; handles undefined scalars.3638 /// operands must be (vectors of) integers; handles undefined scalars.
3618 pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, target: Target) !Value {3639 pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
3619 if (ty.zigTypeTag() == .Vector) {3640 if (ty.zigTypeTag() == .Vector) {
3620 const result_data = try arena.alloc(Value, ty.vectorLen());3641 const result_data = try arena.alloc(Value, ty.vectorLen());
3621 for (result_data) |*scalar, i| {3642 for (result_data) |*scalar, i| {
3622 scalar.* = try bitwiseNandScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);3643 var lhs_buf: Value.ElemValueBuffer = undefined;
3644 var rhs_buf: Value.ElemValueBuffer = undefined;
3645 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3646 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3647 scalar.* = try bitwiseNandScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, mod);
3623 }3648 }
3624 return Value.Tag.aggregate.create(arena, result_data);3649 return Value.Tag.aggregate.create(arena, result_data);
3625 }3650 }
3626 return bitwiseNandScalar(lhs, rhs, ty, arena, target);3651 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);
3627 }3652 }
36283653
3629 /// operands must be integers; handles undefined.3654 /// operands must be integers; handles undefined.
3630 pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, target: Target) !Value {3655 pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
3631 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);3656 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);
36323657
3633 const anded = try bitwiseAnd(lhs, rhs, ty, arena, target);3658 const anded = try bitwiseAnd(lhs, rhs, ty, arena, mod);
36343659
3635 const all_ones = if (ty.isSignedInt())3660 const all_ones = if (ty.isSignedInt())
3636 try Value.Tag.int_i64.create(arena, -1)3661 try Value.Tag.int_i64.create(arena, -1)
3637 else3662 else
3638 try ty.maxInt(arena, target);3663 try ty.maxInt(arena, mod.getTarget());
36393664
3640 return bitwiseXor(anded, all_ones, ty, arena, target);3665 return bitwiseXor(anded, all_ones, ty, arena, mod);
3641 }3666 }
36423667
3643 /// operands must be (vectors of) integers; handles undefined scalars.3668 /// operands must be (vectors of) integers; handles undefined scalars.
3644 pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {3669 pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3670 const target = mod.getTarget();
3645 if (ty.zigTypeTag() == .Vector) {3671 if (ty.zigTypeTag() == .Vector) {
3646 const result_data = try allocator.alloc(Value, ty.vectorLen());3672 const result_data = try allocator.alloc(Value, ty.vectorLen());
3647 for (result_data) |*scalar, i| {3673 for (result_data) |*scalar, i| {
3648 scalar.* = try bitwiseOrScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);3674 var lhs_buf: Value.ElemValueBuffer = undefined;
3675 var rhs_buf: Value.ElemValueBuffer = undefined;
3676 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3677 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3678 scalar.* = try bitwiseOrScalar(lhs_elem, rhs_elem, allocator, target);
3649 }3679 }
3650 return Value.Tag.aggregate.create(allocator, result_data);3680 return Value.Tag.aggregate.create(allocator, result_data);
3651 }3681 }
...@@ -3672,11 +3702,16 @@ pub const Value = extern union {...@@ -3672,11 +3702,16 @@ pub const Value = extern union {
3672 }3702 }
36733703
3674 /// operands must be (vectors of) integers; handles undefined scalars.3704 /// operands must be (vectors of) integers; handles undefined scalars.
3675 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {3705 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3706 const target = mod.getTarget();
3676 if (ty.zigTypeTag() == .Vector) {3707 if (ty.zigTypeTag() == .Vector) {
3677 const result_data = try allocator.alloc(Value, ty.vectorLen());3708 const result_data = try allocator.alloc(Value, ty.vectorLen());
3678 for (result_data) |*scalar, i| {3709 for (result_data) |*scalar, i| {
3679 scalar.* = try bitwiseXorScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);3710 var lhs_buf: Value.ElemValueBuffer = undefined;
3711 var rhs_buf: Value.ElemValueBuffer = undefined;
3712 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3713 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3714 scalar.* = try bitwiseXorScalar(lhs_elem, rhs_elem, allocator, target);
3680 }3715 }
3681 return Value.Tag.aggregate.create(allocator, result_data);3716 return Value.Tag.aggregate.create(allocator, result_data);
3682 }3717 }
...@@ -3703,11 +3738,16 @@ pub const Value = extern union {...@@ -3703,11 +3738,16 @@ pub const Value = extern union {
3703 return fromBigInt(arena, result_bigint.toConst());3738 return fromBigInt(arena, result_bigint.toConst());
3704 }3739 }
37053740
3706 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {3741 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3742 const target = mod.getTarget();
3707 if (ty.zigTypeTag() == .Vector) {3743 if (ty.zigTypeTag() == .Vector) {
3708 const result_data = try allocator.alloc(Value, ty.vectorLen());3744 const result_data = try allocator.alloc(Value, ty.vectorLen());
3709 for (result_data) |*scalar, i| {3745 for (result_data) |*scalar, i| {
3710 scalar.* = try intDivScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);3746 var lhs_buf: Value.ElemValueBuffer = undefined;
3747 var rhs_buf: Value.ElemValueBuffer = undefined;
3748 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3749 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3750 scalar.* = try intDivScalar(lhs_elem, rhs_elem, allocator, target);
3711 }3751 }
3712 return Value.Tag.aggregate.create(allocator, result_data);3752 return Value.Tag.aggregate.create(allocator, result_data);
3713 }3753 }
...@@ -3739,11 +3779,16 @@ pub const Value = extern union {...@@ -3739,11 +3779,16 @@ pub const Value = extern union {
3739 return fromBigInt(allocator, result_q.toConst());3779 return fromBigInt(allocator, result_q.toConst());
3740 }3780 }
37413781
3742 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {3782 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3783 const target = mod.getTarget();
3743 if (ty.zigTypeTag() == .Vector) {3784 if (ty.zigTypeTag() == .Vector) {
3744 const result_data = try allocator.alloc(Value, ty.vectorLen());3785 const result_data = try allocator.alloc(Value, ty.vectorLen());
3745 for (result_data) |*scalar, i| {3786 for (result_data) |*scalar, i| {
3746 scalar.* = try intDivFloorScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);3787 var lhs_buf: Value.ElemValueBuffer = undefined;
3788 var rhs_buf: Value.ElemValueBuffer = undefined;
3789 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3790 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3791 scalar.* = try intDivFloorScalar(lhs_elem, rhs_elem, allocator, target);
3747 }3792 }
3748 return Value.Tag.aggregate.create(allocator, result_data);3793 return Value.Tag.aggregate.create(allocator, result_data);
3749 }3794 }
...@@ -3775,11 +3820,16 @@ pub const Value = extern union {...@@ -3775,11 +3820,16 @@ pub const Value = extern union {
3775 return fromBigInt(allocator, result_q.toConst());3820 return fromBigInt(allocator, result_q.toConst());
3776 }3821 }
37773822
3778 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {3823 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3824 const target = mod.getTarget();
3779 if (ty.zigTypeTag() == .Vector) {3825 if (ty.zigTypeTag() == .Vector) {
3780 const result_data = try allocator.alloc(Value, ty.vectorLen());3826 const result_data = try allocator.alloc(Value, ty.vectorLen());
3781 for (result_data) |*scalar, i| {3827 for (result_data) |*scalar, i| {
3782 scalar.* = try intModScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);3828 var lhs_buf: Value.ElemValueBuffer = undefined;
3829 var rhs_buf: Value.ElemValueBuffer = undefined;
3830 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3831 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3832 scalar.* = try intModScalar(lhs_elem, rhs_elem, allocator, target);
3783 }3833 }
3784 return Value.Tag.aggregate.create(allocator, result_data);3834 return Value.Tag.aggregate.create(allocator, result_data);
3785 }3835 }
...@@ -3846,11 +3896,16 @@ pub const Value = extern union {...@@ -3846,11 +3896,16 @@ pub const Value = extern union {
3846 };3896 };
3847 }3897 }
38483898
3849 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value {3899 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3900 const target = mod.getTarget();
3850 if (float_type.zigTypeTag() == .Vector) {3901 if (float_type.zigTypeTag() == .Vector) {
3851 const result_data = try arena.alloc(Value, float_type.vectorLen());3902 const result_data = try arena.alloc(Value, float_type.vectorLen());
3852 for (result_data) |*scalar, i| {3903 for (result_data) |*scalar, i| {
3853 scalar.* = try floatRemScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);3904 var lhs_buf: Value.ElemValueBuffer = undefined;
3905 var rhs_buf: Value.ElemValueBuffer = undefined;
3906 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3907 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3908 scalar.* = try floatRemScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
3854 }3909 }
3855 return Value.Tag.aggregate.create(arena, result_data);3910 return Value.Tag.aggregate.create(arena, result_data);
3856 }3911 }
...@@ -3888,11 +3943,16 @@ pub const Value = extern union {...@@ -3888,11 +3943,16 @@ pub const Value = extern union {
3888 }3943 }
3889 }3944 }
38903945
3891 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value {3946 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3947 const target = mod.getTarget();
3892 if (float_type.zigTypeTag() == .Vector) {3948 if (float_type.zigTypeTag() == .Vector) {
3893 const result_data = try arena.alloc(Value, float_type.vectorLen());3949 const result_data = try arena.alloc(Value, float_type.vectorLen());
3894 for (result_data) |*scalar, i| {3950 for (result_data) |*scalar, i| {
3895 scalar.* = try floatModScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);3951 var lhs_buf: Value.ElemValueBuffer = undefined;
3952 var rhs_buf: Value.ElemValueBuffer = undefined;
3953 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3954 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3955 scalar.* = try floatModScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
3896 }3956 }
3897 return Value.Tag.aggregate.create(arena, result_data);3957 return Value.Tag.aggregate.create(arena, result_data);
3898 }3958 }
...@@ -3930,11 +3990,16 @@ pub const Value = extern union {...@@ -3930,11 +3990,16 @@ pub const Value = extern union {
3930 }3990 }
3931 }3991 }
39323992
3933 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {3993 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3994 const target = mod.getTarget();
3934 if (ty.zigTypeTag() == .Vector) {3995 if (ty.zigTypeTag() == .Vector) {
3935 const result_data = try allocator.alloc(Value, ty.vectorLen());3996 const result_data = try allocator.alloc(Value, ty.vectorLen());
3936 for (result_data) |*scalar, i| {3997 for (result_data) |*scalar, i| {
3937 scalar.* = try intMulScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);3998 var lhs_buf: Value.ElemValueBuffer = undefined;
3999 var rhs_buf: Value.ElemValueBuffer = undefined;
4000 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4001 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4002 scalar.* = try intMulScalar(lhs_elem, rhs_elem, allocator, target);
3938 }4003 }
3939 return Value.Tag.aggregate.create(allocator, result_data);4004 return Value.Tag.aggregate.create(allocator, result_data);
3940 }4005 }
...@@ -3962,11 +4027,14 @@ pub const Value = extern union {...@@ -3962,11 +4027,14 @@ pub const Value = extern union {
3962 return fromBigInt(allocator, result_bigint.toConst());4027 return fromBigInt(allocator, result_bigint.toConst());
3963 }4028 }
39644029
3965 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, target: Target) !Value {4030 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, mod: *Module) !Value {
4031 const target = mod.getTarget();
3966 if (ty.zigTypeTag() == .Vector) {4032 if (ty.zigTypeTag() == .Vector) {
3967 const result_data = try allocator.alloc(Value, ty.vectorLen());4033 const result_data = try allocator.alloc(Value, ty.vectorLen());
3968 for (result_data) |*scalar, i| {4034 for (result_data) |*scalar, i| {
3969 scalar.* = try intTruncScalar(val.indexVectorlike(i), allocator, signedness, bits, target);4035 var buf: Value.ElemValueBuffer = undefined;
4036 const elem_val = val.elemValueBuffer(mod, i, &buf);
4037 scalar.* = try intTruncScalar(elem_val, allocator, signedness, bits, target);
3970 }4038 }
3971 return Value.Tag.aggregate.create(allocator, result_data);4039 return Value.Tag.aggregate.create(allocator, result_data);
3972 }4040 }
...@@ -3980,12 +4048,17 @@ pub const Value = extern union {...@@ -3980,12 +4048,17 @@ pub const Value = extern union {
3980 allocator: Allocator,4048 allocator: Allocator,
3981 signedness: std.builtin.Signedness,4049 signedness: std.builtin.Signedness,
3982 bits: Value,4050 bits: Value,
3983 target: Target,4051 mod: *Module,
3984 ) !Value {4052 ) !Value {
4053 const target = mod.getTarget();
3985 if (ty.zigTypeTag() == .Vector) {4054 if (ty.zigTypeTag() == .Vector) {
3986 const result_data = try allocator.alloc(Value, ty.vectorLen());4055 const result_data = try allocator.alloc(Value, ty.vectorLen());
3987 for (result_data) |*scalar, i| {4056 for (result_data) |*scalar, i| {
3988 scalar.* = try intTruncScalar(val.indexVectorlike(i), allocator, signedness, @intCast(u16, bits.indexVectorlike(i).toUnsignedInt(target)), target);4057 var buf: Value.ElemValueBuffer = undefined;
4058 const elem_val = val.elemValueBuffer(mod, i, &buf);
4059 var bits_buf: Value.ElemValueBuffer = undefined;
4060 const bits_elem = bits.elemValueBuffer(mod, i, &bits_buf);
4061 scalar.* = try intTruncScalar(elem_val, allocator, signedness, @intCast(u16, bits_elem.toUnsignedInt(target)), target);
3989 }4062 }
3990 return Value.Tag.aggregate.create(allocator, result_data);4063 return Value.Tag.aggregate.create(allocator, result_data);
3991 }4064 }
...@@ -4008,11 +4081,16 @@ pub const Value = extern union {...@@ -4008,11 +4081,16 @@ pub const Value = extern union {
4008 return fromBigInt(allocator, result_bigint.toConst());4081 return fromBigInt(allocator, result_bigint.toConst());
4009 }4082 }
40104083
4011 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {4084 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
4085 const target = mod.getTarget();
4012 if (ty.zigTypeTag() == .Vector) {4086 if (ty.zigTypeTag() == .Vector) {
4013 const result_data = try allocator.alloc(Value, ty.vectorLen());4087 const result_data = try allocator.alloc(Value, ty.vectorLen());
4014 for (result_data) |*scalar, i| {4088 for (result_data) |*scalar, i| {
4015 scalar.* = try shlScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);4089 var lhs_buf: Value.ElemValueBuffer = undefined;
4090 var rhs_buf: Value.ElemValueBuffer = undefined;
4091 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4092 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4093 scalar.* = try shlScalar(lhs_elem, rhs_elem, allocator, target);
4016 }4094 }
4017 return Value.Tag.aggregate.create(allocator, result_data);4095 return Value.Tag.aggregate.create(allocator, result_data);
4018 }4096 }
...@@ -4043,13 +4121,18 @@ pub const Value = extern union {...@@ -4043,13 +4121,18 @@ pub const Value = extern union {
4043 rhs: Value,4121 rhs: Value,
4044 ty: Type,4122 ty: Type,
4045 allocator: Allocator,4123 allocator: Allocator,
4046 target: Target,4124 mod: *Module,
4047 ) !OverflowArithmeticResult {4125 ) !OverflowArithmeticResult {
4126 const target = mod.getTarget();
4048 if (ty.zigTypeTag() == .Vector) {4127 if (ty.zigTypeTag() == .Vector) {
4049 const overflowed_data = try allocator.alloc(Value, ty.vectorLen());4128 const overflowed_data = try allocator.alloc(Value, ty.vectorLen());
4050 const result_data = try allocator.alloc(Value, ty.vectorLen());4129 const result_data = try allocator.alloc(Value, ty.vectorLen());
4051 for (result_data) |*scalar, i| {4130 for (result_data) |*scalar, i| {
4052 const of_math_result = try shlWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), allocator, target);4131 var lhs_buf: Value.ElemValueBuffer = undefined;
4132 var rhs_buf: Value.ElemValueBuffer = undefined;
4133 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4134 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4135 const of_math_result = try shlWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(), allocator, target);
4053 overflowed_data[i] = of_math_result.overflowed;4136 overflowed_data[i] = of_math_result.overflowed;
4054 scalar.* = of_math_result.wrapped_result;4137 scalar.* = of_math_result.wrapped_result;
4055 }4138 }
...@@ -4097,12 +4180,17 @@ pub const Value = extern union {...@@ -4097,12 +4180,17 @@ pub const Value = extern union {
4097 rhs: Value,4180 rhs: Value,
4098 ty: Type,4181 ty: Type,
4099 arena: Allocator,4182 arena: Allocator,
4100 target: Target,4183 mod: *Module,
4101 ) !Value {4184 ) !Value {
4185 const target = mod.getTarget();
4102 if (ty.zigTypeTag() == .Vector) {4186 if (ty.zigTypeTag() == .Vector) {
4103 const result_data = try arena.alloc(Value, ty.vectorLen());4187 const result_data = try arena.alloc(Value, ty.vectorLen());
4104 for (result_data) |*scalar, i| {4188 for (result_data) |*scalar, i| {
4105 scalar.* = try shlSatScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);4189 var lhs_buf: Value.ElemValueBuffer = undefined;
4190 var rhs_buf: Value.ElemValueBuffer = undefined;
4191 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4192 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4193 scalar.* = try shlSatScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
4106 }4194 }
4107 return Value.Tag.aggregate.create(arena, result_data);4195 return Value.Tag.aggregate.create(arena, result_data);
4108 }4196 }
...@@ -4141,16 +4229,20 @@ pub const Value = extern union {...@@ -4141,16 +4229,20 @@ pub const Value = extern union {
4141 rhs: Value,4229 rhs: Value,
4142 ty: Type,4230 ty: Type,
4143 arena: Allocator,4231 arena: Allocator,
4144 target: Target,4232 mod: *Module,
4145 ) !Value {4233 ) !Value {
4146 if (ty.zigTypeTag() == .Vector) {4234 if (ty.zigTypeTag() == .Vector) {
4147 const result_data = try arena.alloc(Value, ty.vectorLen());4235 const result_data = try arena.alloc(Value, ty.vectorLen());
4148 for (result_data) |*scalar, i| {4236 for (result_data) |*scalar, i| {
4149 scalar.* = try shlTruncScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);4237 var lhs_buf: Value.ElemValueBuffer = undefined;
4238 var rhs_buf: Value.ElemValueBuffer = undefined;
4239 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4240 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4241 scalar.* = try shlTruncScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, mod);
4150 }4242 }
4151 return Value.Tag.aggregate.create(arena, result_data);4243 return Value.Tag.aggregate.create(arena, result_data);
4152 }4244 }
4153 return shlTruncScalar(lhs, rhs, ty, arena, target);4245 return shlTruncScalar(lhs, rhs, ty, arena, mod);
4154 }4246 }
41554247
4156 pub fn shlTruncScalar(4248 pub fn shlTruncScalar(
...@@ -4158,19 +4250,24 @@ pub const Value = extern union {...@@ -4158,19 +4250,24 @@ pub const Value = extern union {
4158 rhs: Value,4250 rhs: Value,
4159 ty: Type,4251 ty: Type,
4160 arena: Allocator,4252 arena: Allocator,
4161 target: Target,4253 mod: *Module,
4162 ) !Value {4254 ) !Value {
4163 const shifted = try lhs.shl(rhs, ty, arena, target);4255 const shifted = try lhs.shl(rhs, ty, arena, mod);
4164 const int_info = ty.intInfo(target);4256 const int_info = ty.intInfo(mod.getTarget());
4165 const truncated = try shifted.intTrunc(ty, arena, int_info.signedness, int_info.bits, target);4257 const truncated = try shifted.intTrunc(ty, arena, int_info.signedness, int_info.bits, mod);
4166 return truncated;4258 return truncated;
4167 }4259 }
41684260
4169 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {4261 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
4262 const target = mod.getTarget();
4170 if (ty.zigTypeTag() == .Vector) {4263 if (ty.zigTypeTag() == .Vector) {
4171 const result_data = try allocator.alloc(Value, ty.vectorLen());4264 const result_data = try allocator.alloc(Value, ty.vectorLen());
4172 for (result_data) |*scalar, i| {4265 for (result_data) |*scalar, i| {
4173 scalar.* = try shrScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);4266 var lhs_buf: Value.ElemValueBuffer = undefined;
4267 var rhs_buf: Value.ElemValueBuffer = undefined;
4268 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4269 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4270 scalar.* = try shrScalar(lhs_elem, rhs_elem, allocator, target);
4174 }4271 }
4175 return Value.Tag.aggregate.create(allocator, result_data);4272 return Value.Tag.aggregate.create(allocator, result_data);
4176 }4273 }
...@@ -4212,12 +4309,15 @@ pub const Value = extern union {...@@ -4212,12 +4309,15 @@ pub const Value = extern union {
4212 val: Value,4309 val: Value,
4213 float_type: Type,4310 float_type: Type,
4214 arena: Allocator,4311 arena: Allocator,
4215 target: Target,4312 mod: *Module,
4216 ) !Value {4313 ) !Value {
4314 const target = mod.getTarget();
4217 if (float_type.zigTypeTag() == .Vector) {4315 if (float_type.zigTypeTag() == .Vector) {
4218 const result_data = try arena.alloc(Value, float_type.vectorLen());4316 const result_data = try arena.alloc(Value, float_type.vectorLen());
4219 for (result_data) |*scalar, i| {4317 for (result_data) |*scalar, i| {
4220 scalar.* = try floatNegScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4318 var buf: Value.ElemValueBuffer = undefined;
4319 const elem_val = val.elemValueBuffer(mod, i, &buf);
4320 scalar.* = try floatNegScalar(elem_val, float_type.scalarType(), arena, target);
4221 }4321 }
4222 return Value.Tag.aggregate.create(arena, result_data);4322 return Value.Tag.aggregate.create(arena, result_data);
4223 }4323 }
...@@ -4245,12 +4345,17 @@ pub const Value = extern union {...@@ -4245,12 +4345,17 @@ pub const Value = extern union {
4245 rhs: Value,4345 rhs: Value,
4246 float_type: Type,4346 float_type: Type,
4247 arena: Allocator,4347 arena: Allocator,
4248 target: Target,4348 mod: *Module,
4249 ) !Value {4349 ) !Value {
4350 const target = mod.getTarget();
4250 if (float_type.zigTypeTag() == .Vector) {4351 if (float_type.zigTypeTag() == .Vector) {
4251 const result_data = try arena.alloc(Value, float_type.vectorLen());4352 const result_data = try arena.alloc(Value, float_type.vectorLen());
4252 for (result_data) |*scalar, i| {4353 for (result_data) |*scalar, i| {
4253 scalar.* = try floatDivScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);4354 var lhs_buf: Value.ElemValueBuffer = undefined;
4355 var rhs_buf: Value.ElemValueBuffer = undefined;
4356 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4357 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4358 scalar.* = try floatDivScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
4254 }4359 }
4255 return Value.Tag.aggregate.create(arena, result_data);4360 return Value.Tag.aggregate.create(arena, result_data);
4256 }4361 }
...@@ -4299,12 +4404,17 @@ pub const Value = extern union {...@@ -4299,12 +4404,17 @@ pub const Value = extern union {
4299 rhs: Value,4404 rhs: Value,
4300 float_type: Type,4405 float_type: Type,
4301 arena: Allocator,4406 arena: Allocator,
4302 target: Target,4407 mod: *Module,
4303 ) !Value {4408 ) !Value {
4409 const target = mod.getTarget();
4304 if (float_type.zigTypeTag() == .Vector) {4410 if (float_type.zigTypeTag() == .Vector) {
4305 const result_data = try arena.alloc(Value, float_type.vectorLen());4411 const result_data = try arena.alloc(Value, float_type.vectorLen());
4306 for (result_data) |*scalar, i| {4412 for (result_data) |*scalar, i| {
4307 scalar.* = try floatDivFloorScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);4413 var lhs_buf: Value.ElemValueBuffer = undefined;
4414 var rhs_buf: Value.ElemValueBuffer = undefined;
4415 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4416 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4417 scalar.* = try floatDivFloorScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
4308 }4418 }
4309 return Value.Tag.aggregate.create(arena, result_data);4419 return Value.Tag.aggregate.create(arena, result_data);
4310 }4420 }
...@@ -4353,12 +4463,17 @@ pub const Value = extern union {...@@ -4353,12 +4463,17 @@ pub const Value = extern union {
4353 rhs: Value,4463 rhs: Value,
4354 float_type: Type,4464 float_type: Type,
4355 arena: Allocator,4465 arena: Allocator,
4356 target: Target,4466 mod: *Module,
4357 ) !Value {4467 ) !Value {
4468 const target = mod.getTarget();
4358 if (float_type.zigTypeTag() == .Vector) {4469 if (float_type.zigTypeTag() == .Vector) {
4359 const result_data = try arena.alloc(Value, float_type.vectorLen());4470 const result_data = try arena.alloc(Value, float_type.vectorLen());
4360 for (result_data) |*scalar, i| {4471 for (result_data) |*scalar, i| {
4361 scalar.* = try floatDivTruncScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);4472 var lhs_buf: Value.ElemValueBuffer = undefined;
4473 var rhs_buf: Value.ElemValueBuffer = undefined;
4474 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4475 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4476 scalar.* = try floatDivTruncScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
4362 }4477 }
4363 return Value.Tag.aggregate.create(arena, result_data);4478 return Value.Tag.aggregate.create(arena, result_data);
4364 }4479 }
...@@ -4407,12 +4522,17 @@ pub const Value = extern union {...@@ -4407,12 +4522,17 @@ pub const Value = extern union {
4407 rhs: Value,4522 rhs: Value,
4408 float_type: Type,4523 float_type: Type,
4409 arena: Allocator,4524 arena: Allocator,
4410 target: Target,4525 mod: *Module,
4411 ) !Value {4526 ) !Value {
4527 const target = mod.getTarget();
4412 if (float_type.zigTypeTag() == .Vector) {4528 if (float_type.zigTypeTag() == .Vector) {
4413 const result_data = try arena.alloc(Value, float_type.vectorLen());4529 const result_data = try arena.alloc(Value, float_type.vectorLen());
4414 for (result_data) |*scalar, i| {4530 for (result_data) |*scalar, i| {
4415 scalar.* = try floatMulScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);4531 var lhs_buf: Value.ElemValueBuffer = undefined;
4532 var rhs_buf: Value.ElemValueBuffer = undefined;
4533 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4534 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4535 scalar.* = try floatMulScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
4416 }4536 }
4417 return Value.Tag.aggregate.create(arena, result_data);4537 return Value.Tag.aggregate.create(arena, result_data);
4418 }4538 }
...@@ -4456,11 +4576,14 @@ pub const Value = extern union {...@@ -4456,11 +4576,14 @@ pub const Value = extern union {
4456 }4576 }
4457 }4577 }
44584578
4459 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4579 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4580 const target = mod.getTarget();
4460 if (float_type.zigTypeTag() == .Vector) {4581 if (float_type.zigTypeTag() == .Vector) {
4461 const result_data = try arena.alloc(Value, float_type.vectorLen());4582 const result_data = try arena.alloc(Value, float_type.vectorLen());
4462 for (result_data) |*scalar, i| {4583 for (result_data) |*scalar, i| {
4463 scalar.* = try sqrtScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4584 var buf: Value.ElemValueBuffer = undefined;
4585 const elem_val = val.elemValueBuffer(mod, i, &buf);
4586 scalar.* = try sqrtScalar(elem_val, float_type.scalarType(), arena, target);
4464 }4587 }
4465 return Value.Tag.aggregate.create(arena, result_data);4588 return Value.Tag.aggregate.create(arena, result_data);
4466 }4589 }
...@@ -4493,11 +4616,14 @@ pub const Value = extern union {...@@ -4493,11 +4616,14 @@ pub const Value = extern union {
4493 }4616 }
4494 }4617 }
44954618
4496 pub fn sin(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4619 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4620 const target = mod.getTarget();
4497 if (float_type.zigTypeTag() == .Vector) {4621 if (float_type.zigTypeTag() == .Vector) {
4498 const result_data = try arena.alloc(Value, float_type.vectorLen());4622 const result_data = try arena.alloc(Value, float_type.vectorLen());
4499 for (result_data) |*scalar, i| {4623 for (result_data) |*scalar, i| {
4500 scalar.* = try sinScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4624 var buf: Value.ElemValueBuffer = undefined;
4625 const elem_val = val.elemValueBuffer(mod, i, &buf);
4626 scalar.* = try sinScalar(elem_val, float_type.scalarType(), arena, target);
4501 }4627 }
4502 return Value.Tag.aggregate.create(arena, result_data);4628 return Value.Tag.aggregate.create(arena, result_data);
4503 }4629 }
...@@ -4530,11 +4656,14 @@ pub const Value = extern union {...@@ -4530,11 +4656,14 @@ pub const Value = extern union {
4530 }4656 }
4531 }4657 }
45324658
4533 pub fn cos(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4659 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4660 const target = mod.getTarget();
4534 if (float_type.zigTypeTag() == .Vector) {4661 if (float_type.zigTypeTag() == .Vector) {
4535 const result_data = try arena.alloc(Value, float_type.vectorLen());4662 const result_data = try arena.alloc(Value, float_type.vectorLen());
4536 for (result_data) |*scalar, i| {4663 for (result_data) |*scalar, i| {
4537 scalar.* = try cosScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4664 var buf: Value.ElemValueBuffer = undefined;
4665 const elem_val = val.elemValueBuffer(mod, i, &buf);
4666 scalar.* = try cosScalar(elem_val, float_type.scalarType(), arena, target);
4538 }4667 }
4539 return Value.Tag.aggregate.create(arena, result_data);4668 return Value.Tag.aggregate.create(arena, result_data);
4540 }4669 }
...@@ -4567,11 +4696,14 @@ pub const Value = extern union {...@@ -4567,11 +4696,14 @@ pub const Value = extern union {
4567 }4696 }
4568 }4697 }
45694698
4570 pub fn tan(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4699 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4700 const target = mod.getTarget();
4571 if (float_type.zigTypeTag() == .Vector) {4701 if (float_type.zigTypeTag() == .Vector) {
4572 const result_data = try arena.alloc(Value, float_type.vectorLen());4702 const result_data = try arena.alloc(Value, float_type.vectorLen());
4573 for (result_data) |*scalar, i| {4703 for (result_data) |*scalar, i| {
4574 scalar.* = try tanScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4704 var buf: Value.ElemValueBuffer = undefined;
4705 const elem_val = val.elemValueBuffer(mod, i, &buf);
4706 scalar.* = try tanScalar(elem_val, float_type.scalarType(), arena, target);
4575 }4707 }
4576 return Value.Tag.aggregate.create(arena, result_data);4708 return Value.Tag.aggregate.create(arena, result_data);
4577 }4709 }
...@@ -4604,11 +4736,14 @@ pub const Value = extern union {...@@ -4604,11 +4736,14 @@ pub const Value = extern union {
4604 }4736 }
4605 }4737 }
46064738
4607 pub fn exp(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4739 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4740 const target = mod.getTarget();
4608 if (float_type.zigTypeTag() == .Vector) {4741 if (float_type.zigTypeTag() == .Vector) {
4609 const result_data = try arena.alloc(Value, float_type.vectorLen());4742 const result_data = try arena.alloc(Value, float_type.vectorLen());
4610 for (result_data) |*scalar, i| {4743 for (result_data) |*scalar, i| {
4611 scalar.* = try expScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4744 var buf: Value.ElemValueBuffer = undefined;
4745 const elem_val = val.elemValueBuffer(mod, i, &buf);
4746 scalar.* = try expScalar(elem_val, float_type.scalarType(), arena, target);
4612 }4747 }
4613 return Value.Tag.aggregate.create(arena, result_data);4748 return Value.Tag.aggregate.create(arena, result_data);
4614 }4749 }
...@@ -4641,11 +4776,14 @@ pub const Value = extern union {...@@ -4641,11 +4776,14 @@ pub const Value = extern union {
4641 }4776 }
4642 }4777 }
46434778
4644 pub fn exp2(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4779 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4780 const target = mod.getTarget();
4645 if (float_type.zigTypeTag() == .Vector) {4781 if (float_type.zigTypeTag() == .Vector) {
4646 const result_data = try arena.alloc(Value, float_type.vectorLen());4782 const result_data = try arena.alloc(Value, float_type.vectorLen());
4647 for (result_data) |*scalar, i| {4783 for (result_data) |*scalar, i| {
4648 scalar.* = try exp2Scalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4784 var buf: Value.ElemValueBuffer = undefined;
4785 const elem_val = val.elemValueBuffer(mod, i, &buf);
4786 scalar.* = try exp2Scalar(elem_val, float_type.scalarType(), arena, target);
4649 }4787 }
4650 return Value.Tag.aggregate.create(arena, result_data);4788 return Value.Tag.aggregate.create(arena, result_data);
4651 }4789 }
...@@ -4678,11 +4816,14 @@ pub const Value = extern union {...@@ -4678,11 +4816,14 @@ pub const Value = extern union {
4678 }4816 }
4679 }4817 }
46804818
4681 pub fn log(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4819 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4820 const target = mod.getTarget();
4682 if (float_type.zigTypeTag() == .Vector) {4821 if (float_type.zigTypeTag() == .Vector) {
4683 const result_data = try arena.alloc(Value, float_type.vectorLen());4822 const result_data = try arena.alloc(Value, float_type.vectorLen());
4684 for (result_data) |*scalar, i| {4823 for (result_data) |*scalar, i| {
4685 scalar.* = try logScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4824 var buf: Value.ElemValueBuffer = undefined;
4825 const elem_val = val.elemValueBuffer(mod, i, &buf);
4826 scalar.* = try logScalar(elem_val, float_type.scalarType(), arena, target);
4686 }4827 }
4687 return Value.Tag.aggregate.create(arena, result_data);4828 return Value.Tag.aggregate.create(arena, result_data);
4688 }4829 }
...@@ -4715,11 +4856,14 @@ pub const Value = extern union {...@@ -4715,11 +4856,14 @@ pub const Value = extern union {
4715 }4856 }
4716 }4857 }
47174858
4718 pub fn log2(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4859 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4860 const target = mod.getTarget();
4719 if (float_type.zigTypeTag() == .Vector) {4861 if (float_type.zigTypeTag() == .Vector) {
4720 const result_data = try arena.alloc(Value, float_type.vectorLen());4862 const result_data = try arena.alloc(Value, float_type.vectorLen());
4721 for (result_data) |*scalar, i| {4863 for (result_data) |*scalar, i| {
4722 scalar.* = try log2Scalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4864 var buf: Value.ElemValueBuffer = undefined;
4865 const elem_val = val.elemValueBuffer(mod, i, &buf);
4866 scalar.* = try log2Scalar(elem_val, float_type.scalarType(), arena, target);
4723 }4867 }
4724 return Value.Tag.aggregate.create(arena, result_data);4868 return Value.Tag.aggregate.create(arena, result_data);
4725 }4869 }
...@@ -4752,11 +4896,14 @@ pub const Value = extern union {...@@ -4752,11 +4896,14 @@ pub const Value = extern union {
4752 }4896 }
4753 }4897 }
47544898
4755 pub fn log10(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4899 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4900 const target = mod.getTarget();
4756 if (float_type.zigTypeTag() == .Vector) {4901 if (float_type.zigTypeTag() == .Vector) {
4757 const result_data = try arena.alloc(Value, float_type.vectorLen());4902 const result_data = try arena.alloc(Value, float_type.vectorLen());
4758 for (result_data) |*scalar, i| {4903 for (result_data) |*scalar, i| {
4759 scalar.* = try log10Scalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4904 var buf: Value.ElemValueBuffer = undefined;
4905 const elem_val = val.elemValueBuffer(mod, i, &buf);
4906 scalar.* = try log10Scalar(elem_val, float_type.scalarType(), arena, target);
4760 }4907 }
4761 return Value.Tag.aggregate.create(arena, result_data);4908 return Value.Tag.aggregate.create(arena, result_data);
4762 }4909 }
...@@ -4789,11 +4936,14 @@ pub const Value = extern union {...@@ -4789,11 +4936,14 @@ pub const Value = extern union {
4789 }4936 }
4790 }4937 }
47914938
4792 pub fn fabs(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4939 pub fn fabs(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4940 const target = mod.getTarget();
4793 if (float_type.zigTypeTag() == .Vector) {4941 if (float_type.zigTypeTag() == .Vector) {
4794 const result_data = try arena.alloc(Value, float_type.vectorLen());4942 const result_data = try arena.alloc(Value, float_type.vectorLen());
4795 for (result_data) |*scalar, i| {4943 for (result_data) |*scalar, i| {
4796 scalar.* = try fabsScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4944 var buf: Value.ElemValueBuffer = undefined;
4945 const elem_val = val.elemValueBuffer(mod, i, &buf);
4946 scalar.* = try fabsScalar(elem_val, float_type.scalarType(), arena, target);
4797 }4947 }
4798 return Value.Tag.aggregate.create(arena, result_data);4948 return Value.Tag.aggregate.create(arena, result_data);
4799 }4949 }
...@@ -4826,11 +4976,14 @@ pub const Value = extern union {...@@ -4826,11 +4976,14 @@ pub const Value = extern union {
4826 }4976 }
4827 }4977 }
48284978
4829 pub fn floor(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {4979 pub fn floor(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4980 const target = mod.getTarget();
4830 if (float_type.zigTypeTag() == .Vector) {4981 if (float_type.zigTypeTag() == .Vector) {
4831 const result_data = try arena.alloc(Value, float_type.vectorLen());4982 const result_data = try arena.alloc(Value, float_type.vectorLen());
4832 for (result_data) |*scalar, i| {4983 for (result_data) |*scalar, i| {
4833 scalar.* = try floorScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);4984 var buf: Value.ElemValueBuffer = undefined;
4985 const elem_val = val.elemValueBuffer(mod, i, &buf);
4986 scalar.* = try floorScalar(elem_val, float_type.scalarType(), arena, target);
4834 }4987 }
4835 return Value.Tag.aggregate.create(arena, result_data);4988 return Value.Tag.aggregate.create(arena, result_data);
4836 }4989 }
...@@ -4863,11 +5016,14 @@ pub const Value = extern union {...@@ -4863,11 +5016,14 @@ pub const Value = extern union {
4863 }5016 }
4864 }5017 }
48655018
4866 pub fn ceil(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {5019 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
5020 const target = mod.getTarget();
4867 if (float_type.zigTypeTag() == .Vector) {5021 if (float_type.zigTypeTag() == .Vector) {
4868 const result_data = try arena.alloc(Value, float_type.vectorLen());5022 const result_data = try arena.alloc(Value, float_type.vectorLen());
4869 for (result_data) |*scalar, i| {5023 for (result_data) |*scalar, i| {
4870 scalar.* = try ceilScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);5024 var buf: Value.ElemValueBuffer = undefined;
5025 const elem_val = val.elemValueBuffer(mod, i, &buf);
5026 scalar.* = try ceilScalar(elem_val, float_type.scalarType(), arena, target);
4871 }5027 }
4872 return Value.Tag.aggregate.create(arena, result_data);5028 return Value.Tag.aggregate.create(arena, result_data);
4873 }5029 }
...@@ -4900,11 +5056,14 @@ pub const Value = extern union {...@@ -4900,11 +5056,14 @@ pub const Value = extern union {
4900 }5056 }
4901 }5057 }
49025058
4903 pub fn round(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {5059 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
5060 const target = mod.getTarget();
4904 if (float_type.zigTypeTag() == .Vector) {5061 if (float_type.zigTypeTag() == .Vector) {
4905 const result_data = try arena.alloc(Value, float_type.vectorLen());5062 const result_data = try arena.alloc(Value, float_type.vectorLen());
4906 for (result_data) |*scalar, i| {5063 for (result_data) |*scalar, i| {
4907 scalar.* = try roundScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);5064 var buf: Value.ElemValueBuffer = undefined;
5065 const elem_val = val.elemValueBuffer(mod, i, &buf);
5066 scalar.* = try roundScalar(elem_val, float_type.scalarType(), arena, target);
4908 }5067 }
4909 return Value.Tag.aggregate.create(arena, result_data);5068 return Value.Tag.aggregate.create(arena, result_data);
4910 }5069 }
...@@ -4937,11 +5096,14 @@ pub const Value = extern union {...@@ -4937,11 +5096,14 @@ pub const Value = extern union {
4937 }5096 }
4938 }5097 }
49395098
4940 pub fn trunc(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {5099 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
5100 const target = mod.getTarget();
4941 if (float_type.zigTypeTag() == .Vector) {5101 if (float_type.zigTypeTag() == .Vector) {
4942 const result_data = try arena.alloc(Value, float_type.vectorLen());5102 const result_data = try arena.alloc(Value, float_type.vectorLen());
4943 for (result_data) |*scalar, i| {5103 for (result_data) |*scalar, i| {
4944 scalar.* = try truncScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);5104 var buf: Value.ElemValueBuffer = undefined;
5105 const elem_val = val.elemValueBuffer(mod, i, &buf);
5106 scalar.* = try truncScalar(elem_val, float_type.scalarType(), arena, target);
4945 }5107 }
4946 return Value.Tag.aggregate.create(arena, result_data);5108 return Value.Tag.aggregate.create(arena, result_data);
4947 }5109 }
...@@ -4980,16 +5142,23 @@ pub const Value = extern union {...@@ -4980,16 +5142,23 @@ pub const Value = extern union {
4980 mulend2: Value,5142 mulend2: Value,
4981 addend: Value,5143 addend: Value,
4982 arena: Allocator,5144 arena: Allocator,
4983 target: Target,5145 mod: *Module,
4984 ) Allocator.Error!Value {5146 ) !Value {
5147 const target = mod.getTarget();
4985 if (float_type.zigTypeTag() == .Vector) {5148 if (float_type.zigTypeTag() == .Vector) {
4986 const result_data = try arena.alloc(Value, float_type.vectorLen());5149 const result_data = try arena.alloc(Value, float_type.vectorLen());
4987 for (result_data) |*scalar, i| {5150 for (result_data) |*scalar, i| {
5151 var mulend1_buf: Value.ElemValueBuffer = undefined;
5152 const mulend1_elem = mulend1.elemValueBuffer(mod, i, &mulend1_buf);
5153 var mulend2_buf: Value.ElemValueBuffer = undefined;
5154 const mulend2_elem = mulend2.elemValueBuffer(mod, i, &mulend2_buf);
5155 var addend_buf: Value.ElemValueBuffer = undefined;
5156 const addend_elem = addend.elemValueBuffer(mod, i, &addend_buf);
4988 scalar.* = try mulAddScalar(5157 scalar.* = try mulAddScalar(
4989 float_type.scalarType(),5158 float_type.scalarType(),
4990 mulend1.indexVectorlike(i),5159 mulend1_elem,
4991 mulend2.indexVectorlike(i),5160 mulend2_elem,
4992 addend.indexVectorlike(i),5161 addend_elem,
4993 arena,5162 arena,
4994 target,5163 target,
4995 );5164 );