cpu_capabilities(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’… cpu_capabilities(3) β€” the Allegro manual, but make it cute ✨

okay bestie, sit down, we're talking about cpu_capabilities β€” a little global from the Allegro game programming library that tells you what your CPU can actually do. it's giving "tell me your red flags but it's processor instructions" πŸ’–


🌸 SYNOPSIS 🌸

#include <allegro.h>

extern int cpu_capabilities;

like. that's it. one extern int. she's lowkey simple but highkey important πŸŽ€


✨ DESCRIPTION ✨

so cpu_capabilities holds a bunch of CPU flags that say which features your current CPU has. and not just one β€” it can be any combination of these, all OR-ed together in one int. let's go through the whole roster, no skipping, periodt πŸ‘‘

  • CPU_ID β€” this one means the "cpuid" instruction is available. and bestie, this matters: if this flag is set, then all Allegro CPU variables are 100% reliable. if it's not set? there may be some mistakes 😭 so if you don't see CPU_ID, don't be out here trusting everything you read, okay?
  • CPU_FPU β€” an FPU is available πŸ’« (floating point, she's here)
  • CPU_IA64 β€” running on an Intel 64 bit CPU
  • CPU_AMD64 β€” running on an AMD 64 bit CPU
  • CPU_MMX β€” Intel MMX instruction set is available πŸ”₯
  • CPU_MMXPLUS β€” Intel MMX+ instruction set is available
  • CPU_SSE β€” Intel SSE instruction set is available ✨
  • CPU_SSE2 β€” Intel SSE2 instruction set is available ✨
  • CPU_SSE3 β€” Intel SSE3 instruction set is available ✨
  • CPU_3DNOW β€” AMD 3DNow! instruction set is available
  • CPU_ENH3DNOW β€” AMD Enhanced 3DNow! instruction set is available
  • CPU_CMOV β€” Pentium Pro "cmov" instruction is available

πŸ¦‹ how to actually use her πŸ¦‹

you check for multiple features by OR-ing the flags together. iconic behaviour honestly.

so for example, if you wanna know whether the CPU has both an FPU and MMX instructions, you'd do:

if ((cpu_capabilities & (CPU_FPU | CPU_MMX)) ==
    (CPU_FPU | CPU_MMX)) {
   printf("CPU has both an FPU and MMX instructions!\n");
}

see the double-check on both sides of the ==? that's not a typo, that's the vibe check β€” you're making sure every flag you asked for is actually present, not just one of them πŸ™ˆ

and like, you can only read this variable after you've called check_cpu() β€” which, good news, gets automatically called by allegro_init() for you. so if you did your allegro_init(), you're covered, no extra steps required πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, bestie 🫢 this was Allegro, version 4.4.3, and we've been reading cpu_capabilities(3) β€” go forth and check your flags, you ate πŸ’–βœ¨πŸŒˆ

πŸ“¦ where this page comes from