baselibc: Add option to disable memset and memcpy#3657
Open
kasjer wants to merge 2 commits into
Open
Conversation
baselibc version of memcpy and memset are optimized for speed if compared to pure C code. However compiler provided version are more efficient. Additionally baselibc version for ARM copies data in revers direction which is allowed but may degrade performance when buffers are aligned but number of bytes to copy is not multiply of 4. Second case where this approach shows it's drawbacks is when memcpy is used to copy data from memory mapped QSPI flash when reading from the last byte is very inefficient. This just add option to drop baselibc version in favor of other (compiler provided or user provided).
andrzej-kaczmarek
approved these changes
Jun 1, 2026
memcpy used to work in descending order to minimize code size. Updates ARM memcpy version to work in ascending order. For aligned buffers time to copy does not changes significantly when buffer to copy increases by 1 which was the case when even for aligned buffers code performed unaligned reads when nuber of bytes to copy was not multiply of 4. Code enables 32-bit copy for Cortex-M0 (which was not the case), aligned buffers are copied much faster now. This change also improves performance on memory mapped QSPI flashes when reading successful data is much faster then reading in reverse direction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
baselibc version of memcpy and memset are optimized for speed if compared to pure C code.
However compiler provided version are more efficient. Additionally baselibc version for ARM copies data
in revers direction which is allowed but may degrade performance when buffers are aligned but number of bytes to copy is not multiply of 4.
Second case where this approach shows it's drawbacks is when memcpy is used to copy data from memory mapped QSPI flash when reading from the last byte is very inefficient.
This just add option to drop baselibc version in favor of other (compiler provided or user provided).
baselibc version now copies 8-bit/32-bit words from the beginning. It is slightly slower that previous version when 8-bit copy kicks in. It is much faster for Cortex-M0 when buffers are aligned. It is faster when buffers are aligned but length is not multiply of 4.