Commit faffed3
perf(strncpy): SWAR scan + wide copy + wide pad for strncpy/stpncpy (bd-2g7oyh.363)
strncpy copied byte-at-a-time to the NUL then byte-padded the remainder with
NUL. Replace the copy+pad loop with a composition of the already-shipped,
independently-gated SWAR/wide primitives: scan_c_string (SWAR) finds the source
NUL within the bound, raw_memcpy_bytes (wide u128-block) copies the prefix
clamped to the dst bound, and raw_memset_bytes (wide) NUL-fills the remainder —
byte-identical to the scalar loop including the membrane-repair clamping
(safe_src_len/safe_dst_len). stpncpy delegates to strncpy + strnlen, so it
inherits this and the SWAR strnlen win.
Measured (rch, median ns/op, copy-heavy strlen==n full copy, no pad):
n old(ns) new(ns) glibc(ns) self vs-glibc
64 33.4 7.6 20.9 4.39x 2.76x
256 116.0 20.7 34.1 5.60x 1.64x
1024 449.0 77.5 92.6 5.80x 1.20x
4096 1783.0 291.9 308.0 6.11x 1.06x
65536 28402.6 4524.2 4531.0 6.28x 1.00x
Self-speedup 4.4-6.3x for n>=64 (>=2.0); matches-or-beats glibc strncpy at every
size. (Pad-heavy strncpy was already fast — the byte pad lowered to memset — so
this is the copy-portion win; total strncpy never slower.)
Parity: conformance_diff_strncpy.rs proves fl strncpy/stpncpy produce byte-
identical destination buffers (full n bytes incl. NUL padding) + stpncpy end
offset vs host glibc across 2400 cases (src len 0..300 x n straddling the NUL x
src/dst alignments 0..7). The composed primitives stay independently gated by
conformance_diff_{scan_c_string,memcpy,memset}. Tenth ABI string-vein win.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent e343836 commit faffed3
3 files changed
Lines changed: 140 additions & 12 deletions
File tree
- crates
- frankenlibc-abi
- src
- tests
- frankenlibc-bench/benches
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2651 | 2651 | | |
2652 | 2652 | | |
2653 | 2653 | | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
2654 | 2660 | | |
2655 | | - | |
2656 | | - | |
2657 | | - | |
2658 | | - | |
2659 | | - | |
2660 | | - | |
2661 | | - | |
2662 | | - | |
2663 | | - | |
2664 | | - | |
2665 | | - | |
2666 | | - | |
| 2661 | + | |
| 2662 | + | |
| 2663 | + | |
| 2664 | + | |
| 2665 | + | |
2667 | 2666 | | |
2668 | 2667 | | |
2669 | 2668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
19 | 52 | | |
20 | 53 | | |
21 | 54 | | |
| |||
380 | 413 | | |
381 | 414 | | |
382 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
383 | 448 | | |
0 commit comments