Skip to main content

Module scan

Module scan 

Source
Expand description

SIMD byte scanning for the HTTP parsers (owned by the simoom-http1 work). SIMD byte scanning for the HTTP parsers, with runtime detection and a scalar fallback.

The parsers ask one question many times: “how long is the run of bytes, starting here, that belong to this class?” (a token, a request target, a field value). The first byte outside the class is the delimiter (:, SP, CR) or an invalid byte, so finding and validating happen in one pass. scan answers it; find_byte is a plain memchr.

Kernels: SSSE3/SSE4.2 (16 bytes per step) and AVX2 (32) on x86-64, NEON (16) on aarch64. Class membership uses the nibble-table method: a 16-byte table indexed by the low nibble holds, per high nibble 0..7, whether that byte is in the class, so any set of ASCII bytes is exact. Bytes 0x80..=0xFF are either all in or all out of a class. The level is detected once and cached; force overrides it for benchmarks.

Structs§

ByteClass
A set of byte values, usable by every kernel.

Enums§

Level
A scanning implementation.

Statics§

FIELD_VALUE
RFC 9110 field-value bytes: HTAB, SP, VCHAR and obs-text. Stops at CR, LF, NUL, DEL and every other control byte.
TCHAR
RFC 9110 tchar: the bytes of a token (method, field name, transfer coding).
URI
RFC 3986 bytes of a request target other than % (checked separately with its two hex digits) and [ ] (IP literals only): unreserved, sub-delims, :, @, /, ?.

Functions§

available
True if this CPU can run level.
field_line
Offsets of one header field line at the start of buf, found in a single dispatch: (name_end, value_start, value_end). name_end is the length of the TCHAR run. If the byte there is :, value_start is past the colon and any SP/HTAB, and value_end ends the FIELD_VALUE run from there (trailing whitespace included); otherwise both equal name_end. The caller checks the bytes at name_end and value_end.
find_byte
Index of the first byte in buf.
find_byte_at
find_byte with an explicit level; an unavailable level falls back to scalar.
force
Uses level from now on, process-wide; returns false (and changes nothing) if the CPU lacks it. Meant for benchmarks and tests.
level
The level in use: the best one this CPU supports, unless force chose another.
scan
Length of the run of bytes at the start of buf that are in class: the index of the first byte outside it, or buf.len().
scan_at
scan with an explicit level; an unavailable level falls back to scalar.