diff options
| author | Pavel Verigo <paul.verigo@gmail.com> | 2024-07-23 21:17:04 +0200 |
|---|---|---|
| committer | Pavel Verigo <paul.verigo@gmail.com> | 2024-07-23 21:17:04 +0200 |
| commit | ba8522e6c79b5c93cfbd8bdfbecabf8255848624 (patch) | |
| tree | f3d183c7e776751ad8fe8bc660baefac653c5dc6 /src/arch/wasm/CodeGen.zig | |
| parent | 8fd1f01f2ac6f23d8e383c7dda276c604bdf7e2f (diff) | |
| download | zig-ba8522e6c79b5c93cfbd8bdfbecabf8255848624.tar.gz zig-ba8522e6c79b5c93cfbd8bdfbecabf8255848624.zip | |
stage2-wasm: fix bigint div and trunc
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index c23b8f3f72..68b7f72938 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -2666,8 +2666,8 @@ fn binOpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) Inner switch (op) { .mul => return func.callIntrinsic("__multi3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }), .div => switch (int_info.signedness) { - .signed => return func.callIntrinsic("__udivti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }), - .unsigned => return func.callIntrinsic("__divti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }), + .signed => return func.callIntrinsic("__divti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }), + .unsigned => return func.callIntrinsic("__udivti3", &.{ ty.toIntern(), ty.toIntern() }, ty, &.{ lhs, rhs }), }, .rem => switch (int_info.signedness) { .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 { else try func.intcast(operand, operand_ty, ty); - return func.finishAir(inst, result, &.{}); + return func.finishAir(inst, result, &.{ty_op.operand}); } /// 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 { const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; const operand = try func.resolveInst(ty_op.operand); - const wanted_ty = ty_op.ty.toType(); + const wanted_ty: Type = ty_op.ty.toType(); const op_ty = func.typeOf(ty_op.operand); + const pt = func.pt; + const mod = pt.zcu; + + if (wanted_ty.zigTypeTag(mod) == .Vector or op_ty.zigTypeTag(mod) == .Vector) { + return func.fail("TODO: trunc for vectors", .{}); + } + + const result = if (op_ty.bitSize(pt) == wanted_ty.bitSize(pt)) + func.reuseOperand(ty_op.operand, operand) + else + try func.trunc(operand, wanted_ty, op_ty); - const result = try func.trunc(operand, wanted_ty, op_ty); return func.finishAir(inst, result, &.{ty_op.operand}); } |
