File indexing completed on 2025-01-18 09:29:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_DETAIL_CPU_INFO_HPP
0011 #define BOOST_BEAST_DETAIL_CPU_INFO_HPP
0012
0013 #include <boost/config.hpp>
0014
0015 #ifndef BOOST_BEAST_NO_INTRINSICS
0016 # if defined(BOOST_MSVC) || ((defined(BOOST_GCC) || defined(BOOST_CLANG)) && defined(__SSE4_2__))
0017 # define BOOST_BEAST_NO_INTRINSICS 0
0018 # else
0019 # define BOOST_BEAST_NO_INTRINSICS 1
0020 # endif
0021 #endif
0022
0023 #if ! BOOST_BEAST_NO_INTRINSICS
0024
0025 #ifdef BOOST_MSVC
0026 #include <intrin.h> // __cpuid
0027 #else
0028 #include <cpuid.h> // __get_cpuid
0029 #endif
0030
0031 namespace boost {
0032 namespace beast {
0033 namespace detail {
0034
0035
0036
0037
0038 template<class = void>
0039 void
0040 cpuid(
0041 std::uint32_t id,
0042 std::uint32_t& eax,
0043 std::uint32_t& ebx,
0044 std::uint32_t& ecx,
0045 std::uint32_t& edx)
0046 {
0047 #ifdef BOOST_MSVC
0048 int regs[4];
0049 __cpuid(regs, id);
0050 eax = regs[0];
0051 ebx = regs[1];
0052 ecx = regs[2];
0053 edx = regs[3];
0054 #else
0055 __get_cpuid(id, &eax, &ebx, &ecx, &edx);
0056 #endif
0057 }
0058
0059 struct cpu_info
0060 {
0061 bool sse42 = false;
0062
0063 cpu_info();
0064 };
0065
0066 inline
0067 cpu_info::
0068 cpu_info()
0069 {
0070 constexpr std::uint32_t SSE42 = 1 << 20;
0071
0072 std::uint32_t eax = 0;
0073 std::uint32_t ebx = 0;
0074 std::uint32_t ecx = 0;
0075 std::uint32_t edx = 0;
0076
0077 cpuid(0, eax, ebx, ecx, edx);
0078 if(eax >= 1)
0079 {
0080 cpuid(1, eax, ebx, ecx, edx);
0081 sse42 = (ecx & SSE42) != 0;
0082 }
0083 }
0084
0085 template<class = void>
0086 cpu_info const&
0087 get_cpu_info()
0088 {
0089 static cpu_info const ci;
0090 return ci;
0091 }
0092
0093 }
0094 }
0095 }
0096
0097 #endif
0098
0099 #endif