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.
This commit is contained in:
Jacob Young 2022-10-31 21:40:39 -04:00
parent ebf9ffd342
commit 93d60d0de7
4 changed files with 25 additions and 7 deletions

View File

@ -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).*;

View File

@ -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;

View File

@ -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 {

View File

@ -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 {