mirror of
https://github.com/apache/nuttx.git
synced 2026-08-25 23:47:16 +00:00
The BSD string functions take a word path only when both pointers are
aligned, and a byte path otherwise. A pair at the same offset from a
boundary takes the byte path even though copying or comparing a few leading
bytes aligns both at once, since aligning one aligns the other.
Add MISALIGNED(), which asks whether two pointers disagree about where a
boundary falls, and walk an agreeing pair up to the boundary before the
existing path selection. MISALIGNED4() does the same for the 4-byte path,
so a pair that is 4-byte but not 8-byte aligned reaches the wide path
instead of the middle one. No existing line changes: the walk is a new step
ahead of the current decisions. A pair at differing offsets still takes the
byte path, since no single boundary serves both.
Measured on an EIC7700 EVB (EIC7700X, RV64GC, 1.4GHz) with the BSD string
functions selected and the RISC-V assembly ones disabled, using the
benchmark in apps#3706, medians of 3 runs in MB/s at its largest size:
equal offset aligned
memcpy 414 -> 4148 10.0x 4214 -> 4208
memcmp 41 -> 361 8.8x 362 -> 360
strncmp 28 -> 202 7.4x 207 -> 207
strcmp 42 -> 273 6.5x 278 -> 276
strncpy 377 -> 1676 4.5x 1824 -> 1748
stpncpy 376 -> 1654 4.4x 1843 -> 1724
stpcpy 551 -> 1833 3.3x 1970 -> 1939
memccpy 650 -> 2012 3.1x 2478 -> 2016
strcpy 636 -> 1837 2.9x 1678 -> 1965
Cases the walk never runs for move in both directions by up to a third, the
largest being memccpy at differing offsets, 648 -> 414. Their code is
unchanged, so that is code placement rather than an effect of the change.
The change is architecture independent but has only been measured on
RV64GC. Word size, alignment cost and byte loop codegen all differ
elsewhere, so the balance wants measuring on other architectures.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Justin Hammond <justin@dynam.ac>
|
||
|---|---|---|
| .. | ||
| CMakeLists.txt | ||
| Kconfig | ||
| lib_bsdmemccpy.c | ||
| lib_bsdmemchr.c | ||
| lib_bsdmemcmp.c | ||
| lib_bsdmemcpy.c | ||
| lib_bsdmemrchr.c | ||
| lib_bsdmemset.c | ||
| lib_bsdstpcpy.c | ||
| lib_bsdstpncpy.c | ||
| lib_bsdstrcat.c | ||
| lib_bsdstrchr.c | ||
| lib_bsdstrchrnul.c | ||
| lib_bsdstrcmp.c | ||
| lib_bsdstrcpy.c | ||
| lib_bsdstrlen.c | ||
| lib_bsdstrncmp.c | ||
| lib_bsdstrncpy.c | ||
| lib_bsdstrrchr.c | ||
| lib_explicit_bzero.c | ||
| lib_ffs.c | ||
| lib_ffsl.c | ||
| lib_ffsll.c | ||
| lib_fls.c | ||
| lib_flsl.c | ||
| lib_flsll.c | ||
| lib_index.c | ||
| lib_isbasedigit.c | ||
| lib_memccpy.c | ||
| lib_memchr.c | ||
| lib_memcmp.c | ||
| lib_memcpy.c | ||
| lib_memmem.c | ||
| lib_memmove.c | ||
| lib_mempcpy.c | ||
| lib_memrchr.c | ||
| lib_memset.c | ||
| lib_popcount.c | ||
| lib_popcountl.c | ||
| lib_popcountll.c | ||
| lib_rawmemchr.c | ||
| lib_rindex.c | ||
| lib_skipspace.c | ||
| lib_stpcpy.c | ||
| lib_stpncpy.c | ||
| lib_strcasecmp.c | ||
| lib_strcasestr.c | ||
| lib_strcat.c | ||
| lib_strchr.c | ||
| lib_strchrnul.c | ||
| lib_strcmp.c | ||
| lib_strcoll.c | ||
| lib_strcpy.c | ||
| lib_strcspn.c | ||
| lib_strdup.c | ||
| lib_strerror.c | ||
| lib_strerrorr.c | ||
| lib_strlcat.c | ||
| lib_strlcpy.c | ||
| lib_strlen.c | ||
| lib_strncasecmp.c | ||
| lib_strncat.c | ||
| lib_strncmp.c | ||
| lib_strncpy.c | ||
| lib_strndup.c | ||
| lib_strnlen.c | ||
| lib_strpbrk.c | ||
| lib_strrchr.c | ||
| lib_strsep.c | ||
| lib_strsignal.c | ||
| lib_strspn.c | ||
| lib_strstr.c | ||
| lib_strtok.c | ||
| lib_strtokr.c | ||
| lib_strverscmp.c | ||
| lib_strxfrm.c | ||
| lib_timingsafe_bcmp.c | ||
| lib_vikmemcpy.c | ||
| Make.defs | ||