Commit 7707a1e
perf(string): SIMD swab — 16-34x self, 10-20x faster than glibc
swab() byte-swapped adjacent pairs with two scalar stores per pair
(dest[2k]=src[2k+1]; dest[2k+1]=src[2k]) — ~0.58-0.66 ns/B, ~1.6x SLOWER than
glibc's tuned loop. Replace the body with a single 32-byte portable-SIMD
shuffle (lane 2k <-> 2k+1) plus a 2-byte scalar tail. The swizzle is exactly
the pairwise transposition, so it is byte-for-byte identical to the scalar
loop; bytes is even so neither the SIMD step (multiple of 32) nor the tail
splits a pair, and an odd trailing byte (n odd) stays untouched per POSIX.
swab (ns/B): scalar 0.564-0.790 -> SIMD 0.018-0.050 = 15.8-33.9x self;
vs glibc 0.36-0.48 ns/B -> 0.05-0.10x (10-20x FASTER than glibc).
Isomorphism: conformance_diff_string_mut::diff_swab_cases vs host glibc —
extended with a 16..511-byte even/odd sweep so the SIMD block, its boundary,
and the scalar tail are all covered (was <=8 bytes = scalar tail only);
+ core unit tests (basic + odd_length). 0 divergences.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7f83e5e commit 7707a1e
2 files changed
Lines changed: 57 additions & 4 deletions
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1811 | 1811 | | |
1812 | 1812 | | |
1813 | 1813 | | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
1814 | 1844 | | |
1815 | 1845 | | |
1816 | 1846 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
769 | 769 | | |
770 | 770 | | |
771 | 771 | | |
772 | | - | |
773 | | - | |
774 | | - | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
775 | 798 | | |
776 | | - | |
| 799 | + | |
777 | 800 | | |
778 | 801 | | |
779 | 802 | | |
| |||
0 commit comments