aboutsummaryrefslogtreecommitdiff
path: root/lib/std/http/HeadParser.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-05-21 12:15:03 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2025-05-28 15:10:22 -0400
commit1f6f8b0ffe33696ce980955cceacd98171d7ea0c (patch)
treedc720d4fc02e891cb3cd53dc50d174010521eabb /lib/std/http/HeadParser.zig
parentd69f4c48fc6694293573aec6e370d429877a4c7d (diff)
downloadzig-1f6f8b0ffe33696ce980955cceacd98171d7ea0c.tar.gz
zig-1f6f8b0ffe33696ce980955cceacd98171d7ea0c.zip
x86_64: implement integer `@reduce(.Add)`
Diffstat (limited to 'lib/std/http/HeadParser.zig')
-rw-r--r--lib/std/http/HeadParser.zig35
1 files changed, 14 insertions, 21 deletions
diff --git a/lib/std/http/HeadParser.zig b/lib/std/http/HeadParser.zig
index bb49faa14b..7b9ca6d2c5 100644
--- a/lib/std/http/HeadParser.zig
+++ b/lib/std/http/HeadParser.zig
@@ -109,27 +109,21 @@ pub fn feed(p: *HeadParser, bytes: []const u8) usize {
continue;
},
else => {
+ const Vector = @Vector(vector_len, u8);
+ // const BoolVector = @Vector(vector_len, bool);
+ const BitVector = @Vector(vector_len, u1);
+ const SizeVector = @Vector(vector_len, u8);
+
const chunk = bytes[index..][0..vector_len];
- const matches = if (use_vectors) matches: {
- const Vector = @Vector(vector_len, u8);
- // const BoolVector = @Vector(vector_len, bool);
- const BitVector = @Vector(vector_len, u1);
- const SizeVector = @Vector(vector_len, u8);
-
- const v: Vector = chunk.*;
- const matches_r: BitVector = @bitCast(v == @as(Vector, @splat('\r')));
- const matches_n: BitVector = @bitCast(v == @as(Vector, @splat('\n')));
- const matches_or: SizeVector = matches_r | matches_n;
-
- break :matches @reduce(.Add, matches_or);
- } else matches: {
- var matches: u8 = 0;
- for (chunk) |byte| switch (byte) {
- '\r', '\n' => matches += 1,
- else => {},
- };
- break :matches matches;
- };
+ const v: Vector = chunk.*;
+ // depends on https://github.com/ziglang/zig/issues/19755
+ // const matches_r: BitVector = @bitCast(v == @as(Vector, @splat('\r')));
+ // const matches_n: BitVector = @bitCast(v == @as(Vector, @splat('\n')));
+ const matches_r: BitVector = @select(u1, v == @as(Vector, @splat('\r')), @as(Vector, @splat(1)), @as(Vector, @splat(0)));
+ const matches_n: BitVector = @select(u1, v == @as(Vector, @splat('\n')), @as(Vector, @splat(1)), @as(Vector, @splat(0)));
+ const matches_or: SizeVector = matches_r | matches_n;
+
+ const matches = @reduce(.Add, matches_or);
switch (matches) {
0 => {},
1 => switch (chunk[vector_len - 1]) {
@@ -357,7 +351,6 @@ inline fn intShift(comptime T: type, x: anytype) T {
const HeadParser = @This();
const std = @import("std");
-const use_vectors = builtin.zig_backend != .stage2_x86_64;
const builtin = @import("builtin");
test feed {