authorgravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-10-20 17:31:54-07:00
committergravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-10-21 02:17:59-07:00
logbd2db84eede87bf2336a624ff21e798e8b631921
treea3c425ef6a1b48035865c4b6249b6e5e1534b1c4
parente572063f92ddd497c5bb6a067358bdbae1c16aab

Remove no longer necessary `splat` helper from x86_64 backend tests


3 files changed, 22 insertions(+), 30 deletions(-)

test/behavior/x86_64/binary.zig+9-10
...@@ -16,7 +16,6 @@ const nan = math.nan;...@@ -16,7 +16,6 @@ const nan = math.nan;
16const Scalar = math.Scalar;16const Scalar = math.Scalar;
17const select = math.select;17const select = math.select;
18const sign = math.sign;18const sign = math.sign;
19const splat = math.splat;
20const Sse = math.Sse;19const Sse = math.Sse;
21const tmin = math.tmin;20const tmin = math.tmin;
2221
...@@ -5250,7 +5249,7 @@ test divTruncUnoptimized {...@@ -5250,7 +5249,7 @@ test divTruncUnoptimized {
52505249
5251inline fn divTruncOptimized(comptime Type: type, lhs: Type, rhs: Type) Type {5250inline fn divTruncOptimized(comptime Type: type, lhs: Type, rhs: Type) Type {
5252 @setFloatMode(.optimized);5251 @setFloatMode(.optimized);
5253 return @divTrunc(lhs, select(@abs(rhs) > splat(Type, 0.0), rhs, splat(Type, 1.0)));5252 return @divTrunc(lhs, select(@abs(rhs) > @as(Type, @splat(0.0)), rhs, @as(Type, @splat(1.0))));
5254}5253}
5255test divTruncOptimized {5254test divTruncOptimized {
5256 const test_div_trunc_optimized = binary(divTruncOptimized, .{ .compare = .approx_int });5255 const test_div_trunc_optimized = binary(divTruncOptimized, .{ .compare = .approx_int });
...@@ -5271,7 +5270,7 @@ test divFloorUnoptimized {...@@ -5271,7 +5270,7 @@ test divFloorUnoptimized {
52715270
5272inline fn divFloorOptimized(comptime Type: type, lhs: Type, rhs: Type) Type {5271inline fn divFloorOptimized(comptime Type: type, lhs: Type, rhs: Type) Type {
5273 @setFloatMode(.optimized);5272 @setFloatMode(.optimized);
5274 return @divFloor(lhs, select(@abs(rhs) > splat(Type, 0.0), rhs, splat(Type, 1.0)));5273 return @divFloor(lhs, select(@abs(rhs) > @as(Type, @splat(0.0)), rhs, @as(Type, @splat(1.0))));
5275}5274}
5276test divFloorOptimized {5275test divFloorOptimized {
5277 const test_div_floor_optimized = binary(divFloorOptimized, .{ .compare = .approx_int });5276 const test_div_floor_optimized = binary(divFloorOptimized, .{ .compare = .approx_int });
...@@ -5292,7 +5291,7 @@ test divCeilUnoptimized {...@@ -5292,7 +5291,7 @@ test divCeilUnoptimized {
52925291
5293inline fn divCeilOptimized(comptime Type: type, lhs: Type, rhs: Type) Type {5292inline fn divCeilOptimized(comptime Type: type, lhs: Type, rhs: Type) Type {
5294 @setFloatMode(.optimized);5293 @setFloatMode(.optimized);
5295 return @divCeil(lhs, select(@abs(rhs) > splat(Type, 0.0), rhs, splat(Type, 1.0)));5294 return @divCeil(lhs, select(@abs(rhs) > @as(Type, @splat(0.0)), rhs, @as(Type, @splat(1.0))));
5296}5295}
5297test divCeilOptimized {5296test divCeilOptimized {
5298 const test_div_ceil_optimized = binary(divCeilOptimized, .{ .compare = .approx_int });5297 const test_div_ceil_optimized = binary(divCeilOptimized, .{ .compare = .approx_int });
...@@ -5393,7 +5392,7 @@ test mulWithOverflow {...@@ -5393,7 +5392,7 @@ test mulWithOverflow {
5393inline fn shlWithOverflow(comptime Type: type, lhs: Type, rhs: Type) struct { Type, ChangeScalar(Type, u1) } {5392inline fn shlWithOverflow(comptime Type: type, lhs: Type, rhs: Type) struct { Type, ChangeScalar(Type, u1) } {
5394 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);5393 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
5395 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5394 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5396 return @shlWithOverflow(lhs, if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs);5395 return @shlWithOverflow(lhs, if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs);
5397}5396}
5398test shlWithOverflow {5397test shlWithOverflow {
5399 const test_shl_with_overflow = binary(shlWithOverflow, .{});5398 const test_shl_with_overflow = binary(shlWithOverflow, .{});
...@@ -5492,7 +5491,7 @@ test bitOr {...@@ -5492,7 +5491,7 @@ test bitOr {
5492inline fn shr(comptime Type: type, lhs: Type, rhs: Type) Type {5491inline fn shr(comptime Type: type, lhs: Type, rhs: Type) Type {
5493 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);5492 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
5494 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5493 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5495 return lhs >> if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs;5494 return lhs >> if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;
5496}5495}
5497test shr {5496test shr {
5498 const test_shr = binary(shr, .{});5497 const test_shr = binary(shr, .{});
...@@ -5503,7 +5502,7 @@ test shr {...@@ -5503,7 +5502,7 @@ test shr {
5503inline fn shrExact(comptime Type: type, lhs: Type, rhs: Type) Type {5502inline fn shrExact(comptime Type: type, lhs: Type, rhs: Type) Type {
5504 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);5503 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
5505 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5504 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5506 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs;5505 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;
5507 return @shrExact(lhs >> final_rhs << final_rhs, final_rhs);5506 return @shrExact(lhs >> final_rhs << final_rhs, final_rhs);
5508}5507}
5509test shrExact {5508test shrExact {
...@@ -5515,7 +5514,7 @@ test shrExact {...@@ -5515,7 +5514,7 @@ test shrExact {
5515inline fn shl(comptime Type: type, lhs: Type, rhs: Type) Type {5514inline fn shl(comptime Type: type, lhs: Type, rhs: Type) Type {
5516 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);5515 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
5517 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5516 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5518 return lhs << if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs;5517 return lhs << if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;
5519}5518}
5520test shl {5519test shl {
5521 const test_shl = binary(shl, .{});5520 const test_shl = binary(shl, .{});
...@@ -5527,7 +5526,7 @@ inline fn shlExactUnsafe(comptime Type: type, lhs: Type, rhs: Type) Type {...@@ -5527,7 +5526,7 @@ inline fn shlExactUnsafe(comptime Type: type, lhs: Type, rhs: Type) Type {
5527 @setRuntimeSafety(false);5526 @setRuntimeSafety(false);
5528 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);5527 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
5529 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5528 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5530 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % splat(Log2Int(Type), bits) else truncate_rhs;5529 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;
5531 return @shlExact(lhs << final_rhs >> final_rhs, final_rhs);5530 return @shlExact(lhs << final_rhs >> final_rhs, final_rhs);
5532}5531}
5533test shlExactUnsafe {5532test shlExactUnsafe {
...@@ -5540,7 +5539,7 @@ inline fn shlSaturate(comptime Type: type, lhs: Type, rhs: Type) Type {...@@ -5540,7 +5539,7 @@ inline fn shlSaturate(comptime Type: type, lhs: Type, rhs: Type) Type {
5540 // workaround https://github.com/ziglang/zig/issues/230345539 // workaround https://github.com/ziglang/zig/issues/23034
5541 if (@inComptime()) {5540 if (@inComptime()) {
5542 // workaround https://github.com/ziglang/zig/issues/231395541 // workaround https://github.com/ziglang/zig/issues/23139
5543 return lhs <<| @min(@abs(rhs), splat(ChangeScalar(Type, u64), imax(u64)));5542 return lhs <<| @min(@abs(rhs), @as(ChangeScalar(Type, u64), @splat(imax(u64))));
5544 }5543 }
5545 return lhs <<| @abs(rhs);5544 return lhs <<| @abs(rhs);
5546}5545}
test/behavior/x86_64/cast.zig+7-8
...@@ -12,7 +12,6 @@ const math = @import("math.zig");...@@ -12,7 +12,6 @@ const math = @import("math.zig");
12const nan = math.nan;12const nan = math.nan;
13const next = math.next;13const next = math.next;
14const Scalar = math.Scalar;14const Scalar = math.Scalar;
15const splat = math.splat;
16const Sse = math.Sse;15const Sse = math.Sse;
17const tmin = math.tmin;16const tmin = math.tmin;
1817
...@@ -14508,18 +14507,18 @@ inline fn intCast(comptime Result: type, comptime Type: type, rhs: Type, comptim...@@ -14508,18 +14507,18 @@ inline fn intCast(comptime Result: type, comptime Type: type, rhs: Type, comptim
14508 rhs & imax(Type) >> bits,14507 rhs & imax(Type) >> bits,
14509 .vector => rhs | @select(14508 .vector => rhs | @select(
14510 Scalar(Type),14509 Scalar(Type),
14511 ct_rhs < splat(Type, 0),14510 ct_rhs < @as(Type, @splat(0)),
14512 splat(Type, imin(Scalar(Type)) >> bits),14511 @as(Type, @splat(imin(Scalar(Type)) >> bits)),
14513 splat(Type, 0),14512 @as(Type, @splat(0)),
14514 ) & ~@select(14513 ) & ~@select(
14515 Scalar(Type),14514 Scalar(Type),
14516 ct_rhs >= splat(Type, 0),14515 ct_rhs >= @as(Type, @splat(0)),
14517 splat(Type, imin(Scalar(Type)) >> bits),14516 @as(Type, @splat(imin(Scalar(Type)) >> bits)),
14518 splat(Type, 0),14517 @as(Type, @splat(0)),
14519 ),14518 ),
14520 else => comptime unreachable,14519 else => comptime unreachable,
14521 },14520 },
14522 .mask => |bits| if (bits == rhs_info.bits) rhs else rhs & splat(Type, (1 << bits) - 1),14521 .mask => |bits| if (bits == rhs_info.bits) rhs else rhs & @as(Type, @splat((1 << bits) - 1)),
14523 });14522 });
14524}14523}
14525test intCast {14524test intCast {
test/behavior/x86_64/math.zig+6-12
...@@ -72,19 +72,13 @@ pub fn Log2Int(comptime Type: type) type {...@@ -72,19 +72,13 @@ pub fn Log2Int(comptime Type: type) type {
72pub fn Log2IntCeil(comptime Type: type) type {72pub fn Log2IntCeil(comptime Type: type) type {
73 return ChangeScalar(Type, math.Log2IntCeil(Scalar(Type)));73 return ChangeScalar(Type, math.Log2IntCeil(Scalar(Type)));
74}74}
75pub fn splat(comptime Type: type, scalar: Scalar(Type)) Type {
76 return switch (@typeInfo(Type)) {
77 else => scalar,
78 .vector => @splat(scalar),
79 };
80}
81pub fn sign(rhs: anytype) ChangeScalar(@TypeOf(rhs), bool) {75pub fn sign(rhs: anytype) ChangeScalar(@TypeOf(rhs), bool) {
82 const Int = ChangeScalar(@TypeOf(rhs), switch (@typeInfo(Scalar(@TypeOf(rhs)))) {76 const Int = ChangeScalar(@TypeOf(rhs), switch (@typeInfo(Scalar(@TypeOf(rhs)))) {
83 .int, .comptime_int => Scalar(@TypeOf(rhs)),77 .int, .comptime_int => Scalar(@TypeOf(rhs)),
84 .float => |float| @Int(.signed, float.bits),78 .float => |float| @Int(.signed, float.bits),
85 else => @compileError(@typeName(@TypeOf(rhs))),79 else => @compileError(@typeName(@TypeOf(rhs))),
86 });80 });
87 return @as(Int, @bitCast(rhs)) < splat(Int, 0);81 return @as(Int, @bitCast(rhs)) < @as(Int, @splat(0));
88}82}
89pub fn select(cond: anytype, lhs: anytype, rhs: @TypeOf(lhs)) @TypeOf(lhs) {83pub fn select(cond: anytype, lhs: anytype, rhs: @TypeOf(lhs)) @TypeOf(lhs) {
90 return switch (@typeInfo(@TypeOf(cond))) {84 return switch (@typeInfo(@TypeOf(cond))) {
...@@ -117,19 +111,19 @@ pub noinline fn checkExpected(expected: anytype, actual: @TypeOf(expected), comp...@@ -117,19 +111,19 @@ pub noinline fn checkExpected(expected: anytype, actual: @TypeOf(expected), comp
117 .approx_or_overflow => @exp2(@log2(epsilon) * 0.4),111 .approx_or_overflow => @exp2(@log2(epsilon) * 0.4),
118 };112 };
119 const approx_unequal = @abs(expected - actual) > @max(113 const approx_unequal = @abs(expected - actual) > @max(
120 @abs(expected) * splat(Expected, tolerance),114 @abs(expected) * @as(Expected, @splat(tolerance)),
121 splat(Expected, switch (compare) {115 @as(Expected, @splat(switch (compare) {
122 .strict, .relaxed => comptime unreachable,116 .strict, .relaxed => comptime unreachable,
123 .approx, .approx_or_overflow => tolerance,117 .approx, .approx_or_overflow => tolerance,
124 .approx_int => 1,118 .approx_int => 1,
125 }),119 })),
126 );120 );
127 break :unexpected switch (compare) {121 break :unexpected switch (compare) {
128 .strict, .relaxed => comptime unreachable,122 .strict, .relaxed => comptime unreachable,
129 .approx, .approx_int => approx_unequal,123 .approx, .approx_int => approx_unequal,
130 .approx_or_overflow => approx_unequal &124 .approx_or_overflow => approx_unequal &
131 (((@abs(expected) != splat(Expected, inf(Expected))) &125 (((@abs(expected) != @as(Expected, @splat(inf(Expected)))) &
132 (@abs(actual) != splat(Expected, inf(Expected)))) |126 (@abs(actual) != @as(Expected, @splat(inf(Expected))))) |
133 (sign(expected) != sign(actual))),127 (sign(expected) != sign(actual))),
134 };128 };
135 },129 },