aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-02-25 21:43:20 -0800
committerGitHub <noreply@github.com>2024-02-25 21:43:20 -0800
commit91fb211faa3f37d08da55b0c8df92a6475624316 (patch)
treead824c8fcdd386e378669c21a3e65923b52d0133 /test/behavior
parentd656c2a7abe90d00ef6dbc3731b82bd26180038a (diff)
parent4fcc750ba58f51606c49310bdd7c81c156d48cfc (diff)
downloadzig-91fb211faa3f37d08da55b0c8df92a6475624316.tar.gz
zig-91fb211faa3f37d08da55b0c8df92a6475624316.zip
Merge pull request #18906 from jacobly0/x86_64-tests
x86_64: pass more tests
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/bitcast.zig2
-rw-r--r--test/behavior/cast.zig54
-rw-r--r--test/behavior/optional.zig109
-rw-r--r--test/behavior/select.zig4
-rw-r--r--test/behavior/shuffle.zig3
-rw-r--r--test/behavior/vector.zig42
6 files changed, 144 insertions, 70 deletions
diff --git a/test/behavior/bitcast.zig b/test/behavior/bitcast.zig
index 001f8c34db..3ac6115216 100644
--- a/test/behavior/bitcast.zig
+++ b/test/behavior/bitcast.zig
@@ -336,7 +336,7 @@ test "comptime @bitCast packed struct to int and back" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_llvm and native_endian == .big) {
// https://github.com/ziglang/zig/issues/13782
diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig
index 2ed29eb92d..19e5ebb3c1 100644
--- a/test/behavior/cast.zig
+++ b/test/behavior/cast.zig
@@ -601,25 +601,25 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
test "@intCast on vector" {
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_x86_64) return error.SkipZigTest;
const S = struct {
fn doTheTest() !void {
// Upcast (implicit, equivalent to @intCast)
var up0: @Vector(2, u8) = [_]u8{ 0x55, 0xaa };
_ = &up0;
- const up1 = @as(@Vector(2, u16), up0);
- const up2 = @as(@Vector(2, u32), up0);
- const up3 = @as(@Vector(2, u64), up0);
+ const up1: @Vector(2, u16) = up0;
+ const up2: @Vector(2, u32) = up0;
+ const up3: @Vector(2, u64) = up0;
// Downcast (safety-checked)
var down0 = up3;
_ = &down0;
- const down1 = @as(@Vector(2, u32), @intCast(down0));
- const down2 = @as(@Vector(2, u16), @intCast(down0));
- const down3 = @as(@Vector(2, u8), @intCast(down0));
+ const down1: @Vector(2, u32) = @intCast(down0);
+ const down2: @Vector(2, u16) = @intCast(down0);
+ const down3: @Vector(2, u8) = @intCast(down0);
try expect(mem.eql(u16, &@as([2]u16, up1), &[2]u16{ 0x55, 0xaa }));
try expect(mem.eql(u32, &@as([2]u32, up2), &[2]u32{ 0x55, 0xaa }));
@@ -629,20 +629,10 @@ test "@intCast on vector" {
try expect(mem.eql(u16, &@as([2]u16, down2), &[2]u16{ 0x55, 0xaa }));
try expect(mem.eql(u8, &@as([2]u8, down3), &[2]u8{ 0x55, 0xaa }));
}
-
- fn doTheTestFloat() !void {
- var vec: @Vector(2, f32) = @splat(1234.0);
- _ = &vec;
- const wider: @Vector(2, f64) = vec;
- try expect(wider[0] == 1234.0);
- try expect(wider[1] == 1234.0);
- }
};
try S.doTheTest();
try comptime S.doTheTest();
- try S.doTheTestFloat();
- try comptime S.doTheTestFloat();
}
test "@floatCast cast down" {
@@ -2340,10 +2330,31 @@ test "@floatCast on vector" {
const S = struct {
fn doTheTest() !void {
- var a: @Vector(3, f64) = .{ 1.5, 2.5, 3.5 };
- _ = &a;
- const b: @Vector(3, f32) = @floatCast(a);
- try expectEqual(@Vector(3, f32){ 1.5, 2.5, 3.5 }, b);
+ {
+ var a: @Vector(2, f64) = .{ 1.5, 2.5 };
+ _ = &a;
+ const b: @Vector(2, f32) = @floatCast(a);
+ try expectEqual(@Vector(2, f32){ 1.5, 2.5 }, b);
+ }
+ {
+ var a: @Vector(2, f32) = .{ 3.25, 4.25 };
+ _ = &a;
+ const b: @Vector(2, f64) = @floatCast(a);
+ try expectEqual(@Vector(2, f64){ 3.25, 4.25 }, b);
+ }
+ {
+ var a: @Vector(2, f32) = .{ 5.75, 6.75 };
+ _ = &a;
+ const b: @Vector(2, f64) = a;
+ try expectEqual(@Vector(2, f64){ 5.75, 6.75 }, b);
+ }
+ {
+ var vec: @Vector(2, f32) = @splat(1234.0);
+ _ = &vec;
+ const wider: @Vector(2, f64) = vec;
+ try expect(wider[0] == 1234.0);
+ try expect(wider[1] == 1234.0);
+ }
}
};
@@ -2441,6 +2452,7 @@ test "@intFromBool on vector" {
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_x86_64) return error.SkipZigTest;
const S = struct {
fn doTheTest() !void {
diff --git a/test/behavior/optional.zig b/test/behavior/optional.zig
index 2030645d3d..edf02d3e6e 100644
--- a/test/behavior/optional.zig
+++ b/test/behavior/optional.zig
@@ -110,44 +110,89 @@ test "nested optional field in struct" {
try expect(s.x.?.y == 127);
}
-test "equality compare optional with non-optional" {
+test "equality compare optionals and non-optionals" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
- try test_cmp_optional_non_optional();
- try comptime test_cmp_optional_non_optional();
+ const S = struct {
+ fn doTheTest() !void {
+ var five: isize = 5;
+ var ten: isize = 10;
+ var opt_null: ?isize = null;
+ var opt_ten: ?isize = 10;
+ _ = .{ &five, &ten, &opt_null, &opt_ten };
+ try expect(opt_null != five);
+ try expect(opt_null != ten);
+ try expect(opt_ten != five);
+ try expect(opt_ten == ten);
+
+ var opt_int: ?isize = null;
+ try expect(opt_int != five);
+ try expect(opt_int != ten);
+ try expect(opt_int == opt_null);
+ try expect(opt_int != opt_ten);
+
+ opt_int = 10;
+ try expect(opt_int != five);
+ try expect(opt_int == ten);
+ try expect(opt_int != opt_null);
+ try expect(opt_int == opt_ten);
+
+ opt_int = five;
+ try expect(opt_int == five);
+ try expect(opt_int != ten);
+ try expect(opt_int != opt_null);
+ try expect(opt_int != opt_ten);
+
+ // test evaluation is always lexical
+ // ensure that the optional isn't always computed before the non-optional
+ var mutable_state: i32 = 0;
+ _ = blk1: {
+ mutable_state += 1;
+ break :blk1 @as(?f64, 10.0);
+ } != blk2: {
+ try expect(mutable_state == 1);
+ break :blk2 @as(f64, 5.0);
+ };
+ _ = blk1: {
+ mutable_state += 1;
+ break :blk1 @as(f64, 10.0);
+ } != blk2: {
+ try expect(mutable_state == 2);
+ break :blk2 @as(?f64, 5.0);
+ };
+ }
+ };
+
+ try S.doTheTest();
+ try comptime S.doTheTest();
}
-fn test_cmp_optional_non_optional() !void {
- var ten: i32 = 10;
- var opt_ten: ?i32 = 10;
- var five: i32 = 5;
- var int_n: ?i32 = null;
-
- _ = .{ &ten, &opt_ten, &five, &int_n };
-
- try expect(int_n != ten);
- try expect(opt_ten == ten);
- try expect(opt_ten != five);
-
- // test evaluation is always lexical
- // ensure that the optional isn't always computed before the non-optional
- var mutable_state: i32 = 0;
- _ = blk1: {
- mutable_state += 1;
- break :blk1 @as(?f64, 10.0);
- } != blk2: {
- try expect(mutable_state == 1);
- break :blk2 @as(f64, 5.0);
- };
- _ = blk1: {
- mutable_state += 1;
- break :blk1 @as(f64, 10.0);
- } != blk2: {
- try expect(mutable_state == 2);
- break :blk2 @as(?f64, 5.0);
- };
+test "compare optionals with modified payloads" {
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
+
+ var lhs: ?bool = false;
+ const lhs_payload = &lhs.?;
+ var rhs: ?bool = true;
+ const rhs_payload = &rhs.?;
+ try expect(lhs != rhs and !(lhs == rhs));
+
+ lhs = null;
+ lhs_payload.* = false;
+ rhs = false;
+ try expect(lhs != rhs and !(lhs == rhs));
+
+ lhs = true;
+ rhs = null;
+ rhs_payload.* = true;
+ try expect(lhs != rhs and !(lhs == rhs));
+
+ lhs = null;
+ lhs_payload.* = false;
+ rhs = null;
+ rhs_payload.* = true;
+ try expect(lhs == rhs and !(lhs != rhs));
}
test "unwrap function call with optional pointer return value" {
diff --git a/test/behavior/select.zig b/test/behavior/select.zig
index de717e5e5b..2396d8bb11 100644
--- a/test/behavior/select.zig
+++ b/test/behavior/select.zig
@@ -5,7 +5,6 @@ const expect = std.testing.expect;
test "@select vectors" {
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_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
@@ -36,11 +35,12 @@ fn selectVectors() !void {
test "@select arrays" {
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_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) 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_x86_64 and
+ !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .avx2)) return error.SkipZigTest;
try comptime selectArrays();
try selectArrays();
diff --git a/test/behavior/shuffle.zig b/test/behavior/shuffle.zig
index 95913be3af..c3d760103d 100644
--- a/test/behavior/shuffle.zig
+++ b/test/behavior/shuffle.zig
@@ -4,10 +4,11 @@ const mem = std.mem;
const expect = std.testing.expect;
test "@shuffle int" {
- 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_x86_64 and
+ !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .ssse3)) return error.SkipZigTest;
const S = struct {
fn doTheTest() !void {
diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig
index cb9cd4a87a..9d21f8fdb0 100644
--- a/test/behavior/vector.zig
+++ b/test/behavior/vector.zig
@@ -29,7 +29,7 @@ test "vector wrap operators" {
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_x86_64 and
- !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest; // TODO
+ !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest;
const S = struct {
fn doTheTest() !void {
@@ -906,22 +906,26 @@ test "vector @reduce comptime" {
}
test "mask parameter of @shuffle is comptime scope" {
- 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_x86_64 and
+ !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .ssse3)) return error.SkipZigTest;
const __v4hi = @Vector(4, i16);
- var v4_a = __v4hi{ 0, 0, 0, 0 };
- var v4_b = __v4hi{ 0, 0, 0, 0 };
+ var v4_a = __v4hi{ 1, 2, 3, 4 };
+ var v4_b = __v4hi{ 5, 6, 7, 8 };
_ = .{ &v4_a, &v4_b };
const shuffled: __v4hi = @shuffle(i16, v4_a, v4_b, @Vector(4, i32){
std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
- std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
- std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
- std.zig.c_translation.shuffleVectorIndex(0, @typeInfo(@TypeOf(v4_a)).Vector.len),
+ std.zig.c_translation.shuffleVectorIndex(2, @typeInfo(@TypeOf(v4_a)).Vector.len),
+ std.zig.c_translation.shuffleVectorIndex(4, @typeInfo(@TypeOf(v4_a)).Vector.len),
+ std.zig.c_translation.shuffleVectorIndex(6, @typeInfo(@TypeOf(v4_a)).Vector.len),
});
- _ = shuffled;
+ try expect(shuffled[0] == 1);
+ try expect(shuffled[1] == 3);
+ try expect(shuffled[2] == 5);
+ try expect(shuffled[3] == 7);
}
test "saturating add" {
@@ -1177,10 +1181,22 @@ test "@shlWithOverflow" {
}
test "alignment of vectors" {
- try expect(@alignOf(@Vector(2, u8)) == 2);
- try expect(@alignOf(@Vector(2, u1)) == 1);
- try expect(@alignOf(@Vector(1, u1)) == 1);
- try expect(@alignOf(@Vector(2, u16)) == 4);
+ try expect(@alignOf(@Vector(2, u8)) == switch (builtin.zig_backend) {
+ else => 2,
+ .stage2_x86_64 => 16,
+ });
+ try expect(@alignOf(@Vector(2, u1)) == switch (builtin.zig_backend) {
+ else => 1,
+ .stage2_x86_64 => 16,
+ });
+ try expect(@alignOf(@Vector(1, u1)) == switch (builtin.zig_backend) {
+ else => 1,
+ .stage2_x86_64 => 16,
+ });
+ try expect(@alignOf(@Vector(2, u16)) == switch (builtin.zig_backend) {
+ else => 4,
+ .stage2_x86_64 => 16,
+ });
}
test "loading the second vector from a slice of vectors" {
@@ -1316,10 +1332,10 @@ test "modRem with zero divisor" {
test "array operands to shuffle are coerced to vectors" {
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_x86_64) return error.SkipZigTest;
const mask = [5]i32{ -1, 0, 1, 2, 3 };