29struct StageUseEstimate {
30 static constexpr int MIN_WAYS = 1;
31 static constexpr int MAX_WAYS = 8;
32 static constexpr int MAX_METER_ALUS = 4;
33 static constexpr int MAX_STATS_ALUS = 4;
34 static constexpr int MAX_LOCAL_TINDS = 16;
36 static constexpr int MAX_DLEFT_HASH_SIZE = 23;
37 static constexpr int COMPILER_DEFAULT_SELECTOR_POOLS = 4;
38 static constexpr int SINGLE_RAMLINE_POOL_SIZE = 120;
39 static constexpr int MAX_MOD = 31;
40 static constexpr int MAX_MOD_SHIFT = 5;
41 static constexpr int MAX_POOL_RAMLINES = MAX_MOD << MAX_MOD_SHIFT;
42 static constexpr int MOD_INPUT_BITS = 10;
49 int exact_ixbar_bytes = 0;
50 int ternary_ixbar_groups = 0;
54 int hash_bits_masked = 0;
69 size_t preferred_index = 0;
71 StageUseEstimate &operator+=(
const StageUseEstimate &a) {
72 logical_ids += a.logical_ids;
75 local_tinds += a.local_tinds;
77 exact_ixbar_bytes += a.exact_ixbar_bytes;
78 ternary_ixbar_groups += a.ternary_ixbar_groups;
79 meter_alus += a.meter_alus;
80 stats_alus += a.stats_alus;
83 StageUseEstimate(
const IR::MAU::Table *,
int &, attached_entries_t &,
LayoutChoices *lc,
84 bool prev_placed,
bool gateway_attached,
bool disable_split,
PhvInfo &phv);
86 StageUseEstimate operator+(
const StageUseEstimate &a)
const {
87 StageUseEstimate rv = *
this;
91 static StageUseEstimate max() {
93 rv.logical_ids = StageUse::MAX_LOGICAL_IDS;
94 rv.srams = StageUse::MAX_SRAMS;
95 rv.tcams = StageUse::MAX_TCAMS;
96 rv.local_tinds = MAX_LOCAL_TINDS;
97 rv.maprams = StageUse::MAX_MAPRAMS;
98 rv.exact_ixbar_bytes = StageUse::MAX_IXBAR_BYTES;
99 rv.ternary_ixbar_groups = StageUse::MAX_TERNARY_GROUPS;
100 rv.meter_alus = MAX_METER_ALUS;
101 rv.stats_alus = MAX_STATS_ALUS;
104 bool operator<=(
const StageUseEstimate &a) {
105 return logical_ids <= a.logical_ids && srams <= a.srams && tcams <= a.tcams &&
106 maprams <= a.maprams && exact_ixbar_bytes <= a.exact_ixbar_bytes &&
107 ternary_ixbar_groups <= a.ternary_ixbar_groups && meter_alus < a.meter_alus &&
108 stats_alus <= a.stats_alus && local_tinds <= a.local_tinds;
115 exact_ixbar_bytes = 0;
116 ternary_ixbar_groups = 0;
123 void options_to_ways(
const IR::MAU::Table *tbl,
int entries);
124 void options_to_rams(
const IR::MAU::Table *tbl,
const attached_entries_t &att_entries);
125 void select_best_option(
const IR::MAU::Table *tbl);
126 void options_to_ternary_entries(
const IR::MAU::Table *tbl,
int entries);
127 void select_best_option_ternary();
130 void calculate_attached_rams(
const IR::MAU::Table *tbl,
const attached_entries_t &att_entries,
132 void fill_estimate_from_option(
int &entries);
133 void remove_invalid_option() {
134 erase_if(layout_options, [](
const LayoutOption &lo) {
return lo.entries == 0; });
137 if (layout_options.empty())
140 return &layout_options[preferred_index];
144 auto option = preferred();
145 if (option ==
nullptr)
return nullptr;
146 return &action_formats[option->action_format_index];
151 void determine_initial_layout_option(
const IR::MAU::Table *tbl,
int &entries,
152 attached_entries_t &);
153 bool adjust_choices(
const IR::MAU::Table *tbl,
int &entries, attached_entries_t &);
155 bool calculate_for_leftover_srams(
const IR::MAU::Table *tbl,
int &srams_left,
int &entries,
156 attached_entries_t &);
157 void calculate_for_leftover_tcams(
const IR::MAU::Table *tbl,
int srams_left,
int tcams_left,
158 int &entries, attached_entries_t &);
159 void calculate_for_leftover_atcams(
const IR::MAU::Table *tbl,
int srams_left,
int &entries,
160 attached_entries_t &);
161 void shrink_preferred_srams_lo(
const IR::MAU::Table *tbl,
int &entries,
162 attached_entries_t &attached_entries);
163 void shrink_preferred_tcams_lo(
const IR::MAU::Table *tbl,
int &entries,
164 attached_entries_t &attached_entries);
165 void shrink_preferred_atcams_lo(
const IR::MAU::Table *tbl,
int &entries,
166 attached_entries_t &attached_entries);
167 void known_srams_needed(
const IR::MAU::Table *tbl,
const attached_entries_t &,
169 void unknown_srams_needed(
const IR::MAU::Table *tbl,
LayoutOption *lo,
int srams_left);
170 void unknown_tcams_needed(
const IR::MAU::Table *tbl,
LayoutOption *lo,
int tcams_left,
177 void srams_left_best_option(
int srams_left);
178 void max_entries_best_option();
179 void tcams_left_best_option();
185 RAM_counter() : per_word(0), width(0), need_srams(
false), need_maprams(
false) {}
186 RAM_counter(
int p,
int w,
bool ns,
bool nm)
187 : per_word(p), width(w), need_srams(ns), need_maprams(nm) {}
192 int stages_required()
const;