swap_words_64(9)
π swap_words_64 β like, the manual page, bestie
okay so you found swap_words_64(9) in the Kernel API Manual and you're like "what is this" β don't worry, I got you. sit down, hydrate, let's go π«Ά
β¨ NAME β¨
swap_words_64 β swap two elements in 64-bit chunks π« (yes that's literally it, and yes it's iconic)
π SYNOPSIS π
void swap_words_64 (void *a , void *b , size_t n );
like, that's the whole vibe. three args, no return, in and out. slay π
πΈ ARGUMENTS πΈ
aβ pointer to the first element to swap π₯ like, the first one of the two things we're tradingbβ pointer to the second element to swap π₯ and here's the other onenβ element size, and it must be a multiple of 8 β οΈ no cap, fr fr, if it's not a multiple of 8 that's a you problem
π¦ DESCRIPTION π¦
okay so what it does: it exchanges the two objects in memory π that's the whole thing. and the way it does it is genuinely clever β it exploits base+index addressing, which basically all CPUs have, to minimize loop overhead computations. like, the CPU already knows how to do this, so let's not make it do extra math, periodt β¨
we'd like to use 64-bit loads if possible, obviously, main character energy. but if they're not available, emulating one requires base+index+4 addressing, which x86 has but most other processors do not π so that's a whole thing.
if CONFIG_64BIT is set, we definitely have 64-bit loads π₯ but β and this is the fun part β it's possible to have 64-bit loads without 64-bit pointers (e.g. the x32 ABI π). and then the manpage just. asks. out loud:
Are there any cases the kernel needs to worry about? π€
like it's literally posing the question in the documentation. no answer. just vibes and an open question. honestly? iconic. iykyk π
π₯ SEE ALSO π₯
- Kernel file
./lib/sort.cπ is_aligned(9)swap_words_32(9)swap_bytes(9)parent(9)sort_r(9)sort_r_nonatomic(9)
go read those too, bestie, they're all in the family π
ok so that's the page!! it's from the Kernel API Manual, lives in ./lib, and the date on it is October 2026 πΈ mwah, go forth and swap your words in 64-bit chunks, you absolute legend ππ
π¦ 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