File: mptCPU.h

package info (click to toggle)
libopenmpt 0.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,844 kB
  • sloc: cpp: 129,366; sh: 4,695; ansic: 1,107; makefile: 712
file content (113 lines) | stat: -rw-r--r-- 2,480 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * mptCPU.h
 * --------
 * Purpose: CPU feature detection.
 * Notes  : (currently none)
 * Authors: OpenMPT Devs
 * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
 */


#pragma once

#include "openmpt/all/BuildSettings.hpp"

#include "mpt/base/macros.hpp"
#ifdef MPT_ENABLE_ARCH_INTRINSICS
#include "mpt/arch/arch.hpp"
#endif


OPENMPT_NAMESPACE_BEGIN


namespace CPU
{


#ifdef MPT_ENABLE_ARCH_INTRINSICS


#if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_WINESUPPORT)


namespace detail
{

inline MPT_CONSTINIT mpt::arch::current::feature_flags EnabledFeatures;
inline MPT_CONSTINIT mpt::arch::current::mode_flags EnabledModes;

} // namespace detail

inline void EnableAvailableFeatures() noexcept
{
	CPU::detail::EnabledFeatures = mpt::arch::get_cpu_info().get_features();
	CPU::detail::EnabledModes = mpt::arch::get_cpu_info().get_modes();
}

// enabled processor features for inline asm and intrinsics
[[nodiscard]] MPT_FORCEINLINE mpt::arch::current::feature_flags GetEnabledFeatures() noexcept
{
	return CPU::detail::EnabledFeatures;
}
[[nodiscard]] MPT_FORCEINLINE mpt::arch::current::mode_flags GetEnabledModes() noexcept
{
	return CPU::detail::EnabledModes;
}

struct Info
{
	[[nodiscard]] MPT_FORCEINLINE bool HasFeatureSet(mpt::arch::current::feature_flags features) const noexcept
	{
		return features == (GetEnabledFeatures() & features);
	}
	[[nodiscard]] MPT_FORCEINLINE bool HasModesEnabled(mpt::arch::current::mode_flags modes) const noexcept
	{
		return modes == (GetEnabledModes() & modes);
	}
};


#else // !MODPLUG_TRACKER


struct Info
{
private:
	const mpt::arch::flags_cache m_flags{mpt::arch::get_cpu_info()};
public:
	[[nodiscard]] MPT_FORCEINLINE bool HasFeatureSet(mpt::arch::current::feature_flags features) const noexcept
	{
		return m_flags[features];
	}
	[[nodiscard]] MPT_FORCEINLINE bool HasModesEnabled(mpt::arch::current::mode_flags modes) const noexcept
	{
		return m_flags[modes];
	}
};


#endif // MODPLUG_TRACKER


namespace feature = mpt::arch::current::feature;
namespace mode = mpt::arch::current::mode;

[[nodiscard]] MPT_FORCEINLINE bool HasFeatureSet(mpt::arch::current::feature_flags features) noexcept
{
	return CPU::Info{}.HasFeatureSet(features);
}

[[nodiscard]] MPT_FORCEINLINE bool HasModesEnabled(mpt::arch::current::mode_flags modes) noexcept
{
	return CPU::Info{}.HasModesEnabled(modes);
}


#endif // MPT_ENABLE_ARCH_INTRINSICS


} // namespace CPU


OPENMPT_NAMESPACE_END