MRPT  1.9.9
cpu.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/core/common.h>
13 #include <array>
14 #include <string>
15 
16 namespace mrpt::cpu
17 {
18 /** OS-portable set of CPU feature definitions, for usage in mrpt::cpu::supports
19  * \ingroup mrpt_core_grp
20  */
21 enum class feature : unsigned int
22 {
23  MMX = 0,
24  POPCNT,
25  SSE,
26  SSE2,
27  SSE3,
28  SSSE3,
29  SSE4_1,
30  SSE4_2,
31  AVX,
32  AVX2,
33  // ---- end of list ----
35 };
36 
37 namespace internal
38 {
39 /** Auxiliary class. Users should use mrpt::core::supports() instead.
40  * \ingroup mrpt_core_grp
41  */
43 {
44  public:
45  static CPU_analyzer& Instance() noexcept;
46 
47  std::array<
48  bool, static_cast<std::size_t>(mrpt::cpu::feature::FEATURE_COUNT)>
50 
51  inline bool& feat(mrpt::cpu::feature f) noexcept
52  {
53  return feat_detected[static_cast<std::size_t>(f)];
54  }
55  inline bool feat(mrpt::cpu::feature f) const noexcept
56  {
57  return feat_detected[static_cast<std::size_t>(f)];
58  }
59 
60  private:
61  // Ctor: runs all the checks and fills in the vector of features:
62  CPU_analyzer() noexcept
63  {
64  // Start with all falses:
65  feat_detected.fill(false);
66  detect_impl();
67  }
68  void detect_impl() noexcept;
69 };
70 } // namespace internal
71 
72 /** Returns true if CPU (and OS) supports the given CPU feature, *and* that
73  * instruction set or feature was also enabled by the compiler flags used while
74  * building MRPT.
75  * \ingroup mrpt_core_grp
76  */
77 inline bool supports(feature f) noexcept
78 {
79  const auto& o = internal::CPU_analyzer::Instance();
80  return o.feat(f);
81 }
82 
83 /** Returns a string with detected features: "MMX:1 SSE2:0 etc."
84  * \ingroup mrpt_core_grp
85  */
87 
88 } // namespace mrpt::cpu
bool feat(mrpt::cpu::feature f) const noexcept
Definition: cpu.h:55
bool & feat(mrpt::cpu::feature f) noexcept
Definition: cpu.h:51
feature
OS-portable set of CPU feature definitions, for usage in mrpt::cpu::supports.
Definition: cpu.h:21
bool supports(feature f) noexcept
Returns true if CPU (and OS) supports the given CPU feature, and that instruction set or feature was ...
Definition: cpu.h:77
Auxiliary class.
Definition: cpu.h:42
std::array< bool, static_cast< std::size_t >mrpt::cpu::feature::FEATURE_COUNT)> feat_detected
Definition: cpu.h:49
Definition: cpu.h:16
GLsizei const GLchar ** string
Definition: glext.h:4116
std::string features_as_string() noexcept
Returns a string with detected features: "MMX:1 SSE2:0 etc.".
Definition: cpu.cpp:117
void detect_impl() noexcept
Definition: cpu.cpp:79
static CPU_analyzer & Instance() noexcept
Definition: cpu.cpp:22



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: cb8dd5fc8 Sat Dec 7 21:55:39 2019 +0100 at sáb dic 7 22:00:13 CET 2019