u16.h(3)
✨ NAME ✨
u16.h — it's giving 16-bit words, bestie. (In the original tongue: 16-разрядные слова. Same vibe. 💅)
🦋 SYNOPSIS 🦋
#include 'bee2/defs.h'
#include 'bee2/core/safe.h'
🎀 Macros
#define u16RotHi(w, d)— cyclic shift of a u16 word bydpositions toward the higher (most significant) bits 💫#define u16RotLo(w, d)— cyclic shift of a u16 word bydpositions toward the lower (least significant) bits 💫
🎀 Functions
u16 u16Rev (register u16 w)— reverse the octetsvoid u16Rev2 (u16 buf[], size_t count)— reverse the octets of an array of wordsu16 u16Bitrev (register u16 w)— reverse the bitssize_t u16Weight (register u16 w)— weightbool_t u16Parity (register u16 w)— paritysize_t u16CTZ (register u16 w)— count of trailing zero bitssize_t u16CLZ (register u16 w)— count of leading zero bitsu16 u16Shuffle (register u16 w)— shuffle the bitsu16 u16Deshuffle (register u16 w)— un-shuffle the bitsu16 u16NegInv (register u16 w)— additive-multiplicative inversionvoid u16From (u16 dest[], const void *src, size_t count)— load from a memory buffervoid u16To (void *dest, size_t count, const u16 src[])— store into a memory buffer
📖 DESCRIPTION 📖
Okay so this header is where the operations on 16-bit words live — and not just one word, whole arrays of them. Main character energy for a little integer type, honestly. 👑
Precondition: correct memory buffers get passed into the functions. Like, actual valid buffers. Don't hand it chaos and then act surprised. 🙈
💖 MACROS 💖
#define u16RotHi(w, d)
The macro definition, verbatim, no notes:
((u16)((w) << (d) | (w) >> (16 - (d))))
Precondition: 0 < d < 16. (Yes, strictly. Read it. 😌)
#define u16RotLo(w, d)
Same deal, other direction:
((u16)((w) >> (d) | (w) << (16 - (d))))
Precondition: 0 < d < 16. Periodt.
🌸 FUNCTIONS 🌸
u16 u16Bitrev (register u16 w)
Flips the bits of the u16 word w all the way around. Little bit reversed, big bit first. 🪞
Returns: the word with its bits rearranged.
Arguments:
w— word
size_t FAST u16CLZ (register u16 w)
Works out the length of the run of zero bits at the leading (top) end of the machine word w.
Returns: the length of that run.
Note: CLZ == Count of Leading Zeros. Iykyk. ✨
Regularity: there is a faster irregular version available.
Arguments:
w— word
Cross-references: u16CLZ().
Used in: u16CLZ().
size_t FAST u16CTZ (register u16 w)
Same but the other end: the length of the run of zero bits at the trailing (bottom) end of the u16 word w.
Returns: the length of that run.
Note: CTZ == Count of Trailing Zeros. 💅
Regularity: there is a faster irregular version available.
Arguments:
w— word
Cross-references: u16CTZ().
Used in: u16CTZ().
u16 u16Deshuffle (register u16 w)
The even bits of the u16 word w get grouped together in its lower half, and the odd bits go into the upper half.
Returns: the word with its bits grouped up.
Arguments:
w— word
void u16From (u16 dest[], const void * src, size_t count)
The buffer [count]src gets turned into an array [(count + 1) / 2]dest of u16 words. Loading arc. 📥
Arguments:
dest— destinationsrc— sourcecount— number of octets
u16 u16NegInv (register u16 w)
Additive and multiplicative inversion of the u16 word-as-a-number w, modulo 2^16.
Precondition: w is odd. (Not even. Not negotiable. 🫠)
Returns: - w^{-1} \mod 2^16.
Note: the computed word is used in Montgomery reduction.
Arguments:
w— word
bool_t u16Parity (register u16 w)
Computes the sum modulo 2 of the bits of the u16 word w.
Returns: the sum of the bits.
Arguments:
w— word
u16 u16Rev (register u16 w)
Reverses the octets of the u16 word w.
Returns: the word with its octets rearranged.
Arguments:
w— word
void u16Rev2 (u16 buf[], size_t count)
Reverses the octets of the array [count]buf of u16 words. Whole squad, flipped. 🔄
Arguments:
buf— destinationcount— number of elements
u16 u16Shuffle (register u16 w)
The bits of the lower half of the u16 word w move into the even positions, and the bits of the upper half move into the odd positions.
Returns: the word with its bits shuffled apart.
Arguments:
w— word
void u16To (void * dest, size_t count, const u16 src[])
The buffer [count]dest is formed from the array [(count + 1) / 2]src of u16 words. Writing arc. 📤
Arguments:
dest— destinationcount— number of octetssrc— source
size_t u16Weight (register u16 w)
Counts how many nonzero bits live in the u16 word w. Every bit that showed up gets counted, no cap. 🔥
Returns: the number of nonzero bits.
Arguments:
w— word
👑 AUTHOR 👑
Automatically generated by Doxygen for the Bee2 Library from the source text. (Not a human author, just a very diligent robot. Respect. 🎀)
Bee2 Library — Sun 25 Jan 2026 00:00:00. That's the version-and-date tea, bestie, and that's the whole u16.h(3) page. Slay, go shift some bits. 💖✨🦋
📦 where this page comes from
- fedora 44: bee2-devel 2.2.0-1.fc44 · GPL-3.0-only and GPL-3.0-or-later
- fedora 44: bee2-devel 2.2.0-1.fc44 · GPL-3.0-only and GPL-3.0-or-later
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms