(git:ed6f26b)
Loading...
Searching...
No Matches
machine_cpuid.c
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2025 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: GPL-2.0-or-later */
6/*----------------------------------------------------------------------------*/
7
8/* shared between C and Fortran */
9#include "machine_cpuid.h"
10
11#if defined(__cplusplus)
12extern "C" {
13#endif
14
15/*******************************************************************************
16 * \brief This routine determines the CPUID according to the given compiler
17 * flags (expected to be similar to Fortran). Similar to other Fortran
18 * compilers, "gfortran -E -dM -mavx - < /dev/null | grep AVX" defines a
19 * variety of predefined macros (also similar to C). However, with a
20 * Fortran translation unit only a subset of these definitions disappears
21 * ("gfortran -E -dM -mavx my.F | grep AVX")
22 * hence an implementation in C is used.
23 ******************************************************************************/
24int m_cpuid_static(void); /* avoid pedantic warning about missing prototype */
25int m_cpuid_static(void) {
26#if (defined(__x86_64__) && 0 != (__x86_64__)) || \
27 (defined(__amd64__) && 0 != (__amd64__)) || \
28 (defined(_M_X64) || defined(_M_AMD64)) || \
29 (defined(__i386__) && 0 != (__i386__)) || (defined(_M_IX86))
30#if (__AVX512F__ && __AVX512CD__ && __AVX2__ && __FMA__ && __AVX__ && \
31 __SSE4_2__ && __SSE4_1__ && __SSE3__)
33#elif (__AVX2__ && __FMA__ && __AVX__ && __SSE4_2__ && __SSE4_1__ && __SSE3__)
35#elif (__AVX__ && __SSE4_2__ && __SSE4_1__ && __SSE3__)
36 return CP_MACHINE_X86_AVX;
37#elif (__SSE4_2__ && __SSE4_1__ && __SSE3__)
39#else
41#endif
42#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
43 /* only care about SVE, embrace "thermometer approach" like for x86 */
44#if (512 <= __ARM_FEATURE_SVE_BITS)
46#elif (256 <= __ARM_FEATURE_SVE_BITS)
48#elif (128 <= __ARM_FEATURE_SVE_BITS)
50#else
52#endif
53#elif defined(__ARM_ARCH)
55#else
56 return CP_MACHINE_UNKNOWN;
57#endif
58}
59
60#if defined(__cplusplus)
61}
62#endif
int m_cpuid_static(void)
This routine determines the CPUID according to the given compiler flags (expected to be similar to Fo...
#define CP_MACHINE_ARM_SVE256
#define CP_MACHINE_CPU_GENERIC
#define CP_MACHINE_ARM_ARCH64
#define CP_MACHINE_X86_AVX
#define CP_MACHINE_X86_AVX2
#define CP_MACHINE_ARM_SVE128
#define CP_MACHINE_X86_AVX512
#define CP_MACHINE_ARM_SVE512
#define CP_MACHINE_UNKNOWN
#define CP_MACHINE_X86_SSE4