Skip to content

Commit

Permalink
Support for 128 bit operations
Browse files Browse the repository at this point in the history
Signed-off-by: Sosutha Sethuramapandian
<[email protected]>

* Added movh statement definition
* Added support for 128 bitwise operation
* Added support for 128 bit equal and not equal operators.
* Added support for 128 bit compliment operation
* Updated testcase and output
  • Loading branch information
Sosutha committed Oct 23, 2024
1 parent b4a9df0 commit d40ff2f
Show file tree
Hide file tree
Showing 23 changed files with 4,807 additions and 63 deletions.
3 changes: 2 additions & 1 deletion backends/dpdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ set (P4_16_SUITES
"${P4C_SOURCE_DIR}/testdata/p4_16_samples/pna-*.p4"
"${P4C_SOURCE_DIR}/testdata/p4_16_psa_errors/*.p4"
"${P4C_SOURCE_DIR}/testdata/p4_16_dpdk_errors/*.p4"
"${P4C_SOURCE_DIR}/testdata/p4_16_pna_errors/*.p4")
"${P4C_SOURCE_DIR}/testdata/p4_16_pna_errors/*.p4"
"${P4C_SOURCE_DIR}/testdata/p4_16_samples/dash/dash-pipeline-pna-dpdk.p4")
p4c_add_tests("dpdk" ${DPDK_COMPILER_DRIVER} "${P4_16_SUITES}" "" "--bfrt")

#### DPDK-PTF Tests
Expand Down
1 change: 1 addition & 0 deletions backends/dpdk/DpdkXfail.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ p4c_add_xfail_reason("dpdk"
testdata/p4_16_samples/pna-dpdk-invalid-hdr-warnings5.p4
testdata/p4_16_samples/pna-dpdk-invalid-hdr-warnings6.p4
testdata/p4_16_samples/pna-dpdk-header-union-stack2.p4
testdata/p4_16_samples/dash/dash-pipeline-pna-dpdk.p4
)

p4c_add_xfail_reason("dpdk"
Expand Down
4 changes: 4 additions & 0 deletions backends/dpdk/dbprint-dpdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ void IR::DpdkMovStatement::dbprint(std::ostream &out) const {
out << "mov " << dst << " " << src << std::endl;
}

void IR::DpdkMovhStatement::dbprint(std::ostream &out) const {
out << "movh " << dst << " " << src << std::endl;
}

} // namespace P4
14 changes: 14 additions & 0 deletions backends/dpdk/dpdk.def
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class DpdkHeaderType : Type_Header, IDPDKNode {
#nodbprint
}

class DpdkHeaderInstance : IDPDKNode {
Declaration_Variable name;
Type_Header headerType;
std::ostream& toSpec(std::ostream& out) const override;
#nodbprint
}

class DpdkStructType : Type_Struct, IDPDKNode {
std::ostream& toSpec(std::ostream& out) const override;
#nodbprint
Expand Down Expand Up @@ -99,6 +106,7 @@ class DpdkLearner {
class DpdkAsmProgram {
inline IndexedVector<DpdkHeaderType> headerType;
inline IndexedVector<DpdkStructType> structType;
inline IndexedVector<DpdkHeaderInstance> headerInstance;
inline IndexedVector<DpdkExternDeclaration> externDeclarations;
inline IndexedVector<DpdkAction> actions;
inline IndexedVector<DpdkTable> tables;
Expand Down Expand Up @@ -304,6 +312,12 @@ class DpdkMovStatement : DpdkUnaryStatement {
#noconstructor
}

class DpdkMovhStatement : DpdkUnaryStatement {
DpdkMovhStatement(Expression dst, Expression src) :
DpdkUnaryStatement("movh"_cs, dst, src) { }
#noconstructor
}

abstract DpdkBinaryStatement : DpdkAssignmentStatement {
Expression src1;
Expression src2;
Expand Down
11 changes: 11 additions & 0 deletions backends/dpdk/dpdkArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1101,13 +1101,24 @@ class ValidateOperandSize : public Inspector {
}

void postorder(const IR::Operation_Binary *binop) override {
if (binop->is<IR::BOr>() || binop->is<IR::BAnd>() || binop->is<IR::BXor>() ||
binop->is<IR::Equ>() || binop->is<IR::Neq>()) {
if (auto src1Type = binop->left->type->to<IR::Type_Bits>()) {
if (src1Type->width_bits() == 128) return;
}
}
isValidOperandSize(binop->left);
isValidOperandSize(binop->right);
}

// Reject all operations except typecast if the operand size is beyond the supported limit
void postorder(const IR::Operation_Unary *unop) override {
if (unop->is<IR::Cast>()) return;
if (unop->is<IR::Cmpl>()) {
if (auto src1Type = unop->expr->type->to<IR::Type_Bits>()) {
if (src1Type->width_bits() == 128) return;
}
}
isValidOperandSize(unop->expr);
}

Expand Down
354 changes: 314 additions & 40 deletions backends/dpdk/dpdkHelpers.cpp

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions backends/dpdk/dpdkHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ limitations under the License.

namespace P4::DPDK {

class ConvertStatementToDpdk;

/// @brief Name of the metadata used as output port.
///
/// PNA specification does not contain standard metadata for specifying output port.
Expand Down Expand Up @@ -115,6 +117,7 @@ const char DirectResourceTableEntryIndex[] = "table_entry_index";
* optmized.
*/
class BranchingInstructionGeneration {
ConvertStatementToDpdk *convert;
P4::ReferenceMap *refMap;
P4::TypeMap *typeMap;
bool nested(const IR::Node *n) {
Expand All @@ -126,9 +129,9 @@ class BranchingInstructionGeneration {
}

public:
IR::IndexedVector<IR::DpdkAsmStatement> instructions;
BranchingInstructionGeneration(P4::ReferenceMap *refMap, P4::TypeMap *typeMap)
: refMap(refMap), typeMap(typeMap) {}
BranchingInstructionGeneration(ConvertStatementToDpdk *convert, P4::ReferenceMap *refMap,
P4::TypeMap *typeMap)
: convert(convert), refMap(refMap), typeMap(typeMap) {}
bool generate(const IR::Expression *, cstring, cstring, bool);
};

Expand All @@ -150,13 +153,18 @@ class ConvertStatementToDpdk : public Inspector {
const IR::P4Parser *parser = nullptr;
const IR::Node *parent = nullptr;
IR::Type_Struct *metadataStruct = nullptr;
bool createSandboxHeaderType = false;
bool createTmpVar = false;

private:
void processHashParams(const IR::Argument *field, IR::Vector<IR::Expression> &components);
bool checkIfBelongToSameHdrMdStructure(const IR::Argument *field);
void updateMdStrAndGenInstr(const IR::Argument *field, IR::Vector<IR::Expression> &components);
cstring getHdrMdStrName(const IR::Member *mem);
bool checkIfConsecutiveHdrMdfields(const IR::Argument *field);
void createSandboxHeader();
void createTmpVarForSandbox();
friend class BranchingInstructionGeneration;

public:
ConvertStatementToDpdk(P4::ReferenceMap *refmap, P4::TypeMap *typemap,
Expand Down Expand Up @@ -185,8 +193,13 @@ class ConvertStatementToDpdk : public Inspector {
void set_parser(const IR::P4Parser *p) { parser = p; }
void set_parent(const IR::Node *p) { parent = p; }
bool handleConstSwitch(const IR::SwitchStatement *a);
bool checkIf128bitOp(const IR::Expression *, const IR::Expression *);
void add128bitwiseInstr(const IR::Expression *src1Op, const IR::Expression *src2Op,
const char *op);
void add128ComparisonInstr(cstring true_label, const IR::Expression *src1Op,
const IR::Expression *src2Op, const char *op);
void add128bitComplInstr(const IR::Expression *, const IR::Expression *);
};

/// Only simplify complex expression in ingress/egress.
class ProcessControls : public P4::RemoveComplexExpressionsPolicy {
const std::set<cstring> *process;
Expand Down
11 changes: 9 additions & 2 deletions backends/dpdk/dpdkProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,15 @@ const IR::DpdkAsmProgram *ConvertToDpdkProgram::create(IR::P4Program *prog) {
learners.append(egress_converter->getLearners());
}

return new IR::DpdkAsmProgram(headerType, structType, dpdkExternDecls, actions, tables,
selectors, learners, statements, structure->get_globals());
IR::IndexedVector<IR::DpdkHeaderInstance> headerInstances;

for (auto it : structure->header_instances) {
headerInstances.push_back(it.second);
}

return new IR::DpdkAsmProgram(headerType, structType, headerInstances, dpdkExternDecls, actions,
tables, selectors, learners, statements,
structure->get_globals());
}

const IR::Node *ConvertToDpdkProgram::preorder(IR::P4Program *prog) {
Expand Down
7 changes: 7 additions & 0 deletions backends/dpdk/dpdkProgramStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct DpdkProgramStructure {
ordered_map<cstring, const IR::P4Table *> learner_action_table;
ordered_map<cstring, enum InternalTableType> table_type_map;
ordered_map<cstring, const IR::P4Table *> direct_resource_map;
ordered_map<cstring, const IR::DpdkHeaderInstance *> header_instances;

IR::IndexedVector<IR::DpdkDeclaration> variables;

Expand Down Expand Up @@ -70,6 +71,12 @@ struct DpdkProgramStructure {
void push_variable(const IR::DpdkDeclaration *d) { variables.push_back(d); }
IR::IndexedVector<IR::DpdkDeclaration> &get_globals() { return variables; }

void addHeaderInstances(const IR::DpdkHeaderInstance *d) {
if (header_instances.find(d->name->toString()) == header_instances.end()) {
header_instances.emplace(d->name->toString(), d);
}
}

bool hasVisited(const IR::Type_StructLike *st) {
if (auto h = st->to<IR::Type_Header>())
return header_types.count(h->getName());
Expand Down
9 changes: 9 additions & 0 deletions backends/dpdk/spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ std::ostream &IR::DpdkAsmProgram::toSpec(std::ostream &out) const {
add_comment(out, s->name.toString());
s->toSpec(out) << std::endl;
}
for (auto hi : headerInstance) {
add_comment(out, hi->name->toString());
hi->toSpec(out) << std::endl;
}
for (auto s : externDeclarations) {
add_comment(out, s->name.toString());
s->toSpec(out);
Expand Down Expand Up @@ -213,6 +217,11 @@ std::ostream &IR::DpdkHeaderType::toSpec(std::ostream &out) const {
return out;
}

std::ostream &IR::DpdkHeaderInstance::toSpec(std::ostream &out) const {
out << "header " << name->toString() << " instanceof " << headerType->toString();
return out;
}

std::ostream &IR::DpdkStructType::toSpec(std::ostream &out) const {
if (getAnnotations()->getSingle("__packet_data__"_cs)) {
for (auto it = fields.begin(); it != fields.end(); ++it) {
Expand Down
Loading

0 comments on commit d40ff2f

Please sign in to comment.