libcpp: Improve search_line_sve2 performance
Optimized `search_line_sve2` in libcpp for better performance and simpler code, especially with unaligned inputs.
The search_line_sve2 function in libcpp/lex.cc has been optimized to improve performance and code simplicity. Similar to its AdvSIMD counterpart, it now loops until a match is found, even with unaligned input pointers or when near the end of the buffer. This relies on CPP_BUFFER_PADDING being at least 256 bytes (the maximum SVE vector length) and assumes a match exists within the buffer. Performance testing shows a 1-2% improvement on a trace of libcpp calls.
In Details
The search_line_sve2 function, responsible for finding line boundaries within a buffer using SVE, has been refactored for better performance and clarity. The key change is to loop until a match is found, irrespective of alignment or proximity to the buffer's end. This is safe due to the guarantee that CPP_BUFFER_PADDING is at least 256 (maximum SVE vector length) and that a match is present. This simplifies the logic compared to the previous version, which likely had more complex handling for boundary conditions, and yields a measurable performance improvement for typical libcpp workloads.
- libcpp
- The C++ standard library implementation used by Clang/LLVM.
- SVE
- Scalable Vector Extension, an instruction set architecture for ARM processors that allows vector operations to adapt to different vector lengths.
- AdvSIMD
- ARM's Advanced Single Instruction, Multiple Data (SIMD) architecture extension, also known as NEON.
- CPP_BUFFER_PADDING
- A macro likely defining the amount of extra padding added to buffers in libcpp to ensure safe access during vectorized operations, especially near the end of the buffer.