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(
92259225 // If the destination type is signed, then we need to double its
92269226 // range to account for negative values.
92279227 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);
92299229 break :range_val try sema.intAdd(range_minus_one, Value.one, unsigned_operand_ty);
92309230 } else dest_max_val;
92319231 const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val);
......@@ -11683,9 +11683,11 @@ fn zirShl(
1168311683 if (rhs_ty.zigTypeTag() == .Vector) {
1168411684 var i: usize = 0;
1168511685 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)) {
1168711689 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),
1168911691 i,
1169011692 scalar_ty.fmt(sema.mod),
1169111693 });
......@@ -11701,9 +11703,11 @@ fn zirShl(
1170111703 if (rhs_ty.zigTypeTag() == .Vector) {
1170211704 var i: usize = 0;
1170311705 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)) {
1170511709 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),
1170711711 i,
1170811712 });
1170911713 }
......@@ -11726,7 +11730,7 @@ fn zirShl(
1172611730
1172711731 const val = switch (air_tag) {
1172811732 .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);
1173011734 if (scalar_ty.zigTypeTag() == .ComptimeInt) {
1173111735 break :val shifted.wrapped_result;
1173211736 }
......@@ -11737,14 +11741,14 @@ fn zirShl(
1173711741 },
1173811742
1173911743 .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)
1174111745 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
1174411748 .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)
1174611750 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
1174911753 else => unreachable,
1175011754 };
......@@ -11867,9 +11871,11 @@ fn zirShr(
1186711871 if (rhs_ty.zigTypeTag() == .Vector) {
1186811872 var i: usize = 0;
1186911873 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)) {
1187111877 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),
1187311879 i,
1187411880 scalar_ty.fmt(sema.mod),
1187511881 });
......@@ -11885,9 +11891,11 @@ fn zirShr(
1188511891 if (rhs_ty.zigTypeTag() == .Vector) {
1188611892 var i: usize = 0;
1188711893 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)) {
1188911897 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),
1189111899 i,
1189211900 });
1189311901 }
......@@ -11903,12 +11911,12 @@ fn zirShr(
1190311911 }
1190411912 if (air_tag == .shr_exact) {
1190511913 // 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);
1190711915 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) {
1190811916 return sema.fail(block, src, "exact shift shifted out 1 bits", .{});
1190911917 }
1191011918 }
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);
1191211920 return sema.addConstant(lhs_ty, val);
1191311921 } else {
1191411922 break :rs lhs_src;
......@@ -11992,7 +12000,6 @@ fn zirBitwise(
1199212000 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1199312001
1199412002 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
11995 const target = sema.mod.getTarget();
1199612003
1199712004 if (!is_int) {
1199812005 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(
1200412011 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {
1200512012 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {
1200612013 const result_val = switch (air_tag) {
12007 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, target),
12008 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, target),
12009 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, target),
12014 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, sema.mod),
12015 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, sema.mod),
12016 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, sema.mod),
1201012017 else => unreachable,
1201112018 };
1201212019 return sema.addConstant(resolved_type, result_val);
......@@ -12033,7 +12040,6 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1203312040 const operand = try sema.resolveInst(inst_data.operand);
1203412041 const operand_type = sema.typeOf(operand);
1203512042 const scalar_type = operand_type.scalarType();
12036 const target = sema.mod.getTarget();
1203712043
1203812044 if (scalar_type.zigTypeTag() != .Int) {
1203912045 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.
1205012056 const elems = try sema.arena.alloc(Value, vec_len);
1205112057 for (elems) |*elem, i| {
1205212058 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);
1205412060 }
1205512061 return sema.addConstant(
1205612062 operand_type,
1205712063 try Value.Tag.aggregate.create(sema.arena, elems),
1205812064 );
1205912065 } 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);
1206112067 return sema.addConstant(operand_type, result_val);
1206212068 }
1206312069 }
......@@ -12586,8 +12592,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1258612592 // We handle float negation here to ensure negative zero is represented in the bits.
1258712593 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
1258812594 if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty);
12589 const target = sema.mod.getTarget();
12590 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target));
12595 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, sema.mod));
1259112596 }
1259212597 try sema.requireRuntimeBlock(block, src, null);
1259312598 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
1267912684 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div);
1268012685
1268112686 const mod = sema.mod;
12682 const target = mod.getTarget();
1268312687 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1268412688 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
1269012694 // If lhs % rhs is 0, it doesn't matter.
1269112695 const lhs_val = maybe_lhs_val orelse unreachable;
1269212696 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;
1269412698 if (!rem.compareAllWithZero(.eq)) {
1269512699 return sema.fail(block, src, "ambiguous coercion of division operands '{s}' and '{s}'; non-zero remainder '{}'", .{
1269612700 @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
1276612770
1276712771 if (maybe_rhs_val) |rhs_val| {
1276812772 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);
1277012774 var vector_index: usize = undefined;
1277112775 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1277212776 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
1277512779 } else {
1277612780 return sema.addConstant(
1277712781 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),
1277912783 );
1278012784 }
1278112785 } else {
......@@ -12839,7 +12843,6 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1283912843 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_exact);
1284012844
1284112845 const mod = sema.mod;
12842 const target = mod.getTarget();
1284312846 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1284412847 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
1288412887 if (maybe_lhs_val) |lhs_val| {
1288512888 if (maybe_rhs_val) |rhs_val| {
1288612889 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);
1288812891 if (!(modulus_val.compareAllWithZero(.eq))) {
1288912892 return sema.fail(block, src, "exact division produced remainder", .{});
1289012893 }
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);
1289212895 var vector_index: usize = undefined;
1289312896 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1289412897 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
1289512898 }
1289612899 return sema.addConstant(resolved_type, res);
1289712900 } 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);
1289912902 if (!(modulus_val.compareAllWithZero(.eq))) {
1290012903 return sema.fail(block, src, "exact division produced remainder", .{});
1290112904 }
1290212905 return sema.addConstant(
1290312906 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),
1290512908 );
1290612909 }
1290712910 } else break :rs rhs_src;
......@@ -13004,7 +13007,6 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1300413007 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_floor);
1300513008
1300613009 const mod = sema.mod;
13007 const target = mod.getTarget();
1300813010 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1300913011 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
1306413066 if (is_int) {
1306513067 return sema.addConstant(
1306613068 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),
1306813070 );
1306913071 } else {
1307013072 return sema.addConstant(
1307113073 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),
1307313075 );
1307413076 }
1307513077 } else break :rs rhs_src;
......@@ -13121,7 +13123,6 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1312113123 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_trunc);
1312213124
1312313125 const mod = sema.mod;
13124 const target = mod.getTarget();
1312513126 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1312613127 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
1317813179
1317913180 if (maybe_rhs_val) |rhs_val| {
1318013181 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);
1318213183 var vector_index: usize = undefined;
1318313184 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1318413185 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
1318713188 } else {
1318813189 return sema.addConstant(
1318913190 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),
1319113192 );
1319213193 }
1319313194 } else break :rs rhs_src;
......@@ -13365,7 +13366,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1336513366 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod_rem);
1336613367
1336713368 const mod = sema.mod;
13368 const target = mod.getTarget();
1336913369 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1337013370 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.
1344213442 }
1344313443 return sema.addConstant(
1344413444 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),
1344613446 );
1344713447 } else {
1344813448 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
......@@ -13471,7 +13471,11 @@ fn intRem(
1347113471 if (ty.zigTypeTag() == .Vector) {
1347213472 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
1347313473 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);
1347513479 }
1347613480 return Value.Tag.aggregate.create(sema.arena, result_data);
1347713481 }
......@@ -13541,7 +13545,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1354113545 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod);
1354213546
1354313547 const mod = sema.mod;
13544 const target = mod.getTarget();
1354513548 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1354613549 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
1357313576 if (maybe_lhs_val) |lhs_val| {
1357413577 return sema.addConstant(
1357513578 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),
1357713580 );
1357813581 }
1357913582 break :rs lhs_src;
......@@ -13597,7 +13600,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1359713600 if (maybe_rhs_val) |rhs_val| {
1359813601 return sema.addConstant(
1359913602 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),
1360113604 );
1360213605 } else break :rs rhs_src;
1360313606 } else break :rs lhs_src;
......@@ -13644,7 +13647,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1364413647 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .rem);
1364513648
1364613649 const mod = sema.mod;
13647 const target = mod.getTarget();
1364813650 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1364913651 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
1370013702 if (maybe_rhs_val) |rhs_val| {
1370113703 return sema.addConstant(
1370213704 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),
1370413706 );
1370513707 } else break :rs rhs_src;
1370613708 } else break :rs lhs_src;
......@@ -13739,7 +13741,6 @@ fn zirOverflowArithmetic(
1373913741 const lhs_ty = sema.typeOf(lhs);
1374013742 const rhs_ty = sema.typeOf(rhs);
1374113743 const mod = sema.mod;
13742 const target = mod.getTarget();
1374313744
1374413745 // Note, the types of lhs/rhs (also for shifting)/ptr are already correct as ensured by astgen.
1374513746 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
......@@ -13839,7 +13840,7 @@ fn zirOverflowArithmetic(
1383913840 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
1384013841 }
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);
1384313844 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);
1384413845 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);
1384513846 break :result .{ .overflowed = overflowed, .wrapped = wrapped };
......@@ -13866,7 +13867,7 @@ fn zirOverflowArithmetic(
1386613867 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
1386713868 }
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);
1387013871 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);
1387113872 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);
1387213873 break :result .{ .overflowed = overflowed, .wrapped = wrapped };
......@@ -13979,13 +13980,12 @@ fn analyzeArithmetic(
1397913980 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, zir_tag);
1398013981
1398113982 const mod = sema.mod;
13982 const target = mod.getTarget();
1398313983 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1398413984 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1398513985 const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: {
1398613986 switch (zir_tag) {
1398713987 .add => {
13988 // For integers:
13988 // For integers:intAddSat
1398913989 // If either of the operands are zero, then the other operand is
1399013990 // returned, even if it is undefined.
1399113991 // If either of the operands are undefined, it's a compile error
......@@ -14080,7 +14080,7 @@ fn analyzeArithmetic(
1408014080 const val = if (scalar_tag == .ComptimeInt)
1408114081 try sema.intAdd(lhs_val, rhs_val, resolved_type)
1408214082 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
1408514085 return sema.addConstant(resolved_type, val);
1408614086 } else break :rs .{ .src = lhs_src, .air_tag = .add_sat };
......@@ -14177,7 +14177,7 @@ fn analyzeArithmetic(
1417714177 const val = if (scalar_tag == .ComptimeInt)
1417814178 try sema.intSub(lhs_val, rhs_val, resolved_type)
1417914179 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
1418214182 return sema.addConstant(resolved_type, val);
1418314183 } else break :rs .{ .src = rhs_src, .air_tag = .sub_sat };
......@@ -14258,7 +14258,7 @@ fn analyzeArithmetic(
1425814258 }
1425914259 }
1426014260 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);
1426214262 var vector_index: usize = undefined;
1426314263 if (!(try sema.intFitsInType(product, resolved_type, &vector_index))) {
1426414264 return sema.failWithIntegerOverflow(block, src, resolved_type, product, vector_index);
......@@ -14267,7 +14267,7 @@ fn analyzeArithmetic(
1426714267 } else {
1426814268 return sema.addConstant(
1426914269 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),
1427114271 );
1427214272 }
1427314273 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
......@@ -14311,7 +14311,7 @@ fn analyzeArithmetic(
1431114311 }
1431214312 return sema.addConstant(
1431314313 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),
1431514315 );
1431614316 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
1431714317 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
......@@ -14353,9 +14353,9 @@ fn analyzeArithmetic(
1435314353 }
1435414354
1435514355 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)
1435714357 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
1436014360 return sema.addConstant(resolved_type, val);
1436114361 } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat };
......@@ -17947,7 +17947,7 @@ fn zirUnaryMath(
1794717947 block: *Block,
1794817948 inst: Zir.Inst.Index,
1794917949 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,
1795117951) CompileError!Air.Inst.Ref {
1795217952 const tracy = trace(@src());
1795317953 defer tracy.end();
......@@ -17956,7 +17956,6 @@ fn zirUnaryMath(
1795617956 const operand = try sema.resolveInst(inst_data.operand);
1795717957 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1795817958 const operand_ty = sema.typeOf(operand);
17959 const target = sema.mod.getTarget();
1796017959
1796117960 switch (operand_ty.zigTypeTag()) {
1796217961 .ComptimeFloat, .Float => {},
......@@ -17983,7 +17982,7 @@ fn zirUnaryMath(
1798317982 const elems = try sema.arena.alloc(Value, vec_len);
1798417983 for (elems) |*elem, i| {
1798517984 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);
1798717986 }
1798817987 return sema.addConstant(
1798917988 result_ty,
......@@ -17998,7 +17997,7 @@ fn zirUnaryMath(
1799817997 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
1799917998 if (operand_val.isUndef())
1800017999 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);
1800218001 return sema.addConstant(operand_ty, result_val);
1800318002 }
1800418003
......@@ -19220,8 +19219,7 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1922019219 _ = try sema.checkIntType(block, operand_src, operand_ty);
1922119220
1922219221 if (try sema.resolveMaybeUndefVal(operand)) |val| {
19223 const target = sema.mod.getTarget();
19224 const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, target, sema);
19222 const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, sema.mod, sema);
1922519223 return sema.addConstant(dest_ty, result_val);
1922619224 } else if (dest_ty.zigTypeTag() == .ComptimeFloat) {
1922719225 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
1954719545 if (!is_vector) {
1954819546 return sema.addConstant(
1954919547 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),
1955119549 );
1955219550 }
1955319551 var elem_buf: Value.ElemValueBuffer = undefined;
1955419552 const elems = try sema.arena.alloc(Value, operand_ty.vectorLen());
1955519553 for (elems) |*elem, i| {
1955619554 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);
1955819556 }
1955919557 return sema.addConstant(
1956019558 dest_ty,
......@@ -20523,13 +20521,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2052320521 while (i < vec_len) : (i += 1) {
2052420522 const elem_val = operand_val.elemValueBuffer(sema.mod, i, &elem_buf);
2052520523 switch (operation) {
20526 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, target),
20527 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, target),
20528 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, target),
20524 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, sema.mod),
20525 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, sema.mod),
20526 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, sema.mod),
2052920527 .Min => accum = accum.numberMin(elem_val, target),
2053020528 .Max => accum = accum.numberMax(elem_val, target),
2053120529 .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),
2053320531 }
2053420532 }
2053520533 return sema.addConstant(scalar_ty, accum);
......@@ -20925,10 +20923,10 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2092520923 .Xchg => operand_val,
2092620924 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),
2092720925 .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty),
20928 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, target),
20929 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, target),
20930 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, target),
20931 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, target),
20926 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, sema.mod),
20927 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, sema.mod),
20928 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, sema.mod),
20929 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, sema.mod),
2093220930 .Max => stored_val.numberMax (operand_val, target),
2093320931 .Min => stored_val.numberMin (operand_val, target),
2093420932 // zig fmt: on
......@@ -21001,8 +20999,6 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2100120999 const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src);
2100221000 const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src);
2100321001
21004 const target = sema.mod.getTarget();
21005
2100621002 const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1);
2100721003 const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2);
2100821004 const maybe_addend = try sema.resolveMaybeUndefVal(addend);
......@@ -21018,7 +21014,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2101821014
2101921015 if (maybe_addend) |addend_val| {
2102021016 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);
2102221018 return sema.addConstant(ty, result_val);
2102321019 } else {
2102421020 break :rs addend_src;
......@@ -24830,7 +24826,7 @@ fn coerceExtra(
2483024826 }
2483124827 break :int;
2483224828 };
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);
2483424830 // TODO implement this compile error
2483524831 //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty);
2483624832 //if (!int_again_val.eql(val, inst_ty, mod)) {
......@@ -32263,7 +32259,11 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
3226332259 if (ty.zigTypeTag() == .Vector) {
3226432260 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3226532261 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);
3226732267 }
3226832268 return Value.Tag.aggregate.create(sema.arena, result_data);
3226932269 }
......@@ -32297,7 +32297,11 @@ fn numberAddWrap(
3229732297 if (ty.zigTypeTag() == .Vector) {
3229832298 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3229932299 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());
3230132305 }
3230232306 return Value.Tag.aggregate.create(sema.arena, result_data);
3230332307 }
......@@ -32334,7 +32338,11 @@ fn intSub(
3233432338 if (ty.zigTypeTag() == .Vector) {
3233532339 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3233632340 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);
3233832346 }
3233932347 return Value.Tag.aggregate.create(sema.arena, result_data);
3234032348 }
......@@ -32368,7 +32376,11 @@ fn numberSubWrap(
3236832376 if (ty.zigTypeTag() == .Vector) {
3236932377 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3237032378 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());
3237232384 }
3237332385 return Value.Tag.aggregate.create(sema.arena, result_data);
3237432386 }
......@@ -32405,7 +32417,11 @@ fn floatAdd(
3240532417 if (float_type.zigTypeTag() == .Vector) {
3240632418 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());
3240732419 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());
3240932425 }
3241032426 return Value.Tag.aggregate.create(sema.arena, result_data);
3241132427 }
......@@ -32458,7 +32474,11 @@ fn floatSub(
3245832474 if (float_type.zigTypeTag() == .Vector) {
3245932475 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());
3246032476 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());
3246232482 }
3246332483 return Value.Tag.aggregate.create(sema.arena, result_data);
3246432484 }
......@@ -32512,7 +32532,11 @@ fn intSubWithOverflow(
3251232532 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
3251332533 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3251432534 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());
3251632540 overflowed_data[i] = of_math_result.overflowed;
3251732541 scalar.* = of_math_result.wrapped_result;
3251832542 }
......@@ -32562,7 +32586,9 @@ fn floatToInt(
3256232586 const elem_ty = float_ty.childType();
3256332587 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen());
3256432588 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());
3256632592 }
3256732593 return Value.Tag.aggregate.create(sema.arena, result_data);
3256832594 }
......@@ -32857,7 +32883,11 @@ fn intAddWithOverflow(
3285732883 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
3285832884 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3285932885 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());
3286132891 overflowed_data[i] = of_math_result.overflowed;
3286232892 scalar.* = of_math_result.wrapped_result;
3286332893 }
......@@ -32909,7 +32939,11 @@ fn compareAll(
3290932939 if (ty.zigTypeTag() == .Vector) {
3291032940 var i: usize = 0;
3291132941 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()))) {
3291332947 return false;
3291432948 }
3291532949 }
......@@ -32953,7 +32987,11 @@ fn compareVector(
3295332987 assert(ty.zigTypeTag() == .Vector);
3295432988 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3295532989 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());
3295732995 scalar.* = Value.makeBool(res_bool);
3295832996 }
3295932997 return Value.Tag.aggregate.create(sema.arena, result_data);
src/value.zig+305-136
......@@ -2044,7 +2044,11 @@ pub const Value = extern union {
20442044 if (ty.zigTypeTag() == .Vector) {
20452045 var i: usize = 0;
20462046 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)) {
20482052 return false;
20492053 }
20502054 }
......@@ -2793,27 +2797,6 @@ pub const Value = extern union {
27932797 };
27942798 }
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
28172800 /// Asserts the value is a single-item pointer to an array, or an array,
28182801 /// or an unknown-length pointer, and returns the element value at the index.
28192802 pub fn elemValue(val: Value, mod: *Module, arena: Allocator, index: usize) !Value {
......@@ -2889,18 +2872,21 @@ pub const Value = extern union {
28892872 // to have only one possible value itself.
28902873 .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
28982875 .opt_payload_ptr => return val.castTag(.opt_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),
28992876 .eu_payload_ptr => return val.castTag(.eu_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),
29002877
29012878 .opt_payload => return val.castTag(.opt_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),
29022879 .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
29042890 else => unreachable,
29052891 }
29062892 }
......@@ -3172,18 +3158,21 @@ pub const Value = extern union {
31723158 };
31733159 }
31743160
3175 pub fn intToFloat(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, target: Target) !Value {
3176 return intToFloatAdvanced(val, arena, int_ty, float_ty, target, null) catch |err| switch (err) {
3161 pub fn intToFloat(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module) !Value {
3162 return intToFloatAdvanced(val, arena, int_ty, float_ty, mod, null) catch |err| switch (err) {
31773163 error.OutOfMemory => return error.OutOfMemory,
31783164 else => unreachable,
31793165 };
31803166 }
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();
31833170 if (int_ty.zigTypeTag() == .Vector) {
31843171 const result_data = try arena.alloc(Value, int_ty.vectorLen());
31853172 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);
31873176 }
31883177 return Value.Tag.aggregate.create(arena, result_data);
31893178 }
......@@ -3289,12 +3278,17 @@ pub const Value = extern union {
32893278 rhs: Value,
32903279 ty: Type,
32913280 arena: Allocator,
3292 target: Target,
3281 mod: *Module,
32933282 ) !Value {
3283 const target = mod.getTarget();
32943284 if (ty.zigTypeTag() == .Vector) {
32953285 const result_data = try arena.alloc(Value, ty.vectorLen());
32963286 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);
32983292 }
32993293 return Value.Tag.aggregate.create(arena, result_data);
33003294 }
......@@ -3333,12 +3327,17 @@ pub const Value = extern union {
33333327 rhs: Value,
33343328 ty: Type,
33353329 arena: Allocator,
3336 target: Target,
3330 mod: *Module,
33373331 ) !Value {
3332 const target = mod.getTarget();
33383333 if (ty.zigTypeTag() == .Vector) {
33393334 const result_data = try arena.alloc(Value, ty.vectorLen());
33403335 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);
33423341 }
33433342 return Value.Tag.aggregate.create(arena, result_data);
33443343 }
......@@ -3376,13 +3375,18 @@ pub const Value = extern union {
33763375 rhs: Value,
33773376 ty: Type,
33783377 arena: Allocator,
3379 target: Target,
3378 mod: *Module,
33803379 ) !OverflowArithmeticResult {
3380 const target = mod.getTarget();
33813381 if (ty.zigTypeTag() == .Vector) {
33823382 const overflowed_data = try arena.alloc(Value, ty.vectorLen());
33833383 const result_data = try arena.alloc(Value, ty.vectorLen());
33843384 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);
33863390 overflowed_data[i] = of_math_result.overflowed;
33873391 scalar.* = of_math_result.wrapped_result;
33883392 }
......@@ -3435,16 +3439,20 @@ pub const Value = extern union {
34353439 rhs: Value,
34363440 ty: Type,
34373441 arena: Allocator,
3438 target: Target,
3442 mod: *Module,
34393443 ) !Value {
34403444 if (ty.zigTypeTag() == .Vector) {
34413445 const result_data = try arena.alloc(Value, ty.vectorLen());
34423446 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);
34443452 }
34453453 return Value.Tag.aggregate.create(arena, result_data);
34463454 }
3447 return numberMulWrapScalar(lhs, rhs, ty, arena, target);
3455 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);
34483456 }
34493457
34503458 /// Supports both floats and ints; handles undefined.
......@@ -3453,19 +3461,19 @@ pub const Value = extern union {
34533461 rhs: Value,
34543462 ty: Type,
34553463 arena: Allocator,
3456 target: Target,
3464 mod: *Module,
34573465 ) !Value {
34583466 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);
34593467
34603468 if (ty.zigTypeTag() == .ComptimeInt) {
3461 return intMul(lhs, rhs, ty, arena, target);
3469 return intMul(lhs, rhs, ty, arena, mod);
34623470 }
34633471
34643472 if (ty.isAnyFloat()) {
3465 return floatMul(lhs, rhs, ty, arena, target);
3473 return floatMul(lhs, rhs, ty, arena, mod);
34663474 }
34673475
3468 const overflow_result = try intMulWithOverflow(lhs, rhs, ty, arena, target);
3476 const overflow_result = try intMulWithOverflow(lhs, rhs, ty, arena, mod);
34693477 return overflow_result.wrapped_result;
34703478 }
34713479
......@@ -3475,12 +3483,17 @@ pub const Value = extern union {
34753483 rhs: Value,
34763484 ty: Type,
34773485 arena: Allocator,
3478 target: Target,
3486 mod: *Module,
34793487 ) !Value {
3488 const target = mod.getTarget();
34803489 if (ty.zigTypeTag() == .Vector) {
34813490 const result_data = try arena.alloc(Value, ty.vectorLen());
34823491 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);
34843497 }
34853498 return Value.Tag.aggregate.create(arena, result_data);
34863499 }
......@@ -3547,11 +3560,14 @@ pub const Value = extern union {
35473560 }
35483561
35493562 /// 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();
35513565 if (ty.zigTypeTag() == .Vector) {
35523566 const result_data = try arena.alloc(Value, ty.vectorLen());
35533567 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);
35553571 }
35563572 return Value.Tag.aggregate.create(arena, result_data);
35573573 }
......@@ -3583,11 +3599,16 @@ pub const Value = extern union {
35833599 }
35843600
35853601 /// 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();
35873604 if (ty.zigTypeTag() == .Vector) {
35883605 const result_data = try allocator.alloc(Value, ty.vectorLen());
35893606 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);
35913612 }
35923613 return Value.Tag.aggregate.create(allocator, result_data);
35933614 }
......@@ -3615,37 +3636,46 @@ pub const Value = extern union {
36153636 }
36163637
36173638 /// 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 {
36193640 if (ty.zigTypeTag() == .Vector) {
36203641 const result_data = try arena.alloc(Value, ty.vectorLen());
36213642 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);
36233648 }
36243649 return Value.Tag.aggregate.create(arena, result_data);
36253650 }
3626 return bitwiseNandScalar(lhs, rhs, ty, arena, target);
3651 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);
36273652 }
36283653
36293654 /// 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 {
36313656 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
36353660 const all_ones = if (ty.isSignedInt())
36363661 try Value.Tag.int_i64.create(arena, -1)
36373662 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);
36413666 }
36423667
36433668 /// 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();
36453671 if (ty.zigTypeTag() == .Vector) {
36463672 const result_data = try allocator.alloc(Value, ty.vectorLen());
36473673 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);
36493679 }
36503680 return Value.Tag.aggregate.create(allocator, result_data);
36513681 }
......@@ -3672,11 +3702,16 @@ pub const Value = extern union {
36723702 }
36733703
36743704 /// 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();
36763707 if (ty.zigTypeTag() == .Vector) {
36773708 const result_data = try allocator.alloc(Value, ty.vectorLen());
36783709 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);
36803715 }
36813716 return Value.Tag.aggregate.create(allocator, result_data);
36823717 }
......@@ -3703,11 +3738,16 @@ pub const Value = extern union {
37033738 return fromBigInt(arena, result_bigint.toConst());
37043739 }
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();
37073743 if (ty.zigTypeTag() == .Vector) {
37083744 const result_data = try allocator.alloc(Value, ty.vectorLen());
37093745 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);
37113751 }
37123752 return Value.Tag.aggregate.create(allocator, result_data);
37133753 }
......@@ -3739,11 +3779,16 @@ pub const Value = extern union {
37393779 return fromBigInt(allocator, result_q.toConst());
37403780 }
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();
37433784 if (ty.zigTypeTag() == .Vector) {
37443785 const result_data = try allocator.alloc(Value, ty.vectorLen());
37453786 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);
37473792 }
37483793 return Value.Tag.aggregate.create(allocator, result_data);
37493794 }
......@@ -3775,11 +3820,16 @@ pub const Value = extern union {
37753820 return fromBigInt(allocator, result_q.toConst());
37763821 }
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();
37793825 if (ty.zigTypeTag() == .Vector) {
37803826 const result_data = try allocator.alloc(Value, ty.vectorLen());
37813827 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);
37833833 }
37843834 return Value.Tag.aggregate.create(allocator, result_data);
37853835 }
......@@ -3846,11 +3896,16 @@ pub const Value = extern union {
38463896 };
38473897 }
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();
38503901 if (float_type.zigTypeTag() == .Vector) {
38513902 const result_data = try arena.alloc(Value, float_type.vectorLen());
38523903 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);
38543909 }
38553910 return Value.Tag.aggregate.create(arena, result_data);
38563911 }
......@@ -3888,11 +3943,16 @@ pub const Value = extern union {
38883943 }
38893944 }
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();
38923948 if (float_type.zigTypeTag() == .Vector) {
38933949 const result_data = try arena.alloc(Value, float_type.vectorLen());
38943950 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);
38963956 }
38973957 return Value.Tag.aggregate.create(arena, result_data);
38983958 }
......@@ -3930,11 +3990,16 @@ pub const Value = extern union {
39303990 }
39313991 }
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();
39343995 if (ty.zigTypeTag() == .Vector) {
39353996 const result_data = try allocator.alloc(Value, ty.vectorLen());
39363997 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);
39384003 }
39394004 return Value.Tag.aggregate.create(allocator, result_data);
39404005 }
......@@ -3962,11 +4027,14 @@ pub const Value = extern union {
39624027 return fromBigInt(allocator, result_bigint.toConst());
39634028 }
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();
39664032 if (ty.zigTypeTag() == .Vector) {
39674033 const result_data = try allocator.alloc(Value, ty.vectorLen());
39684034 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);
39704038 }
39714039 return Value.Tag.aggregate.create(allocator, result_data);
39724040 }
......@@ -3980,12 +4048,17 @@ pub const Value = extern union {
39804048 allocator: Allocator,
39814049 signedness: std.builtin.Signedness,
39824050 bits: Value,
3983 target: Target,
4051 mod: *Module,
39844052 ) !Value {
4053 const target = mod.getTarget();
39854054 if (ty.zigTypeTag() == .Vector) {
39864055 const result_data = try allocator.alloc(Value, ty.vectorLen());
39874056 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);
39894062 }
39904063 return Value.Tag.aggregate.create(allocator, result_data);
39914064 }
......@@ -4008,11 +4081,16 @@ pub const Value = extern union {
40084081 return fromBigInt(allocator, result_bigint.toConst());
40094082 }
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();
40124086 if (ty.zigTypeTag() == .Vector) {
40134087 const result_data = try allocator.alloc(Value, ty.vectorLen());
40144088 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);
40164094 }
40174095 return Value.Tag.aggregate.create(allocator, result_data);
40184096 }
......@@ -4043,13 +4121,18 @@ pub const Value = extern union {
40434121 rhs: Value,
40444122 ty: Type,
40454123 allocator: Allocator,
4046 target: Target,
4124 mod: *Module,
40474125 ) !OverflowArithmeticResult {
4126 const target = mod.getTarget();
40484127 if (ty.zigTypeTag() == .Vector) {
40494128 const overflowed_data = try allocator.alloc(Value, ty.vectorLen());
40504129 const result_data = try allocator.alloc(Value, ty.vectorLen());
40514130 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);
40534136 overflowed_data[i] = of_math_result.overflowed;
40544137 scalar.* = of_math_result.wrapped_result;
40554138 }
......@@ -4097,12 +4180,17 @@ pub const Value = extern union {
40974180 rhs: Value,
40984181 ty: Type,
40994182 arena: Allocator,
4100 target: Target,
4183 mod: *Module,
41014184 ) !Value {
4185 const target = mod.getTarget();
41024186 if (ty.zigTypeTag() == .Vector) {
41034187 const result_data = try arena.alloc(Value, ty.vectorLen());
41044188 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);
41064194 }
41074195 return Value.Tag.aggregate.create(arena, result_data);
41084196 }
......@@ -4141,16 +4229,20 @@ pub const Value = extern union {
41414229 rhs: Value,
41424230 ty: Type,
41434231 arena: Allocator,
4144 target: Target,
4232 mod: *Module,
41454233 ) !Value {
41464234 if (ty.zigTypeTag() == .Vector) {
41474235 const result_data = try arena.alloc(Value, ty.vectorLen());
41484236 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);
41504242 }
41514243 return Value.Tag.aggregate.create(arena, result_data);
41524244 }
4153 return shlTruncScalar(lhs, rhs, ty, arena, target);
4245 return shlTruncScalar(lhs, rhs, ty, arena, mod);
41544246 }
41554247
41564248 pub fn shlTruncScalar(
......@@ -4158,19 +4250,24 @@ pub const Value = extern union {
41584250 rhs: Value,
41594251 ty: Type,
41604252 arena: Allocator,
4161 target: Target,
4253 mod: *Module,
41624254 ) !Value {
4163 const shifted = try lhs.shl(rhs, ty, arena, target);
4164 const int_info = ty.intInfo(target);
4165 const truncated = try shifted.intTrunc(ty, arena, int_info.signedness, int_info.bits, target);
4255 const shifted = try lhs.shl(rhs, ty, arena, mod);
4256 const int_info = ty.intInfo(mod.getTarget());
4257 const truncated = try shifted.intTrunc(ty, arena, int_info.signedness, int_info.bits, mod);
41664258 return truncated;
41674259 }
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();
41704263 if (ty.zigTypeTag() == .Vector) {
41714264 const result_data = try allocator.alloc(Value, ty.vectorLen());
41724265 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);
41744271 }
41754272 return Value.Tag.aggregate.create(allocator, result_data);
41764273 }
......@@ -4212,12 +4309,15 @@ pub const Value = extern union {
42124309 val: Value,
42134310 float_type: Type,
42144311 arena: Allocator,
4215 target: Target,
4312 mod: *Module,
42164313 ) !Value {
4314 const target = mod.getTarget();
42174315 if (float_type.zigTypeTag() == .Vector) {
42184316 const result_data = try arena.alloc(Value, float_type.vectorLen());
42194317 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);
42214321 }
42224322 return Value.Tag.aggregate.create(arena, result_data);
42234323 }
......@@ -4245,12 +4345,17 @@ pub const Value = extern union {
42454345 rhs: Value,
42464346 float_type: Type,
42474347 arena: Allocator,
4248 target: Target,
4348 mod: *Module,
42494349 ) !Value {
4350 const target = mod.getTarget();
42504351 if (float_type.zigTypeTag() == .Vector) {
42514352 const result_data = try arena.alloc(Value, float_type.vectorLen());
42524353 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);
42544359 }
42554360 return Value.Tag.aggregate.create(arena, result_data);
42564361 }
......@@ -4299,12 +4404,17 @@ pub const Value = extern union {
42994404 rhs: Value,
43004405 float_type: Type,
43014406 arena: Allocator,
4302 target: Target,
4407 mod: *Module,
43034408 ) !Value {
4409 const target = mod.getTarget();
43044410 if (float_type.zigTypeTag() == .Vector) {
43054411 const result_data = try arena.alloc(Value, float_type.vectorLen());
43064412 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);
43084418 }
43094419 return Value.Tag.aggregate.create(arena, result_data);
43104420 }
......@@ -4353,12 +4463,17 @@ pub const Value = extern union {
43534463 rhs: Value,
43544464 float_type: Type,
43554465 arena: Allocator,
4356 target: Target,
4466 mod: *Module,
43574467 ) !Value {
4468 const target = mod.getTarget();
43584469 if (float_type.zigTypeTag() == .Vector) {
43594470 const result_data = try arena.alloc(Value, float_type.vectorLen());
43604471 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);
43624477 }
43634478 return Value.Tag.aggregate.create(arena, result_data);
43644479 }
......@@ -4407,12 +4522,17 @@ pub const Value = extern union {
44074522 rhs: Value,
44084523 float_type: Type,
44094524 arena: Allocator,
4410 target: Target,
4525 mod: *Module,
44114526 ) !Value {
4527 const target = mod.getTarget();
44124528 if (float_type.zigTypeTag() == .Vector) {
44134529 const result_data = try arena.alloc(Value, float_type.vectorLen());
44144530 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);
44164536 }
44174537 return Value.Tag.aggregate.create(arena, result_data);
44184538 }
......@@ -4456,11 +4576,14 @@ pub const Value = extern union {
44564576 }
44574577 }
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();
44604581 if (float_type.zigTypeTag() == .Vector) {
44614582 const result_data = try arena.alloc(Value, float_type.vectorLen());
44624583 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);
44644587 }
44654588 return Value.Tag.aggregate.create(arena, result_data);
44664589 }
......@@ -4493,11 +4616,14 @@ pub const Value = extern union {
44934616 }
44944617 }
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();
44974621 if (float_type.zigTypeTag() == .Vector) {
44984622 const result_data = try arena.alloc(Value, float_type.vectorLen());
44994623 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);
45014627 }
45024628 return Value.Tag.aggregate.create(arena, result_data);
45034629 }
......@@ -4530,11 +4656,14 @@ pub const Value = extern union {
45304656 }
45314657 }
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();
45344661 if (float_type.zigTypeTag() == .Vector) {
45354662 const result_data = try arena.alloc(Value, float_type.vectorLen());
45364663 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);
45384667 }
45394668 return Value.Tag.aggregate.create(arena, result_data);
45404669 }
......@@ -4567,11 +4696,14 @@ pub const Value = extern union {
45674696 }
45684697 }
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();
45714701 if (float_type.zigTypeTag() == .Vector) {
45724702 const result_data = try arena.alloc(Value, float_type.vectorLen());
45734703 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);
45754707 }
45764708 return Value.Tag.aggregate.create(arena, result_data);
45774709 }
......@@ -4604,11 +4736,14 @@ pub const Value = extern union {
46044736 }
46054737 }
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();
46084741 if (float_type.zigTypeTag() == .Vector) {
46094742 const result_data = try arena.alloc(Value, float_type.vectorLen());
46104743 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);
46124747 }
46134748 return Value.Tag.aggregate.create(arena, result_data);
46144749 }
......@@ -4641,11 +4776,14 @@ pub const Value = extern union {
46414776 }
46424777 }
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();
46454781 if (float_type.zigTypeTag() == .Vector) {
46464782 const result_data = try arena.alloc(Value, float_type.vectorLen());
46474783 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);
46494787 }
46504788 return Value.Tag.aggregate.create(arena, result_data);
46514789 }
......@@ -4678,11 +4816,14 @@ pub const Value = extern union {
46784816 }
46794817 }
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();
46824821 if (float_type.zigTypeTag() == .Vector) {
46834822 const result_data = try arena.alloc(Value, float_type.vectorLen());
46844823 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);
46864827 }
46874828 return Value.Tag.aggregate.create(arena, result_data);
46884829 }
......@@ -4715,11 +4856,14 @@ pub const Value = extern union {
47154856 }
47164857 }
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();
47194861 if (float_type.zigTypeTag() == .Vector) {
47204862 const result_data = try arena.alloc(Value, float_type.vectorLen());
47214863 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);
47234867 }
47244868 return Value.Tag.aggregate.create(arena, result_data);
47254869 }
......@@ -4752,11 +4896,14 @@ pub const Value = extern union {
47524896 }
47534897 }
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();
47564901 if (float_type.zigTypeTag() == .Vector) {
47574902 const result_data = try arena.alloc(Value, float_type.vectorLen());
47584903 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);
47604907 }
47614908 return Value.Tag.aggregate.create(arena, result_data);
47624909 }
......@@ -4789,11 +4936,14 @@ pub const Value = extern union {
47894936 }
47904937 }
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();
47934941 if (float_type.zigTypeTag() == .Vector) {
47944942 const result_data = try arena.alloc(Value, float_type.vectorLen());
47954943 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);
47974947 }
47984948 return Value.Tag.aggregate.create(arena, result_data);
47994949 }
......@@ -4826,11 +4976,14 @@ pub const Value = extern union {
48264976 }
48274977 }
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();
48304981 if (float_type.zigTypeTag() == .Vector) {
48314982 const result_data = try arena.alloc(Value, float_type.vectorLen());
48324983 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);
48344987 }
48354988 return Value.Tag.aggregate.create(arena, result_data);
48364989 }
......@@ -4863,11 +5016,14 @@ pub const Value = extern union {
48635016 }
48645017 }
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();
48675021 if (float_type.zigTypeTag() == .Vector) {
48685022 const result_data = try arena.alloc(Value, float_type.vectorLen());
48695023 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);
48715027 }
48725028 return Value.Tag.aggregate.create(arena, result_data);
48735029 }
......@@ -4900,11 +5056,14 @@ pub const Value = extern union {
49005056 }
49015057 }
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();
49045061 if (float_type.zigTypeTag() == .Vector) {
49055062 const result_data = try arena.alloc(Value, float_type.vectorLen());
49065063 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);
49085067 }
49095068 return Value.Tag.aggregate.create(arena, result_data);
49105069 }
......@@ -4937,11 +5096,14 @@ pub const Value = extern union {
49375096 }
49385097 }
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();
49415101 if (float_type.zigTypeTag() == .Vector) {
49425102 const result_data = try arena.alloc(Value, float_type.vectorLen());
49435103 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);
49455107 }
49465108 return Value.Tag.aggregate.create(arena, result_data);
49475109 }
......@@ -4980,16 +5142,23 @@ pub const Value = extern union {
49805142 mulend2: Value,
49815143 addend: Value,
49825144 arena: Allocator,
4983 target: Target,
4984 ) Allocator.Error!Value {
5145 mod: *Module,
5146 ) !Value {
5147 const target = mod.getTarget();
49855148 if (float_type.zigTypeTag() == .Vector) {
49865149 const result_data = try arena.alloc(Value, float_type.vectorLen());
49875150 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);
49885157 scalar.* = try mulAddScalar(
49895158 float_type.scalarType(),
4990 mulend1.indexVectorlike(i),
4991 mulend2.indexVectorlike(i),
4992 addend.indexVectorlike(i),
5159 mulend1_elem,
5160 mulend2_elem,
5161 addend_elem,
49935162 arena,
49945163 target,
49955164 );