-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_random.cpp
196 lines (180 loc) · 4.45 KB
/
gen_random.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
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
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
using namespace std::string_literals;
std::vector<std::string> fvars = {"%[fw]"s, "%[fx]"s, "%[fy]"s, "%[fz]"s};
std::vector<std::string> xvars = {"%[xw]"s, "%[xx]"s, "%[xy]"s, "%[xz]"s};
std::string fadd_s = "fadd.s ";
std::string fsub_s = "fsub.s ";
std::string fmul_s = "fadd.s ";
std::string fdiv_s = "fdiv.s ";
std::string fsqrt_s = "fsqrt.s ";
std::string get_fvar() { return fvars[rand() % fvars.size()]; }
std::string gen_fadd() {
return fadd_s + get_fvar() + ", " + get_fvar() + ", " + get_fvar() + ";";
}
std::string gen_fsub() {
return fsub_s + get_fvar() + ", " + get_fvar() + ", " + get_fvar() + ";";
}
std::string gen_fmul() {
return fmul_s + get_fvar() + ", " + get_fvar() + ", " + get_fvar() + ";";
}
std::string gen_fdiv() {
return fdiv_s + get_fvar() + ", " + get_fvar() + ", " + get_fvar() + ";";
}
std::string gen_fsqrt() {
return fsqrt_s + get_fvar() + ", " + get_fvar() + ";";
}
std::string gen_fmadd() {
return "fmadd.s " + get_fvar() + ", " + get_fvar() + ", " + get_fvar() +
", " + get_fvar() + ";";
}
std::string gen_fmsub() {
return "fmsub.s " + get_fvar() + ", " + get_fvar() + ", " + get_fvar() +
", " + get_fvar() + ";";
}
std::string get_xvar() { return xvars[rand() % xvars.size()]; }
std::string gen_xadd() {
return "add " + get_xvar() + ", " + get_xvar() + ", " + get_xvar() + ";";
}
std::string gen_xsub() {
return "sub " + get_xvar() + ", " + get_xvar() + ", " + get_xvar() + ";";
}
std::string gen_xmul() {
return "mul " + get_xvar() + ", " + get_xvar() + ", " + get_xvar() + ";";
}
std::string gen_xdiv() {
return "div " + get_xvar() + ", " + get_xvar() + ", " + get_xvar() + ";";
}
std::string fload_x() { return "flw " + get_fvar() + ",0(sp);"; }
std::string fload_y() { return "flw " + get_fvar() + ",4(sp);"; }
std::string fload_z() { return "flw " + get_fvar() + ",8(sp);"; }
std::string fload_w() { return "flw " + get_fvar() + ",12(sp);"; }
std::string fsave_x() { return "fsw " + get_fvar() + ",0(sp);"; }
std::string fsave_y() { return "fsw " + get_fvar() + ",4(sp);"; }
std::string fsave_z() { return "fsw " + get_fvar() + ",8(sp);"; }
std::string fsave_w() { return "fsw " + get_fvar() + ",12(sp);"; }
std::string xload_x() { return "lw " + get_xvar() + ",16(sp);"; }
std::string xload_y() { return "lw " + get_xvar() + ",20(sp);"; }
std::string xload_z() { return "lw " + get_xvar() + ",24(sp);"; }
std::string xload_w() { return "lw " + get_xvar() + ",28(sp);"; }
std::string xsave_x() { return "sw " + get_xvar() + ",16(sp);"; }
std::string xsave_y() { return "sw " + get_xvar() + ",20(sp);"; }
std::string xsave_z() { return "sw " + get_xvar() + ",24(sp);"; }
std::string xsave_w() { return "sw " + get_xvar() + ",28(sp);"; }
std::string get_inst() {
int id, lw;
id = rand() % 20;
switch (id) {
case 0:
return gen_fadd();
break;
case 1:
return gen_fsub();
break;
case 2:
return gen_fmul();
break;
case 3:
return gen_fdiv();
break;
case 4:
case 17:
lw = rand() % 4;
switch (lw) {
case 0:
return fload_x();
break;
case 1:
return fload_y();
break;
case 2:
return fload_w();
break;
case 3:
return fload_z();
break;
}
break;
case 5:
return gen_fmadd();
break;
case 6:
return gen_fmsub();
break;
case 7:
return gen_fsub();
break;
case 8:
return gen_fdiv();
break;
case 9:
return gen_fsub();
break;
case 10:
return fsave_w();
break;
case 11:
return fsave_x();
break;
case 12:
return fsave_y();
break;
case 13:
return fsave_z();
break;
case 14:
return gen_xadd();
break;
case 15:
return gen_xsub();
break;
case 16:
return gen_xmul();
break;
case 18:
lw = rand() % 4;
switch (lw) {
case 0:
return xload_x();
break;
case 1:
return xload_y();
break;
case 2:
return xload_w();
break;
case 3:
return xload_z();
break;
}
break;
case 19:
lw = rand() % 4;
switch (lw) {
case 0:
return xsave_x();
break;
case 1:
return xsave_y();
break;
case 2:
return xsave_z();
break;
case 3:
return xsave_w();
break;
}
break;
default:
return "";
}
}
int main() {
srand(time(0));
for (int i = 0; i < 200; ++i) {
std::cout << "\"" << get_inst() << "\"\n";
}
}