diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2022-08-07 16:30:29 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2022-08-07 16:30:29 +0300 |
commit | a18d511fddf3023584cf873456d21c895fd82d7e (patch) | |
tree | 35da32f31ebcd45b96e8b750af5a8b85e834c6ec /contrib/restricted/boost/atomic/src/cpuid.hpp | |
parent | 8b163f003d8db5f6520630da7e2e6b393bfb2b5c (diff) | |
download | ydb-a18d511fddf3023584cf873456d21c895fd82d7e.tar.gz |
Update contrib/restricted/boost/atomic to 1.79.0
Diffstat (limited to 'contrib/restricted/boost/atomic/src/cpuid.hpp')
-rw-r--r-- | contrib/restricted/boost/atomic/src/cpuid.hpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/contrib/restricted/boost/atomic/src/cpuid.hpp b/contrib/restricted/boost/atomic/src/cpuid.hpp new file mode 100644 index 0000000000..452917a33c --- /dev/null +++ b/contrib/restricted/boost/atomic/src/cpuid.hpp @@ -0,0 +1,86 @@ +/* + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + * + * Copyright (c) 2020 Andrey Semashev + */ +/*! + * \file cpuid.hpp + * + * This file contains declaration of \c cpuid function + */ + +#ifndef BOOST_ATOMIC_CPUID_HPP_INCLUDED_ +#define BOOST_ATOMIC_CPUID_HPP_INCLUDED_ + +#include <boost/predef/architecture/x86.h> + +#if BOOST_ARCH_X86 + +#if defined(_MSC_VER) +#include <intrin.h> // __cpuid +#endif +#include <boost/cstdint.hpp> +#include <boost/atomic/detail/config.hpp> + +#include <boost/atomic/detail/header.hpp> + +namespace boost { +namespace atomics { +namespace detail { + +//! The function invokes x86 cpuid instruction +inline void cpuid(uint32_t& eax, uint32_t& ebx, uint32_t& ecx, uint32_t& edx) +{ +#if defined(__GNUC__) +#if (defined(__i386__) || defined(__VXWORKS__)) && (defined(__PIC__) || defined(__PIE__)) && !(defined(__clang__) || (defined(BOOST_GCC) && BOOST_GCC >= 50100)) + // 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. + // For VxWorks ebx is reserved on 64-bit as well. +#if defined(__x86_64__) + uint64_t rbx = ebx; + __asm__ __volatile__ + ( + "xchgq %%rbx, %0\n\t" + "cpuid\n\t" + "xchgq %%rbx, %0\n\t" + : "+DS" (rbx), "+a" (eax), "+c" (ecx), "+d" (edx) + ); + ebx = static_cast< uint32_t >(rbx); +#else // defined(__x86_64__) + __asm__ __volatile__ + ( + "xchgl %%ebx, %0\n\t" + "cpuid\n\t" + "xchgl %%ebx, %0\n\t" + : "+DS" (ebx), "+a" (eax), "+c" (ecx), "+d" (edx) + ); +#endif // defined(__x86_64__) +#else + __asm__ __volatile__ + ( + "cpuid\n\t" + : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) + ); +#endif +#elif defined(_MSC_VER) + int regs[4] = {}; + __cpuid(regs, eax); + eax = regs[0]; + ebx = regs[1]; + ecx = regs[2]; + edx = regs[3]; +#else +#error "Boost.Atomic: Unsupported compiler, cpuid instruction cannot be generated" +#endif +} + +} // namespace detail +} // namespace atomics +} // namespace boost + +#include <boost/atomic/detail/footer.hpp> + +#endif // BOOST_ARCH_X86 + +#endif // BOOST_ATOMIC_CPUID_HPP_INCLUDED_ |