2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * Copyright (c) 2020 Andrey Semashev
11 * This file contains declaration of \c cpuid function
14 #ifndef BOOST_ATOMIC_CPUID_HPP_INCLUDED_
15 #define BOOST_ATOMIC_CPUID_HPP_INCLUDED_
17 #include <boost/predef/architecture/x86.h>
22 #include <intrin.h> // __cpuid
24 #include <boost/cstdint.hpp>
25 #include <boost/atomic/detail/config.hpp>
27 #include <boost/atomic/detail/header.hpp>
33 //! The function invokes x86 cpuid instruction
34 inline void cpuid(uint32_t& eax, uint32_t& ebx, uint32_t& ecx, uint32_t& edx)
37 #if (defined(__i386__) || defined(__VXWORKS__)) && (defined(__PIC__) || defined(__PIE__)) && !(defined(__clang__) || (defined(BOOST_GCC) && BOOST_GCC >= 50100))
38 // Unless the compiler can do it automatically, we have to backup ebx in 32-bit PIC/PIE code because it is reserved by the ABI.
39 // For VxWorks ebx is reserved on 64-bit as well.
40 #if defined(__x86_64__)
47 : "+DS" (rbx), "+a" (eax), "+c" (ecx), "+d" (edx)
49 ebx = static_cast< uint32_t >(rbx);
50 #else // defined(__x86_64__)
56 : "+DS" (ebx), "+a" (eax), "+c" (ecx), "+d" (edx)
58 #endif // defined(__x86_64__)
63 : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx)
66 #elif defined(_MSC_VER)
74 #error "Boost.Atomic: Unsupported compiler, cpuid instruction cannot be generated"
79 } // namespace atomics
82 #include <boost/atomic/detail/footer.hpp>
84 #endif // BOOST_ARCH_X86
86 #endif // BOOST_ATOMIC_CPUID_HPP_INCLUDED_