Files
ruapu/README.md
T
2024-02-21 14:44:44 +08:00

2.1 KiB
Raw Blame History

ruapu

Detect cpu ISA features with single-file

CPU✅ x86, x86-64
✅ arm, aarch64
#define RUAPU_IMPLEMENTATION
#include "ruapu.h"

int main()
{
    // initialize ruapu once
    ruapu_init();

    // now, tell me if this cpu has avx2
    int has_avx2 = ruapu_supports("avx2");

    return 0;
}
OS✅ Windows
✅ Linux
✅ macOS
✅ Android
✅ iOS
Compiler✅ GCC
✅ Clang
✅ MSVC
✅ MinGW

Let's ruapu

Compile ruapu test program

# GCC / MinGW
gcc main.c -o ruapu
# Clang
clang main.c -o ruapu
# MSVC
cl.exe /Fe: ruapu.exe main.c

Run ruapu in command line

./ruapu 
mmx = 1
sse = 1
sse2 = 1
sse3 = 1
ssse3 = 1
sse41 = 1
sse42 = 1
sse4a = 1
xop = 0
... more lines omitted ...

Features

  • Detect CPU ISA with single-file    x86-sse, x86-avx, x86-avx512f, x86-avxvnni, arm-neon, etc.
  • Detect vendor extended ISA     apple amx, risc-v vendor ISA, etc.
  • Detect richer ISA on Windows ARM   IsProcessorFeaturePresent() returns little ISA information
  • Detect x86-avx512 on macOS correctly  macOS hides it in cpuid
  • Detect new CPU's ISA on old systems  they are usually not exposed in auxv or MISA
  • Detect CPU hidden ISA        x86-fma4 on zen1, ISA in hypervisor, etc.

Techniques inside ruapu

ruapu is implemented in C language to ensure the widest possible portability.

ruapu determines whether the CPU supports certain instruction sets by trying to execute instructions and detecting whether an Illegal Instruction exception occurs. ruapu does not rely on the cpuid instructions and registers related to the CPU architecture, nor does it rely on the MISA information and system calls of the operating system. This can help us get more detailed CPU ISA information.