From 5119f0a70de2565f22e1edc5d43d49b655c6f7a7 Mon Sep 17 00:00:00 2001 From: Pavel Verigo Date: Wed, 16 Sep 2026 02:07:05 +0200 Subject: [PATCH] wasm: .toStdMem was removed --- src/codegen/wasm/CodeGen.zig | 26 +++++++++++++------------- src/codegen/wasm/Emit.zig | 2 +- src/codegen/wasm/Mir.zig | 4 ++-- src/codegen/wasm/assembly.zig | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/codegen/wasm/CodeGen.zig b/src/codegen/wasm/CodeGen.zig index aec24e1e8ce59b81d43f7bc31facaa6b9ab4195e..6db24a407587e22d736169a154788ad6a340e63c 100644 --- a/src/codegen/wasm/CodeGen.zig +++ b/src/codegen/wasm/CodeGen.zig @@ -646,7 +646,7 @@ fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 { i32 => @bitCast(@field(extra, field_name)), InternPool.Index, InternPool.Nav.Index, - mem.Alignment, + Alignment, => @backingInt(@field(extra, field_name)), else => @compileError("Unsupported field type " ++ @typeName(field_type)), }), @@ -2386,7 +2386,7 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, memarg: MemArg) Inner cg.mir_extra.appendAssumeCapacity(@backingInt(std.wasm.SimdOpcode.v128_store)); _ = try cg.addExtraAssumeCapacity(Mir.MemArg{ .offset = base_offset + memarg.offset, - .alignment = alignment.toStdMem(), + .alignment = alignment, }); return cg.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } }); } @@ -2416,7 +2416,7 @@ fn store(cg: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, memarg: MemArg) Inner store_opcode, .{ .offset = base_offset + memarg.offset, - .alignment = alignment.toStdMem(), + .alignment = alignment, }, ); } @@ -2480,7 +2480,7 @@ fn load(cg: *CodeGen, operand: WValue, ty: Type, memarg: MemArg) InnerError!WVal cg.mir_extra.appendAssumeCapacity(@backingInt(std.wasm.SimdOpcode.v128_load)); _ = try cg.addExtraAssumeCapacity(Mir.MemArg{ .offset = base_offset + memarg.offset, - .alignment = alignment.toStdMem(), + .alignment = alignment, }); try cg.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } }); return .stack; @@ -2511,7 +2511,7 @@ fn load(cg: *CodeGen, operand: WValue, ty: Type, memarg: MemArg) InnerError!WVal load_opcode, .{ .offset = base_offset + memarg.offset, - .alignment = alignment.toStdMem(), + .alignment = alignment, }, ); @@ -6141,7 +6141,7 @@ fn airIsErr(cg: *CodeGen, inst: Air.Inst.Index, opcode: std.wasm.Opcode, op_kind try cg.emitMemBase(operand); try cg.addMemArg(.i32_load16_u, .{ .offset = operand.memOffset() + errUnionErrorOffset(pl_ty, zcu), - .alignment = Type.anyerror.abiAlignment(zcu).toStdMem(), + .alignment = Type.anyerror.abiAlignment(zcu), }); } else { try cg.emitWValue(operand); @@ -6827,7 +6827,7 @@ fn airSplat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { cg.mir_extra.appendAssumeCapacity(opcode); _ = try cg.addExtraAssumeCapacity(Mir.MemArg{ .offset = operand.memOffset(), - .alignment = elem_ty.abiAlignment(zcu).toStdMem(), + .alignment = elem_ty.abiAlignment(zcu), }); try cg.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } }); return cg.finishAir(inst, .stack, &.{ty_op.operand}); @@ -7418,7 +7418,7 @@ fn lowerTry( const err_offset = errUnionErrorOffset(pl_ty, zcu); try cg.addMemArg(.i32_load16_u, .{ .offset = err_union.memOffset() + err_offset, - .alignment = Type.anyerror.abiAlignment(zcu).toStdMem(), + .alignment = Type.anyerror.abiAlignment(zcu), }); } else { try cg.emitWValue(err_union); @@ -7637,7 +7637,7 @@ fn airCmpxchg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { else => |size| return cg.fail("TODO: implement `@cmpxchg` for types with abi size '{d}'", .{size}), }, .{ .offset = ptr_operand.memOffset(), - .alignment = ty.abiAlignment(zcu).toStdMem(), + .alignment = ty.abiAlignment(zcu), }); try cg.addLocal(.local_tee, val_local.local); _ = try cg.intCmp(int_ty, .eq, .stack, expected_val); @@ -7701,7 +7701,7 @@ fn airAtomicLoad(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { try cg.emitMemBase(ptr); try cg.addAtomicMemArg(tag, .{ .offset = ptr.memOffset(), - .alignment = ty.abiAlignment(zcu).toStdMem(), + .alignment = ty.abiAlignment(zcu), }); } else { _ = try cg.load(ptr, ty, .{}); @@ -7761,7 +7761,7 @@ fn airAtomicRmw(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { }, .{ .offset = ptr.memOffset(), - .alignment = ty.abiAlignment(zcu).toStdMem(), + .alignment = ty.abiAlignment(zcu), }, ); var select_res = try cg.allocLocal(ty); @@ -7822,7 +7822,7 @@ fn airAtomicRmw(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { }; try cg.addAtomicMemArg(tag, .{ .offset = ptr.memOffset(), - .alignment = ty.abiAlignment(zcu).toStdMem(), + .alignment = ty.abiAlignment(zcu), }); return cg.finishAir(inst, .stack, &.{ pl_op.operand, extra.operand }); }, @@ -7935,7 +7935,7 @@ fn airAtomicStore(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { try cg.emitWValue(operand); try cg.addAtomicMemArg(tag, .{ .offset = ptr.memOffset(), - .alignment = ty.abiAlignment(zcu).toStdMem(), + .alignment = ty.abiAlignment(zcu), }); } else { try cg.store(ptr, operand, ty, .{}); diff --git a/src/codegen/wasm/Emit.zig b/src/codegen/wasm/Emit.zig index 3c76c439ec948111832be4a0fa336abe79c38b21..6193650464133168e21379e8cf810d8fb9e9ac12 100644 --- a/src/codegen/wasm/Emit.zig +++ b/src/codegen/wasm/Emit.zig @@ -990,7 +990,7 @@ pub fn lower(emit: *Emit) Error!void { /// Asserts 20 unused capacity. fn encodeMemArg(code: *ArrayList(u8), mem_arg: Mir.MemArg) void { assert(code.unusedCapacitySlice().len >= 20); - writeUleb128(code, @backingInt(mem_arg.alignment)); + writeUleb128(code, mem_arg.alignment.toLog2Units()); writeUleb128(code, mem_arg.offset); } diff --git a/src/codegen/wasm/Mir.zig b/src/codegen/wasm/Mir.zig index ea40a3f76ebfab55f17eb1ab20ce93527d441909..1f8502a2faaaa084770fad1e1665bb76c1185476 100644 --- a/src/codegen/wasm/Mir.zig +++ b/src/codegen/wasm/Mir.zig @@ -705,7 +705,7 @@ pub fn extraData(self: *const Mir, comptime T: type, index: usize) struct { data Wasm.UavsExeIndex, InternPool.Nav.Index, InternPool.Index, - std.mem.Alignment, + Alignment, => @fromBackingInt(@intCast(self.extra[i])), else => @compileError("Unsupported field type " ++ @typeName(field_type)), }; @@ -755,7 +755,7 @@ pub const Float64 = struct { pub const MemArg = struct { offset: u64, - alignment: std.mem.Alignment, + alignment: Alignment, }; pub const UavRefOff = struct { diff --git a/src/codegen/wasm/assembly.zig b/src/codegen/wasm/assembly.zig index 7aa056aae95e22cc5da42cb9f03ebe56257d41f4..445f2deeecb3172626435524ed52a2a82ee660d5 100644 --- a/src/codegen/wasm/assembly.zig +++ b/src/codegen/wasm/assembly.zig @@ -686,7 +686,7 @@ fn parseMemArg(cg: *CodeGen, inst: []const u8, word_it: *mem.TokenIterator(u8, . return cg.fail("Malformed assembly, malformed offset \"{s}\"", .{alignment_str}); }; - return .{ .offset = @bitCast(offset), .alignment = @fromBackingInt(@intCast(alignment_p2)) }; + return .{ .offset = @bitCast(offset), .alignment = .fromLog2Units(alignment_p2) }; } else { const offset_str = mem_arg_str; const offset = std.fmt.parseInt(i64, offset_str, 0) catch { -- 2.54.0