19#ifndef BF_P4C_MAU_TABLE_FORMAT_H_
20#define BF_P4C_MAU_TABLE_FORMAT_H_
25#include "backends/tofino/bf-p4c/mau/input_xbar.h"
26#include "backends/tofino/bf-p4c/mau/resource_estimate.h"
28#include "lib/bitops.h"
29#include "lib/bitvec.h"
30#include "lib/safe_vector.h"
39 int byte_location = -1;
43 void dbprint(std::ostream &out)
const;
46 enum HoleType_t { LSB, MIDDLE, MSB, INVALID };
48 int hole_size(HoleType_t hole_type,
int *hole_start_pos =
nullptr)
const;
53 bool interleaved =
false;
54 HoleType_t hole_type = INVALID;
58 int overhead_start = 0;
60 int match_byte_start = 0;
61 void dbprint(std::ostream &out)
const;
68 static constexpr int OVERHEAD_BITS = 64;
69 static constexpr int SINGLE_RAM_BITS = 128;
70 static constexpr int SINGLE_RAM_BYTES = 16;
71 static constexpr int MAX_GROUPS_PER_LAMB = 4;
72 static constexpr int RAM_GHOST_BITS = IXBar::RAM_LINE_SELECT_BITS;
73 static constexpr int GATEWAY_BYTES = 4;
74 static constexpr int VERSION_BYTES = 14;
75 static constexpr int VERSION_BITS = 4;
76 static constexpr int VERSION_NIBBLES = 4;
77 static constexpr int MID_BYTE_LO = 0;
78 static constexpr int MID_BYTE_HI = 1;
79 static constexpr int MID_BYTE_VERS = 3;
80 static constexpr int MAX_SHARED_GROUPS = 2;
81 static constexpr int MAX_GROUPS_PER_RAM = 5;
82 static constexpr int FULL_IMEM_ADDRESS_BITS = 6;
83 static constexpr int FULL_NEXT_TABLE_BITS = 8;
84 static constexpr int NEXT_MAP_TABLE_ENTRIES = 8;
85 static constexpr int IMEM_MAP_TABLE_ENTRIES = 8;
87 static constexpr int SELECTOR_LENGTH_MAX_BIT = 16;
117 std::map<IXBar::Use::Byte, bitvec>
match;
126 match_byte_mask.clear();
131 allocated_bytes.clear();
132 for (
int i = 0; i < ENTRY_TYPES; i++) mask[i].clear();
135 bitvec match_bit_mask()
const {
return mask[MATCH] | mask[VERS]; }
137 bitvec entry_info_bit_mask()
const {
139 for (
int i = 0; i < ENTRY_TYPES; i++) rv |= mask[i];
143 int entry_min_word()
const {
144 return entry_info_bit_mask().min().index() / SINGLE_RAM_BITS;
147 int entry_max_word()
const {
148 return entry_info_bit_mask().max().index() / SINGLE_RAM_BITS;
151 bitvec overhead_mask()
const {
return entry_info_bit_mask() - match_bit_mask(); }
153 bool overhead_in_RAM_word(
int RAM_word)
const {
154 bitvec bv = overhead_mask();
155 bv = bv &
bitvec(RAM_word * SINGLE_RAM_BITS, SINGLE_RAM_BITS);
159 bool match_data_in_RAM_word(
int RAM_word)
const {
160 bitvec bv = match_bit_mask();
161 bv = bv &
bitvec(RAM_word * SINGLE_RAM_BITS, SINGLE_RAM_BITS);
169 int byte_config = -1;
172 void set_group(
int _group,
bitvec _dirtcam);
173 void set_midbyte(
int _byte_group,
int _byte_config);
175 int range_index = -1;
179 bool only_one_result_bus =
false;
183 int split_midbyte = -1;
185 std::map<int, safe_vector<int>> ixbar_group_per_width;
188 int proxy_hash_group = -1;
189 bool identity_hash =
false;
196 IR::MAU::PfeLocation stats_pfe_loc = IR::MAU::PfeLocation::NOT_SET;
197 IR::MAU::PfeLocation meter_pfe_loc = IR::MAU::PfeLocation::NOT_SET;
198 IR::MAU::TypeLocation meter_type_loc = IR::MAU::TypeLocation::NOT_SET;
200 std::map<int, int> payload_map;
204 match_groups.clear();
205 match_group_map.clear();
208 ixbar_group_per_width.clear();
209 result_bus_needed.clear();
210 avail_sb_bytes.clear();
212 stats_pfe_loc = IR::MAU::PfeLocation::NOT_SET;
213 meter_pfe_loc = IR::MAU::PfeLocation::NOT_SET;
214 meter_type_loc = IR::MAU::TypeLocation::NOT_SET;
218 bool has_overhead()
const {
219 if (match_groups.empty())
return false;
220 return !match_groups[0].overhead_mask().empty();
225 for (
auto &match_group : match_groups) rv |= match_group.overhead_mask();
229 bool instr_in_overhead()
const {
230 if (match_groups.empty())
return false;
231 return !match_groups[0].mask[ACTION].empty();
234 int next_table_bits()
const {
235 if (match_groups.empty())
return false;
236 return match_groups[0].mask[NEXT].popcount();
245 bitvec interleaved_match_byte_use;
267 int ghost_bits_count = 0;
269 const IR::MAU::Table *tbl;
274 std::set<int> fully_ghosted_search_buses;
277 bitvec pre_match_total_use;
279 bitvec interleaved_bit_use;
281 enum packing_algorithm_t { SAVE_GW_SPACE, PACK_TIGHT, PACKING_ALGORITHMS };
283 packing_algorithm_t pa = PACKING_ALGORITHMS;
295 const bitvec immediate_mask;
302 void clear_match_state();
303 void clear_pre_allocation_state();
305 bitvec bitvec_necessary(type_t type)
const;
306 int overhead_bits_necessary()
const;
307 bool allocate_overhead_field(type_t type,
int lsb_mem_word_offset,
int bit_width,
int entry,
309 bool allocate_overhead_entry(
int entry,
int RAM_word,
int lsb_mem_word_offset);
310 void setup_pfes_and_types();
311 bool allocate_all_indirect_ptrs();
312 bool allocate_all_immediate();
313 bool allocate_all_instr_selection();
314 bool allocate_match();
315 bool allocate_match_with_algorithm();
316 bool is_match_entry_wide()
const;
318 bool allocate_all_ternary_match();
320 void ternary_midbyte(
int midbyte,
size_t &index,
bool lo_midbyte);
321 void ternary_version(
size_t &index);
325 void analyze_proxy_hash_option(
int per_RAM);
327 int hit_actions()
const;
328 bool allocate_next_table();
329 bool allocate_selector_length();
330 bool allocate_indirect_ptr(
int total, type_t type,
int group,
int RAM);
333 int width_sect,
int entry,
bitvec &byte_attempt,
338 int determine_group(
int width_sect,
int groups_allocated);
341 bitvec &bit_attempt,
bool overhead_section);
342 bool attempt_allocate_shares();
343 bool allocate_shares();
344 bool redistribute_entry_priority();
345 void redistribute_next_table();
346 bool build_match_group_map();
347 bool build_payload_map();
348 bool interleave_match_and_overhead();
350 virtual void classify_match_bits();
351 virtual bool allocate_sram_match();
353 int width_sect,
bitvec &byte_attempt,
bitvec &bit_attempt);
354 virtual bool requires_versioning()
const {
return layout_option.layout.requires_versioning; }
355 virtual bool requires_valid_bit()
const {
return false; }
362 safe_vector<std::pair<IXBar::Use::Byte, bitvec>> &potential_ghost);
364 safe_vector<std::pair<IXBar::Use::Byte, bitvec>> &potential_ghost);
365 int bits_necessary(type_t type)
const;
380 proxy_hash_ixbar(phi),
388 const IR::MAU::Table *t,
const bitvec im,
bool gl,
Definition payload_gateway.h:31
Definition table_layout.h:34
Definition stringify.h:33
Definition safe_vector.h:27
Definition phv_fields.h:1095
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void info(const int kind, const char *format, const T *node, Args &&...args)
Report info messages of type kind. Requires that the node argument have source info.
Definition lib/error.h:148
Definition table_format.h:52
void dbprint(std::ostream &out) const
Definition table_format.cpp:27
Definition table_format.h:35
void set_interleave_info(int overhead_bits)
Definition table_format.cpp:2650
bool better_hole_type(int hole, int comp_hole, int overhead_bits) const
Definition table_format.cpp:2602
bool is_better_for_overhead(const ByteInfo &bi, int overhead_bits) const
Definition table_format.cpp:2624
Definition input_xbar.h:230
Definition input_xbar.h:191