mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
codegen.wasm: fix 64-bit saturating shl
Previously, 64-bit '<<|' operations were emitting 64-bit shifts with one 64-bit operand and one 32-bit operand, which is illegal. Instead, as in the lowering for regular shifts, we need to cast the RHS in this case.
This commit is contained in:
parent
f7f0b9d28f
commit
b3c498454b
1 changed files with 13 additions and 2 deletions
|
|
@ -6973,9 +6973,20 @@ fn airShlSat(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
|
|||
return cg.fail("TODO: Saturating shifting left for integers with bitsize '{d}'", .{int_info.bits});
|
||||
}
|
||||
|
||||
const lhs = try cg.resolveInst(bin_op.lhs);
|
||||
const rhs = try cg.resolveInst(bin_op.rhs);
|
||||
const wasm_bits = toWasmBits(int_info.bits).?;
|
||||
|
||||
const lhs = try cg.resolveInst(bin_op.lhs);
|
||||
const rhs = rhs: {
|
||||
const rhs = try cg.resolveInst(bin_op.rhs);
|
||||
const rhs_ty = cg.typeOf(bin_op.rhs);
|
||||
// The type of `rhs` is the log2 int of the type of `lhs`, but WASM wants the lhs and rhs types to match.
|
||||
if (toWasmBits(@intCast(rhs_ty.bitSize(zcu))).? == wasm_bits) {
|
||||
break :rhs rhs; // the WASM types match, so no cast necessary
|
||||
}
|
||||
const casted = try cg.intcast(rhs, rhs_ty, ty);
|
||||
break :rhs try casted.toLocal(cg, ty);
|
||||
};
|
||||
|
||||
const result = try cg.allocLocal(ty);
|
||||
|
||||
if (wasm_bits == int_info.bits) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue