28struct ActionBusSource {
54 short xcmp_group, xcmp_byte;
57 ActionBusSource() : type(None) { field =
nullptr; }
58 ActionBusSource(Table::Format::Field *f) : type(Field) {
61 ActionBusSource(HashDistribution *h) : type(HashDist) { hd = h; }
62 ActionBusSource(HashDistribution *h1, HashDistribution *h2) : type(HashDistPair) {
66 ActionBusSource(Table *t,
67 TableOutputModifier m = TableOutputModifier::NONE)
70 case TableOutputModifier::Color:
73 case TableOutputModifier::Address:
81 ActionBusSource(Table::Ref *t,
82 TableOutputModifier m = TableOutputModifier::NONE)
85 case TableOutputModifier::Color:
88 case TableOutputModifier::Address:
96 ActionBusSource(MeterBus_t,
97 TableOutputModifier m = TableOutputModifier::NONE)
100 case TableOutputModifier::Color:
103 case TableOutputModifier::Address:
111 ActionBusSource(RandomNumberGen r) : type(RandomGen) {
115 ActionBusSource(InputXbar::Group grp,
int byte) : type(XcmpData) {
116 BUG_CHECK(grp.type == InputXbar::Group::XCMP,
"Not xcmp ixbar");
118 xcmp_data.xcmp_group = grp.index;
119 xcmp_data.xcmp_byte = byte;
121 bool operator==(
const ActionBusSource &a)
const {
122 if (type == XcmpData)
123 return a.type == XcmpData && xcmp_data.xcmp_group == a.xcmp_data.xcmp_group &&
124 xcmp_data.xcmp_byte == a.xcmp_data.xcmp_byte;
125 if (type == HashDistPair && hd_tuple.hd2 != a.hd_tuple.hd2)
return false;
126 return type == a.type && field == a.field;
128 bool operator<(
const ActionBusSource &a)
const {
129 if (type != a.type)
return type < a.type;
132 return hd_tuple.hd1 == a.hd_tuple.hd1 ? hd_tuple.hd2 < a.hd_tuple.hd2
133 : hd_tuple.hd1 < a.hd_tuple.hd1;
135 return xcmp_data.xcmp_group == a.xcmp_data.xcmp_group
136 ? xcmp_data.xcmp_byte < a.xcmp_data.xcmp_byte
137 : xcmp_data.xcmp_group < a.xcmp_data.xcmp_group;
139 return field < a.field;
142 std::string name(Table *tbl)
const;
143 std::string toString(Table *tbl)
const;
144 friend std::ostream &operator<<(std::ostream &,
const ActionBusSource &);
159 Slot(std::string n,
unsigned b,
unsigned s) : name(n), byte(b), size(s) {}
160 Slot(std::string n,
unsigned b,
unsigned s,
ActionBusSource src,
unsigned off)
161 : name(n), byte(b), size(s) {
162 data.emplace(src, off);
164 unsigned lo(
Table *tbl)
const;
165 bool is_table_output()
const {
166 for (
auto &d : data) {
167 BUG_CHECK(d.first.type != ActionBusSource::NameRef,
"Unexpected name ref");
168 if (d.first.type == ActionBusSource::TableOutput)
return true;
173 friend std::ostream &operator<<(std::ostream &,
const Slot &);
174 friend std::ostream &operator<<(std::ostream &,
const ActionBus &);
181 std::vector<std::array<unsigned, ACTION_HV_XBAR_SLICES>> action_hv_slice_use;
188 unsigned sz,
unsigned off);
190 int find_free(
Table *tbl,
unsigned min,
unsigned max,
unsigned step,
unsigned lobyte,
193 bool check_atcam_sharing(
Table *tbl1,
Table *tbl2);
196 ActionBus() : lineno(-1) {}
201 static std::unique_ptr<ActionBus> create();
202 static std::unique_ptr<ActionBus> create(
Table *, VECTOR(
pair_t) &);
204 void pass1(
Table *tbl);
205 void pass2(
Table *tbl) {}
206 void pass3(Table *tbl);
207 template <
class REGS>
208 void write_immed_regs(REGS ®s, Table *tbl);
209 template <
class REGS>
210 void write_action_regs(REGS ®s, Table *tbl,
int homerow,
unsigned action_slice);
212 void do_alloc(Table *tbl, ActionBusSource src,
unsigned use,
int lobyte,
int bytes,
214 static const unsigned size_masks[8];
215 virtual void alloc_field(Table *, ActionBusSource src,
unsigned offset,
unsigned sizes_needed);
216 void need_alloc(Table *tbl,
const ActionBusSource &src,
unsigned lo,
unsigned hi,
218 void need_alloc(Table *tbl, Table *attached, TableOutputModifier mod,
unsigned lo,
unsigned hi,
220 need_alloc(tbl, ActionBusSource(attached, mod), lo, hi, size);
223 int find(
const char *name, TableOutputModifier mod,
int lo,
int hi,
int size,
int *len = 0);
224 int find(
const char *name,
int lo,
int hi,
int size,
int *len = 0) {
225 return find(name, TableOutputModifier::NONE, lo, hi, size, len);
227 int find(
const std::string &name, TableOutputModifier mod,
int lo,
int hi,
int size,
229 return find(name.c_str(), mod, lo, hi, size, len);
231 int find(
const std::string &name,
int lo,
int hi,
int size,
int *len = 0) {
232 return find(name.c_str(), lo, hi, size, len);
234 int find(
const ActionBusSource &src,
int lo,
int hi,
int size,
int pos = -1,
int *len = 0);
235 int find(Table *attached, TableOutputModifier mod,
int lo,
int hi,
int size,
int *len = 0) {
236 return find(ActionBusSource(attached, mod), lo, hi, size, -1, len);
238 static int find(Stage *stage, ActionBusSource src,
int lo,
int hi,
int size,
int *len = 0);
241 for (
auto &slot : by_byte) rv += slot.second.size;
244 auto slots()
const {
return Values(by_byte); }
int find_free(Table *tbl, unsigned min, unsigned max, unsigned step, unsigned lobyte, unsigned bytes)
Definition action_bus.cpp:545
int find(const char *name, TableOutputModifier mod, int lo, int hi, int size, int *len=0)
find an action bus slot that contains the requested thing.
Definition action_bus.cpp:786
int find_merge(Table *tbl, int offset, int bytes, int use)
Definition action_bus.cpp:595