Q_SIGNSHFT(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… Q_SIGNSHFT(3) β€” Library Functions Manual, bestie

okay so this is Q_SIGNSHFT(3) from the library functions manual, and honestly? it's giving low-level bit-fiddling royalty. ✨ these are the fixed-point math girlies that mess with the control bits and the sign bit, and i need you to stay with me because it's actually so good once it clicks.


🌸 NAME 🌸

Q_SIGNSHFT, Q_SSIGN, Q_CRAWMASK, Q_SRAWMASK, Q_GCRAW, Q_GCVAL, Q_SCVAL β€” fixed-point math functions which manipulate the control/sign data bits

like yes, that's the whole squad. seven functions, one job: touching the control bits and the sign bit. no cap. πŸŽ€


✨ SYNOPSIS ✨

#include <sys/qmath.h>

uint32_t
Q_SIGNSHFT(QTYPE q);

QTYPE
Q_SSIGN(QTYPE q, bool isneg);

ITYPE
Q_CRAWMASK(QTYPE q);

ITYPE
Q_SRAWMASK(QTYPE q);

ITYPE
Q_GCRAW(QTYPE q);

ITYPE
Q_GCVAL(QTYPE q);

QTYPE
Q_SCVAL(QTYPE q, ITYPE cv);

copy it exactly, don't be weird about it 🫢


πŸ’– DESCRIPTION πŸ’–

okay so, function by function, here's the vibe:

  • Q_SIGNSHFT() β€” gets the bit position of q's sign bit relative to bit zero. so basically "where does the sign bit live," as a number. iconic. πŸ“
  • Q_SSIGN() β€” sets the sign bit of q based on the boolean isneg. true means negative energy, false means positive energy. πŸ’…
  • Q_CRAWMASK() and Q_SRAWMASK() β€” return q-specific bit masks for q's control bits and sign bit respectively. masks! for the control bits and the sign bit! matching set, slay. πŸŽ€
  • Q_GCRAW() and Q_GCVAL() β€” get the raw masked control bits and value of q's control bits respectively. one's the raw masked version, one's the value. don't mix them up bestie. πŸ™ˆ
  • Q_SCVAL() β€” sets q's control bits to the value cv. boom. done. ✨

and here's the thing β€” all of those functions operate on the following data types: s8q_t, u8q_t, s16q_t, u16q_t, s32q_t, u32q_t, s64q_t, and u64q_t, which are referred to generically as QTYPE. so like, that's the whole QTYPE family, all eight of them, signed and unsigned, 8 through 64. the ITYPE refers to the stdint(7) integer types. πŸ¦‹

For more details, see qmath(3). (go read it, it's the main character.)


πŸ¦‹ RETURN VALUES πŸ¦‹

what comes back out, per function:

  • Q_SIGNSHFT() returns the sign bit's position as an integer.
  • Q_SSIGN() returns the value of q post change. so you get your q back, but changed. glow-up returned. πŸ‘‘
  • Q_CRAWMASK(), Q_SRAWMASK(), Q_GCRAW() and Q_GCVAL() return their respective values as integers of the same underlying ITYPE as q. same underlying type as q, always. matching energy. 🧚
  • Q_SCVAL() returns the value of q post change.

⭐ SEE ALSO ⭐

the friend group. go say hi. 🌈


πŸ’€ HISTORY πŸ’€

The qmath(3) functions first appeared in FreeBSD 13.0. so like, they're not ancient, they're just established. periodt.


πŸ“ AUTHORS πŸ“

The qmath(3) functions and this manual page were written by Lawrence Stewart <lstewart@FreeBSD.org> and sponsored by Netflix, Inc. β€” yes, that Netflix. sponsoring bit-level fixed-point math. main character behavior fr fr. 🎬πŸ”₯


ok that's the whole page bestie, every flag-free function, every type, every return value, nothing skipped πŸ’œ

and finally, the cute little sign-off the manpage came with: this one's from Debian, dated July 8, 2018. πŸ’– bye bestie, go manipulate some control bits responsibly! 🫢✨

πŸ“¦ where this page comes from