-
Notifications
You must be signed in to change notification settings - Fork 3
/
Util.h
51 lines (37 loc) · 1.19 KB
/
Util.h
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
#pragma once
#include <immintrin.h>
#define INVALID -1
#define DATA_PATH(file_name) "./Data/" file_name
#define PI 3.14159265359f
#define ONE_OVER_PI 0.31830988618f
#define TWO_PI 6.28318530718f
#define ONE_OVER_TWO_PI 0.15915494309f
#define DEG_TO_RAD(angle) ((angle) * PI * 0.00555555555f)
#define RAD_TO_DEG(angle) ((angle) * ONE_OVER_PI * 180.0f)
#define KILO_BYTE(value) ((value) * 1024)
#define MEGA_BYTE(value) ((value) * 1024 * 1024)
#define GIGA_BYTE(value) ((value) * 1024 * 1024 * 1024)
#define FORCEINLINE __forceinline
#define CACHE_LINE_WIDTH 64 // In bytes
#define ALIGNED_MALLOC(size, align) _aligned_malloc(size, align)
#define ALIGNED_FREE(ptr) _aligned_free(ptr)
namespace Util {
const char * get_path(const char * file_path);
template<typename T>
void swap(T & a, T & b) {
T temp = a;
a = b;
b = temp;
}
// Fast float to int conversion
inline int float_to_int(float x) {
return _mm_cvtss_si32(_mm_load_ss(&x));
}
template<typename T>
inline T * aligned_malloc(int count, int align) {
return reinterpret_cast<T *>(ALIGNED_MALLOC(count * sizeof(T), align));
}
inline void aligned_free(void * ptr) {
ALIGNED_FREE(ptr);
}
}