| ... | @@ -48,6 +48,60 @@ pub const CValue = union(enum) { | ... | @@ -48,6 +48,60 @@ pub const CValue = union(enum) { |
| 48 | payload_identifier: []const u8, | 48 | payload_identifier: []const u8, |
| 49 | /// Rendered with fmtCTypePoolString | 49 | /// Rendered with fmtCTypePoolString |
| 50 | ctype_pool_string: CType.Pool.String, | 50 | ctype_pool_string: CType.Pool.String, |
| | 51 | |
| | 52 | fn eql(lhs: CValue, rhs: CValue) bool { |
| | 53 | return switch (lhs) { |
| | 54 | .none => rhs == .none, |
| | 55 | .new_local, .local => |lhs_local| switch (rhs) { |
| | 56 | .new_local, .local => |rhs_local| lhs_local == rhs_local, |
| | 57 | else => false, |
| | 58 | }, |
| | 59 | .local_ref => |lhs_local| switch (rhs) { |
| | 60 | .local_ref => |rhs_local| lhs_local == rhs_local, |
| | 61 | else => false, |
| | 62 | }, |
| | 63 | .constant => |lhs_val| switch (rhs) { |
| | 64 | .constant => |rhs_val| lhs_val.toIntern() == rhs_val.toIntern(), |
| | 65 | else => false, |
| | 66 | }, |
| | 67 | .arg => |lhs_arg_index| switch (rhs) { |
| | 68 | .arg => |rhs_arg_index| lhs_arg_index == rhs_arg_index, |
| | 69 | else => false, |
| | 70 | }, |
| | 71 | .arg_array => |lhs_arg_index| switch (rhs) { |
| | 72 | .arg_array => |rhs_arg_index| lhs_arg_index == rhs_arg_index, |
| | 73 | else => false, |
| | 74 | }, |
| | 75 | .field => |lhs_field_index| switch (rhs) { |
| | 76 | .field => |rhs_field_index| lhs_field_index == rhs_field_index, |
| | 77 | else => false, |
| | 78 | }, |
| | 79 | .nav => |lhs_nav| switch (rhs) { |
| | 80 | .nav => |rhs_nav| lhs_nav == rhs_nav, |
| | 81 | else => false, |
| | 82 | }, |
| | 83 | .nav_ref => |lhs_nav| switch (rhs) { |
| | 84 | .nav_ref => |rhs_nav| lhs_nav == rhs_nav, |
| | 85 | else => false, |
| | 86 | }, |
| | 87 | .undef => |lhs_ty| switch (rhs) { |
| | 88 | .undef => |rhs_ty| lhs_ty.toIntern() == rhs_ty.toIntern(), |
| | 89 | else => false, |
| | 90 | }, |
| | 91 | .identifier => |lhs_id| switch (rhs) { |
| | 92 | .identifier => |rhs_id| std.mem.eql(u8, lhs_id, rhs_id), |
| | 93 | else => false, |
| | 94 | }, |
| | 95 | .payload_identifier => |lhs_id| switch (rhs) { |
| | 96 | .payload_identifier => |rhs_id| std.mem.eql(u8, lhs_id, rhs_id), |
| | 97 | else => false, |
| | 98 | }, |
| | 99 | .ctype_pool_string => |lhs_str| switch (rhs) { |
| | 100 | .ctype_pool_string => |rhs_str| lhs_str.index == rhs_str.index, |
| | 101 | else => false, |
| | 102 | }, |
| | 103 | }; |
| | 104 | } |
| 51 | }; | 105 | }; |
| 52 | | 106 | |
| 53 | const BlockData = struct { | 107 | const BlockData = struct { |
| ... | @@ -4219,17 +4273,23 @@ fn airCmpOp( | ... | @@ -4219,17 +4273,23 @@ fn airCmpOp( |
| 4219 | const writer = f.object.writer(); | 4273 | const writer = f.object.writer(); |
| 4220 | const local = try f.allocLocal(inst, inst_ty); | 4274 | const local = try f.allocLocal(inst, inst_ty); |
| 4221 | const v = try Vectorize.start(f, inst, writer, lhs_ty); | 4275 | const v = try Vectorize.start(f, inst, writer, lhs_ty); |
| | 4276 | const a = try Assignment.start(f, writer, try f.ctypeFromType(scalar_ty, .complete)); |
| 4222 | try f.writeCValue(writer, local, .Other); | 4277 | try f.writeCValue(writer, local, .Other); |
| 4223 | try v.elem(f, writer); | 4278 | try v.elem(f, writer); |
| 4224 | try writer.writeAll(" = "); | 4279 | try a.assign(f, writer); |
| 4225 | if (need_cast) try writer.writeAll("(void*)"); | 4280 | if (lhs != .undef and lhs.eql(rhs)) try writer.writeAll(switch (operator) { |
| 4226 | try f.writeCValue(writer, lhs, .Other); | 4281 | .lt, .neq, .gt => "false", |
| 4227 | try v.elem(f, writer); | 4282 | .lte, .eq, .gte => "true", |
| 4228 | try writer.writeAll(compareOperatorC(operator)); | 4283 | }) else { |
| 4229 | if (need_cast) try writer.writeAll("(void*)"); | 4284 | if (need_cast) try writer.writeAll("(void*)"); |
| 4230 | try f.writeCValue(writer, rhs, .Other); | 4285 | try f.writeCValue(writer, lhs, .Other); |
| 4231 | try v.elem(f, writer); | 4286 | try v.elem(f, writer); |
| 4232 | try writer.writeAll(";\n"); | 4287 | try writer.writeAll(compareOperatorC(operator)); |
| | 4288 | if (need_cast) try writer.writeAll("(void*)"); |
| | 4289 | try f.writeCValue(writer, rhs, .Other); |
| | 4290 | try v.elem(f, writer); |
| | 4291 | } |
| | 4292 | try a.end(f, writer); |
| 4233 | try v.end(f, inst, writer); | 4293 | try v.end(f, inst, writer); |
| 4234 | | 4294 | |
| 4235 | return local; | 4295 | return local; |
| ... | @@ -4270,7 +4330,11 @@ fn airEquality( | ... | @@ -4270,7 +4330,11 @@ fn airEquality( |
| 4270 | try a.assign(f, writer); | 4330 | try a.assign(f, writer); |
| 4271 | | 4331 | |
| 4272 | const operand_ctype = try f.ctypeFromType(operand_ty, .complete); | 4332 | const operand_ctype = try f.ctypeFromType(operand_ty, .complete); |
| 4273 | switch (operand_ctype.info(ctype_pool)) { | 4333 | if (lhs != .undef and lhs.eql(rhs)) try writer.writeAll(switch (operator) { |
| | 4334 | .lt, .lte, .gte, .gt => unreachable, |
| | 4335 | .neq => "false", |
| | 4336 | .eq => "true", |
| | 4337 | }) else switch (operand_ctype.info(ctype_pool)) { |
| 4274 | .basic, .pointer => { | 4338 | .basic, .pointer => { |
| 4275 | try f.writeCValue(writer, lhs, .Other); | 4339 | try f.writeCValue(writer, lhs, .Other); |
| 4276 | try writer.writeAll(compareOperatorC(operator)); | 4340 | try writer.writeAll(compareOperatorC(operator)); |