authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-20 23:13:36+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-12-20 23:13:36+02:00
loge1345fd0a05b7dd956f027b6ad7061a9b3a15e26
tree1c859fb01d392fb5769c6ac40972f6243559beaf
parentdc22c3b9a5ef382ed9c7fb4ff503c7d8be187cee
parent9f23702c21645aeddd64bcf203bc8b62a328f75f
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #14004 from Vexu/packed-struct-vector

llvm: handle vectors in packed structs

11 files changed, 556 insertions(+), 253 deletions(-)

src/Compilation.zig+1-1
......@@ -572,7 +572,7 @@ pub const AllErrors = struct {
572572 self.arena.promote(gpa).deinit();
573573 }
574574
575 fn add(
575 pub fn add(
576576 module: *Module,
577577 arena: *std.heap.ArenaAllocator,
578578 errors: *std.ArrayList(Message),
src/Sema.zig+156-105
......@@ -113,6 +113,7 @@ const target_util = @import("target.zig");
113113const Package = @import("Package.zig");
114114const crash_report = @import("crash_report.zig");
115115const build_options = @import("build_options");
116const Compilation = @import("Compilation.zig");
116117
117118pub const default_branch_quota = 1000;
118119pub const default_reference_trace_len = 2;
......@@ -2191,18 +2192,16 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
21912192 @setCold(true);
21922193
21932194 if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) {
2194 const err_path = err_msg.src_loc.file_scope.fullPath(sema.mod.gpa) catch unreachable;
2195 const err_source = err_msg.src_loc.file_scope.getSource(sema.mod.gpa) catch unreachable;
21962195 if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation;
2197 const err_span = err_msg.src_loc.span(sema.mod.gpa) catch unreachable;
2198 const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main);
2199 std.debug.print("compile error during Sema:\n{s}:{d}:{d}: error: {s}\n{s}\n\n", .{
2200 err_path,
2201 err_loc.line + 1,
2202 err_loc.column + 1,
2203 err_msg.msg,
2204 err_loc.source_line,
2205 });
2196 var arena = std.heap.ArenaAllocator.init(sema.gpa);
2197 errdefer arena.deinit();
2198 var errors = std.ArrayList(Compilation.AllErrors.Message).init(sema.gpa);
2199 defer errors.deinit();
2200
2201 Compilation.AllErrors.add(sema.mod, &arena, &errors, err_msg.*) catch unreachable;
2202
2203 std.debug.print("compile error during Sema:\n", .{});
2204 Compilation.AllErrors.Message.renderToStdErr(errors.items[0], .no_color);
22062205 crash_report.compilerPanic("unexpected compile error occurred", null, null);
22072206 }
22082207
......@@ -7257,6 +7256,7 @@ fn instantiateGenericCall(
72577256 child_block.error_return_trace_index = error_return_trace_index;
72587257
72597258 const new_func_inst = child_sema.resolveBody(&child_block, fn_info.param_body, fn_info.param_body_inst) catch |err| {
7259 if (err == error.GenericPoison) return error.GenericPoison;
72607260 // TODO look up the compile error that happened here and attach a note to it
72617261 // pointing here, at the generic instantiation callsite.
72627262 if (sema.owner_func) |owner_func| {
......@@ -8820,7 +8820,9 @@ fn analyzeParameter(
88208820 };
88218821 return sema.failWithOwnedErrorMsg(msg);
88228822 }
8823 if (!this_generic and is_noalias and !param.ty.isPtrAtRuntime()) {
8823 if (!sema.is_generic_instantiation and !this_generic and is_noalias and
8824 !(param.ty.zigTypeTag() == .Pointer or param.ty.isPtrLikeOptional()))
8825 {
88248826 return sema.fail(block, param_src, "non-pointer parameter declared noalias", .{});
88258827 }
88268828}
......@@ -8863,6 +8865,11 @@ fn zirParam(
88638865 };
88648866 switch (err) {
88658867 error.GenericPoison => {
8868 if (sema.inst_map.get(inst)) |_| {
8869 // A generic function is about to evaluate to another generic function.
8870 // Return an error instead.
8871 return error.GenericPoison;
8872 }
88668873 // The type is not available until the generic instantiation.
88678874 // We result the param instruction with a poison value and
88688875 // insert an anytype parameter.
......@@ -8879,6 +8886,11 @@ fn zirParam(
88798886 };
88808887 const is_comptime = sema.typeRequiresComptime(param_ty) catch |err| switch (err) {
88818888 error.GenericPoison => {
8889 if (sema.inst_map.get(inst)) |_| {
8890 // A generic function is about to evaluate to another generic function.
8891 // Return an error instead.
8892 return error.GenericPoison;
8893 }
88828894 // The type is not available until the generic instantiation.
88838895 // We result the param instruction with a poison value and
88848896 // insert an anytype parameter.
......@@ -9223,7 +9235,7 @@ fn intCast(
92239235 // If the destination type is signed, then we need to double its
92249236 // range to account for negative values.
92259237 const dest_range_val = if (wanted_info.signedness == .signed) range_val: {
9226 const range_minus_one = try dest_max_val.shl(Value.one, unsigned_operand_ty, sema.arena, target);
9238 const range_minus_one = try dest_max_val.shl(Value.one, unsigned_operand_ty, sema.arena, sema.mod);
92279239 break :range_val try sema.intAdd(range_minus_one, Value.one, unsigned_operand_ty);
92289240 } else dest_max_val;
92299241 const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val);
......@@ -11681,9 +11693,11 @@ fn zirShl(
1168111693 if (rhs_ty.zigTypeTag() == .Vector) {
1168211694 var i: usize = 0;
1168311695 while (i < rhs_ty.vectorLen()) : (i += 1) {
11684 if (rhs_val.indexVectorlike(i).compareHetero(.gte, bit_value, target)) {
11696 var elem_value_buf: Value.ElemValueBuffer = undefined;
11697 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
11698 if (rhs_elem.compareHetero(.gte, bit_value, target)) {
1168511699 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
11686 rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),
11700 rhs_elem.fmtValue(scalar_ty, sema.mod),
1168711701 i,
1168811702 scalar_ty.fmt(sema.mod),
1168911703 });
......@@ -11699,9 +11713,11 @@ fn zirShl(
1169911713 if (rhs_ty.zigTypeTag() == .Vector) {
1170011714 var i: usize = 0;
1170111715 while (i < rhs_ty.vectorLen()) : (i += 1) {
11702 if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) {
11716 var elem_value_buf: Value.ElemValueBuffer = undefined;
11717 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
11718 if (rhs_elem.compareHetero(.lt, Value.zero, target)) {
1170311719 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
11704 rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),
11720 rhs_elem.fmtValue(scalar_ty, sema.mod),
1170511721 i,
1170611722 });
1170711723 }
......@@ -11724,7 +11740,7 @@ fn zirShl(
1172411740
1172511741 const val = switch (air_tag) {
1172611742 .shl_exact => val: {
11727 const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, target);
11743 const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, sema.mod);
1172811744 if (scalar_ty.zigTypeTag() == .ComptimeInt) {
1172911745 break :val shifted.wrapped_result;
1173011746 }
......@@ -11735,14 +11751,14 @@ fn zirShl(
1173511751 },
1173611752
1173711753 .shl_sat => if (scalar_ty.zigTypeTag() == .ComptimeInt)
11738 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, target)
11754 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, sema.mod)
1173911755 else
11740 try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, target),
11756 try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, sema.mod),
1174111757
1174211758 .shl => if (scalar_ty.zigTypeTag() == .ComptimeInt)
11743 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, target)
11759 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, sema.mod)
1174411760 else
11745 try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, target),
11761 try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, sema.mod),
1174611762
1174711763 else => unreachable,
1174811764 };
......@@ -11865,9 +11881,11 @@ fn zirShr(
1186511881 if (rhs_ty.zigTypeTag() == .Vector) {
1186611882 var i: usize = 0;
1186711883 while (i < rhs_ty.vectorLen()) : (i += 1) {
11868 if (rhs_val.indexVectorlike(i).compareHetero(.gte, bit_value, target)) {
11884 var elem_value_buf: Value.ElemValueBuffer = undefined;
11885 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
11886 if (rhs_elem.compareHetero(.gte, bit_value, target)) {
1186911887 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
11870 rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),
11888 rhs_elem.fmtValue(scalar_ty, sema.mod),
1187111889 i,
1187211890 scalar_ty.fmt(sema.mod),
1187311891 });
......@@ -11883,9 +11901,11 @@ fn zirShr(
1188311901 if (rhs_ty.zigTypeTag() == .Vector) {
1188411902 var i: usize = 0;
1188511903 while (i < rhs_ty.vectorLen()) : (i += 1) {
11886 if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) {
11904 var elem_value_buf: Value.ElemValueBuffer = undefined;
11905 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
11906 if (rhs_elem.compareHetero(.lt, Value.zero, target)) {
1188711907 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
11888 rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod),
11908 rhs_elem.fmtValue(scalar_ty, sema.mod),
1188911909 i,
1189011910 });
1189111911 }
......@@ -11901,12 +11921,12 @@ fn zirShr(
1190111921 }
1190211922 if (air_tag == .shr_exact) {
1190311923 // Detect if any ones would be shifted out.
11904 const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, target);
11924 const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, sema.mod);
1190511925 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) {
1190611926 return sema.fail(block, src, "exact shift shifted out 1 bits", .{});
1190711927 }
1190811928 }
11909 const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, target);
11929 const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, sema.mod);
1191011930 return sema.addConstant(lhs_ty, val);
1191111931 } else {
1191211932 break :rs lhs_src;
......@@ -11990,7 +12010,6 @@ fn zirBitwise(
1199012010 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1199112011
1199212012 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
11993 const target = sema.mod.getTarget();
1199412013
1199512014 if (!is_int) {
1199612015 return sema.fail(block, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) });
......@@ -12002,9 +12021,9 @@ fn zirBitwise(
1200212021 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {
1200312022 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {
1200412023 const result_val = switch (air_tag) {
12005 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, target),
12006 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, target),
12007 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, target),
12024 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, sema.mod),
12025 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, sema.mod),
12026 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, sema.mod),
1200812027 else => unreachable,
1200912028 };
1201012029 return sema.addConstant(resolved_type, result_val);
......@@ -12031,7 +12050,6 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1203112050 const operand = try sema.resolveInst(inst_data.operand);
1203212051 const operand_type = sema.typeOf(operand);
1203312052 const scalar_type = operand_type.scalarType();
12034 const target = sema.mod.getTarget();
1203512053
1203612054 if (scalar_type.zigTypeTag() != .Int) {
1203712055 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{
......@@ -12048,14 +12066,14 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1204812066 const elems = try sema.arena.alloc(Value, vec_len);
1204912067 for (elems) |*elem, i| {
1205012068 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_val_buf);
12051 elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, target);
12069 elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod);
1205212070 }
1205312071 return sema.addConstant(
1205412072 operand_type,
1205512073 try Value.Tag.aggregate.create(sema.arena, elems),
1205612074 );
1205712075 } else {
12058 const result_val = try val.bitwiseNot(operand_type, sema.arena, target);
12076 const result_val = try val.bitwiseNot(operand_type, sema.arena, sema.mod);
1205912077 return sema.addConstant(operand_type, result_val);
1206012078 }
1206112079 }
......@@ -12584,8 +12602,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1258412602 // We handle float negation here to ensure negative zero is represented in the bits.
1258512603 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
1258612604 if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty);
12587 const target = sema.mod.getTarget();
12588 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target));
12605 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, sema.mod));
1258912606 }
1259012607 try sema.requireRuntimeBlock(block, src, null);
1259112608 return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs);
......@@ -12677,7 +12694,6 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1267712694 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div);
1267812695
1267912696 const mod = sema.mod;
12680 const target = mod.getTarget();
1268112697 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1268212698 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1268312699
......@@ -12688,7 +12704,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1268812704 // If lhs % rhs is 0, it doesn't matter.
1268912705 const lhs_val = maybe_lhs_val orelse unreachable;
1269012706 const rhs_val = maybe_rhs_val orelse unreachable;
12691 const rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, target) catch unreachable;
12707 const rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod) catch unreachable;
1269212708 if (!rem.compareAllWithZero(.eq)) {
1269312709 return sema.fail(block, src, "ambiguous coercion of division operands '{s}' and '{s}'; non-zero remainder '{}'", .{
1269412710 @tagName(lhs_ty.tag()), @tagName(rhs_ty.tag()), rem.fmtValue(resolved_type, sema.mod),
......@@ -12764,7 +12780,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1276412780
1276512781 if (maybe_rhs_val) |rhs_val| {
1276612782 if (is_int) {
12767 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
12783 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, mod);
1276812784 var vector_index: usize = undefined;
1276912785 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1277012786 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
......@@ -12773,7 +12789,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1277312789 } else {
1277412790 return sema.addConstant(
1277512791 resolved_type,
12776 try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, target),
12792 try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, mod),
1277712793 );
1277812794 }
1277912795 } else {
......@@ -12837,7 +12853,6 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1283712853 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_exact);
1283812854
1283912855 const mod = sema.mod;
12840 const target = mod.getTarget();
1284112856 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1284212857 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1284312858
......@@ -12882,24 +12897,24 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1288212897 if (maybe_lhs_val) |lhs_val| {
1288312898 if (maybe_rhs_val) |rhs_val| {
1288412899 if (is_int) {
12885 const modulus_val = try lhs_val.intMod(rhs_val, resolved_type, sema.arena, target);
12900 const modulus_val = try lhs_val.intMod(rhs_val, resolved_type, sema.arena, mod);
1288612901 if (!(modulus_val.compareAllWithZero(.eq))) {
1288712902 return sema.fail(block, src, "exact division produced remainder", .{});
1288812903 }
12889 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
12904 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, mod);
1289012905 var vector_index: usize = undefined;
1289112906 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1289212907 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
1289312908 }
1289412909 return sema.addConstant(resolved_type, res);
1289512910 } else {
12896 const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, target);
12911 const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod);
1289712912 if (!(modulus_val.compareAllWithZero(.eq))) {
1289812913 return sema.fail(block, src, "exact division produced remainder", .{});
1289912914 }
1290012915 return sema.addConstant(
1290112916 resolved_type,
12902 try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, target),
12917 try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, mod),
1290312918 );
1290412919 }
1290512920 } else break :rs rhs_src;
......@@ -13002,7 +13017,6 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1300213017 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_floor);
1300313018
1300413019 const mod = sema.mod;
13005 const target = mod.getTarget();
1300613020 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1300713021 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1300813022
......@@ -13062,12 +13076,12 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1306213076 if (is_int) {
1306313077 return sema.addConstant(
1306413078 resolved_type,
13065 try lhs_val.intDivFloor(rhs_val, resolved_type, sema.arena, target),
13079 try lhs_val.intDivFloor(rhs_val, resolved_type, sema.arena, mod),
1306613080 );
1306713081 } else {
1306813082 return sema.addConstant(
1306913083 resolved_type,
13070 try lhs_val.floatDivFloor(rhs_val, resolved_type, sema.arena, target),
13084 try lhs_val.floatDivFloor(rhs_val, resolved_type, sema.arena, mod),
1307113085 );
1307213086 }
1307313087 } else break :rs rhs_src;
......@@ -13119,7 +13133,6 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1311913133 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_trunc);
1312013134
1312113135 const mod = sema.mod;
13122 const target = mod.getTarget();
1312313136 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1312413137 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1312513138
......@@ -13176,7 +13189,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1317613189
1317713190 if (maybe_rhs_val) |rhs_val| {
1317813191 if (is_int) {
13179 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
13192 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, mod);
1318013193 var vector_index: usize = undefined;
1318113194 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1318213195 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
......@@ -13185,7 +13198,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1318513198 } else {
1318613199 return sema.addConstant(
1318713200 resolved_type,
13188 try lhs_val.floatDivTrunc(rhs_val, resolved_type, sema.arena, target),
13201 try lhs_val.floatDivTrunc(rhs_val, resolved_type, sema.arena, mod),
1318913202 );
1319013203 }
1319113204 } else break :rs rhs_src;
......@@ -13363,7 +13376,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1336313376 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod_rem);
1336413377
1336513378 const mod = sema.mod;
13366 const target = mod.getTarget();
1336713379 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1336813380 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1336913381
......@@ -13440,7 +13452,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1344013452 }
1344113453 return sema.addConstant(
1344213454 resolved_type,
13443 try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, target),
13455 try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod),
1344413456 );
1344513457 } else {
1344613458 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
......@@ -13469,7 +13481,11 @@ fn intRem(
1346913481 if (ty.zigTypeTag() == .Vector) {
1347013482 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
1347113483 for (result_data) |*scalar, i| {
13472 scalar.* = try sema.intRemScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));
13484 var lhs_buf: Value.ElemValueBuffer = undefined;
13485 var rhs_buf: Value.ElemValueBuffer = undefined;
13486 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
13487 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
13488 scalar.* = try sema.intRemScalar(lhs_elem, rhs_elem);
1347313489 }
1347413490 return Value.Tag.aggregate.create(sema.arena, result_data);
1347513491 }
......@@ -13539,7 +13555,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1353913555 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod);
1354013556
1354113557 const mod = sema.mod;
13542 const target = mod.getTarget();
1354313558 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1354413559 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1354513560
......@@ -13571,7 +13586,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1357113586 if (maybe_lhs_val) |lhs_val| {
1357213587 return sema.addConstant(
1357313588 resolved_type,
13574 try lhs_val.intMod(rhs_val, resolved_type, sema.arena, target),
13589 try lhs_val.intMod(rhs_val, resolved_type, sema.arena, mod),
1357513590 );
1357613591 }
1357713592 break :rs lhs_src;
......@@ -13595,7 +13610,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1359513610 if (maybe_rhs_val) |rhs_val| {
1359613611 return sema.addConstant(
1359713612 resolved_type,
13598 try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, target),
13613 try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, mod),
1359913614 );
1360013615 } else break :rs rhs_src;
1360113616 } else break :rs lhs_src;
......@@ -13642,7 +13657,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1364213657 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .rem);
1364313658
1364413659 const mod = sema.mod;
13645 const target = mod.getTarget();
1364613660 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1364713661 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1364813662
......@@ -13698,7 +13712,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1369813712 if (maybe_rhs_val) |rhs_val| {
1369913713 return sema.addConstant(
1370013714 resolved_type,
13701 try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, target),
13715 try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, mod),
1370213716 );
1370313717 } else break :rs rhs_src;
1370413718 } else break :rs lhs_src;
......@@ -13737,7 +13751,6 @@ fn zirOverflowArithmetic(
1373713751 const lhs_ty = sema.typeOf(lhs);
1373813752 const rhs_ty = sema.typeOf(rhs);
1373913753 const mod = sema.mod;
13740 const target = mod.getTarget();
1374113754
1374213755 // Note, the types of lhs/rhs (also for shifting)/ptr are already correct as ensured by astgen.
1374313756 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
......@@ -13837,7 +13850,7 @@ fn zirOverflowArithmetic(
1383713850 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
1383813851 }
1383913852
13840 const result = try lhs_val.intMulWithOverflow(rhs_val, dest_ty, sema.arena, target);
13853 const result = try lhs_val.intMulWithOverflow(rhs_val, dest_ty, sema.arena, mod);
1384113854 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);
1384213855 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);
1384313856 break :result .{ .overflowed = overflowed, .wrapped = wrapped };
......@@ -13864,7 +13877,7 @@ fn zirOverflowArithmetic(
1386413877 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
1386513878 }
1386613879
13867 const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, target);
13880 const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, sema.mod);
1386813881 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);
1386913882 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);
1387013883 break :result .{ .overflowed = overflowed, .wrapped = wrapped };
......@@ -13977,13 +13990,12 @@ fn analyzeArithmetic(
1397713990 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, zir_tag);
1397813991
1397913992 const mod = sema.mod;
13980 const target = mod.getTarget();
1398113993 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
1398213994 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1398313995 const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: {
1398413996 switch (zir_tag) {
1398513997 .add => {
13986 // For integers:
13998 // For integers:intAddSat
1398713999 // If either of the operands are zero, then the other operand is
1398814000 // returned, even if it is undefined.
1398914001 // If either of the operands are undefined, it's a compile error
......@@ -14078,7 +14090,7 @@ fn analyzeArithmetic(
1407814090 const val = if (scalar_tag == .ComptimeInt)
1407914091 try sema.intAdd(lhs_val, rhs_val, resolved_type)
1408014092 else
14081 try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, target);
14093 try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, mod);
1408214094
1408314095 return sema.addConstant(resolved_type, val);
1408414096 } else break :rs .{ .src = lhs_src, .air_tag = .add_sat };
......@@ -14175,7 +14187,7 @@ fn analyzeArithmetic(
1417514187 const val = if (scalar_tag == .ComptimeInt)
1417614188 try sema.intSub(lhs_val, rhs_val, resolved_type)
1417714189 else
14178 try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, target);
14190 try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, mod);
1417914191
1418014192 return sema.addConstant(resolved_type, val);
1418114193 } else break :rs .{ .src = rhs_src, .air_tag = .sub_sat };
......@@ -14256,7 +14268,7 @@ fn analyzeArithmetic(
1425614268 }
1425714269 }
1425814270 if (is_int) {
14259 const product = try lhs_val.intMul(rhs_val, resolved_type, sema.arena, target);
14271 const product = try lhs_val.intMul(rhs_val, resolved_type, sema.arena, sema.mod);
1426014272 var vector_index: usize = undefined;
1426114273 if (!(try sema.intFitsInType(product, resolved_type, &vector_index))) {
1426214274 return sema.failWithIntegerOverflow(block, src, resolved_type, product, vector_index);
......@@ -14265,7 +14277,7 @@ fn analyzeArithmetic(
1426514277 } else {
1426614278 return sema.addConstant(
1426714279 resolved_type,
14268 try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, target),
14280 try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, sema.mod),
1426914281 );
1427014282 }
1427114283 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
......@@ -14309,7 +14321,7 @@ fn analyzeArithmetic(
1430914321 }
1431014322 return sema.addConstant(
1431114323 resolved_type,
14312 try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, target),
14324 try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, sema.mod),
1431314325 );
1431414326 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
1431514327 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
......@@ -14351,9 +14363,9 @@ fn analyzeArithmetic(
1435114363 }
1435214364
1435314365 const val = if (scalar_tag == .ComptimeInt)
14354 try lhs_val.intMul(rhs_val, resolved_type, sema.arena, target)
14366 try lhs_val.intMul(rhs_val, resolved_type, sema.arena, sema.mod)
1435514367 else
14356 try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, target);
14368 try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, sema.mod);
1435714369
1435814370 return sema.addConstant(resolved_type, val);
1435914371 } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat };
......@@ -17945,7 +17957,7 @@ fn zirUnaryMath(
1794517957 block: *Block,
1794617958 inst: Zir.Inst.Index,
1794717959 air_tag: Air.Inst.Tag,
17948 comptime eval: fn (Value, Type, Allocator, std.Target) Allocator.Error!Value,
17960 comptime eval: fn (Value, Type, Allocator, *Module) Allocator.Error!Value,
1794917961) CompileError!Air.Inst.Ref {
1795017962 const tracy = trace(@src());
1795117963 defer tracy.end();
......@@ -17954,7 +17966,6 @@ fn zirUnaryMath(
1795417966 const operand = try sema.resolveInst(inst_data.operand);
1795517967 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1795617968 const operand_ty = sema.typeOf(operand);
17957 const target = sema.mod.getTarget();
1795817969
1795917970 switch (operand_ty.zigTypeTag()) {
1796017971 .ComptimeFloat, .Float => {},
......@@ -17981,7 +17992,7 @@ fn zirUnaryMath(
1798117992 const elems = try sema.arena.alloc(Value, vec_len);
1798217993 for (elems) |*elem, i| {
1798317994 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
17984 elem.* = try eval(elem_val, scalar_ty, sema.arena, target);
17995 elem.* = try eval(elem_val, scalar_ty, sema.arena, sema.mod);
1798517996 }
1798617997 return sema.addConstant(
1798717998 result_ty,
......@@ -17996,7 +18007,7 @@ fn zirUnaryMath(
1799618007 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
1799718008 if (operand_val.isUndef())
1799818009 return sema.addConstUndef(operand_ty);
17999 const result_val = try eval(operand_val, operand_ty, sema.arena, target);
18010 const result_val = try eval(operand_val, operand_ty, sema.arena, sema.mod);
1800018011 return sema.addConstant(operand_ty, result_val);
1800118012 }
1800218013
......@@ -19218,8 +19229,7 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1921819229 _ = try sema.checkIntType(block, operand_src, operand_ty);
1921919230
1922019231 if (try sema.resolveMaybeUndefVal(operand)) |val| {
19221 const target = sema.mod.getTarget();
19222 const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, target, sema);
19232 const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, sema.mod, sema);
1922319233 return sema.addConstant(dest_ty, result_val);
1922419234 } else if (dest_ty.zigTypeTag() == .ComptimeFloat) {
1922519235 return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known");
......@@ -19545,14 +19555,14 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1954519555 if (!is_vector) {
1954619556 return sema.addConstant(
1954719557 dest_ty,
19548 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, target),
19558 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod),
1954919559 );
1955019560 }
1955119561 var elem_buf: Value.ElemValueBuffer = undefined;
1955219562 const elems = try sema.arena.alloc(Value, operand_ty.vectorLen());
1955319563 for (elems) |*elem, i| {
1955419564 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
19555 elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, target);
19565 elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod);
1955619566 }
1955719567 return sema.addConstant(
1955819568 dest_ty,
......@@ -20521,13 +20531,13 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2052120531 while (i < vec_len) : (i += 1) {
2052220532 const elem_val = operand_val.elemValueBuffer(sema.mod, i, &elem_buf);
2052320533 switch (operation) {
20524 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, target),
20525 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, target),
20526 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, target),
20534 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, sema.mod),
20535 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, sema.mod),
20536 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, sema.mod),
2052720537 .Min => accum = accum.numberMin(elem_val, target),
2052820538 .Max => accum = accum.numberMax(elem_val, target),
2052920539 .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty),
20530 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, target),
20540 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, sema.mod),
2053120541 }
2053220542 }
2053320543 return sema.addConstant(scalar_ty, accum);
......@@ -20923,10 +20933,10 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2092320933 .Xchg => operand_val,
2092420934 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),
2092520935 .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty),
20926 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, target),
20927 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, target),
20928 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, target),
20929 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, target),
20936 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, sema.mod),
20937 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, sema.mod),
20938 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, sema.mod),
20939 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, sema.mod),
2093020940 .Max => stored_val.numberMax (operand_val, target),
2093120941 .Min => stored_val.numberMin (operand_val, target),
2093220942 // zig fmt: on
......@@ -20999,8 +21009,6 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2099921009 const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src);
2100021010 const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src);
2100121011
21002 const target = sema.mod.getTarget();
21003
2100421012 const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1);
2100521013 const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2);
2100621014 const maybe_addend = try sema.resolveMaybeUndefVal(addend);
......@@ -21016,7 +21024,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2101621024
2101721025 if (maybe_addend) |addend_val| {
2101821026 if (addend_val.isUndef()) return sema.addConstUndef(ty);
21019 const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, target);
21027 const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, sema.mod);
2102021028 return sema.addConstant(ty, result_val);
2102121029 } else {
2102221030 break :rs addend_src;
......@@ -24618,8 +24626,9 @@ fn coerceExtra(
2461824626 else => break :p,
2461924627 }
2462024628 if (inst_info.size == .Slice) {
24621 if (dest_info.sentinel == null or inst_info.sentinel == null or
24622 !dest_info.sentinel.?.eql(inst_info.sentinel.?, dest_info.pointee_type, sema.mod))
24629 assert(dest_info.sentinel == null);
24630 if (inst_info.sentinel == null or
24631 !inst_info.sentinel.?.eql(Value.zero, dest_info.pointee_type, sema.mod))
2462324632 break :p;
2462424633
2462524634 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
......@@ -24828,7 +24837,7 @@ fn coerceExtra(
2482824837 }
2482924838 break :int;
2483024839 };
24831 const result_val = try val.intToFloatAdvanced(sema.arena, inst_ty, dest_ty, target, sema);
24840 const result_val = try val.intToFloatAdvanced(sema.arena, inst_ty, dest_ty, sema.mod, sema);
2483224841 // TODO implement this compile error
2483324842 //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty);
2483424843 //if (!int_again_val.eql(val, inst_ty, mod)) {
......@@ -32261,7 +32270,11 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
3226132270 if (ty.zigTypeTag() == .Vector) {
3226232271 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3226332272 for (result_data) |*scalar, i| {
32264 scalar.* = try sema.intAddScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));
32273 var lhs_buf: Value.ElemValueBuffer = undefined;
32274 var rhs_buf: Value.ElemValueBuffer = undefined;
32275 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32276 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32277 scalar.* = try sema.intAddScalar(lhs_elem, rhs_elem);
3226532278 }
3226632279 return Value.Tag.aggregate.create(sema.arena, result_data);
3226732280 }
......@@ -32295,7 +32308,11 @@ fn numberAddWrap(
3229532308 if (ty.zigTypeTag() == .Vector) {
3229632309 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3229732310 for (result_data) |*scalar, i| {
32298 scalar.* = try sema.numberAddWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
32311 var lhs_buf: Value.ElemValueBuffer = undefined;
32312 var rhs_buf: Value.ElemValueBuffer = undefined;
32313 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32314 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32315 scalar.* = try sema.numberAddWrapScalar(lhs_elem, rhs_elem, ty.scalarType());
3229932316 }
3230032317 return Value.Tag.aggregate.create(sema.arena, result_data);
3230132318 }
......@@ -32332,7 +32349,11 @@ fn intSub(
3233232349 if (ty.zigTypeTag() == .Vector) {
3233332350 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3233432351 for (result_data) |*scalar, i| {
32335 scalar.* = try sema.intSubScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));
32352 var lhs_buf: Value.ElemValueBuffer = undefined;
32353 var rhs_buf: Value.ElemValueBuffer = undefined;
32354 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32355 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32356 scalar.* = try sema.intSubScalar(lhs_elem, rhs_elem);
3233632357 }
3233732358 return Value.Tag.aggregate.create(sema.arena, result_data);
3233832359 }
......@@ -32366,7 +32387,11 @@ fn numberSubWrap(
3236632387 if (ty.zigTypeTag() == .Vector) {
3236732388 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3236832389 for (result_data) |*scalar, i| {
32369 scalar.* = try sema.numberSubWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
32390 var lhs_buf: Value.ElemValueBuffer = undefined;
32391 var rhs_buf: Value.ElemValueBuffer = undefined;
32392 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32393 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32394 scalar.* = try sema.numberSubWrapScalar(lhs_elem, rhs_elem, ty.scalarType());
3237032395 }
3237132396 return Value.Tag.aggregate.create(sema.arena, result_data);
3237232397 }
......@@ -32403,7 +32428,11 @@ fn floatAdd(
3240332428 if (float_type.zigTypeTag() == .Vector) {
3240432429 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());
3240532430 for (result_data) |*scalar, i| {
32406 scalar.* = try sema.floatAddScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType());
32431 var lhs_buf: Value.ElemValueBuffer = undefined;
32432 var rhs_buf: Value.ElemValueBuffer = undefined;
32433 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32434 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32435 scalar.* = try sema.floatAddScalar(lhs_elem, rhs_elem, float_type.scalarType());
3240732436 }
3240832437 return Value.Tag.aggregate.create(sema.arena, result_data);
3240932438 }
......@@ -32456,7 +32485,11 @@ fn floatSub(
3245632485 if (float_type.zigTypeTag() == .Vector) {
3245732486 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());
3245832487 for (result_data) |*scalar, i| {
32459 scalar.* = try sema.floatSubScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType());
32488 var lhs_buf: Value.ElemValueBuffer = undefined;
32489 var rhs_buf: Value.ElemValueBuffer = undefined;
32490 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32491 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32492 scalar.* = try sema.floatSubScalar(lhs_elem, rhs_elem, float_type.scalarType());
3246032493 }
3246132494 return Value.Tag.aggregate.create(sema.arena, result_data);
3246232495 }
......@@ -32510,7 +32543,11 @@ fn intSubWithOverflow(
3251032543 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
3251132544 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3251232545 for (result_data) |*scalar, i| {
32513 const of_math_result = try sema.intSubWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
32546 var lhs_buf: Value.ElemValueBuffer = undefined;
32547 var rhs_buf: Value.ElemValueBuffer = undefined;
32548 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32549 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32550 const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType());
3251432551 overflowed_data[i] = of_math_result.overflowed;
3251532552 scalar.* = of_math_result.wrapped_result;
3251632553 }
......@@ -32560,7 +32597,9 @@ fn floatToInt(
3256032597 const elem_ty = float_ty.childType();
3256132598 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen());
3256232599 for (result_data) |*scalar, i| {
32563 scalar.* = try sema.floatToIntScalar(block, src, val.indexVectorlike(i), elem_ty, int_ty.scalarType());
32600 var buf: Value.ElemValueBuffer = undefined;
32601 const elem_val = val.elemValueBuffer(sema.mod, i, &buf);
32602 scalar.* = try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType());
3256432603 }
3256532604 return Value.Tag.aggregate.create(sema.arena, result_data);
3256632605 }
......@@ -32855,7 +32894,11 @@ fn intAddWithOverflow(
3285532894 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
3285632895 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3285732896 for (result_data) |*scalar, i| {
32858 const of_math_result = try sema.intAddWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
32897 var lhs_buf: Value.ElemValueBuffer = undefined;
32898 var rhs_buf: Value.ElemValueBuffer = undefined;
32899 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32900 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32901 const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType());
3285932902 overflowed_data[i] = of_math_result.overflowed;
3286032903 scalar.* = of_math_result.wrapped_result;
3286132904 }
......@@ -32907,7 +32950,11 @@ fn compareAll(
3290732950 if (ty.zigTypeTag() == .Vector) {
3290832951 var i: usize = 0;
3290932952 while (i < ty.vectorLen()) : (i += 1) {
32910 if (!(try sema.compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType()))) {
32953 var lhs_buf: Value.ElemValueBuffer = undefined;
32954 var rhs_buf: Value.ElemValueBuffer = undefined;
32955 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
32956 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
32957 if (!(try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType()))) {
3291132958 return false;
3291232959 }
3291332960 }
......@@ -32951,7 +32998,11 @@ fn compareVector(
3295132998 assert(ty.zigTypeTag() == .Vector);
3295232999 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3295333000 for (result_data) |*scalar, i| {
32954 const res_bool = try sema.compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType());
33001 var lhs_buf: Value.ElemValueBuffer = undefined;
33002 var rhs_buf: Value.ElemValueBuffer = undefined;
33003 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
33004 const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf);
33005 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType());
3295533006 scalar.* = Value.makeBool(res_bool);
3295633007 }
3295733008 return Value.Tag.aggregate.create(sema.arena, result_data);
src/arch/x86_64/abi.zig+2-1
......@@ -143,7 +143,8 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class {
143143 .integer, .integer, .integer, .integer,
144144 .integer, .integer, .integer, .integer,
145145 };
146 if (has_avx512 and bit_size <= 256) return .{
146 const has_avx = target.cpu.features.isEnabled(@enumToInt(std.Target.x86.Feature.avx));
147 if (has_avx and bit_size <= 256) return .{
147148 .integer, .integer, .integer, .integer,
148149 .none, .none, .none, .none,
149150 };
src/codegen/llvm.zig+3-3
......@@ -5973,7 +5973,7 @@ pub const FuncGen = struct {
59735973 const shift_amt = containing_int.typeOf().constInt(bit_offset, .False);
59745974 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");
59755975 const elem_llvm_ty = try self.dg.lowerType(field_ty);
5976 if (field_ty.zigTypeTag() == .Float) {
5976 if (field_ty.zigTypeTag() == .Float or field_ty.zigTypeTag() == .Vector) {
59775977 const elem_bits = @intCast(c_uint, field_ty.bitSize(target));
59785978 const same_size_int = self.context.intType(elem_bits);
59795979 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
......@@ -5996,7 +5996,7 @@ pub const FuncGen = struct {
59965996 assert(struct_ty.containerLayout() == .Packed);
59975997 const containing_int = struct_llvm_val;
59985998 const elem_llvm_ty = try self.dg.lowerType(field_ty);
5999 if (field_ty.zigTypeTag() == .Float) {
5999 if (field_ty.zigTypeTag() == .Float or field_ty.zigTypeTag() == .Vector) {
60006000 const elem_bits = @intCast(c_uint, field_ty.bitSize(target));
60016001 const same_size_int = self.context.intType(elem_bits);
60026002 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");
......@@ -9896,7 +9896,7 @@ pub const FuncGen = struct {
98969896 return result_ptr;
98979897 }
98989898
9899 if (info.pointee_type.zigTypeTag() == .Float) {
9899 if (info.pointee_type.zigTypeTag() == .Float or info.pointee_type.zigTypeTag() == .Vector) {
99009900 const same_size_int = self.context.intType(elem_bits);
99019901 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
99029902 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");
src/value.zig+311-140
......@@ -1072,11 +1072,13 @@ pub const Value = extern union {
10721072 .enum_simple => Module.EnumFull.ValueMap{},
10731073 else => unreachable,
10741074 };
1075 break :field_index if (values.entries.len == 0)
1075 if (values.entries.len == 0) {
10761076 // auto-numbered enum
1077 @intCast(u32, val.toUnsignedInt(mod.getTarget()))
1078 else
1079 @intCast(u32, values.getIndexContext(val, .{ .ty = ty, .mod = mod }).?);
1077 break :field_index @intCast(u32, val.toUnsignedInt(mod.getTarget()));
1078 }
1079 var buffer: Type.Payload.Bits = undefined;
1080 const int_tag_ty = ty.intTagType(&buffer);
1081 break :field_index @intCast(u32, values.getIndexContext(val, .{ .ty = int_tag_ty, .mod = mod }).?);
10801082 },
10811083 };
10821084
......@@ -2042,7 +2044,11 @@ pub const Value = extern union {
20422044 if (ty.zigTypeTag() == .Vector) {
20432045 var i: usize = 0;
20442046 while (i < ty.vectorLen()) : (i += 1) {
2045 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)) {
20462052 return false;
20472053 }
20482054 }
......@@ -2791,27 +2797,6 @@ pub const Value = extern union {
27912797 };
27922798 }
27932799
2794 /// Index into a vector-like `Value`. Asserts `index` is a valid index for `val`.
2795 /// Some scalar values are considered vector-like to avoid needing to allocate
2796 /// a new `repeated` each time a constant is used.
2797 pub fn indexVectorlike(val: Value, index: usize) Value {
2798 return switch (val.tag()) {
2799 .aggregate => val.castTag(.aggregate).?.data[index],
2800
2801 .repeated => val.castTag(.repeated).?.data,
2802 // These values will implicitly be treated as `repeated`.
2803 .zero,
2804 .one,
2805 .bool_false,
2806 .bool_true,
2807 .int_i64,
2808 .int_u64,
2809 => val,
2810
2811 else => unreachable,
2812 };
2813 }
2814
28152800 /// Asserts the value is a single-item pointer to an array, or an array,
28162801 /// or an unknown-length pointer, and returns the element value at the index.
28172802 pub fn elemValue(val: Value, mod: *Module, arena: Allocator, index: usize) !Value {
......@@ -2887,18 +2872,21 @@ pub const Value = extern union {
28872872 // to have only one possible value itself.
28882873 .the_only_possible_value => return val,
28892874
2890 // pointer to integer casted to pointer of array
2891 .int_u64, .int_i64 => {
2892 assert(index == 0);
2893 return val;
2894 },
2895
28962875 .opt_payload_ptr => return val.castTag(.opt_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),
28972876 .eu_payload_ptr => return val.castTag(.eu_payload_ptr).?.data.container_ptr.elemValueAdvanced(mod, index, arena, buffer),
28982877
28992878 .opt_payload => return val.castTag(.opt_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),
29002879 .eu_payload => return val.castTag(.eu_payload).?.data.elemValueAdvanced(mod, index, arena, buffer),
29012880
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
29022890 else => unreachable,
29032891 }
29042892 }
......@@ -3178,18 +3166,21 @@ pub const Value = extern union {
31783166 };
31793167 }
31803168
3181 pub fn intToFloat(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, target: Target) !Value {
3182 return intToFloatAdvanced(val, arena, int_ty, float_ty, target, null) catch |err| switch (err) {
3169 pub fn intToFloat(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module) !Value {
3170 return intToFloatAdvanced(val, arena, int_ty, float_ty, mod, null) catch |err| switch (err) {
31833171 error.OutOfMemory => return error.OutOfMemory,
31843172 else => unreachable,
31853173 };
31863174 }
31873175
3188 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, target: Target, opt_sema: ?*Sema) !Value {
3176 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
3177 const target = mod.getTarget();
31893178 if (int_ty.zigTypeTag() == .Vector) {
31903179 const result_data = try arena.alloc(Value, int_ty.vectorLen());
31913180 for (result_data) |*scalar, i| {
3192 scalar.* = try intToFloatScalar(val.indexVectorlike(i), arena, float_ty.scalarType(), target, opt_sema);
3181 var buf: Value.ElemValueBuffer = undefined;
3182 const elem_val = val.elemValueBuffer(mod, i, &buf);
3183 scalar.* = try intToFloatScalar(elem_val, arena, float_ty.scalarType(), target, opt_sema);
31933184 }
31943185 return Value.Tag.aggregate.create(arena, result_data);
31953186 }
......@@ -3295,12 +3286,17 @@ pub const Value = extern union {
32953286 rhs: Value,
32963287 ty: Type,
32973288 arena: Allocator,
3298 target: Target,
3289 mod: *Module,
32993290 ) !Value {
3291 const target = mod.getTarget();
33003292 if (ty.zigTypeTag() == .Vector) {
33013293 const result_data = try arena.alloc(Value, ty.vectorLen());
33023294 for (result_data) |*scalar, i| {
3303 scalar.* = try intAddSatScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);
3295 var lhs_buf: Value.ElemValueBuffer = undefined;
3296 var rhs_buf: Value.ElemValueBuffer = undefined;
3297 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3298 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3299 scalar.* = try intAddSatScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
33043300 }
33053301 return Value.Tag.aggregate.create(arena, result_data);
33063302 }
......@@ -3339,12 +3335,17 @@ pub const Value = extern union {
33393335 rhs: Value,
33403336 ty: Type,
33413337 arena: Allocator,
3342 target: Target,
3338 mod: *Module,
33433339 ) !Value {
3340 const target = mod.getTarget();
33443341 if (ty.zigTypeTag() == .Vector) {
33453342 const result_data = try arena.alloc(Value, ty.vectorLen());
33463343 for (result_data) |*scalar, i| {
3347 scalar.* = try intSubSatScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);
3344 var lhs_buf: Value.ElemValueBuffer = undefined;
3345 var rhs_buf: Value.ElemValueBuffer = undefined;
3346 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3347 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3348 scalar.* = try intSubSatScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
33483349 }
33493350 return Value.Tag.aggregate.create(arena, result_data);
33503351 }
......@@ -3382,13 +3383,18 @@ pub const Value = extern union {
33823383 rhs: Value,
33833384 ty: Type,
33843385 arena: Allocator,
3385 target: Target,
3386 mod: *Module,
33863387 ) !OverflowArithmeticResult {
3388 const target = mod.getTarget();
33873389 if (ty.zigTypeTag() == .Vector) {
33883390 const overflowed_data = try arena.alloc(Value, ty.vectorLen());
33893391 const result_data = try arena.alloc(Value, ty.vectorLen());
33903392 for (result_data) |*scalar, i| {
3391 const of_math_result = try intMulWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);
3393 var lhs_buf: Value.ElemValueBuffer = undefined;
3394 var rhs_buf: Value.ElemValueBuffer = undefined;
3395 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3396 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3397 const of_math_result = try intMulWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
33923398 overflowed_data[i] = of_math_result.overflowed;
33933399 scalar.* = of_math_result.wrapped_result;
33943400 }
......@@ -3441,16 +3447,20 @@ pub const Value = extern union {
34413447 rhs: Value,
34423448 ty: Type,
34433449 arena: Allocator,
3444 target: Target,
3450 mod: *Module,
34453451 ) !Value {
34463452 if (ty.zigTypeTag() == .Vector) {
34473453 const result_data = try arena.alloc(Value, ty.vectorLen());
34483454 for (result_data) |*scalar, i| {
3449 scalar.* = try numberMulWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);
3455 var lhs_buf: Value.ElemValueBuffer = undefined;
3456 var rhs_buf: Value.ElemValueBuffer = undefined;
3457 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3458 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3459 scalar.* = try numberMulWrapScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, mod);
34503460 }
34513461 return Value.Tag.aggregate.create(arena, result_data);
34523462 }
3453 return numberMulWrapScalar(lhs, rhs, ty, arena, target);
3463 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);
34543464 }
34553465
34563466 /// Supports both floats and ints; handles undefined.
......@@ -3459,19 +3469,19 @@ pub const Value = extern union {
34593469 rhs: Value,
34603470 ty: Type,
34613471 arena: Allocator,
3462 target: Target,
3472 mod: *Module,
34633473 ) !Value {
34643474 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);
34653475
34663476 if (ty.zigTypeTag() == .ComptimeInt) {
3467 return intMul(lhs, rhs, ty, arena, target);
3477 return intMul(lhs, rhs, ty, arena, mod);
34683478 }
34693479
34703480 if (ty.isAnyFloat()) {
3471 return floatMul(lhs, rhs, ty, arena, target);
3481 return floatMul(lhs, rhs, ty, arena, mod);
34723482 }
34733483
3474 const overflow_result = try intMulWithOverflow(lhs, rhs, ty, arena, target);
3484 const overflow_result = try intMulWithOverflow(lhs, rhs, ty, arena, mod);
34753485 return overflow_result.wrapped_result;
34763486 }
34773487
......@@ -3481,12 +3491,17 @@ pub const Value = extern union {
34813491 rhs: Value,
34823492 ty: Type,
34833493 arena: Allocator,
3484 target: Target,
3494 mod: *Module,
34853495 ) !Value {
3496 const target = mod.getTarget();
34863497 if (ty.zigTypeTag() == .Vector) {
34873498 const result_data = try arena.alloc(Value, ty.vectorLen());
34883499 for (result_data) |*scalar, i| {
3489 scalar.* = try intMulSatScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);
3500 var lhs_buf: Value.ElemValueBuffer = undefined;
3501 var rhs_buf: Value.ElemValueBuffer = undefined;
3502 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3503 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3504 scalar.* = try intMulSatScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
34903505 }
34913506 return Value.Tag.aggregate.create(arena, result_data);
34923507 }
......@@ -3553,11 +3568,14 @@ pub const Value = extern union {
35533568 }
35543569
35553570 /// operands must be (vectors of) integers; handles undefined scalars.
3556 pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, target: Target) !Value {
3571 pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
3572 const target = mod.getTarget();
35573573 if (ty.zigTypeTag() == .Vector) {
35583574 const result_data = try arena.alloc(Value, ty.vectorLen());
35593575 for (result_data) |*scalar, i| {
3560 scalar.* = try bitwiseNotScalar(val.indexVectorlike(i), ty.scalarType(), arena, target);
3576 var buf: Value.ElemValueBuffer = undefined;
3577 const elem_val = val.elemValueBuffer(mod, i, &buf);
3578 scalar.* = try bitwiseNotScalar(elem_val, ty.scalarType(), arena, target);
35613579 }
35623580 return Value.Tag.aggregate.create(arena, result_data);
35633581 }
......@@ -3589,11 +3607,16 @@ pub const Value = extern union {
35893607 }
35903608
35913609 /// operands must be (vectors of) integers; handles undefined scalars.
3592 pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
3610 pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3611 const target = mod.getTarget();
35933612 if (ty.zigTypeTag() == .Vector) {
35943613 const result_data = try allocator.alloc(Value, ty.vectorLen());
35953614 for (result_data) |*scalar, i| {
3596 scalar.* = try bitwiseAndScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
3615 var lhs_buf: Value.ElemValueBuffer = undefined;
3616 var rhs_buf: Value.ElemValueBuffer = undefined;
3617 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3618 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3619 scalar.* = try bitwiseAndScalar(lhs_elem, rhs_elem, allocator, target);
35973620 }
35983621 return Value.Tag.aggregate.create(allocator, result_data);
35993622 }
......@@ -3621,37 +3644,46 @@ pub const Value = extern union {
36213644 }
36223645
36233646 /// operands must be (vectors of) integers; handles undefined scalars.
3624 pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, target: Target) !Value {
3647 pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
36253648 if (ty.zigTypeTag() == .Vector) {
36263649 const result_data = try arena.alloc(Value, ty.vectorLen());
36273650 for (result_data) |*scalar, i| {
3628 scalar.* = try bitwiseNandScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);
3651 var lhs_buf: Value.ElemValueBuffer = undefined;
3652 var rhs_buf: Value.ElemValueBuffer = undefined;
3653 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3654 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3655 scalar.* = try bitwiseNandScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, mod);
36293656 }
36303657 return Value.Tag.aggregate.create(arena, result_data);
36313658 }
3632 return bitwiseNandScalar(lhs, rhs, ty, arena, target);
3659 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);
36333660 }
36343661
36353662 /// operands must be integers; handles undefined.
3636 pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, target: Target) !Value {
3663 pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
36373664 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);
36383665
3639 const anded = try bitwiseAnd(lhs, rhs, ty, arena, target);
3666 const anded = try bitwiseAnd(lhs, rhs, ty, arena, mod);
36403667
36413668 const all_ones = if (ty.isSignedInt())
36423669 try Value.Tag.int_i64.create(arena, -1)
36433670 else
3644 try ty.maxInt(arena, target);
3671 try ty.maxInt(arena, mod.getTarget());
36453672
3646 return bitwiseXor(anded, all_ones, ty, arena, target);
3673 return bitwiseXor(anded, all_ones, ty, arena, mod);
36473674 }
36483675
36493676 /// operands must be (vectors of) integers; handles undefined scalars.
3650 pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
3677 pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3678 const target = mod.getTarget();
36513679 if (ty.zigTypeTag() == .Vector) {
36523680 const result_data = try allocator.alloc(Value, ty.vectorLen());
36533681 for (result_data) |*scalar, i| {
3654 scalar.* = try bitwiseOrScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
3682 var lhs_buf: Value.ElemValueBuffer = undefined;
3683 var rhs_buf: Value.ElemValueBuffer = undefined;
3684 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3685 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3686 scalar.* = try bitwiseOrScalar(lhs_elem, rhs_elem, allocator, target);
36553687 }
36563688 return Value.Tag.aggregate.create(allocator, result_data);
36573689 }
......@@ -3678,11 +3710,16 @@ pub const Value = extern union {
36783710 }
36793711
36803712 /// operands must be (vectors of) integers; handles undefined scalars.
3681 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
3713 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3714 const target = mod.getTarget();
36823715 if (ty.zigTypeTag() == .Vector) {
36833716 const result_data = try allocator.alloc(Value, ty.vectorLen());
36843717 for (result_data) |*scalar, i| {
3685 scalar.* = try bitwiseXorScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
3718 var lhs_buf: Value.ElemValueBuffer = undefined;
3719 var rhs_buf: Value.ElemValueBuffer = undefined;
3720 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3721 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3722 scalar.* = try bitwiseXorScalar(lhs_elem, rhs_elem, allocator, target);
36863723 }
36873724 return Value.Tag.aggregate.create(allocator, result_data);
36883725 }
......@@ -3709,11 +3746,16 @@ pub const Value = extern union {
37093746 return fromBigInt(arena, result_bigint.toConst());
37103747 }
37113748
3712 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
3749 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3750 const target = mod.getTarget();
37133751 if (ty.zigTypeTag() == .Vector) {
37143752 const result_data = try allocator.alloc(Value, ty.vectorLen());
37153753 for (result_data) |*scalar, i| {
3716 scalar.* = try intDivScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
3754 var lhs_buf: Value.ElemValueBuffer = undefined;
3755 var rhs_buf: Value.ElemValueBuffer = undefined;
3756 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3757 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3758 scalar.* = try intDivScalar(lhs_elem, rhs_elem, allocator, target);
37173759 }
37183760 return Value.Tag.aggregate.create(allocator, result_data);
37193761 }
......@@ -3745,11 +3787,16 @@ pub const Value = extern union {
37453787 return fromBigInt(allocator, result_q.toConst());
37463788 }
37473789
3748 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
3790 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3791 const target = mod.getTarget();
37493792 if (ty.zigTypeTag() == .Vector) {
37503793 const result_data = try allocator.alloc(Value, ty.vectorLen());
37513794 for (result_data) |*scalar, i| {
3752 scalar.* = try intDivFloorScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
3795 var lhs_buf: Value.ElemValueBuffer = undefined;
3796 var rhs_buf: Value.ElemValueBuffer = undefined;
3797 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3798 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3799 scalar.* = try intDivFloorScalar(lhs_elem, rhs_elem, allocator, target);
37533800 }
37543801 return Value.Tag.aggregate.create(allocator, result_data);
37553802 }
......@@ -3781,11 +3828,16 @@ pub const Value = extern union {
37813828 return fromBigInt(allocator, result_q.toConst());
37823829 }
37833830
3784 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
3831 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3832 const target = mod.getTarget();
37853833 if (ty.zigTypeTag() == .Vector) {
37863834 const result_data = try allocator.alloc(Value, ty.vectorLen());
37873835 for (result_data) |*scalar, i| {
3788 scalar.* = try intModScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
3836 var lhs_buf: Value.ElemValueBuffer = undefined;
3837 var rhs_buf: Value.ElemValueBuffer = undefined;
3838 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3839 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3840 scalar.* = try intModScalar(lhs_elem, rhs_elem, allocator, target);
37893841 }
37903842 return Value.Tag.aggregate.create(allocator, result_data);
37913843 }
......@@ -3852,11 +3904,16 @@ pub const Value = extern union {
38523904 };
38533905 }
38543906
3855 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value {
3907 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3908 const target = mod.getTarget();
38563909 if (float_type.zigTypeTag() == .Vector) {
38573910 const result_data = try arena.alloc(Value, float_type.vectorLen());
38583911 for (result_data) |*scalar, i| {
3859 scalar.* = try floatRemScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);
3912 var lhs_buf: Value.ElemValueBuffer = undefined;
3913 var rhs_buf: Value.ElemValueBuffer = undefined;
3914 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3915 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3916 scalar.* = try floatRemScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
38603917 }
38613918 return Value.Tag.aggregate.create(arena, result_data);
38623919 }
......@@ -3894,11 +3951,16 @@ pub const Value = extern union {
38943951 }
38953952 }
38963953
3897 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value {
3954 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3955 const target = mod.getTarget();
38983956 if (float_type.zigTypeTag() == .Vector) {
38993957 const result_data = try arena.alloc(Value, float_type.vectorLen());
39003958 for (result_data) |*scalar, i| {
3901 scalar.* = try floatModScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);
3959 var lhs_buf: Value.ElemValueBuffer = undefined;
3960 var rhs_buf: Value.ElemValueBuffer = undefined;
3961 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
3962 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
3963 scalar.* = try floatModScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
39023964 }
39033965 return Value.Tag.aggregate.create(arena, result_data);
39043966 }
......@@ -3936,11 +3998,16 @@ pub const Value = extern union {
39363998 }
39373999 }
39384000
3939 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
4001 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
4002 const target = mod.getTarget();
39404003 if (ty.zigTypeTag() == .Vector) {
39414004 const result_data = try allocator.alloc(Value, ty.vectorLen());
39424005 for (result_data) |*scalar, i| {
3943 scalar.* = try intMulScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
4006 var lhs_buf: Value.ElemValueBuffer = undefined;
4007 var rhs_buf: Value.ElemValueBuffer = undefined;
4008 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4009 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4010 scalar.* = try intMulScalar(lhs_elem, rhs_elem, allocator, target);
39444011 }
39454012 return Value.Tag.aggregate.create(allocator, result_data);
39464013 }
......@@ -3968,11 +4035,14 @@ pub const Value = extern union {
39684035 return fromBigInt(allocator, result_bigint.toConst());
39694036 }
39704037
3971 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, target: Target) !Value {
4038 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, mod: *Module) !Value {
4039 const target = mod.getTarget();
39724040 if (ty.zigTypeTag() == .Vector) {
39734041 const result_data = try allocator.alloc(Value, ty.vectorLen());
39744042 for (result_data) |*scalar, i| {
3975 scalar.* = try intTruncScalar(val.indexVectorlike(i), allocator, signedness, bits, target);
4043 var buf: Value.ElemValueBuffer = undefined;
4044 const elem_val = val.elemValueBuffer(mod, i, &buf);
4045 scalar.* = try intTruncScalar(elem_val, allocator, signedness, bits, target);
39764046 }
39774047 return Value.Tag.aggregate.create(allocator, result_data);
39784048 }
......@@ -3986,12 +4056,17 @@ pub const Value = extern union {
39864056 allocator: Allocator,
39874057 signedness: std.builtin.Signedness,
39884058 bits: Value,
3989 target: Target,
4059 mod: *Module,
39904060 ) !Value {
4061 const target = mod.getTarget();
39914062 if (ty.zigTypeTag() == .Vector) {
39924063 const result_data = try allocator.alloc(Value, ty.vectorLen());
39934064 for (result_data) |*scalar, i| {
3994 scalar.* = try intTruncScalar(val.indexVectorlike(i), allocator, signedness, @intCast(u16, bits.indexVectorlike(i).toUnsignedInt(target)), target);
4065 var buf: Value.ElemValueBuffer = undefined;
4066 const elem_val = val.elemValueBuffer(mod, i, &buf);
4067 var bits_buf: Value.ElemValueBuffer = undefined;
4068 const bits_elem = bits.elemValueBuffer(mod, i, &bits_buf);
4069 scalar.* = try intTruncScalar(elem_val, allocator, signedness, @intCast(u16, bits_elem.toUnsignedInt(target)), target);
39954070 }
39964071 return Value.Tag.aggregate.create(allocator, result_data);
39974072 }
......@@ -4014,11 +4089,16 @@ pub const Value = extern union {
40144089 return fromBigInt(allocator, result_bigint.toConst());
40154090 }
40164091
4017 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
4092 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
4093 const target = mod.getTarget();
40184094 if (ty.zigTypeTag() == .Vector) {
40194095 const result_data = try allocator.alloc(Value, ty.vectorLen());
40204096 for (result_data) |*scalar, i| {
4021 scalar.* = try shlScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
4097 var lhs_buf: Value.ElemValueBuffer = undefined;
4098 var rhs_buf: Value.ElemValueBuffer = undefined;
4099 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4100 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4101 scalar.* = try shlScalar(lhs_elem, rhs_elem, allocator, target);
40224102 }
40234103 return Value.Tag.aggregate.create(allocator, result_data);
40244104 }
......@@ -4049,13 +4129,18 @@ pub const Value = extern union {
40494129 rhs: Value,
40504130 ty: Type,
40514131 allocator: Allocator,
4052 target: Target,
4132 mod: *Module,
40534133 ) !OverflowArithmeticResult {
4134 const target = mod.getTarget();
40544135 if (ty.zigTypeTag() == .Vector) {
40554136 const overflowed_data = try allocator.alloc(Value, ty.vectorLen());
40564137 const result_data = try allocator.alloc(Value, ty.vectorLen());
40574138 for (result_data) |*scalar, i| {
4058 const of_math_result = try shlWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), allocator, target);
4139 var lhs_buf: Value.ElemValueBuffer = undefined;
4140 var rhs_buf: Value.ElemValueBuffer = undefined;
4141 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4142 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4143 const of_math_result = try shlWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(), allocator, target);
40594144 overflowed_data[i] = of_math_result.overflowed;
40604145 scalar.* = of_math_result.wrapped_result;
40614146 }
......@@ -4103,12 +4188,17 @@ pub const Value = extern union {
41034188 rhs: Value,
41044189 ty: Type,
41054190 arena: Allocator,
4106 target: Target,
4191 mod: *Module,
41074192 ) !Value {
4193 const target = mod.getTarget();
41084194 if (ty.zigTypeTag() == .Vector) {
41094195 const result_data = try arena.alloc(Value, ty.vectorLen());
41104196 for (result_data) |*scalar, i| {
4111 scalar.* = try shlSatScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);
4197 var lhs_buf: Value.ElemValueBuffer = undefined;
4198 var rhs_buf: Value.ElemValueBuffer = undefined;
4199 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4200 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4201 scalar.* = try shlSatScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, target);
41124202 }
41134203 return Value.Tag.aggregate.create(arena, result_data);
41144204 }
......@@ -4147,16 +4237,20 @@ pub const Value = extern union {
41474237 rhs: Value,
41484238 ty: Type,
41494239 arena: Allocator,
4150 target: Target,
4240 mod: *Module,
41514241 ) !Value {
41524242 if (ty.zigTypeTag() == .Vector) {
41534243 const result_data = try arena.alloc(Value, ty.vectorLen());
41544244 for (result_data) |*scalar, i| {
4155 scalar.* = try shlTruncScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType(), arena, target);
4245 var lhs_buf: Value.ElemValueBuffer = undefined;
4246 var rhs_buf: Value.ElemValueBuffer = undefined;
4247 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4248 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4249 scalar.* = try shlTruncScalar(lhs_elem, rhs_elem, ty.scalarType(), arena, mod);
41564250 }
41574251 return Value.Tag.aggregate.create(arena, result_data);
41584252 }
4159 return shlTruncScalar(lhs, rhs, ty, arena, target);
4253 return shlTruncScalar(lhs, rhs, ty, arena, mod);
41604254 }
41614255
41624256 pub fn shlTruncScalar(
......@@ -4164,19 +4258,24 @@ pub const Value = extern union {
41644258 rhs: Value,
41654259 ty: Type,
41664260 arena: Allocator,
4167 target: Target,
4261 mod: *Module,
41684262 ) !Value {
4169 const shifted = try lhs.shl(rhs, ty, arena, target);
4170 const int_info = ty.intInfo(target);
4171 const truncated = try shifted.intTrunc(ty, arena, int_info.signedness, int_info.bits, target);
4263 const shifted = try lhs.shl(rhs, ty, arena, mod);
4264 const int_info = ty.intInfo(mod.getTarget());
4265 const truncated = try shifted.intTrunc(ty, arena, int_info.signedness, int_info.bits, mod);
41724266 return truncated;
41734267 }
41744268
4175 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, target: Target) !Value {
4269 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
4270 const target = mod.getTarget();
41764271 if (ty.zigTypeTag() == .Vector) {
41774272 const result_data = try allocator.alloc(Value, ty.vectorLen());
41784273 for (result_data) |*scalar, i| {
4179 scalar.* = try shrScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), allocator, target);
4274 var lhs_buf: Value.ElemValueBuffer = undefined;
4275 var rhs_buf: Value.ElemValueBuffer = undefined;
4276 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4277 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4278 scalar.* = try shrScalar(lhs_elem, rhs_elem, allocator, target);
41804279 }
41814280 return Value.Tag.aggregate.create(allocator, result_data);
41824281 }
......@@ -4218,12 +4317,15 @@ pub const Value = extern union {
42184317 val: Value,
42194318 float_type: Type,
42204319 arena: Allocator,
4221 target: Target,
4320 mod: *Module,
42224321 ) !Value {
4322 const target = mod.getTarget();
42234323 if (float_type.zigTypeTag() == .Vector) {
42244324 const result_data = try arena.alloc(Value, float_type.vectorLen());
42254325 for (result_data) |*scalar, i| {
4226 scalar.* = try floatNegScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4326 var buf: Value.ElemValueBuffer = undefined;
4327 const elem_val = val.elemValueBuffer(mod, i, &buf);
4328 scalar.* = try floatNegScalar(elem_val, float_type.scalarType(), arena, target);
42274329 }
42284330 return Value.Tag.aggregate.create(arena, result_data);
42294331 }
......@@ -4251,12 +4353,17 @@ pub const Value = extern union {
42514353 rhs: Value,
42524354 float_type: Type,
42534355 arena: Allocator,
4254 target: Target,
4356 mod: *Module,
42554357 ) !Value {
4358 const target = mod.getTarget();
42564359 if (float_type.zigTypeTag() == .Vector) {
42574360 const result_data = try arena.alloc(Value, float_type.vectorLen());
42584361 for (result_data) |*scalar, i| {
4259 scalar.* = try floatDivScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);
4362 var lhs_buf: Value.ElemValueBuffer = undefined;
4363 var rhs_buf: Value.ElemValueBuffer = undefined;
4364 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4365 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4366 scalar.* = try floatDivScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
42604367 }
42614368 return Value.Tag.aggregate.create(arena, result_data);
42624369 }
......@@ -4305,12 +4412,17 @@ pub const Value = extern union {
43054412 rhs: Value,
43064413 float_type: Type,
43074414 arena: Allocator,
4308 target: Target,
4415 mod: *Module,
43094416 ) !Value {
4417 const target = mod.getTarget();
43104418 if (float_type.zigTypeTag() == .Vector) {
43114419 const result_data = try arena.alloc(Value, float_type.vectorLen());
43124420 for (result_data) |*scalar, i| {
4313 scalar.* = try floatDivFloorScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);
4421 var lhs_buf: Value.ElemValueBuffer = undefined;
4422 var rhs_buf: Value.ElemValueBuffer = undefined;
4423 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4424 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4425 scalar.* = try floatDivFloorScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
43144426 }
43154427 return Value.Tag.aggregate.create(arena, result_data);
43164428 }
......@@ -4359,12 +4471,17 @@ pub const Value = extern union {
43594471 rhs: Value,
43604472 float_type: Type,
43614473 arena: Allocator,
4362 target: Target,
4474 mod: *Module,
43634475 ) !Value {
4476 const target = mod.getTarget();
43644477 if (float_type.zigTypeTag() == .Vector) {
43654478 const result_data = try arena.alloc(Value, float_type.vectorLen());
43664479 for (result_data) |*scalar, i| {
4367 scalar.* = try floatDivTruncScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);
4480 var lhs_buf: Value.ElemValueBuffer = undefined;
4481 var rhs_buf: Value.ElemValueBuffer = undefined;
4482 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4483 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4484 scalar.* = try floatDivTruncScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
43684485 }
43694486 return Value.Tag.aggregate.create(arena, result_data);
43704487 }
......@@ -4413,12 +4530,17 @@ pub const Value = extern union {
44134530 rhs: Value,
44144531 float_type: Type,
44154532 arena: Allocator,
4416 target: Target,
4533 mod: *Module,
44174534 ) !Value {
4535 const target = mod.getTarget();
44184536 if (float_type.zigTypeTag() == .Vector) {
44194537 const result_data = try arena.alloc(Value, float_type.vectorLen());
44204538 for (result_data) |*scalar, i| {
4421 scalar.* = try floatMulScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), float_type.scalarType(), arena, target);
4539 var lhs_buf: Value.ElemValueBuffer = undefined;
4540 var rhs_buf: Value.ElemValueBuffer = undefined;
4541 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
4542 const rhs_elem = rhs.elemValueBuffer(mod, i, &rhs_buf);
4543 scalar.* = try floatMulScalar(lhs_elem, rhs_elem, float_type.scalarType(), arena, target);
44224544 }
44234545 return Value.Tag.aggregate.create(arena, result_data);
44244546 }
......@@ -4462,11 +4584,14 @@ pub const Value = extern union {
44624584 }
44634585 }
44644586
4465 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4587 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4588 const target = mod.getTarget();
44664589 if (float_type.zigTypeTag() == .Vector) {
44674590 const result_data = try arena.alloc(Value, float_type.vectorLen());
44684591 for (result_data) |*scalar, i| {
4469 scalar.* = try sqrtScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4592 var buf: Value.ElemValueBuffer = undefined;
4593 const elem_val = val.elemValueBuffer(mod, i, &buf);
4594 scalar.* = try sqrtScalar(elem_val, float_type.scalarType(), arena, target);
44704595 }
44714596 return Value.Tag.aggregate.create(arena, result_data);
44724597 }
......@@ -4499,11 +4624,14 @@ pub const Value = extern union {
44994624 }
45004625 }
45014626
4502 pub fn sin(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4627 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4628 const target = mod.getTarget();
45034629 if (float_type.zigTypeTag() == .Vector) {
45044630 const result_data = try arena.alloc(Value, float_type.vectorLen());
45054631 for (result_data) |*scalar, i| {
4506 scalar.* = try sinScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4632 var buf: Value.ElemValueBuffer = undefined;
4633 const elem_val = val.elemValueBuffer(mod, i, &buf);
4634 scalar.* = try sinScalar(elem_val, float_type.scalarType(), arena, target);
45074635 }
45084636 return Value.Tag.aggregate.create(arena, result_data);
45094637 }
......@@ -4536,11 +4664,14 @@ pub const Value = extern union {
45364664 }
45374665 }
45384666
4539 pub fn cos(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4667 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4668 const target = mod.getTarget();
45404669 if (float_type.zigTypeTag() == .Vector) {
45414670 const result_data = try arena.alloc(Value, float_type.vectorLen());
45424671 for (result_data) |*scalar, i| {
4543 scalar.* = try cosScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4672 var buf: Value.ElemValueBuffer = undefined;
4673 const elem_val = val.elemValueBuffer(mod, i, &buf);
4674 scalar.* = try cosScalar(elem_val, float_type.scalarType(), arena, target);
45444675 }
45454676 return Value.Tag.aggregate.create(arena, result_data);
45464677 }
......@@ -4573,11 +4704,14 @@ pub const Value = extern union {
45734704 }
45744705 }
45754706
4576 pub fn tan(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4707 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4708 const target = mod.getTarget();
45774709 if (float_type.zigTypeTag() == .Vector) {
45784710 const result_data = try arena.alloc(Value, float_type.vectorLen());
45794711 for (result_data) |*scalar, i| {
4580 scalar.* = try tanScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4712 var buf: Value.ElemValueBuffer = undefined;
4713 const elem_val = val.elemValueBuffer(mod, i, &buf);
4714 scalar.* = try tanScalar(elem_val, float_type.scalarType(), arena, target);
45814715 }
45824716 return Value.Tag.aggregate.create(arena, result_data);
45834717 }
......@@ -4610,11 +4744,14 @@ pub const Value = extern union {
46104744 }
46114745 }
46124746
4613 pub fn exp(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4747 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4748 const target = mod.getTarget();
46144749 if (float_type.zigTypeTag() == .Vector) {
46154750 const result_data = try arena.alloc(Value, float_type.vectorLen());
46164751 for (result_data) |*scalar, i| {
4617 scalar.* = try expScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4752 var buf: Value.ElemValueBuffer = undefined;
4753 const elem_val = val.elemValueBuffer(mod, i, &buf);
4754 scalar.* = try expScalar(elem_val, float_type.scalarType(), arena, target);
46184755 }
46194756 return Value.Tag.aggregate.create(arena, result_data);
46204757 }
......@@ -4647,11 +4784,14 @@ pub const Value = extern union {
46474784 }
46484785 }
46494786
4650 pub fn exp2(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4787 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4788 const target = mod.getTarget();
46514789 if (float_type.zigTypeTag() == .Vector) {
46524790 const result_data = try arena.alloc(Value, float_type.vectorLen());
46534791 for (result_data) |*scalar, i| {
4654 scalar.* = try exp2Scalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4792 var buf: Value.ElemValueBuffer = undefined;
4793 const elem_val = val.elemValueBuffer(mod, i, &buf);
4794 scalar.* = try exp2Scalar(elem_val, float_type.scalarType(), arena, target);
46554795 }
46564796 return Value.Tag.aggregate.create(arena, result_data);
46574797 }
......@@ -4684,11 +4824,14 @@ pub const Value = extern union {
46844824 }
46854825 }
46864826
4687 pub fn log(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4827 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4828 const target = mod.getTarget();
46884829 if (float_type.zigTypeTag() == .Vector) {
46894830 const result_data = try arena.alloc(Value, float_type.vectorLen());
46904831 for (result_data) |*scalar, i| {
4691 scalar.* = try logScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4832 var buf: Value.ElemValueBuffer = undefined;
4833 const elem_val = val.elemValueBuffer(mod, i, &buf);
4834 scalar.* = try logScalar(elem_val, float_type.scalarType(), arena, target);
46924835 }
46934836 return Value.Tag.aggregate.create(arena, result_data);
46944837 }
......@@ -4721,11 +4864,14 @@ pub const Value = extern union {
47214864 }
47224865 }
47234866
4724 pub fn log2(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4867 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4868 const target = mod.getTarget();
47254869 if (float_type.zigTypeTag() == .Vector) {
47264870 const result_data = try arena.alloc(Value, float_type.vectorLen());
47274871 for (result_data) |*scalar, i| {
4728 scalar.* = try log2Scalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4872 var buf: Value.ElemValueBuffer = undefined;
4873 const elem_val = val.elemValueBuffer(mod, i, &buf);
4874 scalar.* = try log2Scalar(elem_val, float_type.scalarType(), arena, target);
47294875 }
47304876 return Value.Tag.aggregate.create(arena, result_data);
47314877 }
......@@ -4758,11 +4904,14 @@ pub const Value = extern union {
47584904 }
47594905 }
47604906
4761 pub fn log10(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4907 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4908 const target = mod.getTarget();
47624909 if (float_type.zigTypeTag() == .Vector) {
47634910 const result_data = try arena.alloc(Value, float_type.vectorLen());
47644911 for (result_data) |*scalar, i| {
4765 scalar.* = try log10Scalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4912 var buf: Value.ElemValueBuffer = undefined;
4913 const elem_val = val.elemValueBuffer(mod, i, &buf);
4914 scalar.* = try log10Scalar(elem_val, float_type.scalarType(), arena, target);
47664915 }
47674916 return Value.Tag.aggregate.create(arena, result_data);
47684917 }
......@@ -4795,11 +4944,14 @@ pub const Value = extern union {
47954944 }
47964945 }
47974946
4798 pub fn fabs(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4947 pub fn fabs(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4948 const target = mod.getTarget();
47994949 if (float_type.zigTypeTag() == .Vector) {
48004950 const result_data = try arena.alloc(Value, float_type.vectorLen());
48014951 for (result_data) |*scalar, i| {
4802 scalar.* = try fabsScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4952 var buf: Value.ElemValueBuffer = undefined;
4953 const elem_val = val.elemValueBuffer(mod, i, &buf);
4954 scalar.* = try fabsScalar(elem_val, float_type.scalarType(), arena, target);
48034955 }
48044956 return Value.Tag.aggregate.create(arena, result_data);
48054957 }
......@@ -4832,11 +4984,14 @@ pub const Value = extern union {
48324984 }
48334985 }
48344986
4835 pub fn floor(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
4987 pub fn floor(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
4988 const target = mod.getTarget();
48364989 if (float_type.zigTypeTag() == .Vector) {
48374990 const result_data = try arena.alloc(Value, float_type.vectorLen());
48384991 for (result_data) |*scalar, i| {
4839 scalar.* = try floorScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
4992 var buf: Value.ElemValueBuffer = undefined;
4993 const elem_val = val.elemValueBuffer(mod, i, &buf);
4994 scalar.* = try floorScalar(elem_val, float_type.scalarType(), arena, target);
48404995 }
48414996 return Value.Tag.aggregate.create(arena, result_data);
48424997 }
......@@ -4869,11 +5024,14 @@ pub const Value = extern union {
48695024 }
48705025 }
48715026
4872 pub fn ceil(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
5027 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
5028 const target = mod.getTarget();
48735029 if (float_type.zigTypeTag() == .Vector) {
48745030 const result_data = try arena.alloc(Value, float_type.vectorLen());
48755031 for (result_data) |*scalar, i| {
4876 scalar.* = try ceilScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
5032 var buf: Value.ElemValueBuffer = undefined;
5033 const elem_val = val.elemValueBuffer(mod, i, &buf);
5034 scalar.* = try ceilScalar(elem_val, float_type.scalarType(), arena, target);
48775035 }
48785036 return Value.Tag.aggregate.create(arena, result_data);
48795037 }
......@@ -4906,11 +5064,14 @@ pub const Value = extern union {
49065064 }
49075065 }
49085066
4909 pub fn round(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
5067 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
5068 const target = mod.getTarget();
49105069 if (float_type.zigTypeTag() == .Vector) {
49115070 const result_data = try arena.alloc(Value, float_type.vectorLen());
49125071 for (result_data) |*scalar, i| {
4913 scalar.* = try roundScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
5072 var buf: Value.ElemValueBuffer = undefined;
5073 const elem_val = val.elemValueBuffer(mod, i, &buf);
5074 scalar.* = try roundScalar(elem_val, float_type.scalarType(), arena, target);
49145075 }
49155076 return Value.Tag.aggregate.create(arena, result_data);
49165077 }
......@@ -4943,11 +5104,14 @@ pub const Value = extern union {
49435104 }
49445105 }
49455106
4946 pub fn trunc(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
5107 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
5108 const target = mod.getTarget();
49475109 if (float_type.zigTypeTag() == .Vector) {
49485110 const result_data = try arena.alloc(Value, float_type.vectorLen());
49495111 for (result_data) |*scalar, i| {
4950 scalar.* = try truncScalar(val.indexVectorlike(i), float_type.scalarType(), arena, target);
5112 var buf: Value.ElemValueBuffer = undefined;
5113 const elem_val = val.elemValueBuffer(mod, i, &buf);
5114 scalar.* = try truncScalar(elem_val, float_type.scalarType(), arena, target);
49515115 }
49525116 return Value.Tag.aggregate.create(arena, result_data);
49535117 }
......@@ -4986,16 +5150,23 @@ pub const Value = extern union {
49865150 mulend2: Value,
49875151 addend: Value,
49885152 arena: Allocator,
4989 target: Target,
4990 ) Allocator.Error!Value {
5153 mod: *Module,
5154 ) !Value {
5155 const target = mod.getTarget();
49915156 if (float_type.zigTypeTag() == .Vector) {
49925157 const result_data = try arena.alloc(Value, float_type.vectorLen());
49935158 for (result_data) |*scalar, i| {
5159 var mulend1_buf: Value.ElemValueBuffer = undefined;
5160 const mulend1_elem = mulend1.elemValueBuffer(mod, i, &mulend1_buf);
5161 var mulend2_buf: Value.ElemValueBuffer = undefined;
5162 const mulend2_elem = mulend2.elemValueBuffer(mod, i, &mulend2_buf);
5163 var addend_buf: Value.ElemValueBuffer = undefined;
5164 const addend_elem = addend.elemValueBuffer(mod, i, &addend_buf);
49945165 scalar.* = try mulAddScalar(
49955166 float_type.scalarType(),
4996 mulend1.indexVectorlike(i),
4997 mulend2.indexVectorlike(i),
4998 addend.indexVectorlike(i),
5167 mulend1_elem,
5168 mulend2_elem,
5169 addend_elem,
49995170 arena,
50005171 target,
50015172 );
test/behavior/bitcast.zig-3
......@@ -358,9 +358,6 @@ test "comptime @bitCast packed struct to int and back" {
358358 const rt_cast = @bitCast(S, i);
359359 const ct_cast = comptime @bitCast(S, @as(Int, 0));
360360 inline for (@typeInfo(S).Struct.fields) |field| {
361 if (@typeInfo(field.type) == .Vector)
362 continue; //TODO: https://github.com/ziglang/zig/issues/13201
363
364361 try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));
365362 }
366363}
test/behavior/call.zig+37
......@@ -344,3 +344,40 @@ test "inline call doesn't re-evaluate non generic struct" {
344344 try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }});
345345 comptime try @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }});
346346}
347
348test "Enum constructed by @Type passed as generic argument" {
349 const S = struct {
350 const E = std.meta.FieldEnum(struct {
351 prev_pos: bool,
352 pos: bool,
353 vel: bool,
354 damp_vel: bool,
355 acc: bool,
356 rgba: bool,
357 prev_scale: bool,
358 scale: bool,
359 prev_rotation: bool,
360 rotation: bool,
361 angular_vel: bool,
362 alive: bool,
363 });
364 fn foo(comptime a: E, b: u32) !void {
365 try expect(@enumToInt(a) == b);
366 }
367 };
368 inline for (@typeInfo(S.E).Enum.fields) |_, i| {
369 try S.foo(@intToEnum(S.E, i), i);
370 }
371}
372
373test "generic function with generic function parameter" {
374 const S = struct {
375 fn f(comptime a: fn (anytype) anyerror!void, b: anytype) anyerror!void {
376 try a(b);
377 }
378 fn g(a: anytype) anyerror!void {
379 try expect(a == 123);
380 }
381 };
382 try S.f(S.g, 123);
383}
test/behavior/cast.zig+10
......@@ -1495,3 +1495,13 @@ test "cast typed undefined to int" {
14951495 _ = b;
14961496 }
14971497}
1498
1499test "implicit cast from [:0]T to [*c]T" {
1500 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1501
1502 var a: [:0]const u8 = "foo";
1503 var b: [*c]const u8 = a;
1504 var c = std.mem.span(b);
1505 try expect(c.len == a.len);
1506 try expect(c.ptr == a.ptr);
1507}
test/c_abi/cfuncs.c+13
......@@ -742,6 +742,19 @@ SmallVec c_ret_small_vec(void) {
742742 return (SmallVec){3, 4};
743743}
744744
745typedef size_t MediumVec __attribute__((vector_size(4 * sizeof(size_t))));
746
747void c_medium_vec(MediumVec vec) {
748 assert_or_panic(vec[0] == 1);
749 assert_or_panic(vec[1] == 2);
750 assert_or_panic(vec[2] == 3);
751 assert_or_panic(vec[3] == 4);
752}
753
754MediumVec c_ret_medium_vec(void) {
755 return (MediumVec){5, 6, 7, 8};
756}
757
745758typedef size_t BigVec __attribute__((vector_size(8 * sizeof(size_t))));
746759
747760void c_big_vec(BigVec vec) {
test/c_abi/main.zig+17
......@@ -801,6 +801,23 @@ test "small simd vector" {
801801 try expect(x[1] == 4);
802802}
803803
804const MediumVec = @Vector(4, usize);
805
806extern fn c_medium_vec(MediumVec) void;
807extern fn c_ret_medium_vec() MediumVec;
808
809test "medium simd vector" {
810 if (comptime builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
811
812 c_medium_vec(.{ 1, 2, 3, 4 });
813
814 var x = c_ret_medium_vec();
815 try expect(x[0] == 5);
816 try expect(x[1] == 6);
817 try expect(x[2] == 7);
818 try expect(x[3] == 8);
819}
820
804821const BigVec = @Vector(8, usize);
805822
806823extern fn c_big_vec(BigVec) void;
test/cases/compile_errors/noalias_on_non_pointer_param.zig+6
......@@ -1,6 +1,12 @@
11fn f(noalias x: i32) void { _ = x; }
22export fn entry() void { f(1234); }
33
4fn generic(comptime T: type, noalias _: [*]T, noalias _: [*]const T, _: usize) void {}
5comptime { _ = generic; }
6
7fn slice(noalias _: []u8) void {}
8comptime { _ = slice; }
9
410// error
511// backend=stage2
612// target=native