Line data Source code
1 : /*----------------------------------------------------------------------------*/ 2 : /* CP2K: A general program to perform molecular dynamics simulations */ 3 : /* Copyright 2000-2024 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) 12 : extern "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 : ******************************************************************************/ 24 : int m_cpuid_static(void); /* avoid pedantic warning about missing prototype */ 25 4608 : int m_cpuid_static(void) { 26 : #if (__AVX512F__ && __AVX512CD__ && __AVX2__ && __FMA__ && __AVX__ && \ 27 : __SSE4_2__ && __SSE4_1__ && __SSE3__) 28 : return CP_MACHINE_X86_AVX512; 29 : #elif (__AVX2__ && __FMA__ && __AVX__ && __SSE4_2__ && __SSE4_1__ && __SSE3__) 30 4608 : return CP_MACHINE_X86_AVX2; 31 : #elif (__AVX__ && __SSE4_2__ && __SSE4_1__ && __SSE3__) 32 : return CP_MACHINE_X86_AVX; 33 : #elif (__SSE4_2__ && __SSE4_1__ && __SSE3__) 34 : return CP_MACHINE_X86_SSE4; 35 : #else 36 : return CP_MACHINE_CPU_GENERIC; 37 : #endif 38 : } 39 : 40 : #if defined(__cplusplus) 41 : } 42 : #endif