authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-25 09:30:53+01:00
committergravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-26 17:21:39+01:00
log1803167db2d5045e71015498b8e5b184c53edf07
treef41994dd5eecaf7d62e10f68fe2dc48b934b9cd5
parentaf844931b2600e50e586436dee0d607d67ed9ff2
signaturelock-open Commit is signed but in an unrecognized format.

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 <jan.hafer@rwth-aachen.de>

2 files changed, 20 insertions(+), 28 deletions(-)

src/Air.zig+16-22
...@@ -134,28 +134,24 @@ pub const Inst = struct {...@@ -134,28 +134,24 @@ pub const Inst = struct {
134 /// Uses the `bin_op` field.134 /// Uses the `bin_op` field.
135 min,135 min,
136 /// Integer addition with overflow. Both operands are guaranteed to be the same type,136 /// Integer addition with overflow. Both operands are guaranteed to be the same type,
137 /// and the result is bool. The wrapped value is written to the pointer given by the in137 /// and the result is a tuple with .{res, ov}. The wrapped value is written to res
138 /// operand of the `pl_op` field. Payload is `Bin` with `lhs` and `rhs` the relevant types138 /// and if an overflow happens, ov is 1. Otherwise ov is 0.
139 /// of the operation.139 /// Uses the `ty_pl` field. Payload is `Bin`.
140 /// Uses the `pl_op` field with payload `Bin`.
141 add_with_overflow,140 add_with_overflow,
142 /// Integer subtraction with overflow. Both operands are guaranteed to be the same type,141 /// Integer subtraction with overflow. Both operands are guaranteed to be the same type,
143 /// and the result is bool. The wrapped value is written to the pointer given by the in142 /// and the result is a tuple with .{res, ov}. The wrapped value is written to res
144 /// operand of the `pl_op` field. Payload is `Bin` with `lhs` and `rhs` the relevant types143 /// and if an overflow happens, ov is 1. Otherwise ov is 0.
145 /// of the operation.144 /// Uses the `ty_pl` field. Payload is `Bin`.
146 /// Uses the `pl_op` field with payload `Bin`.
147 sub_with_overflow,145 sub_with_overflow,
148 /// Integer multiplication with overflow. Both operands are guaranteed to be the same type,146 /// Integer multiplication with overflow. Both operands are guaranteed to be the same type,
149 /// and the result is bool. The wrapped value is written to the pointer given by the in147 /// and the result is a tuple with .{res, ov}. The wrapped value is written to res
150 /// operand of the `pl_op` field. Payload is `Bin` with `lhs` and `rhs` the relevant types148 /// and if an overflow happens, ov is 1. Otherwise ov is 0.
151 /// of the operation.149 /// Uses the `ty_pl` field. Payload is `Bin`.
152 /// Uses the `pl_op` field with payload `Bin`.
153 mul_with_overflow,150 mul_with_overflow,
154 /// Integer left-shift with overflow. Both operands are guaranteed to be the same type,151 /// Integer left-shift with overflow. Both operands are guaranteed to be the same type,
155 /// and the result is bool. The wrapped value is written to the pointer given by the in152 /// and the result is a tuple with .{res, ov}. The wrapped value is written to res
156 /// operand of the `pl_op` field. Payload is `Bin` with `lhs` and `rhs` the relevant types153 /// and if an overflow happens, ov is 1. Otherwise ov is 0.
157 /// of the operation.154 /// Uses the `ty_pl` field. Payload is `Bin`.
158 /// Uses the `pl_op` field with payload `Bin`.
159 shl_with_overflow,155 shl_with_overflow,
160 /// Allocates stack local memory.156 /// Allocates stack local memory.
161 /// Uses the `ty` field.157 /// Uses the `ty` field.
...@@ -964,6 +960,10 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {...@@ -964,6 +960,10 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
964 .union_init,960 .union_init,
965 .field_parent_ptr,961 .field_parent_ptr,
966 .cmp_vector,962 .cmp_vector,
963 .add_with_overflow,
964 .sub_with_overflow,
965 .mul_with_overflow,
966 .shl_with_overflow,
967 => return air.getRefType(datas[inst].ty_pl.ty),967 => return air.getRefType(datas[inst].ty_pl.ty),
968968
969 .not,969 .not,
...@@ -1074,12 +1074,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {...@@ -1074,12 +1074,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
1074 const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data;1074 const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data;
1075 return air.typeOf(extra.lhs);1075 return air.typeOf(extra.lhs);
1076 },1076 },
1077
1078 .add_with_overflow,
1079 .sub_with_overflow,
1080 .mul_with_overflow,
1081 .shl_with_overflow,
1082 => return Type.bool,
1083 }1077 }
1084}1078}
10851079
src/print_air.zig+4-6
...@@ -473,14 +473,12 @@ const Writer = struct {...@@ -473,14 +473,12 @@ const Writer = struct {
473 }473 }
474474
475 fn writeOverflow(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {475 fn writeOverflow(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
476 const pl_op = w.air.instructions.items(.data)[inst].pl_op;476 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
477 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;477 const extra = w.air.extraData(Air.Bin, ty_pl.payload).data;
478478
479 try w.writeOperand(s, inst, 0, pl_op.operand);479 try w.writeOperand(s, inst, 0, extra.lhs);
480 try s.writeAll(", ");
481 try w.writeOperand(s, inst, 1, extra.lhs);
482 try s.writeAll(", ");480 try s.writeAll(", ");
483 try w.writeOperand(s, inst, 2, extra.rhs);481 try w.writeOperand(s, inst, 1, extra.rhs);
484 }482 }
485483
486 fn writeMemset(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {484 fn writeMemset(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {