From 1803167db2d5045e71015498b8e5b184c53edf07 Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Fri, 25 Mar 2022 09:30:53 +0100 Subject: AIR: change signature of overflow arithmetic instructions add_with_overflow and similar functions now have the ty_pl data attached. The Payload will now be a binary operation and the inst is expected to return a tuple consisting of the destination integer type and an overflow bit (u1). Co-authored-by: Jan Philipp Hafer --- src/Air.zig | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/Air.zig') diff --git a/src/Air.zig b/src/Air.zig index 5120e0fd67..a0fb512934 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -134,28 +134,24 @@ pub const Inst = struct { /// Uses the `bin_op` field. min, /// Integer addition with overflow. Both operands are guaranteed to be the same type, - /// and the result is bool. The wrapped value is written to the pointer given by the in - /// operand of the `pl_op` field. Payload is `Bin` with `lhs` and `rhs` the relevant types - /// of the operation. - /// Uses the `pl_op` field with payload `Bin`. + /// and the result is a tuple with .{res, ov}. The wrapped value is written to res + /// and if an overflow happens, ov is 1. Otherwise ov is 0. + /// Uses the `ty_pl` field. Payload is `Bin`. add_with_overflow, /// Integer subtraction with overflow. Both operands are guaranteed to be the same type, - /// and the result is bool. The wrapped value is written to the pointer given by the in - /// operand of the `pl_op` field. Payload is `Bin` with `lhs` and `rhs` the relevant types - /// of the operation. - /// Uses the `pl_op` field with payload `Bin`. + /// and the result is a tuple with .{res, ov}. The wrapped value is written to res + /// and if an overflow happens, ov is 1. Otherwise ov is 0. + /// Uses the `ty_pl` field. Payload is `Bin`. sub_with_overflow, /// Integer multiplication with overflow. Both operands are guaranteed to be the same type, - /// and the result is bool. The wrapped value is written to the pointer given by the in - /// operand of the `pl_op` field. Payload is `Bin` with `lhs` and `rhs` the relevant types - /// of the operation. - /// Uses the `pl_op` field with payload `Bin`. + /// and the result is a tuple with .{res, ov}. The wrapped value is written to res + /// and if an overflow happens, ov is 1. Otherwise ov is 0. + /// Uses the `ty_pl` field. Payload is `Bin`. mul_with_overflow, /// Integer left-shift with overflow. Both operands are guaranteed to be the same type, - /// and the result is bool. The wrapped value is written to the pointer given by the in - /// operand of the `pl_op` field. Payload is `Bin` with `lhs` and `rhs` the relevant types - /// of the operation. - /// Uses the `pl_op` field with payload `Bin`. + /// and the result is a tuple with .{res, ov}. The wrapped value is written to res + /// and if an overflow happens, ov is 1. Otherwise ov is 0. + /// Uses the `ty_pl` field. Payload is `Bin`. shl_with_overflow, /// Allocates stack local memory. /// Uses the `ty` field. @@ -964,6 +960,10 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type { .union_init, .field_parent_ptr, .cmp_vector, + .add_with_overflow, + .sub_with_overflow, + .mul_with_overflow, + .shl_with_overflow, => return air.getRefType(datas[inst].ty_pl.ty), .not, @@ -1074,12 +1074,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type { const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data; return air.typeOf(extra.lhs); }, - - .add_with_overflow, - .sub_with_overflow, - .mul_with_overflow, - .shl_with_overflow, - => return Type.bool, } } -- cgit v1.2.3