From ca5c12587b6e51be7f401c2878800d5d49f615d8 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Sun, 15 Mar 2015 18:05:53 -0400 Subject: Polish lookup tables generation --- bench/analyze-blocking-sizes.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'bench/analyze-blocking-sizes.cpp') diff --git a/bench/analyze-blocking-sizes.cpp b/bench/analyze-blocking-sizes.cpp index c133df599..3d57f4bb3 100644 --- a/bench/analyze-blocking-sizes.cpp +++ b/bench/analyze-blocking-sizes.cpp @@ -347,13 +347,16 @@ void dump_table_for_subset( abort(); } if (only_cubic_sizes) { - cout << "/* Warning: generated with --only-cubic-sizes ! */" << endl; + cerr << "Can't generate tables with --only-cubic-sizes." << endl; + abort(); } - cout << "struct optimal_block_sizes_table {" << endl; - cout << " static const size_t min_size = " << min_product_size.k << ";" << endl; - cout << " static const size_t max_size = " << max_product_size.k << ";" << endl; - cout << " static const uint16_t* table() {" << endl; - cout << " static const uint16_t data[] = {"; + cout << "struct LookupTable {" << endl; + cout << " static const size_t BaseSize = " << min_product_size.k << ";" << endl; + const size_t NumSizes = log2_pot(max_product_size.k / min_product_size.k) + 1; + const size_t TableSize = NumSizes * NumSizes * NumSizes; + cout << " static const size_t NumSizes = " << NumSizes << ";" << endl; + cout << " static const uint16_t* Data() {" << endl; + cout << " static const uint16_t data[" << TableSize << "] = {"; while (entry_index < num_entries) { ++entry_index; if (entry_index == num_entries || @@ -371,18 +374,23 @@ void dump_table_for_subset( best_block_size_this_product_size = first_file.entries[e].block_size; } } - if ((i++) % 8) { - cout << ", "; + if ((i++) % NumSizes) { + cout << " "; } else { cout << endl << " "; } cout << "0x" << hex << best_block_size_this_product_size << dec; if (entry_index < num_entries) { + cout << ","; first_entry_index_with_this_product_size = entry_index; product_size = first_file.entries[entry_index].product_size; } } } + if (i != TableSize) { + cerr << endl << "Wrote " << i << " table entries, expected " << TableSize << endl; + abort(); + } cout << endl << " };" << endl; cout << " return data;" << endl; cout << " }" << endl; @@ -855,6 +863,11 @@ int main(int argc, char* argv[]) input_filenames.emplace_back(argv[i]); } + if (dump_tables && only_cubic_sizes) { + cerr << "Incompatible options: --only-cubic-sizes and --dump-tables." << endl; + show_usage_and_exit(argc, argv, available_actions); + } + if (!action) { show_usage_and_exit(argc, argv, available_actions); } -- cgit v1.2.3