motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 93d60d0de76e5dca666682e51589c0819eed2507 (tree)
parent ebf9ffd342a30c7c79657f5dbfc83fde0647e630
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date:   Mon, 31 Oct 2022 21:40:39 -0400

std: avoid vector usage with the C backend

Vectors are not yet implemented in the C backend, so no reason to
prevent code using the standard library from compiling in the meantime.

Diffstat:
Mlib/std/crypto/blake3.zig | 5++++-
Mlib/std/crypto/gimli.zig | 2+-
Mlib/std/multi_array_list.zig | 12+++++++++---
Mlib/std/target.zig | 13+++++++++++--
4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig @@ -200,7 +200,10 @@ const CompressGeneric = struct { } }; -const compress = if (builtin.cpu.arch == .x86_64) CompressVectorized.compress else CompressGeneric.compress; +const compress = if (builtin.cpu.arch == .x86_64 and builtin.zig_backend != .stage2_c) + CompressVectorized.compress +else + CompressGeneric.compress; fn first8Words(words: [16]u32) [8]u32 { return @ptrCast(*const [8]u32, &words).*; diff --git a/lib/std/crypto/gimli.zig b/lib/std/crypto/gimli.zig @@ -152,7 +152,7 @@ pub const State = struct { self.endianSwap(); } - pub const permute = if (builtin.cpu.arch == .x86_64) impl: { + pub const permute = if (builtin.cpu.arch == .x86_64 and builtin.zig_backend != .stage2_c) impl: { break :impl permute_vectorized; } else if (builtin.mode == .ReleaseSmall) impl: { break :impl permute_small; diff --git a/lib/std/multi_array_list.zig b/lib/std/multi_array_list.zig @@ -436,9 +436,15 @@ pub fn MultiArrayList(comptime S: type) type { } fn capacityInBytes(capacity: usize) usize { - const sizes_vector: @Vector(sizes.bytes.len, usize) = sizes.bytes; - const capacity_vector = @splat(sizes.bytes.len, capacity); - return @reduce(.Add, capacity_vector * sizes_vector); + if (builtin.zig_backend == .stage2_c) { + var bytes: usize = 0; + for (sizes.bytes) |size| bytes += size * capacity; + return bytes; + } else { + const sizes_vector: @Vector(sizes.bytes.len, usize) = sizes.bytes; + const capacity_vector = @splat(sizes.bytes.len, capacity); + return @reduce(.Add, capacity_vector * sizes_vector); + } } fn allocatedBytes(self: Self) []align(@alignOf(S)) u8 { diff --git a/lib/std/target.zig b/lib/std/target.zig @@ -1,4 +1,5 @@ const std = @import("std.zig"); +const builtin = @import("builtin"); const mem = std.mem; const Version = std.builtin.Version; @@ -719,7 +720,11 @@ pub const Target = struct { /// Adds the specified feature set but not its dependencies. pub fn addFeatureSet(set: *Set, other_set: Set) void { - set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints); + if (builtin.zig_backend == .stage2_c) { + for (set.ints) |*int, i| int.* |= other_set.ints[i]; + } else { + 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. @@ -731,7 +736,11 @@ pub const Target = struct { /// Removes the specified feature but not its dependents. pub fn removeFeatureSet(set: *Set, other_set: Set) void { - set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints); + if (builtin.zig_backend == .stage2_c) { + for (set.ints) |*int, i| int.* &= ~other_set.ints[i]; + } else { + 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 {