x86_64: rewrite vector +|

This commit is contained in:
Jacob Young 2025-05-12 06:46:38 -04:00
parent 6dbf1c7682
commit 6d68a494c8
15 changed files with 6927 additions and 305 deletions

View File

@ -2142,7 +2142,7 @@ pub const Inst = struct {
ref_start_index = static_len,
_,
pub const static_len = 97;
pub const static_len = 100;
pub fn toRef(i: Index) Inst.Ref {
return @enumFromInt(@intFromEnum(Index.ref_start_index) + @intFromEnum(i));
@ -2225,6 +2225,7 @@ pub const Inst = struct {
single_const_pointer_to_comptime_int_type,
slice_const_u8_type,
slice_const_u8_sentinel_0_type,
vector_8_i8_type,
vector_16_i8_type,
vector_32_i8_type,
vector_1_u8_type,
@ -2233,8 +2234,10 @@ pub const Inst = struct {
vector_8_u8_type,
vector_16_u8_type,
vector_32_u8_type,
vector_4_i16_type,
vector_8_i16_type,
vector_16_i16_type,
vector_4_u16_type,
vector_8_u16_type,
vector_16_u16_type,
vector_4_i32_type,

View File

@ -995,6 +995,7 @@ pub const Inst = struct {
single_const_pointer_to_comptime_int_type = @intFromEnum(InternPool.Index.single_const_pointer_to_comptime_int_type),
slice_const_u8_type = @intFromEnum(InternPool.Index.slice_const_u8_type),
slice_const_u8_sentinel_0_type = @intFromEnum(InternPool.Index.slice_const_u8_sentinel_0_type),
vector_8_i8_type = @intFromEnum(InternPool.Index.vector_8_i8_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),
@ -1003,8 +1004,10 @@ pub const Inst = struct {
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_4_i16_type = @intFromEnum(InternPool.Index.vector_4_i16_type),
vector_8_i16_type = @intFromEnum(InternPool.Index.vector_8_i16_type),
vector_16_i16_type = @intFromEnum(InternPool.Index.vector_16_i16_type),
vector_4_u16_type = @intFromEnum(InternPool.Index.vector_4_u16_type),
vector_8_u16_type = @intFromEnum(InternPool.Index.vector_8_u16_type),
vector_16_u16_type = @intFromEnum(InternPool.Index.vector_16_u16_type),
vector_4_i32_type = @intFromEnum(InternPool.Index.vector_4_i32_type),

View File

@ -4572,6 +4572,7 @@ pub const Index = enum(u32) {
slice_const_u8_type,
slice_const_u8_sentinel_0_type,
vector_8_i8_type,
vector_16_i8_type,
vector_32_i8_type,
vector_1_u8_type,
@ -4580,8 +4581,10 @@ pub const Index = enum(u32) {
vector_8_u8_type,
vector_16_u8_type,
vector_32_u8_type,
vector_4_i16_type,
vector_8_i16_type,
vector_16_i16_type,
vector_4_u16_type,
vector_8_u16_type,
vector_16_u16_type,
vector_4_i32_type,
@ -5090,6 +5093,8 @@ pub const static_keys = [_]Key{
},
} },
// @Vector(8, i8)
.{ .vector_type = .{ .len = 8, .child = .i8_type } },
// @Vector(16, i8)
.{ .vector_type = .{ .len = 16, .child = .i8_type } },
// @Vector(32, i8)
@ -5106,10 +5111,14 @@ pub const static_keys = [_]Key{
.{ .vector_type = .{ .len = 16, .child = .u8_type } },
// @Vector(32, u8)
.{ .vector_type = .{ .len = 32, .child = .u8_type } },
// @Vector(4, i16)
.{ .vector_type = .{ .len = 4, .child = .i16_type } },
// @Vector(8, i16)
.{ .vector_type = .{ .len = 8, .child = .i16_type } },
// @Vector(16, i16)
.{ .vector_type = .{ .len = 16, .child = .i16_type } },
// @Vector(4, u16)
.{ .vector_type = .{ .len = 4, .child = .u16_type } },
// @Vector(8, u16)
.{ .vector_type = .{ .len = 8, .child = .u16_type } },
// @Vector(16, u16)
@ -11777,6 +11786,7 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
.single_const_pointer_to_comptime_int_type,
.slice_const_u8_type,
.slice_const_u8_sentinel_0_type,
.vector_8_i8_type,
.vector_16_i8_type,
.vector_32_i8_type,
.vector_1_u8_type,
@ -11785,8 +11795,10 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_4_i16_type,
.vector_8_i16_type,
.vector_16_i16_type,
.vector_4_u16_type,
.vector_8_u16_type,
.vector_16_u16_type,
.vector_4_i32_type,
@ -12121,6 +12133,7 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
.slice_const_u8_sentinel_0_type,
=> .pointer,
.vector_8_i8_type,
.vector_16_i8_type,
.vector_32_i8_type,
.vector_1_u8_type,
@ -12129,8 +12142,10 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_4_i16_type,
.vector_8_i16_type,
.vector_16_i16_type,
.vector_4_u16_type,
.vector_8_u16_type,
.vector_16_u16_type,
.vector_4_i32_type,

View File

@ -36502,6 +36502,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
.single_const_pointer_to_comptime_int_type,
.slice_const_u8_type,
.slice_const_u8_sentinel_0_type,
.vector_8_i8_type,
.vector_16_i8_type,
.vector_32_i8_type,
.vector_1_u8_type,
@ -36510,8 +36511,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
.vector_8_u8_type,
.vector_16_u8_type,
.vector_32_u8_type,
.vector_4_i16_type,
.vector_8_i16_type,
.vector_16_i16_type,
.vector_4_u16_type,
.vector_8_u16_type,
.vector_16_u16_type,
.vector_4_i32_type,

View File

@ -4096,6 +4096,7 @@ pub const single_const_pointer_to_comptime_int: Type = .{ .ip_index = .single_co
pub const slice_const_u8: Type = .{ .ip_index = .slice_const_u8_type };
pub const slice_const_u8_sentinel_0: Type = .{ .ip_index = .slice_const_u8_sentinel_0_type };
pub const vector_8_i8: Type = .{ .ip_index = .vector_8_i8_type };
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 };
@ -4104,8 +4105,10 @@ 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_4_i16: Type = .{ .ip_index = .vector_4_i16_type };
pub const vector_8_i16: Type = .{ .ip_index = .vector_8_i16_type };
pub const vector_16_i16: Type = .{ .ip_index = .vector_16_i16_type };
pub const vector_4_u16: Type = .{ .ip_index = .vector_4_u16_type };
pub const vector_8_u16: Type = .{ .ip_index = .vector_8_u16_type };
pub const vector_16_u16: Type = .{ .ip_index = .vector_16_u16_type };
pub const vector_4_i32: Type = .{ .ip_index = .vector_4_i32_type };

File diff suppressed because it is too large Load Diff

View File

@ -2330,8 +2330,8 @@
.{ .pext, .rvm, .{ .r32, .r32, .rm32 }, .{ 0xf3, 0x0f, 0x38, 0xf5 }, 0, .vex_lz_w0, .bmi2 },
.{ .pext, .rvm, .{ .r64, .r64, .rm64 }, .{ 0xf3, 0x0f, 0x38, 0xf5 }, 0, .vex_lz_w1, .bmi2 },
.{ .rorx, .rmi, .{ .r32, .rm32, .imm8 }, .{ 0xf2, 0x0f, 0x3a }, 0, .vex_lz_w0, .bmi2 },
.{ .rorx, .rmi, .{ .r64, .rm64, .imm8 }, .{ 0xf2, 0x0f, 0x3a }, 0, .vex_lz_w1, .bmi2 },
.{ .rorx, .rmi, .{ .r32, .rm32, .imm8 }, .{ 0xf2, 0x0f, 0x3a, 0xf0 }, 0, .vex_lz_w0, .bmi2 },
.{ .rorx, .rmi, .{ .r64, .rm64, .imm8 }, .{ 0xf2, 0x0f, 0x3a, 0xf0 }, 0, .vex_lz_w1, .bmi2 },
.{ .sarx, .rmv, .{ .r32, .rm32, .r32 }, .{ 0xf3, 0x0f, 0x38, 0xf7 }, 0, .vex_lz_w0, .bmi2 },
.{ .shlx, .rmv, .{ .r32, .rm32, .r32 }, .{ 0x66, 0x0f, 0x38, 0xf7 }, 0, .vex_lz_w0, .bmi2 },

View File

@ -1443,6 +1443,21 @@ pub const Pool = struct {
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_8_i8_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .i8,
.len = 8,
});
if (!kind.isParameter()) return vector_ctype;
var fields = [_]Info.Field{
.{
.name = .{ .index = .array },
.ctype = vector_ctype,
.alignas = AlignAs.fromAbiAlignment(Type.i8.abiAlignment(zcu)),
},
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_16_i8_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .i8,
@ -1563,6 +1578,21 @@ pub const Pool = struct {
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_4_i16_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .i16,
.len = 4,
});
if (!kind.isParameter()) return vector_ctype;
var fields = [_]Info.Field{
.{
.name = .{ .index = .array },
.ctype = vector_ctype,
.alignas = AlignAs.fromAbiAlignment(Type.i16.abiAlignment(zcu)),
},
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_8_i16_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .i16,
@ -1593,6 +1623,21 @@ pub const Pool = struct {
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_4_u16_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .u16,
.len = 4,
});
if (!kind.isParameter()) return vector_ctype;
var fields = [_]Info.Field{
.{
.name = .{ .index = .array },
.ctype = vector_ctype,
.alignas = AlignAs.fromAbiAlignment(Type.u16.abiAlignment(zcu)),
},
};
return pool.fromFields(allocator, .@"struct", &fields, kind);
},
.vector_8_u16_type => {
const vector_ctype = try pool.getVector(allocator, .{
.elem_ctype = .u16,

View File

@ -930,12 +930,12 @@ test "mask parameter of @shuffle is comptime scope" {
test "saturating add" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
const S = struct {
fn doTheTest() !void {

View File

@ -2615,263 +2615,23 @@ fn binary(comptime op: anytype, comptime opts: struct { compare: Compare = .rela
0x1b, 0x61, 0x73, 0x63, 0x2c, 0x35, 0x25, 0x19, 0x09, 0x0c, 0x75, 0x5d, 0x01, 0x29, 0x3b, 0x0c,
});
try testArgs(@Vector(128, u7), .{
0x5c,
0x65,
0x65,
0x34,
0x31,
0x03,
0x7a,
0x56,
0x16,
0x74,
0x5c,
0x7f,
0x2a,
0x46,
0x2a,
0x5f,
0x62,
0x06,
0x51,
0x23,
0x58,
0x1f,
0x5a,
0x2d,
0x29,
0x21,
0x26,
0x5a,
0x5a,
0x13,
0x13,
0x46,
0x26,
0x1c,
0x06,
0x2d,
0x08,
0x52,
0x5b,
0x6f,
0x2d,
0x4a,
0x00,
0x40,
0x68,
0x27,
0x00,
0x4a,
0x3a,
0x22,
0x2d,
0x5b,
0x05,
0x26,
0x4e,
0x6f,
0x46,
0x4d,
0x14,
0x70,
0x51,
0x04,
0x66,
0x13,
0x4c,
0x7c,
0x67,
0x23,
0x13,
0x55,
0x1b,
0x30,
0x7d,
0x04,
0x47,
0x78,
0x05,
0x09,
0x5a,
0x20,
0x2e,
0x17,
0x11,
0x49,
0x6c,
0x5e,
0x34,
0x3e,
0x66,
0x60,
0x5d,
0x75,
0x48,
0x1d,
0x69,
0x67,
0x40,
0x2d,
0x7b,
0x31,
0x13,
0x60,
0x19,
0x2f,
0x3e,
0x7d,
0x23,
0x6a,
0x0e,
0x16,
0x44,
0x34,
0x5d,
0x5a,
0x2a,
0x0b,
0x64,
0x07,
0x22,
0x5b,
0x24,
0x22,
0x3b,
0x46,
0x23,
0x65,
0x5d,
0x34,
0x5c, 0x65, 0x65, 0x34, 0x31, 0x03, 0x7a, 0x56, 0x16, 0x74, 0x5c, 0x7f, 0x2a, 0x46, 0x2a, 0x5f,
0x62, 0x06, 0x51, 0x23, 0x58, 0x1f, 0x5a, 0x2d, 0x29, 0x21, 0x26, 0x5a, 0x5a, 0x13, 0x13, 0x46,
0x26, 0x1c, 0x06, 0x2d, 0x08, 0x52, 0x5b, 0x6f, 0x2d, 0x4a, 0x00, 0x40, 0x68, 0x27, 0x00, 0x4a,
0x3a, 0x22, 0x2d, 0x5b, 0x05, 0x26, 0x4e, 0x6f, 0x46, 0x4d, 0x14, 0x70, 0x51, 0x04, 0x66, 0x13,
0x4c, 0x7c, 0x67, 0x23, 0x13, 0x55, 0x1b, 0x30, 0x7d, 0x04, 0x47, 0x78, 0x05, 0x09, 0x5a, 0x20,
0x2e, 0x17, 0x11, 0x49, 0x6c, 0x5e, 0x34, 0x3e, 0x66, 0x60, 0x5d, 0x75, 0x48, 0x1d, 0x69, 0x67,
0x40, 0x2d, 0x7b, 0x31, 0x13, 0x60, 0x19, 0x2f, 0x3e, 0x7d, 0x23, 0x6a, 0x0e, 0x16, 0x44, 0x34,
0x5d, 0x5a, 0x2a, 0x0b, 0x64, 0x07, 0x22, 0x5b, 0x24, 0x22, 0x3b, 0x46, 0x23, 0x65, 0x5d, 0x34,
}, .{
0x4b,
0x36,
0x7a,
0x13,
0x5a,
0x4b,
0x69,
0x4b,
0x1d,
0x02,
0x1b,
0x3f,
0x61,
0x21,
0x45,
0x48,
0x44,
0x61,
0x25,
0x42,
0x57,
0x7d,
0x7a,
0x45,
0x22,
0x2e,
0x44,
0x3f,
0x3a,
0x14,
0x07,
0x6e,
0x68,
0x51,
0x03,
0x6b,
0x11,
0x32,
0x6d,
0x6f,
0x44,
0x5a,
0x61,
0x6d,
0x71,
0x66,
0x54,
0x14,
0x5d,
0x56,
0x22,
0x5c,
0x3a,
0x72,
0x16,
0x39,
0x59,
0x3e,
0x27,
0x4d,
0x3d,
0x44,
0x72,
0x2c,
0x71,
0x74,
0x3b,
0x6c,
0x70,
0x39,
0x0f,
0x5c,
0x71,
0x04,
0x67,
0x02,
0x2c,
0x18,
0x0f,
0x14,
0x2d,
0x24,
0x51,
0x34,
0x6d,
0x0c,
0x19,
0x0f,
0x73,
0x79,
0x3d,
0x74,
0x20,
0x15,
0x22,
0x25,
0x09,
0x14,
0x09,
0x71,
0x2d,
0x6f,
0x09,
0x2e,
0x27,
0x75,
0x57,
0x62,
0x4d,
0x07,
0x62,
0x01,
0x41,
0x2d,
0x5d,
0x4c,
0x77,
0x10,
0x7f,
0x30,
0x0f,
0x50,
0x15,
0x39,
0x34,
0x7c,
0x33,
0x16,
0x4b, 0x36, 0x7a, 0x13, 0x5a, 0x4b, 0x69, 0x4b, 0x1d, 0x02, 0x1b, 0x3f, 0x61, 0x21, 0x45, 0x48,
0x44, 0x61, 0x25, 0x42, 0x57, 0x7d, 0x7a, 0x45, 0x22, 0x2e, 0x44, 0x3f, 0x3a, 0x14, 0x07, 0x6e,
0x68, 0x51, 0x03, 0x6b, 0x11, 0x32, 0x6d, 0x6f, 0x44, 0x5a, 0x61, 0x6d, 0x71, 0x66, 0x54, 0x14,
0x5d, 0x56, 0x22, 0x5c, 0x3a, 0x72, 0x16, 0x39, 0x59, 0x3e, 0x27, 0x4d, 0x3d, 0x44, 0x72, 0x2c,
0x71, 0x74, 0x3b, 0x6c, 0x70, 0x39, 0x0f, 0x5c, 0x71, 0x04, 0x67, 0x02, 0x2c, 0x18, 0x0f, 0x14,
0x2d, 0x24, 0x51, 0x34, 0x6d, 0x0c, 0x19, 0x0f, 0x73, 0x79, 0x3d, 0x74, 0x20, 0x15, 0x22, 0x25,
0x09, 0x14, 0x09, 0x71, 0x2d, 0x6f, 0x09, 0x2e, 0x27, 0x75, 0x57, 0x62, 0x4d, 0x07, 0x62, 0x01,
0x41, 0x2d, 0x5d, 0x4c, 0x77, 0x10, 0x7f, 0x30, 0x0f, 0x50, 0x15, 0x39, 0x34, 0x7c, 0x33, 0x16,
});
try testArgs(@Vector(1, i8), .{
@ -5288,6 +5048,7 @@ inline fn addSat(comptime Type: type, lhs: Type, rhs: Type) Type {
test addSat {
const test_add_sat = binary(addSat, .{});
try test_add_sat.testInts();
try test_add_sat.testIntVectors();
}
inline fn subUnsafe(comptime Type: type, lhs: Type, rhs: Type) AddOneBit(Type) {

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_492'
// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_495'
// tmp.zig:62:39: note: imported here
// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_494'
// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_497'
// tmp.zig:67:44: note: imported here
// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_497'
// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_500'
// 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_466.C' must be comptime-known
// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_469.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_470'
// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_473'
// :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_459'
// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_462'
// :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_496'
// :15:23: error: expected error union type, found 'tmp.test2__struct_499'
// :15:23: note: struct declared here
// :20:27: error: expected error union type, found 'tmp.test3__struct_498'
// :20:27: error: expected error union type, found 'tmp.test3__struct_501'
// :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'