5 points · by mikece · 2y ago · 7 comments
I'm also looking for anybody willing to sponsor a port of this work to other architectures or x86-64-v3/v4 (i.e. AVX2/AVX-512).
For porting, have you considered using github.com/google/highway? This allows you to write the code once using 'portable' intrinsics, and run on >20 instruction sets.
Disclosure: I am the main author of this library, happy to discuss.
* about half the code deals with reading the beginning and end of strings by doing elaborate, careful unaligned loads and masking * the other half is straightforward byte-wise comparison following by pmovmskb to inspect where matches were found. This is very performance sensitive and different strategies have to be used on different platforms. For example, NEON doesn't have an instruction like that, so you need to work around the shortcoming in various painful ways.
* some functions currently use the x86-only pcmpistrm instruction and would need a complete redesign for other platforms
I have so far not had any good experience with SIMD libraries for this kind of code. Even C++ + instrinsics delivers poor performance in this sort of setup. For example, when we ported our UTF-8 <-> UTF-16 kernels (AVX-512) from assembly to C++ with intrinsics, performance dropped by 25%.
Also there are two other important constraints:
* we're working far outside the rules of the C language, overreading buffers here and there. It is unknown if the C compiler would miscompile our code.
* similarly, we don't want any C++ in libc, so using a C++-based library is out.
I'm also curious if you looked into the difference of asm vs intrinsics, where the compiler was going wrong, and/or how long ago that was?
As to careful loads and movmskb, Highway does have LoadN and Find(Known)FirstTrue which is still quite decent on Arm. You might find it useful if/when porting?