All Projects → steinwurf → cpuid

steinwurf / cpuid

Licence: other
C++ library for detecting CPU capabilities

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to cpuid

PyCPU
Central Processing Unit Information Gathering Tool
Stars: ✭ 19 (-76.83%)
Mutual labels:  cpuid, cpuinfo
ddcpuid
🔬 dd's x86 CPU Identification tool
Stars: ✭ 21 (-74.39%)
Mutual labels:  cpuid
cpuwhat
Nim utilities for advanced CPU operations: CPU identification, ISA extension detection, bindings to assorted intrinsics
Stars: ✭ 25 (-69.51%)
Mutual labels:  cpuid
mir-cpuid
BetterC CPU Identification Routines
Stars: ✭ 25 (-69.51%)
Mutual labels:  cpuid

cpuid

Linux make-specs Windows make-specs MacOS make-specs Linux CMake Windows CMake MacOS CMake Raspberry Pi Valgrind No Assertions Clang Format Cppcheck

cpuid is a C++ library for CPU dispatching. Currently the project can detect the following CPU capabilities:

  • Instruction sets detected on x86: FPU, MMX, SSE, SSE2, SSE3, SSSE3,
    SSE 4.1, SSE 4.2, PCLMULQDQ, AVX, and AVX2
  • Instruction sets detected on ARM: NEON

License

cpuid license is based on the BSD License. Please refer to the LICENSE.rst file for more details.

Platforms

We have tested cpuid on various versions of Windows, Linux and Mac. We run automated tests with different compilers like g++, clang and msvc.

Build

Fetch the sources, and we also recommend that you switch to the last released version of the library:

git clone https://github.com/steinwurf/cpuid
cd cpuid
git checkout 6.4.0

We use the waf build system to build the cpuid static library. We have some additional waf tools which can be found at waf.

To configure and build cpuid, run the following commands:

python waf configure
python waf build
python waf install --destdir cpuid_install

The final install step will create a folder containing all the nessecary files needed to use the library (e.g. static library, headers etc.). You can change the output folder by passing a different path to --destdir.

When building the libraries, waf will also build the print_cpuinfo_example executable which is useful to print the available CPU instruction sets. The compiled binary is located in the build/[platform]/examples/print_cpuinfo folder (where [platform] denotes your current platform, e.g. linux, win32 or darwin).

API

class cpuinfo

Scope: cpuid

In header: #include <cpuinfo.hpp>

Member functions (public)

  cpuinfo ()
  ~cpuinfo ()
bool has_avx () const
bool has_avx2 () const
bool has_f16c () const
bool has_fpu () const
bool has_mmx () const
bool has_neon () const
bool has_pclmulqdq () const
bool has_sse () const
bool has_sse2 () const
bool has_sse3 () const
bool has_sse4_1 () const
bool has_sse4_2 () const
bool has_ssse3 () const

Description

The cpuinfo object extract information about which, if any, additional instructions are supported by the CPU.

Member Function Description

cpuinfo ()

Constructor for feature detection with default values.

~cpuinfo ()

Destructor.

bool has_avx ()

Return true if the CPU supports AVX.

bool has_avx2 ()

Return true if the CPU supports AVX2.

bool has_f16c ()

Return true if the CPU supports F16C.

bool has_fpu ()

Has X87 FPU.

bool has_mmx ()

Return true if the CPU supports MMX.

bool has_neon ()

Return true if the CPU supports NEON.

bool has_pclmulqdq ()

Return true if the CPU supports pclmulqdq.

bool has_sse ()

Return true if the CPU supports SSE.

bool has_sse2 ()

Return true if the CPU supports SSE2.

bool has_sse3 ()

Return true if the CPU supports SSE3.

bool has_sse4_1 ()

Return true if the CPU supports SSE 4.1.

bool has_sse4_2 ()

Return true if the CPU supports SSE 4.2.

bool has_ssse3 ()

Return true if the CPU supports SSSE3.

Use as Dependency in CMake

To depend on this project when using the CMake build system, add the following in your CMake build script:

add_subdirectory("/path/to/cpuid" cpuid)
target_link_libraries(<my_target> steinwurf::cpuid)

Where <my_target> is replaced by your target.

Credits

We have created cpuid to fit our specific needs, however we hope that others may also find it useful. When designing cpuid we found inspiration in these other nice projects:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].