authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-10-13 16:57:50+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-10-13 16:58:05+03:00
logc919e9a2806aed62f8fe7cb23da4aa14808daea8
tree53922621121f0798550b4a21f76658909d6c37b6
parentf09313dbc46ae9dc6165cbfb3d0b18760db55752

std.simd: return comptime_int from `suggestVectorSize`


4 files changed, 8 insertions(+), 8 deletions(-)

lib/std/http/protocol.zig+1-1
......@@ -82,7 +82,7 @@ pub const HeadersParser = struct {
8282 /// If the amount returned is less than `bytes.len`, you may assume that the parser is in a content state and the
8383 /// first byte of content is located at `bytes[result]`.
8484 pub fn findHeadersEnd(r: *HeadersParser, bytes: []const u8) u32 {
85 const vector_len: comptime_int = comptime @max(std.simd.suggestVectorSize(u8) orelse 1, 8);
85 const vector_len: comptime_int = @max(std.simd.suggestVectorSize(u8) orelse 1, 8);
8686 const len = @as(u32, @intCast(bytes.len));
8787 var index: u32 = 0;
8888
lib/std/mem.zig+4-4
......@@ -974,7 +974,7 @@ pub fn indexOfSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]co
974974 // The below branch assumes that reading past the end of the buffer is valid, as long
975975 // as we don't read into a new page. This should be the case for most architectures
976976 // which use paged memory, however should be confirmed before adding a new arch below.
977 .aarch64, .x86, .x86_64 => if (comptime std.simd.suggestVectorSize(T)) |block_len| {
977 .aarch64, .x86, .x86_64 => if (std.simd.suggestVectorSize(T)) |block_len| {
978978 comptime std.debug.assert(std.mem.page_size % block_len == 0);
979979 const Block = @Vector(block_len, T);
980980 const mask: Block = @splat(sentinel);
......@@ -1027,7 +1027,7 @@ test "indexOfSentinel vector paths" {
10271027 const allocator = std.testing.allocator;
10281028
10291029 inline for (Types) |T| {
1030 const block_len = comptime std.simd.suggestVectorSize(T) orelse continue;
1030 const block_len = std.simd.suggestVectorSize(T) orelse continue;
10311031
10321032 // Allocate three pages so we guarantee a page-crossing address with a full page after
10331033 const memory = try allocator.alloc(T, 3 * std.mem.page_size / @sizeOf(T));
......@@ -1118,11 +1118,11 @@ pub fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize,
11181118 !@inComptime() and
11191119 (@typeInfo(T) == .Int or @typeInfo(T) == .Float) and std.math.isPowerOfTwo(@bitSizeOf(T)))
11201120 {
1121 if (comptime std.simd.suggestVectorSize(T)) |block_len| {
1121 if (std.simd.suggestVectorSize(T)) |block_len| {
11221122 // For Intel Nehalem (2009) and AMD Bulldozer (2012) or later, unaligned loads on aligned data result
11231123 // in the same execution as aligned loads. We ignore older arch's here and don't bother pre-aligning.
11241124 //
1125 // Use `comptime std.simd.suggestVectorSize(T)` to get the same alignment as used in this function
1125 // Use `std.simd.suggestVectorSize(T)` to get the same alignment as used in this function
11261126 // however this usually isn't necessary unless your arch has a performance penalty due to this.
11271127 //
11281128 // This may differ for other arch's. Arm for example costs a cycle when loading across a cache
lib/std/simd.zig+2-2
......@@ -6,7 +6,7 @@
66const std = @import("std");
77const builtin = @import("builtin");
88
9pub fn suggestVectorSizeForCpu(comptime T: type, comptime cpu: std.Target.Cpu) ?usize {
9pub fn suggestVectorSizeForCpu(comptime T: type, comptime cpu: std.Target.Cpu) ?comptime_int {
1010 // This is guesswork, if you have better suggestions can add it or edit the current here
1111 // This can run in comptime only, but stage 1 fails at it, stage 2 can understand it
1212 const element_bit_size = @max(8, std.math.ceilPowerOfTwo(u16, @bitSizeOf(T)) catch unreachable);
......@@ -55,7 +55,7 @@ pub fn suggestVectorSizeForCpu(comptime T: type, comptime cpu: std.Target.Cpu) ?
5555
5656/// Suggests a target-dependant vector size for a given type, or null if scalars are recommended.
5757/// Not yet implemented for every CPU architecture.
58pub fn suggestVectorSize(comptime T: type) ?usize {
58pub fn suggestVectorSize(comptime T: type) ?comptime_int {
5959 return suggestVectorSizeForCpu(T, builtin.cpu);
6060}
6161
lib/std/unicode.zig+1-1
......@@ -200,7 +200,7 @@ pub fn utf8CountCodepoints(s: []const u8) !usize {
200200pub fn utf8ValidateSlice(input: []const u8) bool {
201201 var remaining = input;
202202
203 const V_len = comptime std.simd.suggestVectorSize(usize) orelse 1;
203 const V_len = std.simd.suggestVectorSize(usize) orelse 1;
204204 const V = @Vector(V_len, usize);
205205 const u8s_in_vector = @sizeOf(usize) * V_len;
206206