From 93d60d0de76e5dca666682e51589c0819eed2507 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Mon, 31 Oct 2022 21:40:39 -0400 Subject: [PATCH] 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. --- lib/std/crypto/blake3.zig | 5 ++++- lib/std/crypto/gimli.zig | 2 +- lib/std/multi_array_list.zig | 12 +++++++++--- lib/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 index 762ec67f31..4f8d023532 100644 --- 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 index 96a7d69e6f..4952937697 100644 --- 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 index c3bfa6537b..89c7869b6b 100644 --- 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 index 342e535c27..34bae7cda2 100644 --- 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 {