r/simd • u/Sesse__ • Jun 02 '24
Detection of nested quotes
Hi SIMDers,
I came across a problem the other day that I found fairly interesting, and thought others might as well: Detection of quoted text, where you can have both "" and '' and single quotes within double quotes or vice versa. I found a solution that I thought was pretty nice, but unfortunately so slow in practice (unless you have fast VPERMB, which I definitely don't; I'm limited to SSE3, not even PSHUFB!) that it's impractical.
All the gory details in a post at https://blog.sesse.net/blog/tech/2024-06-02-11-10_simd_detection_of_nested_quotes
In the end, I went with just detecting it and erroring out to a non-SIMD path, since it's so rare in my dataset. But it is of course always more satisfying to have a full branch-free solution.
View all comments
Show parent comment
1
u/YumiYumiYumi Jun 08 '24
Yeah, constructing the key to use 2 bits per character will be much faster, at the expense of a larger table.
I wouldn't be worried too much about moving to integer registers though, since it's still "SIMD" in the sense that you're processing multiple characters per lookup. Gather is likely much worse, because
PMOVMSKBnaturally moves to an integer register, so you'd have to move it back to a vector register, plus gather is less flexible and is slower than scalar lookups on a number of CPUs.The main benefit of the lookup strategy is that it works on baseline SSE2. But it's much less clever than what you came up with :)
Such CPUs are quite rare these days. What are you using - an AMD K10?