I haven't benchmarked this, but I'm a bit skeptical of using a lookup table for parts other than validating the combination of first and second byte in three-byte or four-byte UTF-8 sequence. My utf8_iter crate does that. (Smaller lookup table. Like here, the table read by second byte does not depend on the table read by first byte.)
I wonder what makes you skeptical. The LUT is sufficiently small to not put much pressure on L1d and the load is not on the critical path. I highly recommend reading @pervognsen 's original gist on shift-DFA.
The point is to reduce the work to 3 operations per input byte. Load the byte, load transition row, shift. And since neither of the loads has a loop-carried dependency, the speed of the algorithm is min(load throughput / 2, shift latency). And everything since Haswell has at least 2 load ports and shift latency of 1, so this ends up running at 1byte/clock. I've been trying to improve on that for a while now, but 2bytes/clock is a hard limit for a scalar DFA. I'd be interested in seeing how utf8_iter stands up to the shift-DFA, when you get around to testing it.
christine | 8 hours ago
The use of SAT solvers to produce DFA lookup tables is interesting.
hsivonen | 8 hours ago
I haven't benchmarked this, but I'm a bit skeptical of using a lookup table for parts other than validating the combination of first and second byte in three-byte or four-byte UTF-8 sequence. My utf8_iter crate does that. (Smaller lookup table. Like here, the table read by second byte does not depend on the table read by first byte.)
maxholl | 6 hours ago
I wonder what makes you skeptical. The LUT is sufficiently small to not put much pressure on L1d and the load is not on the critical path. I highly recommend reading @pervognsen 's original gist on shift-DFA.
The point is to reduce the work to 3 operations per input byte. Load the byte, load transition row, shift. And since neither of the loads has a loop-carried dependency, the speed of the algorithm is min(load throughput / 2, shift latency). And everything since Haswell has at least 2 load ports and shift latency of 1, so this ends up running at 1byte/clock. I've been trying to improve on that for a while now, but 2bytes/clock is a hard limit for a scalar DFA. I'd be interested in seeing how utf8_iter stands up to the shift-DFA, when you get around to testing it.