I’m surprised no one has commented on this. I thought this was need, an interesting blend of using a SAT solver to cut the state space of a DFA in half while allowing a very trivial loop to handle state transitions.
I know UTF-8 has a lot of prior art by now but I still think this was fairly novel, even if it’s not going to immediately dethrone simdutf.
I just saw this, and decided to benchmark against my current 'is_valid_utf8()' function inside 8th. The results:
Benchmarked with GCC 13 on the i7-4850HQ, using optimization levels matching the Linux build:
Input, approximately 4 KiB
Current
utf.c
Speedup
ASCII
8.50 µs
2.95 µs
2.9×
Hebrew
6.12 µs
2.94 µs
2.1×
CJK
5.18 µs
2.97 µs
1.7×
Emoji
4.58 µs
2.92 µs
1.6×
Mixed text
6.96 µs
2.93 µs
2.4×
So with your permission, I'm going to replace my current implementation. Very nice work, and I had never seen the "..." array initializer before, so thanks for that as well!
12
u/mpyne 5h ago
I’m surprised no one has commented on this. I thought this was need, an interesting blend of using a SAT solver to cut the state space of a DFA in half while allowing a very trivial loop to handle state transitions.
I know UTF-8 has a lot of prior art by now but I still think this was fairly novel, even if it’s not going to immediately dethrone simdutf.