-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
| F´ Version | 4.x |
| Affected Component | Fw/Types |
Feature Description
I propose optimizing Fw::StringUtils::string_length by replacing the naive byte-by-byte iteration with a SWAR (SIMD Within A Register) algorithm using word-sized integer registers.
Rationale
A SWAR-based approach can significantly improve performance and CPU efficiency during string length calculation, especially for long strings.
Proposed Solution
Implement a SWAR-based algorithm that loads data in word-sized chunks (size_t) and uses bitwise operations to detect the NUL char in parallel within the register.
Requirements
To ensure safety and correctness, the solution must meet the following criteria:
- We need to handle unaligned pointers safely to avoid hardware faults on architectures that do not support unaligned access. Additionally, prevent reading across memory page boundaries.
- AddressSanitizer may flag the over-read as an error if passed
buffer_lengthis bigger than expected. We need to disable ASan for this specific function. - Add new unit tests for edge cases (unaligned pointer, different lengths).
- Benchmark existing vs. new implementation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
CCB