swap_words_64(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 trading
  • b β€” pointer to the second element to swap πŸ₯ˆ and here's the other one
  • n β€” 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 πŸ”₯

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