croaring-ffi-1.0: cbits/CRoaring/include/roaring/isadetection.h
/*
* isadetection.h
*
* This header declares the small interface used to detect instruction-set
* capabilities relevant to CRoaring's optimized kernels on x64 platforms. It
* also defines compile-time feature macros that indicate whether the compiler
* toolchain is capable of building AVX-512 code paths.
*
* The resulting flags are used to decide whether accelerated implementations,
* such as AVX2 or AVX-512 variants, can be selected safely at runtime.
*/
#ifndef ROARING_ISADETECTION_H
#define ROARING_ISADETECTION_H
#include <roaring/portability.h>
#if CROARING_IS_X64 // x64
#ifndef CROARING_COMPILER_SUPPORTS_AVX512
#ifdef __has_include
// We want to make sure that the AVX-512 functions are only built on compilers
// fully supporting AVX-512.
#if __has_include(<avx512vbmi2intrin.h>)
#define CROARING_COMPILER_SUPPORTS_AVX512 1
#endif // #if __has_include(<avx512vbmi2intrin.h>)
#endif // #ifdef __has_include
// Visual Studio 2019 and up support AVX-512
#ifdef _MSC_VER
#if _MSC_VER >= 1920
#define CROARING_COMPILER_SUPPORTS_AVX512 1
#endif // #if _MSC_VER >= 1920
#endif // #ifdef _MSC_VER
#ifndef CROARING_COMPILER_SUPPORTS_AVX512
#define CROARING_COMPILER_SUPPORTS_AVX512 0
#endif // #ifndef CROARING_COMPILER_SUPPORTS_AVX512
#endif // #ifndef CROARING_COMPILER_SUPPORTS_AVX512
#endif // CROARING_IS_X64
#if CROARING_IS_X64 || CROARING_IS_ARM64
#ifdef __cplusplus
extern "C" {
namespace roaring {
namespace internal {
#endif
enum {
// x64
ROARING_SUPPORTS_AVX2 = 1,
ROARING_SUPPORTS_AVX512 = 2,
// ARM64
ROARING_SUPPORTS_SVE = 4,
ROARING_SUPPORTS_SVE2 = 8,
};
/**
* Returns a bitmask of the ROARING_SUPPORTS_* flags describing the
* instruction sets supported by the current processor and operating system.
* The result is computed once and cached.
*/
int croaring_hardware_support(void);
#ifdef __cplusplus
}
}
} // extern "C" { namespace roaring { namespace internal {
#endif
#endif // CROARING_IS_X64 || CROARING_IS_ARM64
#endif // ROARING_ISADETECTION_H