commit | ebab23ac9a202354f960dd91b9ded11618fc4c0f | [log] [tgz] |
---|---|---|
author | Guillaume Chatelet <gchatelet@google.com> | Thu Feb 01 11:42:40 2018 +0100 |
committer | Guillaume Chatelet <gchatelet@google.com> | Thu Feb 01 11:42:40 2018 +0100 |
tree | 113af9a186d6b1335295248038926e38282b6ca7 | |
parent | 8e58ef0d2b1720d1f6f9f9a5dddfca6de3d4ec93 [diff] |
Adding travis ci configuration.
A cross platform C89 library to get cpu features at runtime.
#include "cpuinfo_x86.h" static const X86Features features = GetX86Info().features; void Compute(void) { if(features.aes && features.sse4_2) { // Run optimized code. } else { // Run standard code. } }
Features are bit packed and some compilers generate poor code when combining them. A simple solution is to read them once and store the result in a global variable.
#include "cpuinfo_arm.h" static const ArmFeatures features = GetArmInfo().features; static const bool has_aes_and_neon = features.aes && features.neon; // use has_aes_and_neon.
#include "cpuinfo_x86.h" static const X86Features features = GetX86Info().features; static const bool has_avx = CPU_FEATURES_COMPILED_X86_AVX || features.avx; // use has_avx.
CPU_FEATURES_COMPILED_X86_AVX
is set to 1 if the compiler is instructed to use AVX, 0 otherwise. This allows combining compile time and runtime knowledge.
#include "cpuinfo_x86.h" static const X86Info info = GetX86Info(); static const X86Microarchitecture uarch = GetX86Microarchitecture(&info); static const bool has_fast_avx = info.features.avx && uarch != INTEL_SNB; // use has_fast_avx.
On x86, the first incarnation of a feature in a microarchitecture may not be very efficient (e.g. AVX on Sandybridge). We provide a function to retrieve the underlying microarchitecture so clients can decide whether they want to use it or not.
x86 | ARM | aarch64 | mips | POWER | |
---|---|---|---|---|---|
Features From cpu | yes | no* | no* | no yet | not yet |
Features From Linux | no | yes | yes | yes | not yet |
Micro Architecture Detection | yes | no | no | no | not yet |
Windows support | yes | no | no | no | not yet |
/proc/self/auxv
/proc/cpuinfo