| ... | @@ -1743,6 +1743,7 @@ pub const DeclGen = struct { | ... | @@ -1743,6 +1743,7 @@ pub const DeclGen = struct { |
| 1743 | .shuffle => try self.airShuffle(inst), | 1743 | .shuffle => try self.airShuffle(inst), |
| 1744 | | 1744 | |
| 1745 | .ptr_add => try self.airPtrAdd(inst), | 1745 | .ptr_add => try self.airPtrAdd(inst), |
| | 1746 | .ptr_sub => try self.airPtrSub(inst), |
| 1746 | | 1747 | |
| 1747 | .bit_and => try self.airBinOpSimple(inst, .OpBitwiseAnd), | 1748 | .bit_and => try self.airBinOpSimple(inst, .OpBitwiseAnd), |
| 1748 | .bit_or => try self.airBinOpSimple(inst, .OpBitwiseOr), | 1749 | .bit_or => try self.airBinOpSimple(inst, .OpBitwiseOr), |
| ... | @@ -2126,14 +2127,7 @@ pub const DeclGen = struct { | ... | @@ -2126,14 +2127,7 @@ pub const DeclGen = struct { |
| 2126 | return result_id; | 2127 | return result_id; |
| 2127 | } | 2128 | } |
| 2128 | | 2129 | |
| 2129 | fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { | 2130 | fn ptrAdd(self: *DeclGen, result_ty: Type, ptr_ty: Type, ptr_id: IdRef, offset_id: IdRef) !IdRef { |
| 2130 | if (self.liveness.isUnused(inst)) return null; | | |
| 2131 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | | |
| 2132 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; | | |
| 2133 | const ptr_id = try self.resolve(bin_op.lhs); | | |
| 2134 | const offset_id = try self.resolve(bin_op.rhs); | | |
| 2135 | const ptr_ty = self.air.typeOf(bin_op.lhs); | | |
| 2136 | const result_ty = self.air.typeOfIndex(inst); | | |
| 2137 | const result_ty_ref = try self.resolveType(result_ty, .direct); | 2131 | const result_ty_ref = try self.resolveType(result_ty, .direct); |
| 2138 | | 2132 | |
| 2139 | switch (ptr_ty.ptrSize()) { | 2133 | switch (ptr_ty.ptrSize()) { |
| ... | @@ -2153,6 +2147,38 @@ pub const DeclGen = struct { | ... | @@ -2153,6 +2147,38 @@ pub const DeclGen = struct { |
| 2153 | } | 2147 | } |
| 2154 | } | 2148 | } |
| 2155 | | 2149 | |
| | 2150 | fn airPtrAdd(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| | 2151 | if (self.liveness.isUnused(inst)) return null; |
| | 2152 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; |
| | 2153 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| | 2154 | const ptr_id = try self.resolve(bin_op.lhs); |
| | 2155 | const offset_id = try self.resolve(bin_op.rhs); |
| | 2156 | const ptr_ty = self.air.typeOf(bin_op.lhs); |
| | 2157 | const result_ty = self.air.typeOfIndex(inst); |
| | 2158 | |
| | 2159 | return try self.ptrAdd(result_ty, ptr_ty, ptr_id, offset_id); |
| | 2160 | } |
| | 2161 | |
| | 2162 | fn airPtrSub(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| | 2163 | if (self.liveness.isUnused(inst)) return null; |
| | 2164 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; |
| | 2165 | const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; |
| | 2166 | const ptr_id = try self.resolve(bin_op.lhs); |
| | 2167 | const ptr_ty = self.air.typeOf(bin_op.lhs); |
| | 2168 | const offset_id = try self.resolve(bin_op.rhs); |
| | 2169 | const offset_ty = self.air.typeOf(bin_op.rhs); |
| | 2170 | const offset_ty_ref = try self.resolveType(offset_ty, .direct); |
| | 2171 | const result_ty = self.air.typeOfIndex(inst); |
| | 2172 | |
| | 2173 | const negative_offset_id = self.spv.allocId(); |
| | 2174 | try self.func.body.emit(self.spv.gpa, .OpSNegate, .{ |
| | 2175 | .id_result_type = self.typeId(offset_ty_ref), |
| | 2176 | .id_result = negative_offset_id, |
| | 2177 | .operand = offset_id, |
| | 2178 | }); |
| | 2179 | return try self.ptrAdd(result_ty, ptr_ty, ptr_id, negative_offset_id); |
| | 2180 | } |
| | 2181 | |
| 2156 | fn cmp( | 2182 | fn cmp( |
| 2157 | self: *DeclGen, | 2183 | self: *DeclGen, |
| 2158 | comptime op: std.math.CompareOperator, | 2184 | comptime op: std.math.CompareOperator, |