authorgravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2024-07-23 21:17:04+02:00
committergravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2024-07-23 21:17:04+02:00
logba8522e6c79b5c93cfbd8bdfbecabf8255848624
treef3d183c7e776751ad8fe8bc660baefac653c5dc6
parent8fd1f01f2ac6f23d8e383c7dda276c604bdf7e2f

stage2-wasm: fix bigint div and trunc


1 files changed, 15 insertions(+), 5 deletions(-)

src/arch/wasm/CodeGen.zig+15-5
......@@ -2666,8 +2666,8 @@ fn binOpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) Inner
26662666 switch (op) {
26672667 .mul => return func.callIntrinsic("__multi3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }),
26682668 .div => switch (int_info.signedness) {
2669 .signed => return func.callIntrinsic("__udivti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }),
2670 .unsigned => return func.callIntrinsic("__divti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }),
2669 .signed => return func.callIntrinsic("__divti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }),
2670 .unsigned => return func.callIntrinsic("__udivti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }),
26712671 },
26722672 .rem => switch (int_info.signedness) {
26732673 .signed => return func.callIntrinsic("__modti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }),
......@@ -4378,7 +4378,7 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43784378 else
43794379 try func.intcast(operand, operand_ty, ty);
43804380
4381 return func.finishAir(inst, result, &.{});
4381 return func.finishAir(inst, result, &.{ty_op.operand});
43824382}
43834383
43844384/// Upcasts or downcasts an integer based on the given and wanted types,
......@@ -4677,10 +4677,20 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46774677 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
46784678
46794679 const operand = try func.resolveInst(ty_op.operand);
4680 const wanted_ty = ty_op.ty.toType();
4680 const wanted_ty: Type = ty_op.ty.toType();
46814681 const op_ty = func.typeOf(ty_op.operand);
4682 const pt = func.pt;
4683 const mod = pt.zcu;
4684
4685 if (wanted_ty.zigTypeTag(mod) == .Vector or op_ty.zigTypeTag(mod) == .Vector) {
4686 return func.fail("TODO: trunc for vectors", .{});
4687 }
4688
4689 const result = if (op_ty.bitSize(pt) == wanted_ty.bitSize(pt))
4690 func.reuseOperand(ty_op.operand, operand)
4691 else
4692 try func.trunc(operand, wanted_ty, op_ty);
46824693
4683 const result = try func.trunc(operand, wanted_ty, op_ty);
46844694 return func.finishAir(inst, result, &.{ty_op.operand});
46854695}
46864696