P4C
The P4 Compiler
Loading...
Searching...
No Matches
mau_spec.h
1
19#ifndef BACKENDS_TOFINO_BF_P4C_MAU_MAU_SPEC_H_
20#define BACKENDS_TOFINO_BF_P4C_MAU_MAU_SPEC_H_
21
22#include "ir/ir.h"
23
24// device-specific parameters for MAU/PPU.
25using namespace P4;
26
27class IMemSpec {
28 public:
29 virtual int rows() const = 0; // pure virtual
30 virtual int colors() const = 0; // pure virtual
31 virtual int color_bits() const = 0; // pure virtual
32 virtual int address_bits() const = 0;
33 virtual int map_table_entries() const = 0;
34};
35
36class TofinoIMemSpec : public IMemSpec {
37 int rows() const override;
38 int colors() const override;
39 int color_bits() const override;
40 int address_bits() const override;
41 int map_table_entries() const override;
42};
43
44class IXBarSpec {
45 public:
46 /* --- common --- */
47 virtual int ternaryBytesPerGroup() const = 0; // pure virtual
48 virtual int ternaryGroups() const = 0; // pure virtual
49
50 // the next two: support for "legacy code" [as of Nov. 10 2022] that gets these via IXBarSpec
51 virtual int tcam_rows() const = 0; // pure virtual
52 virtual int tcam_columns() const = 0; // pure virtual
53
54 /* --- Tofino[1, 2] --- */
55 virtual int byteGroups() const;
56 virtual int exactBytesPerGroup() const;
57 virtual int exactGroups() const;
58 virtual int fairModeHashBits() const;
59 virtual int gatewaySearchBytes() const;
60 virtual int hashDistBits() const;
61 virtual int hashDistExpandBits() const;
62 virtual int hashDistMaxMaskBits() const;
63 virtual int hashDistSlices() const;
64 virtual int hashDistUnits() const;
65 virtual int hashGroups() const;
66 virtual int hashIndexGroups() const;
67 virtual int hashMatrixSize() const;
68 virtual int hashParityBit() const;
69 virtual int hashSingleBits() const;
70 virtual int hashTables() const;
71 virtual int lpfInputBytes() const;
72 virtual int maxHashBits() const;
73 virtual int meterAluHashBits() const;
74 virtual int meterAluHashParityByteStart() const;
75 virtual int meterPrecolorSize() const;
76 virtual int ramLineSelectBits() const;
77 virtual int ramSelectBitStart() const;
78 virtual int repeatingConstraintSect() const;
79 virtual int resilientModeHashBits() const;
80 virtual int ternaryBytesPerBigGroup() const;
81 virtual int tofinoMeterAluByteOffset() const;
82
83 virtual int getExactOrdBase(int group) const = 0;
84 virtual int getTernaryOrdBase(int group) const = 0;
85 virtual int exactMatchTotalBytes() const = 0;
86 virtual int ternaryMatchTotalBytes() const = 0;
87 virtual int xcmpMatchTotalBytes() const = 0;
88};
89
90// TU-local constants to avoid circular dependencies between IXBarSpec subclasses
91// and their respective MauSpec subclasses, while still preserving DRY compliance.
92static constexpr int Tofino_tcam_rows = 12;
93static constexpr int Tofino_tcam_columns = 2;
94
95class MauSpec {
96 public:
97 virtual const IXBarSpec &getIXBarSpec() const = 0; // pure virtual
98 virtual const IMemSpec &getIMemSpec() const = 0; // pure virtual
99
100 // Called at the end of table rewriting in TablePlacement::TransformTables to do
101 // any target-specific fixups needed
102 virtual IR::Node *postTransformTables(IR::MAU::Table *const table) const;
103
104 // The next 4 lines: correct data for Tof.1 + Tof.2 + Tof.3; must override elsewhere for Tof.5
105 virtual int tcam_rows() const;
106 virtual int tcam_columns() const;
107 virtual int tcam_width() const;
108 virtual int tcam_depth() const;
109};
110
112 public:
114
115 int byteGroups() const override;
116
117 int hashDistMaxMaskBits() const override;
118
119 int hashMatrixSize() const override;
120
121 int ternaryGroups() const override;
122
123 int exactBytesPerGroup() const override;
124 int exactGroups() const override;
125 int fairModeHashBits() const override;
126 int gatewaySearchBytes() const override;
127 int hashDistBits() const override;
128 int hashDistExpandBits() const override;
129 int hashDistSlices() const override;
130 int hashDistUnits() const override;
131 int hashGroups() const override;
132
133 int hashIndexGroups() const override;
134 /* groups of 10 bits for indexing */
135
136 int hashParityBit() const override;
137 /* If enabled reserved parity bit position */
138
139 int hashSingleBits() const override;
140 /* top 12 bits of hash table individually */
141
142 int hashTables() const override;
143 int lpfInputBytes() const override;
144 int maxHashBits() const override;
145 int meterAluHashBits() const override;
146 int meterAluHashParityByteStart() const override;
147 int meterPrecolorSize() const override;
148 int ramLineSelectBits() const override;
149 int ramSelectBitStart() const override;
150 int repeatingConstraintSect() const override;
151 int resilientModeHashBits() const override;
152 int ternaryBytesPerBigGroup() const override;
153 int ternaryBytesPerGroup() const override;
154 int tofinoMeterAluByteOffset() const override;
155
156 // the next two: support for "legacy code" [as of Nov. 10 2022] that gets these via IXBarSpec
157 int tcam_rows() const override;
158 int tcam_columns() const override;
159
160 int getExactOrdBase(int group) const override;
161 int getTernaryOrdBase(int group) const override;
162
163 int exactMatchTotalBytes() const override;
164 int ternaryMatchTotalBytes() const override;
165 int xcmpMatchTotalBytes() const override;
166};
167
168class TofinoMauSpec : public MauSpec {
169 const TofinoIXBarSpec ixbar_;
170 const TofinoIMemSpec imem_;
171
172 public:
173 TofinoMauSpec() = default;
174 const IXBarSpec &getIXBarSpec() const override;
175 const IMemSpec &getIMemSpec() const override;
176};
177
178class JBayMauSpec : public MauSpec {
179 const TofinoIXBarSpec ixbar_;
180 const TofinoIMemSpec imem_;
181
182 public:
183 JBayMauSpec() = default;
184 const IXBarSpec &getIXBarSpec() const override;
185 const IMemSpec &getIMemSpec() const override;
186};
187
188#endif /* BACKENDS_TOFINO_BF_P4C_MAU_MAU_SPEC_H_ */
Definition mau_spec.h:27
Definition mau_spec.h:44
Definition mau_spec.h:178
Definition mau_spec.h:95
Definition node.h:95
Definition mau_spec.h:36
Definition mau_spec.h:111
int getExactOrdBase(int group) const override
Definition tofino/mau_spec.cpp:23
Definition mau_spec.h:168
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24