| ... | ... | @@ -6672,33 +6672,43 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6672 | 6672 | const operand_ty = f.air.typeOf(reduce.operand); |
| 6673 | 6673 | const writer = f.object.writer(); |
| 6674 | 6674 | |
| 6675 | const use_operator = scalar_ty.bitSize(target) <= 64; |
| 6675 | 6676 | const op: union(enum) { |
| 6676 | | float_op: []const u8, |
| 6677 | | builtin: []const u8, |
| 6677 | const Func = struct { operation: []const u8, info: BuiltinInfo = .none }; |
| 6678 | float_op: Func, |
| 6679 | builtin: Func, |
| 6678 | 6680 | infix: []const u8, |
| 6679 | 6681 | ternary: []const u8, |
| 6680 | 6682 | } = switch (reduce.operation) { |
| 6681 | | .And => .{ .infix = " &= " }, |
| 6682 | | .Or => .{ .infix = " |= " }, |
| 6683 | | .Xor => .{ .infix = " ^= " }, |
| 6683 | .And => if (use_operator) .{ .infix = " &= " } else .{ .builtin = .{ .operation = "and" } }, |
| 6684 | .Or => if (use_operator) .{ .infix = " |= " } else .{ .builtin = .{ .operation = "or" } }, |
| 6685 | .Xor => if (use_operator) .{ .infix = " ^= " } else .{ .builtin = .{ .operation = "xor" } }, |
| 6684 | 6686 | .Min => switch (scalar_ty.zigTypeTag()) { |
| 6685 | | .Int => .{ .ternary = " < " }, |
| 6686 | | .Float => .{ .float_op = "fmin" }, |
| 6687 | .Int => if (use_operator) .{ .ternary = " < " } else .{ |
| 6688 | .builtin = .{ .operation = "min" }, |
| 6689 | }, |
| 6690 | .Float => .{ .float_op = .{ .operation = "fmin" } }, |
| 6687 | 6691 | else => unreachable, |
| 6688 | 6692 | }, |
| 6689 | 6693 | .Max => switch (scalar_ty.zigTypeTag()) { |
| 6690 | | .Int => .{ .ternary = " > " }, |
| 6691 | | .Float => .{ .float_op = "fmax" }, |
| 6694 | .Int => if (use_operator) .{ .ternary = " > " } else .{ |
| 6695 | .builtin = .{ .operation = "max" }, |
| 6696 | }, |
| 6697 | .Float => .{ .float_op = .{ .operation = "fmax" } }, |
| 6692 | 6698 | else => unreachable, |
| 6693 | 6699 | }, |
| 6694 | 6700 | .Add => switch (scalar_ty.zigTypeTag()) { |
| 6695 | | .Int => .{ .infix = " += " }, |
| 6696 | | .Float => .{ .builtin = "add" }, |
| 6701 | .Int => if (use_operator) .{ .infix = " += " } else .{ |
| 6702 | .builtin = .{ .operation = "addw", .info = .bits }, |
| 6703 | }, |
| 6704 | .Float => .{ .builtin = .{ .operation = "add" } }, |
| 6697 | 6705 | else => unreachable, |
| 6698 | 6706 | }, |
| 6699 | 6707 | .Mul => switch (scalar_ty.zigTypeTag()) { |
| 6700 | | .Int => .{ .infix = " *= " }, |
| 6701 | | .Float => .{ .builtin = "mul" }, |
| 6708 | .Int => if (use_operator) .{ .infix = " *= " } else .{ |
| 6709 | .builtin = .{ .operation = "mulw", .info = .bits }, |
| 6710 | }, |
| 6711 | .Float => .{ .builtin = .{ .operation = "mul" } }, |
| 6702 | 6712 | else => unreachable, |
| 6703 | 6713 | }, |
| 6704 | 6714 | }; |
| ... | ... | @@ -6762,24 +6772,26 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6762 | 6772 | const v = try Vectorizer.start(f, inst, writer, operand_ty); |
| 6763 | 6773 | try f.writeCValue(writer, accum, .Other); |
| 6764 | 6774 | switch (op) { |
| 6765 | | .float_op => |operation| { |
| 6775 | .float_op => |func| { |
| 6766 | 6776 | try writer.writeAll(" = zig_libc_name_"); |
| 6767 | 6777 | try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty); |
| 6768 | | try writer.print("({s})(", .{operation}); |
| 6778 | try writer.print("({s})(", .{func.operation}); |
| 6769 | 6779 | try f.writeCValue(writer, accum, .FunctionArgument); |
| 6770 | 6780 | try writer.writeAll(", "); |
| 6771 | 6781 | try f.writeCValue(writer, operand, .Other); |
| 6772 | 6782 | try v.elem(f, writer); |
| 6783 | try f.object.dg.renderBuiltinInfo(writer, scalar_ty, func.info); |
| 6773 | 6784 | try writer.writeByte(')'); |
| 6774 | 6785 | }, |
| 6775 | | .builtin => |operation| { |
| 6776 | | try writer.print(" = zig_{s}_", .{operation}); |
| 6786 | .builtin => |func| { |
| 6787 | try writer.print(" = zig_{s}_", .{func.operation}); |
| 6777 | 6788 | try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty); |
| 6778 | 6789 | try writer.writeByte('('); |
| 6779 | 6790 | try f.writeCValue(writer, accum, .FunctionArgument); |
| 6780 | 6791 | try writer.writeAll(", "); |
| 6781 | 6792 | try f.writeCValue(writer, operand, .Other); |
| 6782 | 6793 | try v.elem(f, writer); |
| 6794 | try f.object.dg.renderBuiltinInfo(writer, scalar_ty, func.info); |
| 6783 | 6795 | try writer.writeByte(')'); |
| 6784 | 6796 | }, |
| 6785 | 6797 | .infix => |ass| { |