1 /*****************************************************************************
2 
3         CpuOptBase.h
4         Author: Laurent de Soras, 2021
5 
6 --- Legal stuff ---
7 
8 This program is free software. It comes without any warranty, to
9 the extent permitted by applicable law. You can redistribute it
10 and/or modify it under the terms of the Do What The Fuck You Want
11 To Public License, Version 2, as published by Sam Hocevar. See
12 http://www.wtfpl.net/ for more details.
13 
14 *Tab=3***********************************************************************/
15 
16 
17 
18 #pragma once
19 #if ! defined (fmtcl_CpuOptBase_HEADER_INCLUDED)
20 #define fmtcl_CpuOptBase_HEADER_INCLUDED
21 
22 
23 
24 /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
25 
26 #include "fstb/CpuId.h"
27 
28 
29 
30 namespace fmtcl
31 {
32 
33 
34 
35 class CpuOptBase
36 {
37 
38 /*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
39 
40 public:
41 
42 	enum Level
43 	{
44 		Level_NO_OPT = 0,
45 		Level_SSE2,          // 1
46 		Level_SSE3,
47 		Level_SSSE3,
48 		Level_SSE41,
49 		Level_SSE42,
50 		Level_FMA4,
51 		Level_AVX,           // 7
52 		Level_FMA3,
53 		Level_F16C,
54 		Level_AVX2,          // 10
55 		Level_AVX512F,
56 
57 		Level_MASK = 0xFFFF,
58 		Level_ANY_AVAILABLE = Level_MASK
59 	};
60 
61 	               CpuOptBase ()                        = default;
62 	virtual        ~CpuOptBase ()                       = default;
63 	               CpuOptBase (const CpuOptBase &other) = default;
64 	               CpuOptBase (CpuOptBase &&other)      = default;
65 	CpuOptBase &   operator = (const CpuOptBase &other) = default;
66 	CpuOptBase &   operator = (CpuOptBase &&other)      = default;
67 
68 	void           set_level (Level level);
69 
70 	bool           has_mmx () const;
71 	bool           has_isse () const;
72 	bool           has_sse () const;
73 	bool           has_sse2 () const;
74 	bool           has_sse3 () const;
75 	bool           has_ssse3 () const;
76 	bool           has_sse41 () const;
77 	bool           has_sse42 () const;
78 	bool           has_sse4a () const;
79 	bool           has_fma3 () const;
80 	bool           has_fma4 () const;
81 	bool           has_avx () const;
82 	bool           has_avx2 () const;
83 	bool           has_avx512f () const;
84 	bool           has_f16c () const;
85 	bool           has_cx16 () const;
86 
87 	const fstb::CpuId &
88 	               use_raw_cpuid () const;
89 
90 
91 
92 /*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
93 
94 protected:
95 
96 
97 
98 /*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
99 
100 private:
101 
102 	fstb::CpuId    _cpu;
103 	Level          _level = Level_ANY_AVAILABLE;
104 
105 
106 
107 /*\\\ FORBIDDEN MEMBER FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
108 
109 private:
110 
111 	bool           operator == (const CpuOptBase &other) const = delete;
112 	bool           operator != (const CpuOptBase &other) const = delete;
113 
114 }; // class CpuOptBase
115 
116 
117 
118 }  // namespace fmtcl
119 
120 
121 
122 //#include "fmtcl/CpuOptBase.hpp"
123 
124 
125 
126 #endif   // fmtcl_CpuOptBase_HEADER_INCLUDED
127 
128 
129 
130 /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
131