| 1 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 2 |
// Author: Kristian Lytje |
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
// AVX2 implies SSE4.1 and SSE2, but MSVC doesn't always define the latter two |
| 7 |
#if defined __AVX2__ |
| 8 |
#if !defined __SSE2__ |
| 9 |
#define __SSE2__ |
| 10 |
#endif |
| 11 |
#if !defined __SSE4_1__ |
| 12 |
#define __SSE4_1__ |
| 13 |
#endif |
| 14 |
#endif |
| 15 |
|
| 16 |
// Resolve the effective SIMD dispatch level into AUSAXS_USE_{SSE2,AVX2,AVX512}. |
| 17 |
// |
| 18 |
// Supported baseline targets: x86-64-v1/v2 (SSE2), x86-64-v3 (AVX2+FMA), x86-64-v4 (AVX-512). |
| 19 |
// Benchmark builds define one of USE_SCALAR, USE_SSE2, USE_AVX2, USE_AVX512 |
| 20 |
// to set a ceiling on dispatch, acting as safeguards alongside compiler flags. |
| 21 |
// On Apple, SIMD dispatch is suppressed entirely (Clang compatibility). |
| 22 |
// Otherwise, auto-detect from compiler builtins. |
| 23 |
#if defined __APPLE__ || defined USE_SCALAR |
| 24 |
// No SIMD dispatch |
| 25 |
#elif defined USE_SSE2 |
| 26 |
#if defined __SSE2__ |
| 27 |
#define AUSAXS_USE_SSE2 |
| 28 |
#endif |
| 29 |
#elif defined USE_AVX2 |
| 30 |
#if defined __SSE2__ |
| 31 |
#define AUSAXS_USE_SSE2 |
| 32 |
#endif |
| 33 |
#if defined __AVX2__ |
| 34 |
#define AUSAXS_USE_AVX2 |
| 35 |
#endif |
| 36 |
#elif defined USE_AVX512 |
| 37 |
#if defined __SSE2__ |
| 38 |
#define AUSAXS_USE_SSE2 |
| 39 |
#endif |
| 40 |
#if defined __AVX2__ |
| 41 |
#define AUSAXS_USE_AVX2 |
| 42 |
#endif |
| 43 |
#if defined __AVX512F__ |
| 44 |
#define AUSAXS_USE_AVX512 |
| 45 |
#endif |
| 46 |
#else |
| 47 |
// Auto-detect from compiler builtins |
| 48 |
#if defined __SSE2__ |
| 49 |
#define AUSAXS_USE_SSE2 |
| 50 |
#endif |
| 51 |
#if defined __AVX2__ |
| 52 |
#define AUSAXS_USE_AVX2 |
| 53 |
#endif |
| 54 |
#if defined __AVX512F__ |
| 55 |
#define AUSAXS_USE_AVX512 |
| 56 |
#endif |
| 57 |
#endif |