From 235e20d85f599a502183ebaee6e9e44202f44a0c Mon Sep 17 00:00:00 2001 From: Pavel Verigo Date: Sat, 22 Aug 2026 05:43:07 +0200 Subject: [PATCH] wasm: dont align stack if it default value --- src/codegen/wasm/Emit.zig | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/codegen/wasm/Emit.zig b/src/codegen/wasm/Emit.zig index 077cb04266f4d21da0bbbb31ee90d1bae03515ca..3c76c439ec948111832be4a0fa336abe79c38b21 100644 --- a/src/codegen/wasm/Emit.zig +++ b/src/codegen/wasm/Emit.zig @@ -56,13 +56,15 @@ pub fn lower(emit: *Emit) Error!void { writeSleb128(code, aligned_stack); // subtract it from the current stack pointer code.appendAssumeCapacity(@backingInt(std.wasm.Opcode.i32_sub)); - // Get negative stack alignment - const neg_stack_align = @as(i32, @intCast(align_bytes)) * -1; - code.appendAssumeCapacity(@backingInt(std.wasm.Opcode.i32_const)); - writeSleb128(code, neg_stack_align); - // Bitwise-and the value to get the new stack pointer to ensure the - // pointers are aligned with the abi alignment. - code.appendAssumeCapacity(@backingInt(std.wasm.Opcode.i32_and)); + if (align_bytes != 16) { + // Get negative stack alignment + const neg_stack_align = @as(i32, @intCast(align_bytes)) * -1; + code.appendAssumeCapacity(@backingInt(std.wasm.Opcode.i32_const)); + writeSleb128(code, neg_stack_align); + // Bitwise-and the value to get the new stack pointer to ensure the + // pointers are aligned with the abi alignment. + code.appendAssumeCapacity(@backingInt(std.wasm.Opcode.i32_and)); + } // The bottom will be used to calculate all stack pointer offsets. code.appendAssumeCapacity(@backingInt(std.wasm.Opcode.local_tee)); writeUleb128(code, mir.prologue.bottom_stack_local); -- 2.54.0