diff options
| author | Pavel Verigo <paul.verigo@gmail.com> | 2025-02-27 15:12:18 +0100 |
|---|---|---|
| committer | Pavel Verigo <paul.verigo@gmail.com> | 2025-03-24 15:00:00 +0100 |
| commit | 15bc2ab0a868fed31780d73451db4d1c69e7b489 (patch) | |
| tree | 87243ddf2237691ec558bd1543231fd90f7aa72c /src | |
| parent | a429d04ba9cb1205d88211b7b39cbd68113b7178 (diff) | |
| download | zig-15bc2ab0a868fed31780d73451db4d1c69e7b489.tar.gz zig-15bc2ab0a868fed31780d73451db4d1c69e7b489.zip | |
stage2-wasm: clz fix
Diffstat (limited to 'src')
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index a0de387dfd..dbd650ab01 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -6272,11 +6272,21 @@ fn airClz(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void { switch (wasm_bits) { 32 => { - try cg.emitWValue(operand); + if (int_info.signedness == .signed) { + const mask = ~@as(u32, 0) >> @intCast(32 - int_info.bits); + _ = try cg.binOp(operand, .{ .imm32 = mask }, ty, .@"and"); + } else { + try cg.emitWValue(operand); + } try cg.addTag(.i32_clz); }, 64 => { - try cg.emitWValue(operand); + if (int_info.signedness == .signed) { + const mask = ~@as(u64, 0) >> @intCast(64 - int_info.bits); + _ = try cg.binOp(operand, .{ .imm64 = mask }, ty, .@"and"); + } else { + try cg.emitWValue(operand); + } try cg.addTag(.i64_clz); try cg.addTag(.i32_wrap_i64); }, |
