aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-05-31 18:54:01 -0400
committermlugg <mlugg@mlugg.co.uk>2025-06-01 08:24:01 +0100
commitec579aa0f372b2054ad659aaacd190c1a986d7f2 (patch)
tree193cca8db61e7885b94639e18319b4d98e586552 /lib/std
parentadd2976a9ba76ec661ae5668eb2a8dca2ccfad42 (diff)
downloadzig-ec579aa0f372b2054ad659aaacd190c1a986d7f2.tar.gz
zig-ec579aa0f372b2054ad659aaacd190c1a986d7f2.zip
Legalize: implement scalarization of `@shuffle`
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Target.zig27
-rw-r--r--lib/std/array_hash_map.zig17
-rw-r--r--lib/std/crypto/chacha20.zig9
-rw-r--r--lib/std/hash/xxhash.zig3
-rw-r--r--lib/std/simd.zig4
5 files changed, 13 insertions, 47 deletions
diff --git a/lib/std/Target.zig b/lib/std/Target.zig
index bf5a6369b5..b60de995fa 100644
--- a/lib/std/Target.zig
+++ b/lib/std/Target.zig
@@ -1246,11 +1246,7 @@ pub const Cpu = struct {
/// Adds the specified feature set but not its dependencies.
pub fn addFeatureSet(set: *Set, other_set: Set) void {
- 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);
- }
+ set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints);
}
/// Removes the specified feature but not its dependents.
@@ -1262,11 +1258,7 @@ pub const Cpu = struct {
/// Removes the specified feature but not its dependents.
pub fn removeFeatureSet(set: *Set, other_set: Set) void {
- 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);
- }
+ set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints);
}
pub fn populateDependencies(set: *Set, all_features_list: []const Cpu.Feature) void {
@@ -1295,17 +1287,10 @@ pub const Cpu = struct {
}
pub fn isSuperSetOf(set: Set, other_set: Set) bool {
- 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);
- }
+ 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);
}
};
diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig
index b0b9e19169..ac9c70df8e 100644
--- a/lib/std/array_hash_map.zig
+++ b/lib/std/array_hash_map.zig
@@ -889,19 +889,10 @@ pub fn ArrayHashMapUnmanaged(
self.pointer_stability.lock();
defer self.pointer_stability.unlock();
- if (new_capacity <= linear_scan_max) {
- try self.entries.ensureTotalCapacity(gpa, new_capacity);
- return;
- }
-
- if (self.index_header) |header| {
- if (new_capacity <= header.capacity()) {
- try self.entries.ensureTotalCapacity(gpa, new_capacity);
- return;
- }
- }
-
try self.entries.ensureTotalCapacity(gpa, new_capacity);
+ if (new_capacity <= linear_scan_max) return;
+ if (self.index_header) |header| if (new_capacity <= header.capacity()) return;
+
const new_bit_index = try IndexHeader.findBitIndex(new_capacity);
const new_header = try IndexHeader.alloc(gpa, new_bit_index);
@@ -2116,7 +2107,7 @@ const IndexHeader = struct {
fn findBitIndex(desired_capacity: usize) Allocator.Error!u8 {
if (desired_capacity > max_capacity) return error.OutOfMemory;
- var new_bit_index = @as(u8, @intCast(std.math.log2_int_ceil(usize, desired_capacity)));
+ var new_bit_index: u8 = @intCast(std.math.log2_int_ceil(usize, desired_capacity));
if (desired_capacity > index_capacities[new_bit_index]) new_bit_index += 1;
if (new_bit_index < min_bit_index) new_bit_index = min_bit_index;
assert(desired_capacity <= index_capacities[new_bit_index]);
diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig
index 564df2933f..495bad3efc 100644
--- a/lib/std/crypto/chacha20.zig
+++ b/lib/std/crypto/chacha20.zig
@@ -499,15 +499,12 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
fn ChaChaImpl(comptime rounds_nb: usize) type {
switch (builtin.cpu.arch) {
.x86_64 => {
- const has_avx2 = std.Target.x86.featureSetHas(builtin.cpu.features, .avx2);
- const has_avx512f = std.Target.x86.featureSetHas(builtin.cpu.features, .avx512f);
- if (builtin.zig_backend != .stage2_x86_64 and has_avx512f) return ChaChaVecImpl(rounds_nb, 4);
- if (has_avx2) return ChaChaVecImpl(rounds_nb, 2);
+ if (builtin.zig_backend != .stage2_x86_64 and std.Target.x86.featureSetHas(builtin.cpu.features, .avx512f)) return ChaChaVecImpl(rounds_nb, 4);
+ if (std.Target.x86.featureSetHas(builtin.cpu.features, .avx2)) return ChaChaVecImpl(rounds_nb, 2);
return ChaChaVecImpl(rounds_nb, 1);
},
.aarch64 => {
- const has_neon = std.Target.aarch64.featureSetHas(builtin.cpu.features, .neon);
- if (has_neon) return ChaChaVecImpl(rounds_nb, 4);
+ if (builtin.zig_backend != .stage2_aarch64 and std.Target.aarch64.featureSetHas(builtin.cpu.features, .neon)) return ChaChaVecImpl(rounds_nb, 4);
return ChaChaNonVecImpl(rounds_nb);
},
else => return ChaChaNonVecImpl(rounds_nb),
diff --git a/lib/std/hash/xxhash.zig b/lib/std/hash/xxhash.zig
index f12f6341a4..b3128f39b2 100644
--- a/lib/std/hash/xxhash.zig
+++ b/lib/std/hash/xxhash.zig
@@ -780,7 +780,6 @@ fn testExpect(comptime H: type, seed: anytype, input: []const u8, expected: u64)
}
test "xxhash3" {
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
const H = XxHash3;
@@ -814,7 +813,6 @@ test "xxhash3" {
}
test "xxhash3 smhasher" {
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
const Test = struct {
@@ -828,7 +826,6 @@ test "xxhash3 smhasher" {
}
test "xxhash3 iterative api" {
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
if (builtin.cpu.arch.isMIPS64() and (builtin.abi == .gnuabin32 or builtin.abi == .muslabin32)) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/23807
const Test = struct {
diff --git a/lib/std/simd.zig b/lib/std/simd.zig
index cf4f7675fa..b2f8b7db5d 100644
--- a/lib/std/simd.zig
+++ b/lib/std/simd.zig
@@ -231,8 +231,6 @@ pub fn extract(
}
test "vector patterns" {
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
-
const base = @Vector(4, u32){ 10, 20, 30, 40 };
const other_base = @Vector(4, u32){ 55, 66, 77, 88 };
@@ -302,8 +300,6 @@ pub fn reverseOrder(vec: anytype) @TypeOf(vec) {
}
test "vector shifting" {
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
-
const base = @Vector(4, u32){ 10, 20, 30, 40 };
try std.testing.expectEqual([4]u32{ 30, 40, 999, 999 }, shiftElementsLeft(base, 2, 999));