aboutsummaryrefslogtreecommitdiff
path: root/src/arch/wasm/CodeGen.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
-rw-r--r--src/arch/wasm/CodeGen.zig14
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);
},