| ... | ... | @@ -76,6 +76,7 @@ pt: Zcu.PerThread, |
| 76 | 76 | mir_instructions: *std.MultiArrayList(Mir.Inst), |
| 77 | 77 | /// Contains extra data for MIR |
| 78 | 78 | mir_extra: *std.ArrayListUnmanaged(u32), |
| 79 | start_mir_extra_off: u32, |
| 79 | 80 | /// List of all locals' types generated throughout this declaration |
| 80 | 81 | /// used to emit locals count at start of 'code' section. |
| 81 | 82 | locals: *std.ArrayListUnmanaged(u8), |
| ... | ... | @@ -859,7 +860,7 @@ fn addTag(cg: *CodeGen, tag: Mir.Inst.Tag) error{OutOfMemory}!void { |
| 859 | 860 | } |
| 860 | 861 | |
| 861 | 862 | fn addExtended(cg: *CodeGen, opcode: std.wasm.MiscOpcode) error{OutOfMemory}!void { |
| 862 | | const extra_index = @as(u32, @intCast(cg.mir_extra.items.len)); |
| 863 | const extra_index = cg.extraLen(); |
| 863 | 864 | try cg.mir_extra.append(cg.gpa, @intFromEnum(opcode)); |
| 864 | 865 | try cg.addInst(.{ .tag = .misc_prefix, .data = .{ .payload = extra_index } }); |
| 865 | 866 | } |
| ... | ... | @@ -890,7 +891,7 @@ fn addImm64(cg: *CodeGen, imm: u64) error{OutOfMemory}!void { |
| 890 | 891 | /// Accepts the index into the list of 128bit-immediates |
| 891 | 892 | fn addImm128(cg: *CodeGen, index: u32) error{OutOfMemory}!void { |
| 892 | 893 | const simd_values = cg.simd_immediates.items[index]; |
| 893 | | const extra_index = @as(u32, @intCast(cg.mir_extra.items.len)); |
| 894 | const extra_index = cg.extraLen(); |
| 894 | 895 | // tag + 128bit value |
| 895 | 896 | try cg.mir_extra.ensureUnusedCapacity(cg.gpa, 5); |
| 896 | 897 | cg.mir_extra.appendAssumeCapacity(@intFromEnum(std.wasm.SimdOpcode.v128_const)); |
| ... | ... | @@ -935,7 +936,7 @@ fn addExtra(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 { |
| 935 | 936 | /// Returns the index into `mir_extra` |
| 936 | 937 | fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 { |
| 937 | 938 | const fields = std.meta.fields(@TypeOf(extra)); |
| 938 | | const result = @as(u32, @intCast(cg.mir_extra.items.len)); |
| 939 | const result = cg.extraLen(); |
| 939 | 940 | inline for (fields) |field| { |
| 940 | 941 | cg.mir_extra.appendAssumeCapacity(switch (field.type) { |
| 941 | 942 | u32 => @field(extra, field.name), |
| ... | ... | @@ -1267,6 +1268,7 @@ pub fn function( |
| 1267 | 1268 | .mir_instructions = &wasm.mir_instructions, |
| 1268 | 1269 | .mir_extra = &wasm.mir_extra, |
| 1269 | 1270 | .locals = &wasm.all_zcu_locals, |
| 1271 | .start_mir_extra_off = @intCast(wasm.mir_extra.items.len), |
| 1270 | 1272 | }; |
| 1271 | 1273 | defer code_gen.deinit(); |
| 1272 | 1274 | |
| ... | ... | @@ -1281,7 +1283,6 @@ fn functionInner(cg: *CodeGen, any_returns: bool) InnerError!Function { |
| 1281 | 1283 | const zcu = cg.pt.zcu; |
| 1282 | 1284 | |
| 1283 | 1285 | const start_mir_off: u32 = @intCast(wasm.mir_instructions.len); |
| 1284 | | const start_mir_extra_off: u32 = @intCast(wasm.mir_extra.items.len); |
| 1285 | 1286 | const start_locals_off: u32 = @intCast(wasm.all_zcu_locals.items.len); |
| 1286 | 1287 | |
| 1287 | 1288 | try cg.branches.append(cg.gpa, .{}); |
| ... | ... | @@ -1310,8 +1311,8 @@ fn functionInner(cg: *CodeGen, any_returns: bool) InnerError!Function { |
| 1310 | 1311 | return .{ |
| 1311 | 1312 | .mir_off = start_mir_off, |
| 1312 | 1313 | .mir_len = @intCast(wasm.mir_instructions.len - start_mir_off), |
| 1313 | | .mir_extra_off = start_mir_extra_off, |
| 1314 | | .mir_extra_len = @intCast(wasm.mir_extra.items.len - start_mir_extra_off), |
| 1314 | .mir_extra_off = cg.start_mir_extra_off, |
| 1315 | .mir_extra_len = cg.extraLen(), |
| 1315 | 1316 | .locals_off = start_locals_off, |
| 1316 | 1317 | .locals_len = @intCast(wasm.all_zcu_locals.items.len - start_locals_off), |
| 1317 | 1318 | .prologue = if (cg.initial_stack_value == .none) .none else .{ |
| ... | ... | @@ -2349,7 +2350,7 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerErr |
| 2349 | 2350 | try cg.emitWValue(lhs); |
| 2350 | 2351 | try cg.lowerToStack(rhs); |
| 2351 | 2352 | // TODO: Add helper functions for simd opcodes |
| 2352 | | const extra_index: u32 = @intCast(cg.mir_extra.items.len); |
| 2353 | const extra_index = cg.extraLen(); |
| 2353 | 2354 | // stores as := opcode, offset, alignment (opcode::memarg) |
| 2354 | 2355 | try cg.mir_extra.appendSlice(cg.gpa, &[_]u32{ |
| 2355 | 2356 | @intFromEnum(std.wasm.SimdOpcode.v128_store), |
| ... | ... | @@ -2463,7 +2464,7 @@ fn load(cg: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValue |
| 2463 | 2464 | |
| 2464 | 2465 | if (ty.zigTypeTag(zcu) == .vector) { |
| 2465 | 2466 | // TODO: Add helper functions for simd opcodes |
| 2466 | | const extra_index = @as(u32, @intCast(cg.mir_extra.items.len)); |
| 2467 | const extra_index = cg.extraLen(); |
| 2467 | 2468 | // stores as := opcode, offset, alignment (opcode::memarg) |
| 2468 | 2469 | try cg.mir_extra.appendSlice(cg.gpa, &[_]u32{ |
| 2469 | 2470 | @intFromEnum(std.wasm.SimdOpcode.v128_load), |
| ... | ... | @@ -4872,7 +4873,7 @@ fn airArrayElemVal(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4872 | 4873 | |
| 4873 | 4874 | try cg.emitWValue(array); |
| 4874 | 4875 | |
| 4875 | | const extra_index = @as(u32, @intCast(cg.mir_extra.items.len)); |
| 4876 | const extra_index = cg.extraLen(); |
| 4876 | 4877 | try cg.mir_extra.appendSlice(cg.gpa, &operands); |
| 4877 | 4878 | try cg.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } }); |
| 4878 | 4879 | |
| ... | ... | @@ -5024,7 +5025,7 @@ fn airSplat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5024 | 5025 | else => break :blk, // Cannot make use of simd-instructions |
| 5025 | 5026 | }; |
| 5026 | 5027 | try cg.emitWValue(operand); |
| 5027 | | const extra_index: u32 = @intCast(cg.mir_extra.items.len); |
| 5028 | const extra_index: u32 = cg.extraLen(); |
| 5028 | 5029 | // stores as := opcode, offset, alignment (opcode::memarg) |
| 5029 | 5030 | try cg.mir_extra.appendSlice(cg.gpa, &[_]u32{ |
| 5030 | 5031 | opcode, |
| ... | ... | @@ -5043,7 +5044,7 @@ fn airSplat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5043 | 5044 | else => break :blk, // Cannot make use of simd-instructions |
| 5044 | 5045 | }; |
| 5045 | 5046 | try cg.emitWValue(operand); |
| 5046 | | const extra_index = @as(u32, @intCast(cg.mir_extra.items.len)); |
| 5047 | const extra_index = cg.extraLen(); |
| 5047 | 5048 | try cg.mir_extra.append(cg.gpa, opcode); |
| 5048 | 5049 | try cg.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } }); |
| 5049 | 5050 | return cg.finishAir(inst, .stack, &.{ty_op.operand}); |
| ... | ... | @@ -5131,7 +5132,7 @@ fn airShuffle(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 5131 | 5132 | try cg.emitWValue(a); |
| 5132 | 5133 | try cg.emitWValue(b); |
| 5133 | 5134 | |
| 5134 | | const extra_index = @as(u32, @intCast(cg.mir_extra.items.len)); |
| 5135 | const extra_index = cg.extraLen(); |
| 5135 | 5136 | try cg.mir_extra.appendSlice(cg.gpa, &operands); |
| 5136 | 5137 | try cg.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } }); |
| 5137 | 5138 | |
| ... | ... | @@ -7482,3 +7483,7 @@ fn floatCmpIntrinsic(op: std.math.CompareOperator, bits: u16) Mir.Intrinsic { |
| 7482 | 7483 | }, |
| 7483 | 7484 | }; |
| 7484 | 7485 | } |
| 7486 | |
| 7487 | fn extraLen(cg: *const CodeGen) u32 { |
| 7488 | return @intCast(cg.mir_extra.items.len - cg.start_mir_extra_off); |
| 7489 | } |