swap_words_32(9)
πΈ NAME πΈ
okay so bestie, this is swap_words_32(9) from the Kernel API Manual, and it does exactly what it says on the tin: swap_words_32 β swap two elements in 32-bit chunks. iconic behavior, no cap π
β¨ SYNOPSIS β¨
void swap_words_32 (void *a , void *b , size_t n );
π ARGUMENTS π
aβ pointer to the first element to swap. yes queen, the first one.bβ pointer to the second element to swap. the other half of the swap, periodt.nβ element size, and it must be a multiple of 4. don't try to be cute with a weird size, fr fr.
π DESCRIPTION π
so what it does: it exchanges the two objects in memory. it exploits base+index addressing, which basically all CPUs have, to minimize loop overhead computations. lowkey efficient, highkey iconic β‘
for some reason, on x86 gcc 7.3.0 adds a redundant test of n at the bottom of the loop, even though the zero flag is still valid from the subtract (since the intervening mov instructions don't alter the flags). Gcc 8.1.0 doesn't have that problem. not me side-eyeing the compiler π
π¦ SEE ALSO π¦
- Kernel file
./lib/sort.c is_aligned(9)swap_words_64(9)swap_bytes(9)parent(9)sort_r(9)sort_r_nonatomic(9)
okay bye bestie π«Ά this little manual moment is from the ./lib source, dated October 2026, and it's giving swap_words_32(9) in the Kernel API Manual energy β¨π
π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms