Skip to content

Commit 8dbd29c

Browse files
authored
Merge pull request #24011 from jacobly0/legalize-unary
Legalize: implement scalarization and safety check expansion
2 parents 0386730 + 6a63c86 commit 8dbd29c

File tree

92 files changed

+4020
-1681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4020
-1681
lines changed

build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ pub fn build(b: *std.Build) !void {
437437
.skip_non_native = skip_non_native,
438438
.skip_libc = skip_libc,
439439
.use_llvm = use_llvm,
440-
// 2262585344 was observed on an x86_64-linux-gnu host.
441-
.max_rss = 2488843878,
440+
// 2520100864 was observed on an x86_64-linux-gnu host.
441+
.max_rss = 2772110950,
442442
}));
443443

444444
test_modules_step.dependOn(tests.addModuleTests(b, .{

doc/langref/test_intCast_builtin.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ test "integer cast panic" {
55
_ = b;
66
}
77

8-
// test_error=cast truncated bits
8+
// test_error=integer does not fit in destination type

lib/std/Target.zig

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,11 +1246,7 @@ pub const Cpu = struct {
12461246

12471247
/// Adds the specified feature set but not its dependencies.
12481248
pub fn addFeatureSet(set: *Set, other_set: Set) void {
1249-
if (builtin.zig_backend == .stage2_x86_64 and builtin.object_format == .coff) {
1250-
for (&set.ints, other_set.ints) |*set_int, other_set_int| set_int.* |= other_set_int;
1251-
} else {
1252-
set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints);
1253-
}
1249+
set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints);
12541250
}
12551251

12561252
/// Removes the specified feature but not its dependents.
@@ -1262,11 +1258,7 @@ pub const Cpu = struct {
12621258

12631259
/// Removes the specified feature but not its dependents.
12641260
pub fn removeFeatureSet(set: *Set, other_set: Set) void {
1265-
if (builtin.zig_backend == .stage2_x86_64 and builtin.object_format == .coff) {
1266-
for (&set.ints, other_set.ints) |*set_int, other_set_int| set_int.* &= ~other_set_int;
1267-
} else {
1268-
set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints);
1269-
}
1261+
set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints);
12701262
}
12711263

12721264
pub fn populateDependencies(set: *Set, all_features_list: []const Cpu.Feature) void {
@@ -1295,17 +1287,10 @@ pub const Cpu = struct {
12951287
}
12961288

12971289
pub fn isSuperSetOf(set: Set, other_set: Set) bool {
1298-
if (builtin.zig_backend == .stage2_x86_64 and builtin.object_format == .coff) {
1299-
var result = true;
1300-
for (&set.ints, other_set.ints) |*set_int, other_set_int|
1301-
result = result and (set_int.* & other_set_int) == other_set_int;
1302-
return result;
1303-
} else {
1304-
const V = @Vector(usize_count, usize);
1305-
const set_v: V = set.ints;
1306-
const other_v: V = other_set.ints;
1307-
return @reduce(.And, (set_v & other_v) == other_v);
1308-
}
1290+
const V = @Vector(usize_count, usize);
1291+
const set_v: V = set.ints;
1292+
const other_v: V = other_set.ints;
1293+
return @reduce(.And, (set_v & other_v) == other_v);
13091294
}
13101295
};
13111296

lib/std/array_hash_map.zig

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -889,19 +889,10 @@ pub fn ArrayHashMapUnmanaged(
889889
self.pointer_stability.lock();
890890
defer self.pointer_stability.unlock();
891891

892-
if (new_capacity <= linear_scan_max) {
893-
try self.entries.ensureTotalCapacity(gpa, new_capacity);
894-
return;
895-
}
896-
897-
if (self.index_header) |header| {
898-
if (new_capacity <= header.capacity()) {
899-
try self.entries.ensureTotalCapacity(gpa, new_capacity);
900-
return;
901-
}
902-
}
903-
904892
try self.entries.ensureTotalCapacity(gpa, new_capacity);
893+
if (new_capacity <= linear_scan_max) return;
894+
if (self.index_header) |header| if (new_capacity <= header.capacity()) return;
895+
905896
const new_bit_index = try IndexHeader.findBitIndex(new_capacity);
906897
const new_header = try IndexHeader.alloc(gpa, new_bit_index);
907898

@@ -2116,7 +2107,7 @@ const IndexHeader = struct {
21162107

21172108
fn findBitIndex(desired_capacity: usize) Allocator.Error!u8 {
21182109
if (desired_capacity > max_capacity) return error.OutOfMemory;
2119-
var new_bit_index = @as(u8, @intCast(std.math.log2_int_ceil(usize, desired_capacity)));
2110+
var new_bit_index: u8 = @intCast(std.math.log2_int_ceil(usize, desired_capacity));
21202111
if (desired_capacity > index_capacities[new_bit_index]) new_bit_index += 1;
21212112
if (new_bit_index < min_bit_index) new_bit_index = min_bit_index;
21222113
assert(desired_capacity <= index_capacities[new_bit_index]);

lib/std/crypto/chacha20.zig

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,12 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
499499
fn ChaChaImpl(comptime rounds_nb: usize) type {
500500
switch (builtin.cpu.arch) {
501501
.x86_64 => {
502-
const has_avx2 = std.Target.x86.featureSetHas(builtin.cpu.features, .avx2);
503-
const has_avx512f = std.Target.x86.featureSetHas(builtin.cpu.features, .avx512f);
504-
if (builtin.zig_backend != .stage2_x86_64 and has_avx512f) return ChaChaVecImpl(rounds_nb, 4);
505-
if (has_avx2) return ChaChaVecImpl(rounds_nb, 2);
502+
if (builtin.zig_backend != .stage2_x86_64 and std.Target.x86.featureSetHas(builtin.cpu.features, .avx512f)) return ChaChaVecImpl(rounds_nb, 4);
503+
if (std.Target.x86.featureSetHas(builtin.cpu.features, .avx2)) return ChaChaVecImpl(rounds_nb, 2);
506504
return ChaChaVecImpl(rounds_nb, 1);
507505
},
508506
.aarch64 => {
509-
const has_neon = std.Target.aarch64.featureSetHas(builtin.cpu.features, .neon);
510-
if (has_neon) return ChaChaVecImpl(rounds_nb, 4);
507+
if (builtin.zig_backend != .stage2_aarch64 and std.Target.aarch64.featureSetHas(builtin.cpu.features, .neon)) return ChaChaVecImpl(rounds_nb, 4);
511508
return ChaChaNonVecImpl(rounds_nb);
512509
},
513510
else => return ChaChaNonVecImpl(rounds_nb),

lib/std/debug.zig

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {
7878
@branchHint(.cold);
7979
call("invalid error code", @returnAddress());
8080
}
81-
pub fn castTruncatedData() noreturn {
81+
pub fn integerOutOfBounds() noreturn {
8282
@branchHint(.cold);
83-
call("integer cast truncated bits", @returnAddress());
84-
}
85-
pub fn negativeToUnsigned() noreturn {
86-
@branchHint(.cold);
87-
call("attempt to cast negative value to unsigned integer", @returnAddress());
83+
call("integer does not fit in destination type", @returnAddress());
8884
}
8985
pub fn integerOverflow() noreturn {
9086
@branchHint(.cold);
@@ -126,8 +122,6 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type {
126122
@branchHint(.cold);
127123
call("for loop over objects with non-equal lengths", @returnAddress());
128124
}
129-
/// Delete after next zig1.wasm update
130-
pub const memcpyLenMismatch = copyLenMismatch;
131125
pub fn copyLenMismatch() noreturn {
132126
@branchHint(.cold);
133127
call("source and destination arguments have non-equal lengths", @returnAddress());

lib/std/debug/no_panic.zig

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ pub fn invalidErrorCode() noreturn {
6565
@trap();
6666
}
6767

68-
pub fn castTruncatedData() noreturn {
69-
@branchHint(.cold);
70-
@trap();
71-
}
72-
73-
pub fn negativeToUnsigned() noreturn {
68+
pub fn integerOutOfBounds() noreturn {
7469
@branchHint(.cold);
7570
@trap();
7671
}
@@ -125,9 +120,6 @@ pub fn forLenMismatch() noreturn {
125120
@trap();
126121
}
127122

128-
/// Delete after next zig1.wasm update
129-
pub const memcpyLenMismatch = copyLenMismatch;
130-
131123
pub fn copyLenMismatch() noreturn {
132124
@branchHint(.cold);
133125
@trap();

lib/std/debug/simple_panic.zig

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ pub fn invalidErrorCode() noreturn {
7272
call("invalid error code", null);
7373
}
7474

75-
pub fn castTruncatedData() noreturn {
76-
call("integer cast truncated bits", null);
77-
}
78-
79-
pub fn negativeToUnsigned() noreturn {
80-
call("attempt to cast negative value to unsigned integer", null);
75+
pub fn integerOutOfBounds() noreturn {
76+
call("integer does not fit in destination type", null);
8177
}
8278

8379
pub fn integerOverflow() noreturn {
@@ -120,9 +116,6 @@ pub fn forLenMismatch() noreturn {
120116
call("for loop over objects with non-equal lengths", null);
121117
}
122118

123-
/// Delete after next zig1.wasm update
124-
pub const memcpyLenMismatch = copyLenMismatch;
125-
126119
pub fn copyLenMismatch() noreturn {
127120
call("source and destination have non-equal lengths", null);
128121
}

lib/std/hash/xxhash.zig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ fn testExpect(comptime H: type, seed: anytype, input: []const u8, expected: u64)
780780
}
781781

782782
test "xxhash3" {
783-
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
784783
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
785784

786785
const H = XxHash3;
@@ -814,7 +813,6 @@ test "xxhash3" {
814813
}
815814

816815
test "xxhash3 smhasher" {
817-
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
818816
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
819817

820818
const Test = struct {
@@ -828,7 +826,6 @@ test "xxhash3 smhasher" {
828826
}
829827

830828
test "xxhash3 iterative api" {
831-
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
832829
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
833830

834831
const Test = struct {

lib/std/simd.zig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ pub fn extract(
231231
}
232232

233233
test "vector patterns" {
234-
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
235-
236234
const base = @Vector(4, u32){ 10, 20, 30, 40 };
237235
const other_base = @Vector(4, u32){ 55, 66, 77, 88 };
238236

@@ -302,8 +300,6 @@ pub fn reverseOrder(vec: anytype) @TypeOf(vec) {
302300
}
303301

304302
test "vector shifting" {
305-
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
306-
307303
const base = @Vector(4, u32){ 10, 20, 30, 40 };
308304

309305
try std.testing.expectEqual([4]u32{ 30, 40, 999, 999 }, shiftElementsLeft(base, 2, 999));
@@ -368,9 +364,6 @@ pub fn countElementsWithValue(vec: anytype, value: std.meta.Child(@TypeOf(vec)))
368364
}
369365

370366
test "vector searching" {
371-
if (builtin.zig_backend == .stage2_x86_64 and
372-
!comptime std.Target.x86.featureSetHas(builtin.cpu.features, .ssse3)) return error.SkipZigTest;
373-
374367
const base = @Vector(8, u32){ 6, 4, 7, 4, 4, 2, 3, 7 };
375368

376369
try std.testing.expectEqual(@as(?u3, 1), firstIndexOfValue(base, 4));
@@ -462,7 +455,6 @@ pub fn prefixScan(comptime op: std.builtin.ReduceOp, comptime hop: isize, vec: a
462455
}
463456

464457
test "vector prefix scan" {
465-
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
466458
if ((builtin.cpu.arch == .armeb or builtin.cpu.arch == .thumbeb) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/22060
467459
if (builtin.cpu.arch == .aarch64_be and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21893
468460
if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .hexagon) return error.SkipZigTest;

0 commit comments

Comments
 (0)