Skip to content

Commit

Permalink
Support for 128 bit constants in dpdk backend
Browse files Browse the repository at this point in the history
Signed-off-by : Sosutha Sethuramapandian <sosutha.sethuramapandian@intel.com>

* Added support for 128 bit constants usage in dpdk backend
* Updated testcases and outputs
  • Loading branch information
Sosutha committed Nov 11, 2024
1 parent 6f7353f commit 6ca3177
Show file tree
Hide file tree
Showing 27 changed files with 6,189 additions and 1,257 deletions.
1 change: 0 additions & 1 deletion backends/dpdk/DpdkXfail.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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
8 changes: 8 additions & 0 deletions backends/dpdk/dpdkArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2957,6 +2957,14 @@ MoveNonHeaderFieldsToPseudoHeader::addAssignmentStmt(const IR::Expression *e) {
const IR::Node *MoveNonHeaderFieldsToPseudoHeader::postorder(IR::AssignmentStatement *assn) {
if (is_all_args_header) return assn;
auto result = new IR::IndexedVector<IR::StatOrDecl>();
if (isLargeFieldOperand(assn->left) && assn->right->is<IR::Constant>()) {
auto leftType = assn->left->type->to<IR::Type_Bits>()->width_bits();
auto rightType = assn->right->type->to<IR::Type_Bits>()->width_bits();
if (leftType == 128 && rightType == leftType) {
auto cst = assn->right->to<IR::Constant>();
if (!cst->fitsUint64()) return assn;
}
}
if ((isLargeFieldOperand(assn->left) && !isLargeFieldOperand(assn->right) &&
!isInsideHeader(assn->right)) ||
(isLargeFieldOperand(assn->left) && assn->right->is<IR::Constant>())) {
Expand Down
64 changes: 55 additions & 9 deletions backends/dpdk/dpdkHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,11 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) {
}
} else if (right->is<IR::PathExpression>() || right->is<IR::Member>() ||
right->is<IR::BoolLiteral>() || right->is<IR::Constant>()) {
i = new IR::DpdkMovStatement(a->left, a->right);
if (right->is<IR::Constant>() && right->type->to<IR::Type_Bits>()->width_bits() == 128) {
add128bitMovInstr(left, right);
} else {
i = new IR::DpdkMovStatement(left, right);
}
} else {
std::cerr << right->node_type_name() << std::endl;
BUG("Not implemented.");
Expand Down Expand Up @@ -1559,22 +1563,25 @@ void ConvertStatementToDpdk::add128bitwiseInstr(const IR::Expression *src1Op,
add_instr(new IR::DpdkMovhStatement(src1OpUpper, src1Op));
add_instr(new IR::DpdkMovStatement(src1OpLower, src1Op));
if (src2Op->is<IR::Constant>()) {
auto ConstVal = src2Op->to<IR::Constant>()->value;
auto upperConst = new IR::Constant(ConstVal >> 64);
auto lowerConst = new IR::Constant(ConstVal & 0xFFFFFFFFFFFFFFFF);
add_instr(new IR::DpdkMovStatement(tmp, src1OpLower));
if (strcmp(op, "xor") == 0) {
add_instr(new IR::DpdkXorStatement(tmp, tmp, src2Op));
add_instr(new IR::DpdkXorStatement(tmp, tmp, lowerConst));
} else if (strcmp(op, "or") == 0) {
add_instr(new IR::DpdkOrStatement(tmp, tmp, src2Op));
add_instr(new IR::DpdkOrStatement(tmp, tmp, lowerConst));
} else if (strcmp(op, "and") == 0) {
add_instr(new IR::DpdkAndStatement(tmp, tmp, src2Op));
add_instr(new IR::DpdkAndStatement(tmp, tmp, lowerConst));
}
add_instr(new IR::DpdkMovStatement(src1Op, tmp));
add_instr(new IR::DpdkMovStatement(tmp, src1OpUpper));
if (strcmp(op, "xor") == 0) {
add_instr(new IR::DpdkXorStatement(tmp, tmp, src2Op));
add_instr(new IR::DpdkXorStatement(tmp, tmp, upperConst));
} else if (strcmp(op, "or") == 0) {
add_instr(new IR::DpdkOrStatement(tmp, tmp, src2Op));
add_instr(new IR::DpdkOrStatement(tmp, tmp, upperConst));
} else if (strcmp(op, "and") == 0) {
add_instr(new IR::DpdkAndStatement(tmp, tmp, src2Op));
add_instr(new IR::DpdkAndStatement(tmp, tmp, upperConst));
}
add_instr(new IR::DpdkMovhStatement(src1Op, tmp));
} else {
Expand Down Expand Up @@ -1659,8 +1666,11 @@ void ConvertStatementToDpdk::add128ComparisonInstr(cstring true_label, const IR:
add_instr(new IR::DpdkMovhStatement(src1OpUpper, src1Op));
add_instr(new IR::DpdkMovStatement(src1OpLower, src1Op));
if (src2Op->is<IR::Constant>()) {
add_instr(new IR::DpdkXorStatement(src1OpUpper, src1OpUpper, src2Op));
add_instr(new IR::DpdkXorStatement(src1OpLower, src1OpLower, src2Op));
auto ConstVal = src2Op->to<IR::Constant>()->value;
auto upperConst = new IR::Constant(ConstVal >> 64);
auto lowerConst = new IR::Constant(ConstVal & 0xFFFFFFFFFFFFFFFF);
add_instr(new IR::DpdkXorStatement(src1OpUpper, src1OpUpper, upperConst));
add_instr(new IR::DpdkXorStatement(src1OpLower, src1OpLower, lowerConst));
} else {
auto src2OpHeaderName = src2Op->toString();
if (src2Op->is<IR::Member>()) {
Expand Down Expand Up @@ -1734,4 +1744,40 @@ void ConvertStatementToDpdk::add128bitComplInstr(const IR::Expression *dst,
add_instr(new IR::DpdkMovStatement(dst, src1OpLower));
add_instr(new IR::DpdkMovhStatement(dst, src1OpUpper));
}

void ConvertStatementToDpdk::add128bitMovInstr(const IR::Expression *left,
const IR::Expression *right) {
if (!createSandboxHeaderType) {
createSandboxHeaderType = true;
createSandboxHeader();
}
const IR::Type_Header *Type_Header = nullptr;
for (auto header : structure->header_types) {
if (strcmp(header.first, "_p4c_sandbox_header_t") == 0) {
Type_Header = header.second;
}
}
if (Type_Header == nullptr) {
BUG("Header type not found");
}
auto leftHeaderName = left->toString();
if (left->is<IR::Member>()) {
leftHeaderName = left->to<IR::Member>()->member.name;
}
leftHeaderName = leftHeaderName + "_128";
auto leftHeader = new IR::Declaration_Variable(leftHeaderName, Type_Header);
auto leftHeaderInstance = new IR::DpdkHeaderInstance(leftHeader, Type_Header);
structure->addHeaderInstances(leftHeaderInstance);
auto leftUpper =
new IR::Member(new IR::PathExpression("h." + leftHeader->name), IR::ID("upper_half"));
auto leftLower =
new IR::Member(new IR::PathExpression("h." + leftHeader->name), IR::ID("lower_half"));
auto ConstVal = right->to<IR::Constant>()->value;
auto upperConst = new IR::Constant(ConstVal >> 64);
auto lowerConst = new IR::Constant(ConstVal & 0xFFFFFFFFFFFFFFFF);
add_instr(new IR::DpdkMovStatement(leftUpper, upperConst));
add_instr(new IR::DpdkMovStatement(leftLower, lowerConst));
add_instr(new IR::DpdkMovStatement(left, leftLower));
add_instr(new IR::DpdkMovhStatement(left, leftUpper));
}
} // namespace P4::DPDK
1 change: 1 addition & 0 deletions backends/dpdk/dpdkHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class ConvertStatementToDpdk : public Inspector {
void add128ComparisonInstr(cstring true_label, const IR::Expression *src1Op,
const IR::Expression *src2Op, const char *op);
void add128bitComplInstr(const IR::Expression *, const IR::Expression *);
void add128bitMovInstr(const IR::Expression *left, const IR::Expression *right);
};
/// Only simplify complex expression in ingress/egress.
class ProcessControls : public P4::RemoveComplexExpressionsPolicy {
Expand Down
Loading

0 comments on commit 6ca3177

Please sign in to comment.