ゴミ箱
cpu_info.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9 
10 #ifndef BOOST_BEAST_DETAIL_CPU_INFO_HPP
11 #define BOOST_BEAST_DETAIL_CPU_INFO_HPP
12 
13 #include <boost/config.hpp>
14 
15 #ifndef BOOST_BEAST_NO_INTRINSICS
16 # if defined(BOOST_MSVC) || ((defined(BOOST_GCC) || defined(BOOST_CLANG)) && defined(__SSE4_2__))
17 # define BOOST_BEAST_NO_INTRINSICS 0
18 # else
19 # define BOOST_BEAST_NO_INTRINSICS 1
20 # endif
21 #endif
22 
23 #if ! BOOST_BEAST_NO_INTRINSICS
24 
25 #ifdef BOOST_MSVC
26 #include <intrin.h> // __cpuid
27 #else
28 #include <cpuid.h> // __get_cpuid
29 #endif
30 
31 namespace boost {
32 namespace beast {
33 namespace detail {
34 
35 /* Portions from Boost,
36  Copyright Andrey Semashev 2007 - 2015.
37 */
38 template<class = void>
39 void
40 cpuid(
41  std::uint32_t id,
42  std::uint32_t& eax,
43  std::uint32_t& ebx,
44  std::uint32_t& ecx,
45  std::uint32_t& edx)
46 {
47 #ifdef BOOST_MSVC
48  int regs[4];
49  __cpuid(regs, id);
50  eax = regs[0];
51  ebx = regs[1];
52  ecx = regs[2];
53  edx = regs[3];
54 #else
55  __get_cpuid(id, &eax, &ebx, &ecx, &edx);
56 #endif
57 }
58 
59 struct cpu_info
60 {
61  bool sse42 = false;
62 
63  cpu_info();
64 };
65 
66 inline
67 cpu_info::
68 cpu_info()
69 {
70  constexpr std::uint32_t SSE42 = 1 << 20;
71 
72  std::uint32_t eax = 0;
73  std::uint32_t ebx = 0;
74  std::uint32_t ecx = 0;
75  std::uint32_t edx = 0;
76 
77  cpuid(0, eax, ebx, ecx, edx);
78  if(eax >= 1)
79  {
80  cpuid(1, eax, ebx, ecx, edx);
81  sse42 = (ecx & SSE42) != 0;
82  }
83 }
84 
85 template<class = void>
86 cpu_info const&
87 get_cpu_info()
88 {
89  static cpu_info const ci;
90  return ci;
91 }
92 
93 } // detail
94 } // beast
95 } // boost
96 
97 #endif
98 
99 #endif
Definition: async_result.hpp:20