x86_64: rewrite wrapping multiplication

This commit is contained in:
Jacob Young 2025-03-11 18:24:37 -04:00
parent ed284c1f98
commit c5c1c8538d
14 changed files with 2917 additions and 94 deletions

View file

@ -2136,7 +2136,7 @@ pub const Inst = struct {
ref_start_index = static_len,
_,
pub const static_len = 93;
pub const static_len = 97;
pub fn toRef(i: Index) Inst.Ref {
return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
@ -2221,6 +2221,10 @@ pub const Inst = struct {
slice_const_u8_sentinel_0_type,
vector_16_i8_type,
vector_32_i8_type,
vector_1_u8_type,
vector_2_u8_type,
vector_4_u8_type,
vector_8_u8_type,
vector_16_u8_type,
vector_32_u8_type,
vector_8_i16_type,

View file

@ -985,6 +985,10 @@ pub const Inst = struct {
slice_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.slice_const_u8_sentinel_0_type),
vector_16_i8_type = @intFromEnum(InternPool.Index.vector_16_i8_type),
vector_32_i8_type = @intFromEnum(InternPool.Index.vector_32_i8_type),
vector_1_u8_type = @intFromEnum(InternPool.Index.vector_1_u8_type),
vector_2_u8_type = @intFromEnum(InternPool.Index.vector_2_u8_type),
vector_4_u8_type = @intFromEnum(InternPool.Index.vector_4_u8_type),
vector_8_u8_type = @intFromEnum(InternPool.Index.vector_8_u8_type),
vector_16_u8_type = @intFromEnum(InternPool.Index.vector_16_u8_type),
vector_32_u8_type = @intFromEnum(InternPool.Index.vector_32_u8_type),
vector_8_i16_type = @intFromEnum(InternPool.Index.vector_8_i16_type),

View file

@ -4573,6 +4573,10 @@ pub const Index = enum(u32) {
vector_16_i8_type,
vector_32_i8_type,
vector_1_u8_type,
vector_2_u8_type,
vector_4_u8_type,
vector_8_u8_type,
vector_16_u8_type,
vector_32_u8_type,
vector_8_i16_type,
@ -5089,6 +5093,14 @@ pub const static_keys = [_]Key{
.{ .vector_type = .{ .len = 16, .child = .i8_type } },
// @Vector(32, i8)
.{ .vector_type = .{ .len = 32, .child = .i8_type } },
// @Vector(1, u8)
.{ .vector_type = .{ .len = 1, .child = .u8_type } },
// @Vector(2, u8)
.{ .vector_type = .{ .len = 2, .child = .u8_type } },
// @Vector(4, u8)
.{ .vector_type = .{ .len = 4, .child = .u8_type } },
// @Vector(8, u8)
.{ .vector_type = .{ .len = 8, .child = .u8_type } },
// @Vector(16, u8)
.{ .vector_type = .{ .len = 16, .child = .u8_type } },
// @Vector(32, u8)
@ -11766,6 +11778,10 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
.slice_const_u8_sentinel_0_type,
.vector_16_i8_type,
.vector_32_i8_type,
.vector_1_u8_type,
.vector_2_u8_type,
.vector_4_u8_type,
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_8_i16_type,
@ -12106,6 +12122,10 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
.vector_16_i8_type,
.vector_32_i8_type,
.vector_1_u8_type,
.vector_2_u8_type,
.vector_4_u8_type,
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_8_i16_type,

View file

@ -36377,6 +36377,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
.slice_const_u8_sentinel_0_type,
.vector_16_i8_type,
.vector_32_i8_type,
.vector_1_u8_type,
.vector_2_u8_type,
.vector_4_u8_type,
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_8_i16_type,

View file

@ -4201,6 +4201,10 @@ pub const slice_const_u8_sentinel_0: Type = .{ .ip_index = .slice_const_u8_senti
pub const vector_16_i8: Type = .{ .ip_index = .vector_16_i8_type };
pub const vector_32_i8: Type = .{ .ip_index = .vector_32_i8_type };
pub const vector_1_u8: Type = .{ .ip_index = .vector_1_u8_type };
pub const vector_2_u8: Type = .{ .ip_index = .vector_2_u8_type };
pub const vector_4_u8: Type = .{ .ip_index = .vector_4_u8_type };
pub const vector_8_u8: Type = .{ .ip_index = .vector_8_u8_type };
pub const vector_16_u8: Type = .{ .ip_index = .vector_16_u8_type };
pub const vector_32_u8: Type = .{ .ip_index = .vector_32_u8_type };
pub const vector_8_i16: Type = .{ .ip_index = .vector_8_i16_type };

File diff suppressed because it is too large Load diff

View file

@ -579,7 +579,7 @@ fn generic(lower: *Lower, inst: Mir.Inst) Error!void {
.rrri => inst.data.rrri.fixes,
.rri_s, .rri_u => inst.data.rri.fixes,
.ri_s, .ri_u, .ri_64, .ir => inst.data.ri.fixes,
.rm, .rmi_s, .mr => inst.data.rx.fixes,
.rm, .rmi_s, .rmi_u, .mr => inst.data.rx.fixes,
.mrr, .rrm, .rmr => inst.data.rrx.fixes,
.rmi, .mri => inst.data.rix.fixes,
.rrmr => inst.data.rrrx.fixes,

View file

@ -1474,6 +1474,66 @@ pub const Pool = struct {
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_1_u8_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .u8,
.len = 1,
});
if (!kind.isParameter()) return vector_ctype;
var fields = [_]Info.Field{
.{
.name = .{ .index = .array },
.ctype = vector_ctype,
.alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
},
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_2_u8_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .u8,
.len = 2,
});
if (!kind.isParameter()) return vector_ctype;
var fields = [_]Info.Field{
.{
.name = .{ .index = .array },
.ctype = vector_ctype,
.alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
},
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_4_u8_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .u8,
.len = 4,
});
if (!kind.isParameter()) return vector_ctype;
var fields = [_]Info.Field{
.{
.name = .{ .index = .array },
.ctype = vector_ctype,
.alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
},
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_8_u8_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .u8,
.len = 8,
});
if (!kind.isParameter()) return vector_ctype;
var fields = [_]Info.Field{
.{
.name = .{ .index = .array },
.ctype = vector_ctype,
.alignas = AlignAs.fromAbiAlignment(Type.u8.abiAlignment(zcu)),
},
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_16_u8_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .u8,

View file

@ -21684,6 +21684,15 @@ test mulUnsafe {
try test_mul_unsafe.testIntVectors();
}
inline fn mulWrap(comptime Type: type, lhs: Type, rhs: Type) Type {
return lhs *% rhs;
}
test mulWrap {
const test_mul_wrap = binary(mulWrap, .{});
try test_mul_wrap.testInts();
try test_mul_wrap.testIntVectors();
}
inline fn multiply(comptime Type: type, lhs: Type, rhs: Type) @TypeOf(lhs * rhs) {
return lhs * rhs;
}

View file

@ -117,9 +117,9 @@ export fn testMutablePointer() void {
// tmp.zig:37:38: note: imported here
// neg_inf.zon:1:1: error: expected type '?u8'
// tmp.zig:57:28: note: imported here
// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_487'
// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_491'
// tmp.zig:62:39: note: imported here
// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_489'
// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_493'
// tmp.zig:67:44: note: imported here
// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_492'
// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_496'
// tmp.zig:72:50: note: imported here

View file

@ -15,6 +15,6 @@ pub export fn entry() void {
// error
//
// :7:25: error: unable to resolve comptime value
// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_461.C' must be comptime-known
// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_465.C' must be comptime-known
// :4:16: note: struct requires comptime because of this field
// :4:16: note: types are not available at runtime

View file

@ -16,5 +16,5 @@ pub export fn entry2() void {
//
// :3:6: error: no field or member function named 'copy' in '[]const u8'
// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_465'
// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_469'
// :12:6: note: struct declared here

View file

@ -6,6 +6,6 @@ export fn foo() void {
// error
//
// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_454'
// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_458'
// :3:16: note: struct declared here
// :1:11: note: struct declared here

View file

@ -44,9 +44,9 @@ comptime {
//
// :5:23: error: expected error union type, found 'comptime_int'
// :10:23: error: expected error union type, found '@TypeOf(.{})'
// :15:23: error: expected error union type, found 'tmp.test2__struct_491'
// :15:23: error: expected error union type, found 'tmp.test2__struct_495'
// :15:23: note: struct declared here
// :20:27: error: expected error union type, found 'tmp.test3__struct_493'
// :20:27: error: expected error union type, found 'tmp.test3__struct_497'
// :20:27: note: struct declared here
// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'
// :31:13: error: expected error union type, found 'u32'