Merge pull request #22873 from jacobly0/x86_64-rewrite

x86_64: implement conversions between float and int vectors
This commit is contained in:
Andrew Kelley 2025-02-12 13:54:03 -08:00 committed by GitHub
commit de8741271f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 19471 additions and 462 deletions

View File

@ -1240,13 +1240,10 @@ pub const Cpu = struct {
/// Adds the specified feature set but not its dependencies.
pub fn addFeatureSet(set: *Set, other_set: Set) void {
switch (builtin.zig_backend) {
.stage2_x86_64 => {
for (&set.ints, other_set.ints) |*set_int, other_set_int| set_int.* |= other_set_int;
},
else => {
set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints);
},
if (builtin.zig_backend == .stage2_x86_64 and builtin.object_format == .coff) {
for (&set.ints, other_set.ints) |*set_int, other_set_int| set_int.* |= other_set_int;
} else {
set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints);
}
}
@ -1259,13 +1256,10 @@ pub const Cpu = struct {
/// Removes the specified feature but not its dependents.
pub fn removeFeatureSet(set: *Set, other_set: Set) void {
switch (builtin.zig_backend) {
.stage2_x86_64 => {
for (&set.ints, other_set.ints) |*set_int, other_set_int| set_int.* &= ~other_set_int;
},
else => {
set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints);
},
if (builtin.zig_backend == .stage2_x86_64 and builtin.object_format == .coff) {
for (&set.ints, other_set.ints) |*set_int, other_set_int| set_int.* &= ~other_set_int;
} else {
set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints);
}
}
@ -1295,19 +1289,16 @@ pub const Cpu = struct {
}
pub fn isSuperSetOf(set: Set, other_set: Set) bool {
switch (builtin.zig_backend) {
.stage2_x86_64 => {
var result = true;
for (&set.ints, other_set.ints) |*set_int, other_set_int|
result = result and (set_int.* & other_set_int) == other_set_int;
return result;
},
else => {
const V = @Vector(usize_count, usize);
const set_v: V = set.ints;
const other_v: V = other_set.ints;
return @reduce(.And, (set_v & other_v) == other_v);
},
if (builtin.zig_backend == .stage2_x86_64 and builtin.object_format == .coff) {
var result = true;
for (&set.ints, other_set.ints) |*set_int, other_set_int|
result = result and (set_int.* & other_set_int) == other_set_int;
return result;
} else {
const V = @Vector(usize_count, usize);
const set_v: V = set.ints;
const other_v: V = other_set.ints;
return @reduce(.And, (set_v & other_v) == other_v);
}
}
};

View File

@ -1356,7 +1356,7 @@ pub fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t) {
test lerp {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/17884
if (builtin.zig_backend == .stage2_x86_64 and
!comptime std.Target.x86.featureSetHas(builtin.cpu.features, .fma)) return error.SkipZigTest;
!comptime std.Target.x86.featureSetHas(builtin.cpu.features, .fma)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/17884
try testing.expectEqual(@as(f64, 75), lerp(50, 100, 0.5));
try testing.expectEqual(@as(f32, 43.75), lerp(50, 25, 0.25));

File diff suppressed because it is too large Load Diff

View File

@ -746,6 +746,7 @@ pub inline fn backendSupportsFeature(backend: std.builtin.CompilerBackend, compt
else => true,
},
.all_vector_instructions => switch (backend) {
.stage2_x86_64 => true,
else => false,
},
};

View File

@ -2451,6 +2451,7 @@ test "@ptrFromInt on vector" {
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_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 {
@ -2520,6 +2521,7 @@ test "@intFromFloat on vector" {
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_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 {
@ -2540,6 +2542,7 @@ test "@intFromBool on vector" {
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_riscv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
const S = struct {
fn doTheTest() !void {

File diff suppressed because it is too large Load Diff