P4C
The P4 Compiler
Loading...
Searching...
No Matches
tofino/action_data_bus.h
1
19#ifndef BF_P4C_MAU_TOFINO_ACTION_DATA_BUS_H_
20#define BF_P4C_MAU_TOFINO_ACTION_DATA_BUS_H_
21
22/* clang-format off */
23#include "bf-p4c/mau/action_data_bus.h"
24#include "bf-p4c/mau/table_layout.h"
25#include "bf-p4c/mau/action_format.h"
26#include "lib/autoclone.h"
27#include "lib/safe_vector.h"
28#include "bf-p4c/common/alloc.h"
29/* clang-format on */
30namespace Tofino {
31
32using namespace P4;
33
66 static constexpr int OUTPUTS = 32;
67 static constexpr int ADB_BYTES = 128;
68 static constexpr int PAIRED_OFFSET = 16;
69 static constexpr int BYTES_PER_RAM = 16;
70 static constexpr int ADB_STARTS[ActionData::SLOT_TYPES] = {0, 32, 96};
71 static constexpr int IMMED_DIVIDES[ActionData::SLOT_TYPES] = {16, 64, 128};
72 static constexpr int IMMED_SECT = 4;
73 static constexpr int CSR_RANGE = 16;
74 static constexpr int CSR_SECTION[ActionData::SLOT_TYPES] = {4, 3, 2};
75 static constexpr int RANDOM_NUMBER_GENERATORS = 2;
76
77 private:
79 BFN::Alloc1D<cstring /* table name */, ADB_BYTES> total_use;
81
82 bitvec cont_in_use[ActionData::SLOT_TYPES];
83 bitvec total_in_use;
84 bitvec rng_in_use[RANDOM_NUMBER_GENERATORS];
85
87 std::set<cstring> atcam_updates;
88
89 bool reserved_immed[3] = {false, false, false};
90
91 struct ADB_CSR {
92 safe_vector<bool> reserved;
93 ActionData::SlotType_t type;
94
95 explicit ADB_CSR(ActionData::SlotType_t t) : type(t) {
96 reserved.resize(ActionDataBus::CSR_SECTION[type], false);
97 }
98
99 bool operator==(const ADB_CSR &adb_csr) const {
100 if (reserved != adb_csr.reserved) return false;
101 if (type != adb_csr.type) return false;
102 return true;
103 }
104 };
105
107 safe_vector<ActionIXBar> action_ixbars;
108
109 public:
110 struct Use : public ::ActionDataBus::Use {
111 void clear() override {
112 ::ActionDataBus::Use::clear();
113 rng_locs.clear();
114 }
115 Use *clone() const override { return new Use(*this); }
116 bool emit_adb_asm(std::ostream &, const IR::MAU::Table *, bitvec source) const override;
117 bool empty() const override { return ::ActionDataBus::Use::empty() && rng_locs.empty(); }
118 int rng_unit() const override;
119
121 int unit;
122 bitvec bytes;
123
124 RandomNumberGenerator(int u, bitvec b) : unit(u), bytes(b) {}
125
126 bool operator==(const RandomNumberGenerator &rng) const {
127 if (unit != rng.unit) return false;
128 if (bytes != rng.bytes) return false;
129 return true;
130 }
131 };
132
134 bool operator==(const Use &use) const {
135 if (rng_locs != use.rng_locs) return false;
136 return true;
137 }
138 };
139
140 void clear() override;
141
142 bool operator==(const ActionDataBus &adb) const;
143 bool operator!=(ActionDataBus &adb) { return !(*this == adb); }
144
145 private:
146 static Use &getUse(autoclone_ptr<::ActionDataBus::Use> &ac);
147 int byte_to_output(int byte, ActionData::SlotType_t type);
148 int output_to_byte(int output, ActionData::SlotType_t type);
149 int find_byte_sz(ActionData::SlotType_t type);
150 int csr_index(int start_byte, ActionData::SlotType_t type);
151 bool is_csr_reserved(int start_byte, bitvec adjacent, int byte_offset,
152 ActionData::Location_t source);
153 bool is_adf_csr_reserved(int start_byte, bitvec adjacent, int byte_offset);
154 bool is_immed_csr_reserved(int start_byte);
155
156 void reserve_csr(int start_byte, bitvec adjacent, int byte_offset,
157 ActionData::Location_t source);
158 void reserve_adf_csr(int start_byte, bitvec adjacent, int byte_offset);
159 void reserve_immed_csr(int start_byte);
160 bitvec combined(const ActionData::BusInputs bv) const;
161
162 void initialize_action_ixbar();
163
164 bool find_location(bitvec combined_adjacent, int diff, ActionData::SlotType_t init_type,
165 loc_alg_t loc_alg, ActionData::Location_t source, int byte_offset,
166 int &start_byte);
167 bool find_location(bitvec combined_adjacent, int diff, int initial_adb_byte, int final_adb_byte,
168 bool reset, ActionData::SlotType_t type, ActionData::Location_t source,
169 int byte_offset, int &start_byte);
170
171 void analyze_full_share(Use &use, ActionData::BusInputs layouts, FullShare &full_share,
172 int init_byte_offset, int add_byte_offset,
173 ActionData::Location_t source);
174 void analyze_full_shares(Use &use, ActionData::BusInputs layouts, bitvec full_bitmasked,
175 FullShare full_shares[4], int init_byte_offset,
176 ActionData::Location_t source);
177 void reserve_space(Use &use, ActionData::SlotType_t type, bitvec adjacent,
178 bitvec combined_adjacent, int start_byte, int byte_offset,
179 ActionData::Location_t source, cstring name);
180 bool fit_adf_section(Use &use, bitvec adjacent, bitvec combined_adjacent,
181 ActionData::SlotType_t type, loc_alg_t loc_alg, int init_byte_offset,
182 int sec_begin, int size, cstring name, ActionData::Location_t source);
183 bool alloc_bytes(Use &use, bitvec layout, bitvec combined_layout, int init_byte_offset,
184 cstring name, ActionData::Location_t source);
185 bool alloc_halves(Use &use, bitvec layout, bitvec combined_layout, int init_byte_offset,
186 cstring name, ActionData::Location_t source);
187 bool alloc_fulls(Use &use, ActionData::BusInputs layouts, bitvec full_bitmasked,
188 int init_byte_offset, cstring name, ActionData::Location_t source);
189 bool alloc_full_sect(Use &use, FullShare full_shares[4], bitvec combined_layout, int begin,
190 int init_byte_offset, cstring name, bitvec full_bitmasked,
191 ActionData::Location_t source);
192 bool alloc_ad_table(const ActionData::BusInputs total_layouts,
193 const bitvec full_layout_bitmasked, Use &use, cstring name);
194 bool alloc_meter_output(ActionData::BusInputs total_layouts, Use &use, cstring name);
195
196 bitvec paired_immediate(bitvec layout, ActionData::SlotType_t type);
197 bool fit_immed_sect(Use &use, bitvec layout, bitvec combined_layout,
198 ActionData::SlotType_t type, loc_alg_t loc_alg, cstring name);
199 bool alloc_unshared_immed(Use &use, ActionData::SlotType_t, bitvec layout,
200 bitvec combined_layout, cstring name);
201 bool alloc_shared_immed(Use &use, ActionData::BusInputs layouts, cstring name);
202 bool alloc_immediate(const ActionData::BusInputs total_layouts, Use &use, cstring name);
203 bool alloc_rng(Use &use, const ActionData::Format::Use *format, cstring name);
204
205 public:
206 bool alloc_action_data_bus(const IR::MAU::Table *tbl, const ActionData::Format::Use *use,
207 TableResourceAlloc &alloc) override;
208 bool alloc_action_data_bus(const IR::MAU::Table *tbl, const MeterALU::Format::Use *use,
209 TableResourceAlloc &alloc) override;
210 void update(cstring name, const ::ActionDataBus::Use &alloc) override;
211 void update(cstring name, const Use::ReservedSpace &rs) override;
212 void update(cstring name, const Use::RandomNumberGenerator &rng);
213 void update(const IR::MAU::Table *tbl) override;
214};
215
216} // end namespace Tofino
217
218#endif /* BF_P4C_MAU_TOFINO_ACTION_DATA_BUS_H_*/
Definition alloc.h:65
Definition alloc.h:152
Definition bitvec.h:120
Definition cstring.h:85
Definition safe_vector.h:27
Definition autoclone.h:31
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition tofino/action_data_bus.cpp:28
Definition action_format.h:979
Definition action_data_bus.h:92
Definition action_data_bus.h:59
loc_alg_t
Definition action_data_bus.h:139
Definition attached_output.h:42
Definition resource.h:37
Definition tofino/action_data_bus.h:120
Definition tofino/action_data_bus.h:110
Definition tofino/action_data_bus.h:65
void clear() override
Definition tofino/action_data_bus.cpp:42
bool alloc_action_data_bus(const IR::MAU::Table *tbl, const ActionData::Format::Use *use, TableResourceAlloc &alloc) override
Definition tofino/action_data_bus.cpp:1033