Skip to content

Commit 5168ba2

Browse files
committed
Adding test cases, small fixes
1 parent 0ac6ed5 commit 5168ba2

File tree

9 files changed

+923
-784
lines changed

9 files changed

+923
-784
lines changed

experiments/cell_libraries/asap7.genlib

Lines changed: 242 additions & 747 deletions
Large diffs are not rendered by default.

experiments/cell_libraries/multioutput.genlib

Lines changed: 260 additions & 0 deletions
Large diffs are not rendered by default.

experiments/emap.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int main()
5353

5454
/* library to map to technology */
5555
fmt::print( "[i] processing technology library\n" );
56-
std::string library = "asap7";
56+
std::string library = "multioutput";
5757
std::vector<gate> gates;
5858
std::ifstream in( cell_libraries_path( library ) );
5959

@@ -82,9 +82,9 @@ int main()
8282
emap_params ps;
8383
ps.matching_mode = emap_params::hybrid;
8484
ps.area_oriented_mapping = false;
85-
ps.map_multioutput = false;
85+
ps.map_multioutput = true;
8686
emap_stats st;
87-
cell_view<block_network> res = emap<6>( aig, tech_lib, ps, &st );
87+
cell_view<block_network> res = emap<9>( aig, tech_lib, ps, &st );
8888

8989
names_view res_names{ res };
9090
restore_network_name( aig, res_names );

include/mockturtle/utils/struct_library.hpp

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
namespace mockturtle
5656
{
5757

58+
struct struct_library_params
59+
{
60+
/*! \brief Load gates with minimum size only */
61+
bool load_minimum_size_only{ true };
62+
63+
/*! \brief Reports loaded gates */
64+
bool verbose{ false };
65+
};
66+
5867
/*! \brief Library of gates for structural matching
5968
*
6069
* This class creates a technology library from a set
@@ -82,7 +91,6 @@ namespace mockturtle
8291
mockturtle::struct_library lib( gates );
8392
\endverbatim
8493
*/
85-
8694
template<unsigned NInputs = 9u>
8795
class struct_library
8896
{
@@ -172,8 +180,9 @@ class struct_library
172180
using map_label_gate = std::unordered_map<uint32_t, supergates_list_t>;
173181

174182
public:
175-
explicit struct_library( std::vector<gate> const& gates )
183+
explicit struct_library( std::vector<gate> const& gates, struct_library_params const& ps = {} )
176184
: _gates( gates ),
185+
_ps( ps ),
177186
_supergates(),
178187
_dsd_map(),
179188
_and_table(),
@@ -188,9 +197,9 @@ class struct_library
188197
* gate inputs considered for the library creation.
189198
* 0 < min_vars < UINT32_MAX
190199
*/
191-
void construct( uint32_t min_vars = 2u, bool verbose = false )
200+
void construct( uint32_t min_vars = 2u )
192201
{
193-
generate_library( min_vars, verbose );
202+
generate_library( min_vars );
194203
}
195204

196205
/*! \brief Construct the structural library.
@@ -244,6 +253,15 @@ class struct_library
244253
return nullptr;
245254
}
246255

256+
/*! \brief Returns the number of large gates.
257+
*
258+
* Number of gates with more than 6 inputs.
259+
*/
260+
const uint32_t get_num_large_gates() const
261+
{
262+
return num_large_gates;
263+
}
264+
247265
/*! \brief Print and table.
248266
*
249267
*/
@@ -260,15 +278,15 @@ class struct_library
260278
}
261279

262280
private:
263-
void generate_library( uint32_t min_vars, bool verbose )
281+
void generate_library( uint32_t min_vars )
264282
{
265283
/* select and load gates */
266284
_supergates.reserve( _gates.size() );
267285
generate_composed_gates();
268286

269287
/* mark dominate gates */
270288
std::vector<bool> skip_gates( _supergates.size(), false );
271-
select_dominated_gates( skip_gates );
289+
filter_gates( skip_gates );
272290

273291
std::vector<uint32_t> indexes( _supergates.size() );
274292
std::iota( indexes.begin(), indexes.end(), 0 );
@@ -304,17 +322,22 @@ class struct_library
304322
/* ignore gates with reconvergence */
305323
if ( gate_disjoint )
306324
continue;
325+
326+
if ( gate.num_vars > 6 )
327+
{
328+
++num_large_gates;
329+
}
307330

308331
_dsd_map.insert( { gate.function, rule } );
309-
if ( verbose )
332+
if ( _ps.verbose )
310333
{
311334
std::cout << "Dsd:\n";
312335
print_rule( rule, rule[rule.size() - 1] );
313336
}
314337

315338
/* Aig conversion */
316339
auto aig_rule = map_to_aig( rule );
317-
if ( verbose )
340+
if ( _ps.verbose )
318341
{
319342
std::cout << "\nAig:\n";
320343
print_rule( aig_rule, aig_rule[aig_rule.size() - 1] );
@@ -325,7 +348,7 @@ class struct_library
325348
der_rules.push_back( aig_rule );
326349
std::vector<std::tuple<uint32_t, uint32_t>> depths = { { get_depth( aig_rule, aig_rule[aig_rule[aig_rule.size() - 1].fanin[0].index] ), get_depth( aig_rule, aig_rule[aig_rule[aig_rule.size() - 1].fanin[1].index] ) } };
327350
create_rules_from_dsd( der_rules, aig_rule, aig_rule[aig_rule.size() - 1], depths, true, true );
328-
if ( verbose )
351+
if ( _ps.verbose )
329352
{
330353
std::cout << "\nDerived:\n";
331354
}
@@ -364,7 +387,7 @@ class struct_library
364387

365388
v.insert( it, sg );
366389

367-
if ( verbose )
390+
if ( _ps.verbose )
368391
{
369392
print_rule( elem, elem[elem.size() - 1] );
370393
std::cout << "\n";
@@ -379,15 +402,15 @@ class struct_library
379402
}
380403
}
381404

382-
if ( verbose )
405+
if ( _ps.verbose )
383406
{
384407
std::cout << "\n";
385408
std::cout << "And table:\n";
386409
print_and_table();
387410
std::cout << "\n";
388411
}
389412
}
390-
if ( verbose )
413+
if ( _ps.verbose )
391414
std::cout << "\n";
392415
}
393416

@@ -440,7 +463,33 @@ class struct_library
440463
}
441464
}
442465

443-
void select_dominated_gates( std::vector<bool>& skip_gates )
466+
bool compare_sizes( composed_gate<NInputs> const& s1, composed_gate<NInputs> const& s2 )
467+
{
468+
if ( s1.area < s2.area )
469+
return true;
470+
else if ( s1.area > s2.area )
471+
return false;
472+
473+
/* compute average pin delay */
474+
float s1_delay = 0, s2_delay = 0;
475+
assert( s1.num_vars == s2.num_vars );
476+
for ( uint32_t i = 0; i < s1.num_vars; ++i )
477+
{
478+
s1_delay += s1.tdelay[i];
479+
s2_delay += s2.tdelay[i];
480+
}
481+
482+
if ( s1_delay < s2_delay )
483+
return true;
484+
else if ( s1_delay > s2_delay )
485+
return false;
486+
else if ( s1.root->name < s2.root->name )
487+
return true;
488+
489+
return false;
490+
}
491+
492+
void filter_gates( std::vector<bool>& skip_gates )
444493
{
445494
for ( uint32_t i = 0; i < skip_gates.size() - 1; ++i )
446495
{
@@ -456,8 +505,22 @@ class struct_library
456505
auto const& ttj = _supergates[j].function;
457506

458507
/* get the same functionality */
459-
if ( tti != ttj )
508+
if ( skip_gates[j] || tti != ttj )
460509
continue;
510+
511+
if ( _ps.load_minimum_size_only )
512+
{
513+
if ( compare_sizes( _supergates[i], _supergates[j] ) )
514+
{
515+
skip_gates[j] = true;
516+
continue;
517+
}
518+
else
519+
{
520+
skip_gates[i] = true;
521+
break;
522+
}
523+
}
461524

462525
/* is i smaller than j */
463526
bool smaller = _supergates[i].area < _supergates[j].area;
@@ -1459,8 +1522,11 @@ class struct_library
14591522

14601523
private:
14611524
bool gate_disjoint{ false }; /* flag for gate support*/
1525+
uint32_t num_large_gates{ 0 };
14621526

14631527
std::vector<gate> const& _gates; /* collection of gates */
1528+
struct_library_params const _ps;
1529+
14641530
composed_list_t _supergates; /* list of composed_gates */
14651531
lib_rule _dsd_map; /* hash map for DSD decomposition of gates */
14661532
lib_table _and_table; /* AND table */

include/mockturtle/utils/super_utils.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class super_utils
154154
/* create composed gates */
155155
uint32_t ignored = 0;
156156
uint32_t ignored_id = 0;
157+
uint32_t large_gates = 0;
157158
for ( const auto& g : _gates )
158159
{
159160
std::array<float, NInputs> pin_to_pin_delays{};
@@ -165,7 +166,10 @@ class super_utils
165166
continue;
166167
}
167168
if ( g.function.num_vars() > truth_table_size )
169+
{
170+
++large_gates;
168171
continue;
172+
}
169173

170174
auto i = 0u;
171175
for ( auto const& pin : g.pins )
@@ -208,8 +212,8 @@ class super_utils
208212

209213
if ( _ps.verbose )
210214
{
211-
std::cout << fmt::format( "[i] Loading {} simple gates in the library\n", simple_gates_size );
212-
std::cout << fmt::format( "[i] Loading {} multi-output gates in the library\n", _multioutput_gates.size() );
215+
std::cout << fmt::format( "[i] Loading {} simple cells in the library\n", simple_gates_size + large_gates );
216+
std::cout << fmt::format( "[i] Loading {} multi-output cells in the library\n", _multioutput_gates.size() );
213217
}
214218

215219
if ( ignored > 0 )

include/mockturtle/utils/tech_library.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class tech_library
202202
_cells( get_standard_cells( _gates ) ),
203203
_super( _gates, _supergates_spec, super_utils_params{ ps.load_multioutput_gates_single, ps.verbose } ),
204204
_use_supergates( false ),
205-
_struct( _gates ),
205+
_struct( _gates, struct_library_params{ ps.load_minimum_size_only, ps.very_verbose } ),
206206
_super_lib(),
207207
_multi_lib(),
208208
_struct_lib()
@@ -216,7 +216,7 @@ class tech_library
216216

217217
if ( ps.load_large_gates )
218218
{
219-
_struct.construct( 2, _ps.very_verbose );
219+
_struct.construct( 2 );
220220
}
221221
}
222222

@@ -227,7 +227,7 @@ class tech_library
227227
_cells( get_standard_cells( _gates ) ),
228228
_super( _gates, _supergates_spec, super_utils_params{ ps.load_multioutput_gates_single, ps.verbose } ),
229229
_use_supergates( true ),
230-
_struct( _gates ),
230+
_struct( _gates, struct_library_params{ ps.load_minimum_size_only, ps.very_verbose } ),
231231
_super_lib(),
232232
_multi_lib(),
233233
_struct_lib()
@@ -241,7 +241,7 @@ class tech_library
241241

242242
if ( ps.load_large_gates )
243243
{
244-
_struct.construct( 2, _ps.very_verbose );
244+
_struct.construct( 2 );
245245
}
246246
}
247247

@@ -359,6 +359,12 @@ class tech_library
359359
return _struct.get_struct_library().size();
360360
}
361361

362+
/*! \brief Returns the number of gates for structural matching with more than 6 inputs. */
363+
const uint32_t num_structural_large_gates() const
364+
{
365+
return _struct.get_struct_library().size();
366+
}
367+
362368
private:
363369
void generate_library()
364370
{
@@ -1086,7 +1092,7 @@ class tech_library
10861092
auto const& ttj = supergates[j].function;
10871093

10881094
/* get the same functionality */
1089-
if ( tti != ttj )
1095+
if ( skip_gates[j] || tti != ttj )
10901096
continue;
10911097

10921098
if ( _ps.load_minimum_size_only )
@@ -1104,7 +1110,7 @@ class tech_library
11041110
}
11051111

11061112
/* is i smaller than j */
1107-
bool smaller = supergates[i].area < supergates[j].area;
1113+
bool smaller = supergates[i].area <= supergates[j].area;
11081114

11091115
/* is i faster for every pin */
11101116
bool faster = true;
@@ -1121,14 +1127,15 @@ class tech_library
11211127
}
11221128

11231129
/* is j faster for every pin */
1130+
smaller = supergates[i].area >= supergates[j].area;
11241131
faster = true;
11251132
for ( uint32_t k = 0; k < tti.num_vars(); ++k )
11261133
{
11271134
if ( supergates[j].tdelay[k] > supergates[i].tdelay[k] )
11281135
faster = false;
11291136
}
11301137

1131-
if ( !smaller && faster )
1138+
if ( smaller && faster )
11321139
{
11331140
skip_gates[i] = true;
11341141
break;

0 commit comments

Comments
 (0)