forked from adoptware/pinball
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmath.cpp
124 lines (101 loc) · 2.15 KB
/
math.cpp
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
/***************************************************************************
Math profiling.
***************************************************************************/
#include "Private.h"
#include "Engine.h"
#include "EMath.h"
#include <sys/time.h>
#include <iostream>
#ifdef EM_USE_FAST_FLOAT2INT
#define MACRO_A(a_, b_) \
a_.f += 1.1; \
ConvFloat2Int(a_); \
b_ += a_.i;
#define MACRO_B(a_, b_) \
a_ += 1.1; \
b_ += (int)a_;
#define MACRO_AA(a_, b_) \
MACRO_A(a_, b_) \
MACRO_A(a_, b_) \
MACRO_A(a_, b_) \
MACRO_A(a_, b_)
#define MACRO_AAA(a_, b_) \
MACRO_AA(a_, b_) \
MACRO_AA(a_, b_) \
MACRO_AA(a_, b_) \
MACRO_AA(a_, b_)
#define MACRO_AAAA(a_, b_) \
MACRO_AAA(a_, b_) \
MACRO_AAA(a_, b_) \
MACRO_AAA(a_, b_) \
MACRO_AAA(a_, b_)
#define MACRO_AAAAA(a_, b_) \
MACRO_AAAA(a_, b_) \
MACRO_AAAA(a_, b_) \
MACRO_AAAA(a_, b_) \
MACRO_AAAA(a_, b_)
#define MACRO_BB(a_, b_) \
MACRO_B(a_, b_) \
MACRO_B(a_, b_) \
MACRO_B(a_, b_) \
MACRO_B(a_, b_)
#define MACRO_BBB(a_, b_) \
MACRO_BB(a_, b_) \
MACRO_BB(a_, b_) \
MACRO_BB(a_, b_) \
MACRO_BB(a_, b_)
#define MACRO_BBBB(a_, b_) \
MACRO_BBB(a_, b_) \
MACRO_BBB(a_, b_) \
MACRO_BBB(a_, b_) \
MACRO_BBB(a_, b_)
#define MACRO_BBBBB(a_, b_) \
MACRO_BBBB(a_, b_) \
MACRO_BBBB(a_, b_) \
MACRO_BBBB(a_, b_) \
MACRO_BBBB(a_, b_)
/** Main */
int main(int argc, char *argv[]) {
cerr << "Math profiling." << endl;
gBias.i = (23+127) << 23;
long aaa = 0, bbb = 0;
struct timeval tv;
struct timezone tz;
IntOrFloat aa;
aa.f = 0.0f;
int bb = 0;
float cc = 0.0f;
int dd;
for (int a=0; a<500; a++) {
gettimeofday(&tv, &tz);
long msec = tv.tv_usec;
for (int b=0; b<100000; b++) {
MACRO_BBBBB(cc, bb);
}
dd += bb;
gettimeofday(&tv, &tz);
bbb += (tv.tv_usec - msec);
msec = tv.tv_usec;
for (int b=0; b<100000; b++) {
MACRO_AAAAA(aa, bb);
}
dd += bb;
gettimeofday(&tv, &tz);
aaa += (tv.tv_usec - msec);
//cerr << msec << endl;
}
//for (int a=0; a<16; a++) {
cerr << "slow " << bbb << endl;
cerr << "fast " << aaa << endl;
//}
return 0;
}
#else
int main() {
cerr << "not using fast float2int" << endl;
return 0;
}
#endif
#if EM_USE_ALLEGRO
END_OF_MAIN();
#endif