/
cpuinfo.go
216 lines (170 loc) · 4.71 KB
/
cpuinfo.go
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package sdl
/*
#include "sdl_wrapper.h"
#if !(SDL_VERSION_ATLEAST(2,0,9))
#if defined(WARN_OUTDATED)
#pragma message("SDL_HasAVX512F is not supported before SDL 2.0.9")
#endif
static inline SDL_bool SDL_HasAVX512F()
{
return SDL_FALSE;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,1))
#if defined(WARN_OUTDATED)
#pragma message("SDL_GetSystemRAM is not supported before SDL 2.0.1")
#endif
static inline int SDL_GetSystemRAM()
{
return -1;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,2))
#if defined(WARN_OUTDATED)
#pragma message("SDL_HasAVX is not supported before SDL 2.0.2")
#endif
static inline SDL_bool SDL_HasAVX()
{
return SDL_FALSE;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,4))
#if defined(WARN_OUTDATED)
#pragma message("SDL_HasAVX2 is not supported before SDL 2.0.4")
#endif
static inline SDL_bool SDL_HasAVX2()
{
return SDL_FALSE;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,6))
#if defined(WARN_OUTDATED)
#pragma message("SDL_HasNEON is not supported before SDL 2.0.4")
#endif
static inline SDL_bool SDL_HasNEON()
{
return SDL_FALSE;
}
#endif
#if !(SDL_VERSION_ATLEAST(2,0,10))
#if defined(WARN_OUTDATED)
#pragma message("SDL_SIMDGetAlignment is not supported before SDL 2.0.10")
#endif
static inline size_t SDL_SIMDGetAlignment(void)
{
return 0;
}
#if defined(WARN_OUTDATED)
#pragma message("SDL_SIMDAlloc is not supported before SDL 2.0.10")
#endif
static inline void * SDL_SIMDAlloc(const size_t len)
{
return NULL;
}
#if defined(WARN_OUTDATED)
#pragma message("SDL_SIMDFree is not supported before SDL 2.0.10")
#endif
static inline void SDL_SIMDFree(void *ptr)
{
}
#endif
*/
import "C"
import "unsafe"
// CACHELINE_SIZE is a cacheline size used for padding.
const CACHELINE_SIZE = C.SDL_CACHELINE_SIZE
// GetCPUCount returns the number of CPU cores available.
// (https://wiki.libsdl.org/SDL_GetCPUCount)
func GetCPUCount() int {
return int(C.SDL_GetCPUCount())
}
// GetCPUCacheLineSize returns the L1 cache line size of the CPU.
// (https://wiki.libsdl.org/SDL_GetCPUCacheLineSize)
func GetCPUCacheLineSize() int {
return int(C.SDL_GetCPUCacheLineSize())
}
// HasRDTSC reports whether the CPU has the RDTSC instruction.
// (https://wiki.libsdl.org/SDL_HasRDTSC)
func HasRDTSC() bool {
return C.SDL_HasRDTSC() > 0
}
// HasAltiVec reports whether the CPU has AltiVec features.
// (https://wiki.libsdl.org/SDL_HasAltiVec)
func HasAltiVec() bool {
return C.SDL_HasAltiVec() > 0
}
// HasMMX reports whether the CPU has MMX features.
// (https://wiki.libsdl.org/SDL_HasMMX)
func HasMMX() bool {
return C.SDL_HasMMX() > 0
}
// Has3DNow reports whether the CPU has 3DNow! features.
// (https://wiki.libsdl.org/SDL_Has3DNow)
func Has3DNow() bool {
return C.SDL_Has3DNow() > 0
}
// HasSSE reports whether the CPU has SSE features.
// (https://wiki.libsdl.org/SDL_HasSSE)
func HasSSE() bool {
return C.SDL_HasSSE() > 0
}
// HasSSE2 reports whether the CPU has SSE2 features.
// (https://wiki.libsdl.org/SDL_HasSSE2)
func HasSSE2() bool {
return C.SDL_HasSSE2() > 0
}
// HasSSE3 reports whether the CPU has SSE3 features.
// (https://wiki.libsdl.org/SDL_HasSSE3)
func HasSSE3() bool {
return C.SDL_HasSSE3() > 0
}
// HasSSE41 reports whether the CPU has SSE4.1 features.
// (https://wiki.libsdl.org/SDL_HasSSE41)
func HasSSE41() bool {
return C.SDL_HasSSE41() > 0
}
// HasSSE42 reports whether the CPU has SSE4.2 features.
// (https://wiki.libsdl.org/SDL_HasSSE42)
func HasSSE42() bool {
return C.SDL_HasSSE42() > 0
}
// GetSystemRAM returns the amount of RAM configured in the system.
// (https://wiki.libsdl.org/SDL_GetSystemRAM)
func GetSystemRAM() int {
return int(C.SDL_GetSystemRAM())
}
// HasAVX reports whether the CPU has AVX features.
// (https://wiki.libsdl.org/SDL_HasAVX)
func HasAVX() bool {
return C.SDL_HasAVX() > 0
}
// HasAVX512F reports whether the CPU has AVX-512F (foundation) features.
// TODO: (https://wiki.libsdl.org/SDL_HasAVX512F)
func HasAVX512F() bool {
return C.SDL_HasAVX512F() > 0
}
// HasAVX2 reports whether the CPU has AVX2 features.
// (https://wiki.libsdl.org/SDL_HasAVX2)
func HasAVX2() bool {
return C.SDL_HasAVX2() > 0
}
// HasNEON reports whether the CPU has NEON features.
// (https://wiki.libsdl.org/SDL_HasNEON)
func HasNEON() bool {
return C.SDL_HasNEON() > 0
}
// SIMDGetAlignment reports the alignment this system needs for SIMD allocations.
// TODO: (https://wiki.libsdl.org/SDL_SIMDGetAlignment)
func SIMDGetAlignment() int {
return int(C.SDL_SIMDGetAlignment())
}
// SIMDAlloc allocates memory in a SIMD-friendly way.
// TODO: (https://wiki.libsdl.org/SDL_SIMDAlloc)
func SIMDAlloc(_len int) unsafe.Pointer {
return C.SDL_SIMDAlloc(C.size_t(_len))
}
// SIMDFree deallocates memory obtained from SDL_SIMDAlloc.
// TODO: (https://wiki.libsdl.org/SDL_SIMDFree)
func SIMDFree(p unsafe.Pointer) {
C.SDL_SIMDFree(p)
}