-
Notifications
You must be signed in to change notification settings - Fork 19
/
faster.hpp
282 lines (230 loc) · 6.92 KB
/
faster.hpp
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/**
* PEIGEN: a Platform for Evaluation, Implementation, and Generation of S-boxes
*
* Copyright 2019 by
* Zhenzhen Bao <baozhenzhen10[at]gmail.com>
* Jian Guo <guojian[at]ntu.edu.sg>
* San Ling <lingsan[at]ntu.edu.sg>
* Yu Sasaki <yu[dot]sasaki[dot][email protected]>
*
* This platform is developed based on the open source application
* <http://jeremy.jean.free.fr/pub/fse2018_layer_implementations.tar.gz>
* Optimizing Implementations of Lightweight Building Blocks
*
* Copyright 2017 by
* Jade Tourteaux <Jade[dot]Tourteaux[at]gmail.com>
* Jérémy Jean <Jean[dot]Jeremy[at]gmail.com>
*
* We follow the same copyright policy.
*
* This file is part of some open source application.
*
* Some open source application is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* Some open source application is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
* @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
*/
#ifndef FASTER_H__
#define FASTER_H__
#include "faster_func.hpp"
using namespace Peigen::depth;
using namespace std;
template<int N>
class Peigen::depth::faster
{
public:
int pre_l = -1;
string imp_info = "";
ofstream statistician;
string old_instance_name = "";
string instance_name = "";
int max_GE = 0;
vector<bool_op_t> b; // The boolean instructions (B in the paper)
map<int, set<bool_function_t<N>> > f1_succ;
function_t<N> start;
function_t<N> target;
uint32_t flag = 0UL;
int count_list;
int shortest_path = MAX_COST;
int smallest_area = MAX_COST;
set<const bool_function_t<N>* > area_sum;
bool verbose = false;
int l = 1200;
bool write_in_file = false;
int omp_nb_threads = 20;
string conf_file = "TSMC65nm.conf";
long max_ram = 160;
long nodes_cmp = 0;
long max_nodes;
int cost_1;
int gate_not1 = false;
int gate_and2 = false;
int gate_nand2 = false;
int gate_or2 = false;
int gate_nor2 = false;
int gate_xor2 = false;
int gate_xnor2 = false;
int gate_moai1 = false;
int gate_maoi1 = false;
int gate_nand3 = false;
int gate_nor3 = false;
int gate_or3 = false;
int gate_and3 = false;
int gate_andn2 = false;
int gate_orn2 = false;
struct option longopts[16] = {
{ "not1", no_argument, &gate_not1, 1},
{ "and2", no_argument, &gate_and2, 1},
{ "nand2", no_argument, &gate_nand2, 1},
{ "or2", no_argument, &gate_or2, 1},
{ "nor2", no_argument, &gate_nor2, 1},
{ "xor2", no_argument, &gate_xor2, 1},
{ "xnor2", no_argument, &gate_xnor2, 1},
{ "moai1", no_argument, &gate_moai1, 1},
{ "maoi1", no_argument, &gate_maoi1, 1},
{ "nand3", no_argument, &gate_nand3, 1},
{ "nor3", no_argument, &gate_nor3, 1},
{ "and3", no_argument, &gate_and3, 1},
{ "or3", no_argument, &gate_or3, 1},
{ "andn2", no_argument, &gate_andn2, 1},
{ "orn2", no_argument, &gate_orn2, 1},
{0, 0, 0, 0}
};
int not1_cost;
int and2_cost;
int nand2_cost;
int or2_cost;
int nor2_cost;
int xor2_cost;
int xnor2_cost;
int maoi1_cost;
int moai1_cost;
int nand3_cost;
int nor3_cost;
int and3_cost;
int or3_cost;
int andn2_cost;
int orn2_cost;
void init_varbles()
{
shortest_path = MAX_COST;
smallest_area = MAX_COST;
area_sum.clear();
if (pre_l < 0)
{
f1_succ.clear();
}
flag = 0UL;
}
void reset()
{
pre_l = -1;
imp_info = "";
instance_name = "";
old_instance_name = "";
start = function_t<N>::INPUT_DEFAULT();
target = function_t<N>::INPUT_DEFAULT();
flag = 0UL;
max_GE = 0;
b.clear();
f1_succ.clear();
shortest_path = MAX_COST;
smallest_area = MAX_COST;
area_sum.clear();
verbose = false;
l = 1200;
write_in_file = false;
omp_nb_threads = 20;
conf_file = "TSMC65nm.conf";
max_ram = 160;
nodes_cmp = 0;
gate_not1 = false;
gate_and2 = false;
gate_nand2 = false;
gate_or2 = false;
gate_nor2 = false;
gate_xor2 = false;
gate_xnor2 = false;
gate_moai1 = false;
gate_maoi1 = false;
gate_nand3 = false;
gate_nor3 = false;
gate_or3 = false;
gate_and3 = false;
gate_andn2 = false;
gate_orn2 = false;
}
int cur_shortest_path()
{
return shortest_path;
}
int cur_smallest_area()
{
return smallest_area;
}
void all_gates();
void genImpInfo();
int bool_op_cost(uint8_t op);
string bool_op_str(uint8_t op);
void init_b(string conf_file);
void bool_op_one_input(const bool_function_t<N> *f, vector<bool_function_t<N> > *v, bool_op_t bool_op);
void bool_op_two_inputs(const bool_function_t<N> *f1, const bool_function_t<N> *f2, vector<bool_function_t<N> > *v, bool_op_t bool_op);
void bool_op_three_inputs(const bool_function_t<N> *f1, const bool_function_t<N> *f2, const bool_function_t<N> *f3, vector<bool_function_t<N> > *v, bool_op_t bool_op);
string get_implementation(bool_function_t<N> f1);
void get_implementation();
void print_graphe_info();
void exit_m();
void graphe_to_file(map<int, set<bool_function_t<N> > > *graphe,
string graphe_name);
void print_uint16(uint16_t n);
void print_uint8(uint8_t n);
string uint8_to_string(uint8_t n);
void print_uint32(uint32_t n);
void mitm(function_t<N> f1);
void expand(int lambda);
void v_list_process(int lambda, int op_cost, vector<bool_function_t<N> > *tmp,
set<bool_function_t<N> > *to_insert);
bool is_in_graphe(int lambda, int op_cost, bool_function_t<N> f);
bool is_in_graphe_collision(int lambda, int op_cost, bool_function_t<N> f);
void pre_compute(string args);
void pre_computing();
void write_pre_bin();
void read_pre_bin();
void search_batch(string args);
double search_single(string args);
faster(){};
~faster(){};
};
#include "faster_bool_op.hpp"
#include "faster_mitm.hpp"
#include "faster_utils.hpp"
#include "faster_impl_info.hpp"
#undef NOP
#undef NOT1
#undef AND2
#undef NAND2
#undef OR2
#undef NOR2
#undef XOR2
#undef XNOR2
#undef MOAI1
#undef MAOI1
#undef NAND3
#undef NOR3
#undef OR3
#undef AND3
#undef ANDN2
#undef ORN2
#undef MAX_COST
#undef FOUND_ALL
#endif /* FASTER_H__ */