diff --git a/backends/dpdk/dpdkHelpers.cpp b/backends/dpdk/dpdkHelpers.cpp index 4d6d9eb6e47..1096b851321 100644 --- a/backends/dpdk/dpdkHelpers.cpp +++ b/backends/dpdk/dpdkHelpers.cpp @@ -120,6 +120,7 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { } else if (auto r = right->to()) { auto src1Op = r->left; auto src2Op = r->right; + bool isSignExtended = false; if (r->left->is()) { if (isCommutativeBinaryOperation(r)) { src1Op = r->right; @@ -134,27 +135,58 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { src1Op = src1Member; } } + /* If a constant is present in binary operation and it is not 8-bit + aligned and it is signed, then the constant value is sign extended + with a width of either 32 bit if its original bit-width is less than + 32 bit or 64 bit if the bit-width of constant is greater than 32 bit + */ + + if (!isEightBitAligned(src2Op) && src2Op->is()) { + if (auto tb = src2Op->type->to()) { + if (tb != nullptr && tb->isSigned) { + isSignExtended = true; + auto consOrgBitwidth = src2Op->to()->type->width_bits(); + auto bitWidth = consOrgBitwidth < 32 ? 32 : 64; + auto consValue = src2Op->to()->value; + auto val = consValue << (bitWidth - consOrgBitwidth); + consValue = val >> (bitWidth - consOrgBitwidth); + src2Op = new IR::Constant(IR::Type_Bits::get(bitWidth), consValue); + } + } + } + if (right->is()) { - i = new IR::DpdkAddStatement(left, src1Op, src2Op); + add_instr(new IR::DpdkAddStatement(left, src1Op, src2Op)); } else if (right->is()) { - i = new IR::DpdkSubStatement(left, src1Op, src2Op); + add_instr(new IR::DpdkSubStatement(left, src1Op, src2Op)); } else if (right->is()) { - i = new IR::DpdkShlStatement(left, src1Op, src2Op); + add_instr(new IR::DpdkShlStatement(left, src1Op, src2Op)); } else if (right->is()) { - i = new IR::DpdkShrStatement(left, src1Op, src2Op); + add_instr(new IR::DpdkShrStatement(left, src1Op, src2Op)); } else if (right->is()) { - i = new IR::DpdkEquStatement(left, src1Op, src2Op); + add_instr(new IR::DpdkEquStatement(left, src1Op, src2Op)); } else if (right->is() || right->is()) { process_logical_operation(left, r); } else if (right->is()) { - i = new IR::DpdkOrStatement(left, src1Op, src2Op); + add_instr(new IR::DpdkOrStatement(left, src1Op, src2Op)); } else if (right->is()) { - i = new IR::DpdkAndStatement(left, src1Op, src2Op); + add_instr(new IR::DpdkAndStatement(left, src1Op, src2Op)); } else if (right->is()) { - i = new IR::DpdkXorStatement(left, src1Op, src2Op); + add_instr(new IR::DpdkXorStatement(left, src1Op, src2Op)); } else { BUG("%1% not implemented.", right); } + /* If there is a binary operation present which involves non 8-bit aligned + fields , add BAnd operation with mask value of original bit-width to + avoid any result overflow */ + if (!isEightBitAligned(left) && !isSignExtended) { + if (right->is() || right->is() || + right->is() || right->is()) { + auto width = left->type->width_bits(); + auto mask = (1 << width) - 1; + add_instr(new IR::DpdkAndStatement(left, left, new IR::Constant(mask))); + } + } } else if (auto m = right->to()) { auto mi = P4::MethodInstance::resolve(m, refmap, typemap); if (auto e = mi->to()) { diff --git a/backends/dpdk/dpdkUtils.cpp b/backends/dpdk/dpdkUtils.cpp index 5406d50a3fa..222eff7055e 100644 --- a/backends/dpdk/dpdkUtils.cpp +++ b/backends/dpdk/dpdkUtils.cpp @@ -63,4 +63,10 @@ bool isMetadataStruct(const IR::Type_Struct *st) { return false; } +bool isEightBitAligned(const IR::Expression *e) { + if (e->type->width_bits() % 8 != 0) + return false; + return true; +} + } // namespace DPDK diff --git a/backends/dpdk/dpdkUtils.h b/backends/dpdk/dpdkUtils.h index c644448bb64..bd8729a53bc 100644 --- a/backends/dpdk/dpdkUtils.h +++ b/backends/dpdk/dpdkUtils.h @@ -24,5 +24,6 @@ bool isNonConstantSimpleExpression(const IR::Expression *e); bool isCommutativeBinaryOperation(const IR::Operation_Binary *bin); bool isStandardMetadata(cstring name); bool isMetadataStruct(const IR::Type_Struct *st); +bool isEightBitAligned(const IR::Expression *e); } // namespace DPDK #endif /* BACKENDS_DPDK_DPDKUTILS_H_ */ diff --git a/testdata/p4_16_samples/psa-subtract-inst1.p4 b/testdata/p4_16_samples/psa-subtract-inst1.p4 new file mode 100644 index 00000000000..3dcda5c84d9 --- /dev/null +++ b/testdata/p4_16_samples/psa-subtract-inst1.p4 @@ -0,0 +1,146 @@ +/* -*- P4_16 -*- */ +#include +#include + +/************ H E A D E R S ******************************/ +#define MAX_LAYERS 2 + +struct EMPTY {}; + +header ethernet_t { + bit<48> dst_addr; + bit<48> src_addr; + bit<16> ether_type; +} + +header udp_t { + bit<16> sport; + bit<16> dport; + bit<16> length; + bit<16> csum; +} + +struct headers_t { + ethernet_t ethernet; + udp_t[MAX_LAYERS] udp; +} + +struct user_meta_data_t { + bit<48> addr; + bit<3> depth1; + bit<5> depth2; + bit<5> depth3; + bit<5> depth4; + bit<5> depth5; + bit<5> depth6; + bit<5> depth7; +} + +/************************************************************************* + **************** I N G R E S S P R O C E S S I N G ***************** + *************************************************************************/ +parser MyIngressParser( + packet_in pkt, + out headers_t hdr, + inout user_meta_data_t m, + in psa_ingress_parser_input_metadata_t c, + in EMPTY d, + in EMPTY e) { + + state start { + m.depth1 = m.depth1 - 1; + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control MyIngressControl( + inout headers_t hdrs, + inout user_meta_data_t meta, + in psa_ingress_input_metadata_t c, + inout psa_ingress_output_metadata_t d) { + bit<5> var1 = 8; + bit<5> var2 = 2; + int<33> var3; + int<33> var4 = var3 - 3; + action nonDefAct() { + if (var4 == 3) { + meta.depth3 = meta.depth3 - 3; + meta.depth4 = var1 + var2; + meta.depth5 = var1 ^ 2; + meta.depth6 = var2 - 1; + meta.depth7 = var2 + 3; + } + } + + table stub { + key = {} + + actions = { + nonDefAct; + } + const default_action = nonDefAct; + size=1000000; + } + + apply { + meta.depth4 = meta.depth2 - 4; + d.egress_port = (PortId_t) ((bit <32>) c.ingress_port ^ 1); + stub.apply(); + } +} + +control MyIngressDeparser( + packet_out pkt, + out EMPTY a, + out EMPTY b, + out EMPTY c, + inout headers_t hdr, + in user_meta_data_t e, + in psa_ingress_output_metadata_t f) { + + apply { + pkt.emit(hdr.ethernet); + } +} + +/************************************************************************* + **************** E G R E S S P R O C E S S I N G ******************* + *************************************************************************/ +parser MyEgressParser( + packet_in pkt, + out EMPTY a, + inout EMPTY b, + in psa_egress_parser_input_metadata_t c, + in EMPTY d, + in EMPTY e, + in EMPTY f) { + state start { + transition accept; + } +} + +control MyEgressControl( + inout EMPTY a, + inout EMPTY b, + in psa_egress_input_metadata_t c, + inout psa_egress_output_metadata_t d) { + apply {} +} +control MyEgressDeparser( + packet_out pkt, + out EMPTY a, + out EMPTY b, + inout EMPTY c, + in EMPTY d, + in psa_egress_output_metadata_t e, + in psa_egress_deparser_input_metadata_t f) { + apply {} +} + +/************ F I N A L P A C K A G E ******************************/ +IngressPipeline(MyIngressParser(), MyIngressControl(), MyIngressDeparser()) ip; + +EgressPipeline(MyEgressParser(), MyEgressControl(), MyEgressDeparser()) ep; + +PSA_Switch(ip, PacketReplicationEngine(), ep, BufferingQueueingEngine()) main; diff --git a/testdata/p4_16_samples_outputs/pna-example-varIndex-1.p4.spec b/testdata/p4_16_samples_outputs/pna-example-varIndex-1.p4.spec index 7c479f9ae40..4f61e3973e8 100644 --- a/testdata/p4_16_samples_outputs/pna-example-varIndex-1.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-varIndex-1.p4.spec @@ -59,10 +59,12 @@ action execute_1 args none { jmpneq LABEL_FALSE_2 m.local_metadata_depth 0x0 mov m.MainControlT_tmp_1 m.local_metadata_depth add m.MainControlT_tmp_1 0x3 + and m.MainControlT_tmp_1 0x3 jmpneq LABEL_FALSE_3 m.MainControlT_tmp_1 0x0 jmp LABEL_END_3 LABEL_FALSE_3 : mov m.MainControlT_tmp_0 m.local_metadata_depth add m.MainControlT_tmp_0 0x3 + and m.MainControlT_tmp_0 0x3 jmpneq LABEL_FALSE_4 m.MainControlT_tmp_0 0x1 mov m.MainControlT_tmp_5 h.vlan_tag_0.pcp_cfi_vid and m.MainControlT_tmp_5 0xf @@ -79,6 +81,7 @@ action execute_1 args none { jmp LABEL_END_3 LABEL_FALSE_4 : mov m.MainControlT_tmp m.local_metadata_depth add m.MainControlT_tmp 0x3 + and m.MainControlT_tmp 0x3 jmplt LABEL_END_3 m.MainControlT_tmp 0x1 mov m.MainControlT_tmp_11 h.vlan_tag_0.pcp_cfi_vid and m.MainControlT_tmp_11 0xf @@ -93,6 +96,7 @@ action execute_1 args none { LABEL_FALSE_2 : jmpneq LABEL_END_3 m.local_metadata_depth 0x1 mov m.MainControlT_tmp_4 m.local_metadata_depth add m.MainControlT_tmp_4 0x3 + and m.MainControlT_tmp_4 0x3 jmpneq LABEL_FALSE_7 m.MainControlT_tmp_4 0x0 mov m.MainControlT_tmp_15 h.vlan_tag_1.pcp_cfi_vid and m.MainControlT_tmp_15 0xf @@ -109,10 +113,12 @@ action execute_1 args none { jmp LABEL_END_3 LABEL_FALSE_7 : mov m.MainControlT_tmp_3 m.local_metadata_depth add m.MainControlT_tmp_3 0x3 + and m.MainControlT_tmp_3 0x3 jmpneq LABEL_FALSE_8 m.MainControlT_tmp_3 0x1 jmp LABEL_END_3 LABEL_FALSE_8 : mov m.MainControlT_tmp_2 m.local_metadata_depth add m.MainControlT_tmp_2 0x3 + and m.MainControlT_tmp_2 0x3 jmplt LABEL_END_3 m.MainControlT_tmp_2 0x1 mov m.MainControlT_tmp_21 h.vlan_tag_1.pcp_cfi_vid and m.MainControlT_tmp_21 0xf @@ -146,10 +152,12 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG : extract h.vlan_tag_0 add m.local_metadata_depth 0x3 + and m.local_metadata_depth 0x3 jmpeq MAINPARSERIMPL_PARSE_VLAN_TAG1 h.vlan_tag_0.ether_type 0x8100 jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG1 : extract h.vlan_tag_1 add m.local_metadata_depth 0x3 + and m.local_metadata_depth 0x3 jmpeq MAINPARSERIMPL_PARSE_VLAN_TAG2 h.vlan_tag_1.ether_type 0x8100 jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG2 : mov m.pna_pre_input_metadata_parser_error 0x3 diff --git a/testdata/p4_16_samples_outputs/pna-example-varIndex-2.p4.spec b/testdata/p4_16_samples_outputs/pna-example-varIndex-2.p4.spec index 32da4e5fa90..00c3cc663bf 100644 --- a/testdata/p4_16_samples_outputs/pna-example-varIndex-2.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-varIndex-2.p4.spec @@ -112,10 +112,12 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG : extract h.vlan_tag_0 add m.local_metadata_depth 0x3 + and m.local_metadata_depth 0x3 jmpeq MAINPARSERIMPL_PARSE_VLAN_TAG1 h.vlan_tag_0.ether_type 0x8100 jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG1 : extract h.vlan_tag_1 add m.local_metadata_depth 0x3 + and m.local_metadata_depth 0x3 jmpeq MAINPARSERIMPL_PARSE_VLAN_TAG2 h.vlan_tag_1.ether_type 0x8100 jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG2 : mov m.pna_pre_input_metadata_parser_error 0x3 diff --git a/testdata/p4_16_samples_outputs/pna-example-varIndex.p4.spec b/testdata/p4_16_samples_outputs/pna-example-varIndex.p4.spec index 723c8183afe..1e8007d1d57 100644 --- a/testdata/p4_16_samples_outputs/pna-example-varIndex.p4.spec +++ b/testdata/p4_16_samples_outputs/pna-example-varIndex.p4.spec @@ -64,25 +64,30 @@ regarray direction size 0x100 initval 0 action execute_1 args none { mov m.MainControlT_tmp_1 m.local_metadata_depth add m.MainControlT_tmp_1 0x3 + and m.MainControlT_tmp_1 0x3 jmpneq LABEL_FALSE_1 m.MainControlT_tmp_1 0x0 mov m.local_metadata_ethType h.vlan_tag_0.ether_type jmp LABEL_END_2 LABEL_FALSE_1 : mov m.MainControlT_tmp_0 m.local_metadata_depth add m.MainControlT_tmp_0 0x3 + and m.MainControlT_tmp_0 0x3 jmpneq LABEL_FALSE_2 m.MainControlT_tmp_0 0x1 mov m.local_metadata_ethType h.vlan_tag_1.ether_type jmp LABEL_END_2 LABEL_FALSE_2 : mov m.MainControlT_tmp m.local_metadata_depth add m.MainControlT_tmp 0x3 + and m.MainControlT_tmp 0x3 jmplt LABEL_END_2 m.MainControlT_tmp 0x1 mov m.local_metadata_ethType m.MainControlT_hsVar LABEL_END_2 : mov m.MainControlT_tmp_3 m.local_metadata_depth add m.MainControlT_tmp_3 0x3 + and m.MainControlT_tmp_3 0x3 jmpneq LABEL_FALSE_4 m.MainControlT_tmp_3 0x0 mov h.vlan_tag_0.ether_type 0x2 jmp LABEL_END_5 LABEL_FALSE_4 : mov m.MainControlT_tmp_2 m.local_metadata_depth add m.MainControlT_tmp_2 0x3 + and m.MainControlT_tmp_2 0x3 jmpneq LABEL_END_5 m.MainControlT_tmp_2 0x1 mov h.vlan_tag_1.ether_type 0x2 LABEL_END_5 : jmpneq LABEL_FALSE_6 m.local_metadata_depth 0x0 @@ -164,10 +169,12 @@ apply { jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG : extract h.vlan_tag_0 add m.local_metadata_depth 0x3 + and m.local_metadata_depth 0x3 jmpeq MAINPARSERIMPL_PARSE_VLAN_TAG1 h.vlan_tag_0.ether_type 0x8100 jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG1 : extract h.vlan_tag_1 add m.local_metadata_depth 0x3 + and m.local_metadata_depth 0x3 jmpeq MAINPARSERIMPL_PARSE_VLAN_TAG2 h.vlan_tag_1.ether_type 0x8100 jmp MAINPARSERIMPL_ACCEPT MAINPARSERIMPL_PARSE_VLAN_TAG2 : mov m.pna_pre_input_metadata_parser_error 0x3 diff --git a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_1.p4.spec b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_1.p4.spec index 9c045103ada..93b979abb9c 100644 --- a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_1.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_1.p4.spec @@ -166,6 +166,7 @@ apply { mov m.Ingress_tmp_6 h.ipv4.version_ihl mov m.Ingress_tmp_7 m.Ingress_tmp_6 add m.Ingress_tmp_7 0x5 + and m.Ingress_tmp_7 0xf mov m.Ingress_tmp_8 m.Ingress_tmp_7 mov m.Ingress_tmp_9 m.Ingress_tmp_8 and m.Ingress_tmp_9 0xf diff --git a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_3.p4.spec b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_3.p4.spec index 493e8fbd603..3d9b6d91901 100644 --- a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_3.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_3.p4.spec @@ -160,6 +160,7 @@ apply { mov m.Ingress_tmp_6 h.ipv4.version_ihl mov m.Ingress_tmp_7 m.Ingress_tmp_6 add m.Ingress_tmp_7 0x5 + and m.Ingress_tmp_7 0xf mov m.Ingress_tmp_8 m.Ingress_tmp_7 mov m.Ingress_tmp_9 m.Ingress_tmp_8 and m.Ingress_tmp_9 0xf diff --git a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_5.p4.spec b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_5.p4.spec index 53f47e08954..40648caebf4 100644 --- a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_5.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_5.p4.spec @@ -152,6 +152,7 @@ apply { mov m.Ingress_tmp_6 h.ipv4.version_ihl mov m.Ingress_tmp_7 m.Ingress_tmp_6 add m.Ingress_tmp_7 0x5 + and m.Ingress_tmp_7 0xf mov m.Ingress_tmp_8 m.Ingress_tmp_7 mov m.Ingress_tmp_9 m.Ingress_tmp_8 and m.Ingress_tmp_9 0xf diff --git a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_6.p4.spec b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_6.p4.spec index da809baf0b2..6e61f86e47f 100644 --- a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_6.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_6.p4.spec @@ -182,6 +182,7 @@ apply { mov m.Ingress_tmp_8 h.ipv4._version0__ihl1 mov m.Ingress_tmp_9 m.Ingress_tmp_8 add m.Ingress_tmp_9 0x5 + and m.Ingress_tmp_9 0xf mov m.Ingress_tmp_10 m.Ingress_tmp_9 mov m.Ingress_tmp_11 m.Ingress_tmp_10 and m.Ingress_tmp_11 0xf diff --git a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_7.p4.spec b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_7.p4.spec index 06f72e7501a..a415a21f7b0 100644 --- a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_7.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_7.p4.spec @@ -203,6 +203,7 @@ apply { mov m.Ingress_tmp_12 h.ipv4._version0__ihl1 mov m.Ingress_tmp_13 m.Ingress_tmp_12 add m.Ingress_tmp_13 0x5 + and m.Ingress_tmp_13 0xf mov m.Ingress_tmp_14 m.Ingress_tmp_13 mov m.Ingress_tmp_15 m.Ingress_tmp_14 and m.Ingress_tmp_15 0xf diff --git a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_8.p4.spec b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_8.p4.spec index 7d4643af939..c0110d29fb5 100644 --- a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_8.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_8.p4.spec @@ -188,6 +188,7 @@ apply { mov m.Ingress_tmp_8 h.ipv4._version0__ihl1 mov m.Ingress_tmp_9 m.Ingress_tmp_8 add m.Ingress_tmp_9 0x5 + and m.Ingress_tmp_9 0xf mov m.Ingress_tmp_10 m.Ingress_tmp_9 mov m.Ingress_tmp_11 m.Ingress_tmp_10 and m.Ingress_tmp_11 0xf diff --git a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_9.p4.spec b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_9.p4.spec index fb956779ee4..de14ebea707 100644 --- a/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_9.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-example-dpdk-byte-alignment_9.p4.spec @@ -160,6 +160,7 @@ apply { mov m.Ingress_tmp_6 h.ipv4.version_ihl mov m.Ingress_tmp_7 m.Ingress_tmp_6 add m.Ingress_tmp_7 0x5 + and m.Ingress_tmp_7 0xf mov m.Ingress_tmp_8 m.Ingress_tmp_7 mov m.Ingress_tmp_9 m.Ingress_tmp_8 and m.Ingress_tmp_9 0xf diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1-first.p4 b/testdata/p4_16_samples_outputs/psa-subtract-inst1-first.p4 new file mode 100644 index 00000000000..37fec66338f --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1-first.p4 @@ -0,0 +1,101 @@ +#include +#include + +struct EMPTY { +} + +header ethernet_t { + bit<48> dst_addr; + bit<48> src_addr; + bit<16> ether_type; +} + +header udp_t { + bit<16> sport; + bit<16> dport; + bit<16> length; + bit<16> csum; +} + +struct headers_t { + ethernet_t ethernet; + udp_t[2] udp; +} + +struct user_meta_data_t { + bit<48> addr; + bit<3> depth1; + bit<5> depth2; + bit<5> depth3; + bit<5> depth4; + bit<5> depth5; + bit<5> depth6; + bit<5> depth7; +} + +parser MyIngressParser(packet_in pkt, out headers_t hdr, inout user_meta_data_t m, in psa_ingress_parser_input_metadata_t c, in EMPTY d, in EMPTY e) { + state start { + m.depth1 = m.depth1 + 3w7; + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control MyIngressControl(inout headers_t hdrs, inout user_meta_data_t meta, in psa_ingress_input_metadata_t c, inout psa_ingress_output_metadata_t d) { + bit<5> var1 = 5w8; + bit<5> var2 = 5w2; + int<33> var3; + int<33> var4 = var3 + -33s3; + action nonDefAct() { + if (var4 == 33s3) { + meta.depth3 = meta.depth3 + 5w29; + meta.depth4 = var1 + var2; + meta.depth5 = var1 ^ 5w2; + meta.depth6 = var2 + 5w31; + meta.depth7 = var2 + 5w3; + } + } + table stub { + key = { + } + actions = { + nonDefAct(); + } + const default_action = nonDefAct(); + size = 1000000; + } + apply { + meta.depth4 = meta.depth2 + 5w28; + d.egress_port = (PortId_t)((bit<32>)c.ingress_port ^ 32w1); + stub.apply(); + } +} + +control MyIngressDeparser(packet_out pkt, out EMPTY a, out EMPTY b, out EMPTY c, inout headers_t hdr, in user_meta_data_t e, in psa_ingress_output_metadata_t f) { + apply { + pkt.emit(hdr.ethernet); + } +} + +parser MyEgressParser(packet_in pkt, out EMPTY a, inout EMPTY b, in psa_egress_parser_input_metadata_t c, in EMPTY d, in EMPTY e, in EMPTY f) { + state start { + transition accept; + } +} + +control MyEgressControl(inout EMPTY a, inout EMPTY b, in psa_egress_input_metadata_t c, inout psa_egress_output_metadata_t d) { + apply { + } +} + +control MyEgressDeparser(packet_out pkt, out EMPTY a, out EMPTY b, inout EMPTY c, in EMPTY d, in psa_egress_output_metadata_t e, in psa_egress_deparser_input_metadata_t f) { + apply { + } +} + +IngressPipeline(MyIngressParser(), MyIngressControl(), MyIngressDeparser()) ip; + +EgressPipeline(MyEgressParser(), MyEgressControl(), MyEgressDeparser()) ep; + +PSA_Switch(ip, PacketReplicationEngine(), ep, BufferingQueueingEngine()) main; + diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1-frontend.p4 b/testdata/p4_16_samples_outputs/psa-subtract-inst1-frontend.p4 new file mode 100644 index 00000000000..4b136c23e55 --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1-frontend.p4 @@ -0,0 +1,104 @@ +#include +#include + +struct EMPTY { +} + +header ethernet_t { + bit<48> dst_addr; + bit<48> src_addr; + bit<16> ether_type; +} + +header udp_t { + bit<16> sport; + bit<16> dport; + bit<16> length; + bit<16> csum; +} + +struct headers_t { + ethernet_t ethernet; + udp_t[2] udp; +} + +struct user_meta_data_t { + bit<48> addr; + bit<3> depth1; + bit<5> depth2; + bit<5> depth3; + bit<5> depth4; + bit<5> depth5; + bit<5> depth6; + bit<5> depth7; +} + +parser MyIngressParser(packet_in pkt, out headers_t hdr, inout user_meta_data_t m, in psa_ingress_parser_input_metadata_t c, in EMPTY d, in EMPTY e) { + state start { + m.depth1 = m.depth1 + 3w7; + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control MyIngressControl(inout headers_t hdrs, inout user_meta_data_t meta, in psa_ingress_input_metadata_t c, inout psa_ingress_output_metadata_t d) { + @name("MyIngressControl.var1") bit<5> var1_0; + @name("MyIngressControl.var2") bit<5> var2_0; + @name("MyIngressControl.var3") int<33> var3_0; + @name("MyIngressControl.var4") int<33> var4_0; + @name("MyIngressControl.nonDefAct") action nonDefAct() { + if (var4_0 == 33s3) { + meta.depth3 = meta.depth3 + 5w29; + meta.depth4 = var1_0 + var2_0; + meta.depth5 = var1_0 ^ 5w2; + meta.depth6 = var2_0 + 5w31; + meta.depth7 = var2_0 + 5w3; + } + } + @name("MyIngressControl.stub") table stub_0 { + key = { + } + actions = { + nonDefAct(); + } + const default_action = nonDefAct(); + size = 1000000; + } + apply { + var1_0 = 5w8; + var2_0 = 5w2; + var4_0 = var3_0 + -33s3; + meta.depth4 = meta.depth2 + 5w28; + d.egress_port = (PortId_t)((bit<32>)c.ingress_port ^ 32w1); + stub_0.apply(); + } +} + +control MyIngressDeparser(packet_out pkt, out EMPTY a, out EMPTY b, out EMPTY c, inout headers_t hdr, in user_meta_data_t e, in psa_ingress_output_metadata_t f) { + apply { + pkt.emit(hdr.ethernet); + } +} + +parser MyEgressParser(packet_in pkt, out EMPTY a, inout EMPTY b, in psa_egress_parser_input_metadata_t c, in EMPTY d, in EMPTY e, in EMPTY f) { + state start { + transition accept; + } +} + +control MyEgressControl(inout EMPTY a, inout EMPTY b, in psa_egress_input_metadata_t c, inout psa_egress_output_metadata_t d) { + apply { + } +} + +control MyEgressDeparser(packet_out pkt, out EMPTY a, out EMPTY b, inout EMPTY c, in EMPTY d, in psa_egress_output_metadata_t e, in psa_egress_deparser_input_metadata_t f) { + apply { + } +} + +IngressPipeline(MyIngressParser(), MyIngressControl(), MyIngressDeparser()) ip; + +EgressPipeline(MyEgressParser(), MyEgressControl(), MyEgressDeparser()) ep; + +PSA_Switch(ip, PacketReplicationEngine(), ep, BufferingQueueingEngine()) main; + diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1-midend.p4 b/testdata/p4_16_samples_outputs/psa-subtract-inst1-midend.p4 new file mode 100644 index 00000000000..19272cf79fc --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1-midend.p4 @@ -0,0 +1,120 @@ +#include +#include + +struct EMPTY { +} + +header ethernet_t { + bit<48> dst_addr; + bit<48> src_addr; + bit<16> ether_type; +} + +header udp_t { + bit<16> sport; + bit<16> dport; + bit<16> length; + bit<16> csum; +} + +struct headers_t { + ethernet_t ethernet; + udp_t[2] udp; +} + +struct user_meta_data_t { + bit<48> addr; + bit<3> depth1; + bit<5> depth2; + bit<5> depth3; + bit<5> depth4; + bit<5> depth5; + bit<5> depth6; + bit<5> depth7; +} + +parser MyIngressParser(packet_in pkt, out headers_t hdr, inout user_meta_data_t m, in psa_ingress_parser_input_metadata_t c, in EMPTY d, in EMPTY e) { + state start { + m.depth1 = m.depth1 + 3w7; + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control MyIngressControl(inout headers_t hdrs, inout user_meta_data_t meta, in psa_ingress_input_metadata_t c, inout psa_ingress_output_metadata_t d) { + @name("MyIngressControl.var1") bit<5> var1_0; + @name("MyIngressControl.var2") bit<5> var2_0; + @name("MyIngressControl.var3") int<33> var3_0; + @name("MyIngressControl.var4") int<33> var4_0; + @name("MyIngressControl.nonDefAct") action nonDefAct() { + meta.depth3 = (var4_0 == 33s3 ? meta.depth3 + 5w29 : meta.depth3); + meta.depth4 = (var4_0 == 33s3 ? var1_0 + var2_0 : meta.depth4); + meta.depth5 = (var4_0 == 33s3 ? var1_0 ^ 5w2 : meta.depth5); + meta.depth6 = (var4_0 == 33s3 ? var2_0 + 5w31 : meta.depth6); + meta.depth7 = (var4_0 == 33s3 ? var2_0 + 5w3 : meta.depth7); + } + @name("MyIngressControl.stub") table stub_0 { + key = { + } + actions = { + nonDefAct(); + } + const default_action = nonDefAct(); + size = 1000000; + } + @hidden action psasubtractinst1l62() { + var1_0 = 5w8; + var2_0 = 5w2; + var4_0 = var3_0 + -33s3; + meta.depth4 = meta.depth2 + 5w28; + d.egress_port = (bit<32>)c.ingress_port ^ 32w1; + } + @hidden table tbl_psasubtractinst1l62 { + actions = { + psasubtractinst1l62(); + } + const default_action = psasubtractinst1l62(); + } + apply { + tbl_psasubtractinst1l62.apply(); + stub_0.apply(); + } +} + +control MyIngressDeparser(packet_out pkt, out EMPTY a, out EMPTY b, out EMPTY c, inout headers_t hdr, in user_meta_data_t e, in psa_ingress_output_metadata_t f) { + @hidden action psasubtractinst1l103() { + pkt.emit(hdr.ethernet); + } + @hidden table tbl_psasubtractinst1l103 { + actions = { + psasubtractinst1l103(); + } + const default_action = psasubtractinst1l103(); + } + apply { + tbl_psasubtractinst1l103.apply(); + } +} + +parser MyEgressParser(packet_in pkt, out EMPTY a, inout EMPTY b, in psa_egress_parser_input_metadata_t c, in EMPTY d, in EMPTY e, in EMPTY f) { + state start { + transition accept; + } +} + +control MyEgressControl(inout EMPTY a, inout EMPTY b, in psa_egress_input_metadata_t c, inout psa_egress_output_metadata_t d) { + apply { + } +} + +control MyEgressDeparser(packet_out pkt, out EMPTY a, out EMPTY b, inout EMPTY c, in EMPTY d, in psa_egress_output_metadata_t e, in psa_egress_deparser_input_metadata_t f) { + apply { + } +} + +IngressPipeline(MyIngressParser(), MyIngressControl(), MyIngressDeparser()) ip; + +EgressPipeline(MyEgressParser(), MyEgressControl(), MyEgressDeparser()) ep; + +PSA_Switch(ip, PacketReplicationEngine(), ep, BufferingQueueingEngine()) main; + diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4 b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4 new file mode 100644 index 00000000000..cb32f9cba5c --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4 @@ -0,0 +1,101 @@ +#include +#include + +struct EMPTY { +} + +header ethernet_t { + bit<48> dst_addr; + bit<48> src_addr; + bit<16> ether_type; +} + +header udp_t { + bit<16> sport; + bit<16> dport; + bit<16> length; + bit<16> csum; +} + +struct headers_t { + ethernet_t ethernet; + udp_t[2] udp; +} + +struct user_meta_data_t { + bit<48> addr; + bit<3> depth1; + bit<5> depth2; + bit<5> depth3; + bit<5> depth4; + bit<5> depth5; + bit<5> depth6; + bit<5> depth7; +} + +parser MyIngressParser(packet_in pkt, out headers_t hdr, inout user_meta_data_t m, in psa_ingress_parser_input_metadata_t c, in EMPTY d, in EMPTY e) { + state start { + m.depth1 = m.depth1 - 1; + pkt.extract(hdr.ethernet); + transition accept; + } +} + +control MyIngressControl(inout headers_t hdrs, inout user_meta_data_t meta, in psa_ingress_input_metadata_t c, inout psa_ingress_output_metadata_t d) { + bit<5> var1 = 8; + bit<5> var2 = 2; + int<33> var3; + int<33> var4 = var3 - 3; + action nonDefAct() { + if (var4 == 3) { + meta.depth3 = meta.depth3 - 3; + meta.depth4 = var1 + var2; + meta.depth5 = var1 ^ 2; + meta.depth6 = var2 - 1; + meta.depth7 = var2 + 3; + } + } + table stub { + key = { + } + actions = { + nonDefAct; + } + const default_action = nonDefAct; + size = 1000000; + } + apply { + meta.depth4 = meta.depth2 - 4; + d.egress_port = (PortId_t)((bit<32>)c.ingress_port ^ 1); + stub.apply(); + } +} + +control MyIngressDeparser(packet_out pkt, out EMPTY a, out EMPTY b, out EMPTY c, inout headers_t hdr, in user_meta_data_t e, in psa_ingress_output_metadata_t f) { + apply { + pkt.emit(hdr.ethernet); + } +} + +parser MyEgressParser(packet_in pkt, out EMPTY a, inout EMPTY b, in psa_egress_parser_input_metadata_t c, in EMPTY d, in EMPTY e, in EMPTY f) { + state start { + transition accept; + } +} + +control MyEgressControl(inout EMPTY a, inout EMPTY b, in psa_egress_input_metadata_t c, inout psa_egress_output_metadata_t d) { + apply { + } +} + +control MyEgressDeparser(packet_out pkt, out EMPTY a, out EMPTY b, inout EMPTY c, in EMPTY d, in psa_egress_output_metadata_t e, in psa_egress_deparser_input_metadata_t f) { + apply { + } +} + +IngressPipeline(MyIngressParser(), MyIngressControl(), MyIngressDeparser()) ip; + +EgressPipeline(MyEgressParser(), MyEgressControl(), MyEgressDeparser()) ep; + +PSA_Switch(ip, PacketReplicationEngine(), ep, BufferingQueueingEngine()) main; + diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4-error b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4-error new file mode 100644 index 00000000000..1a13def53d0 --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4-error @@ -0,0 +1,4 @@ +psa-subtract-inst1.p4(65): [--Wwarn=uninitialized_use] warning: var3 may be uninitialized + int<33> var4 = var3 - 3; + ^^^^ +[--Wwarn=mismatch] warning: -64w3: negative value with unsigned type diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4-stderr b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4-stderr new file mode 100644 index 00000000000..d56489b6848 --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4-stderr @@ -0,0 +1,3 @@ +psa-subtract-inst1.p4(65): [--Wwarn=uninitialized_use] warning: var3 may be uninitialized + int<33> var4 = var3 - 3; + ^^^^ diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.bfrt.json b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.bfrt.json new file mode 100644 index 00000000000..df1f1fb5759 --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.bfrt.json @@ -0,0 +1,28 @@ +{ + "schema_version" : "1.0.0", + "tables" : [ + { + "name" : "ip.MyIngressControl.stub", + "id" : 43002152, + "table_type" : "MatchAction_Direct", + "size" : 1000000, + "annotations" : [], + "depends_on" : [], + "has_const_default_action" : true, + "key" : [], + "action_specs" : [ + { + "id" : 29027610, + "name" : "MyIngressControl.nonDefAct", + "action_scope" : "TableAndDefault", + "annotations" : [], + "data" : [] + } + ], + "data" : [], + "supported_operations" : [], + "attributes" : ["EntryScope"] + } + ], + "learn_filters" : [] +} \ No newline at end of file diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.entries.txt b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.entries.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.p4info.txt b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.p4info.txt new file mode 100644 index 00000000000..b6a040fb18c --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.p4info.txt @@ -0,0 +1,24 @@ +pkg_info { + arch: "psa" +} +tables { + preamble { + id: 43002152 + name: "MyIngressControl.stub" + alias: "stub" + } + action_refs { + id: 29027610 + } + const_default_action_id: 29027610 + size: 1000000 +} +actions { + preamble { + id: 29027610 + name: "MyIngressControl.nonDefAct" + alias: "nonDefAct" + } +} +type_info { +} diff --git a/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.spec b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.spec new file mode 100644 index 00000000000..d6198298d4a --- /dev/null +++ b/testdata/p4_16_samples_outputs/psa-subtract-inst1.p4.spec @@ -0,0 +1,111 @@ + +struct ethernet_t { + bit<48> dst_addr + bit<48> src_addr + bit<16> ether_type +} + +struct udp_t { + bit<16> sport + bit<16> dport + bit<16> length + bit<16> csum +} + +struct psa_ingress_output_metadata_t { + bit<8> class_of_service + bit<8> clone + bit<16> clone_session_id + bit<8> drop + bit<8> resubmit + bit<32> multicast_group + bit<32> egress_port +} + +struct psa_egress_output_metadata_t { + bit<8> clone + bit<16> clone_session_id + bit<8> drop +} + +struct psa_egress_deparser_input_metadata_t { + bit<32> egress_port +} + +header ethernet instanceof ethernet_t +header udp_0 instanceof udp_t +header udp_1 instanceof udp_t + + +struct user_meta_data_t { + bit<32> psa_ingress_input_metadata_ingress_port + bit<8> psa_ingress_output_metadata_drop + bit<32> psa_ingress_output_metadata_egress_port + bit<32> local_metadata_depth1 + bit<32> local_metadata_depth2 + bit<32> local_metadata_depth3 + bit<32> local_metadata_depth4 + bit<32> local_metadata_depth5 + bit<32> local_metadata_depth6 + bit<32> local_metadata_depth7 + bit<32> Ingress_tmp + bit<32> Ingress_var1 + bit<32> Ingress_var2 + bit<64> Ingress_var3 + bit<64> Ingress_var4 +} +metadata instanceof user_meta_data_t + +action nonDefAct args none { + jmpneq LABEL_END m.Ingress_var4 0x3 + add m.local_metadata_depth3 0x1d + and m.local_metadata_depth3 0x1f + mov m.local_metadata_depth4 m.Ingress_var1 + add m.local_metadata_depth4 m.Ingress_var2 + and m.local_metadata_depth4 0x1f + mov m.local_metadata_depth5 m.Ingress_var1 + xor m.local_metadata_depth5 0x2 + mov m.local_metadata_depth6 m.Ingress_var2 + add m.local_metadata_depth6 0x1f + and m.local_metadata_depth6 0x1f + mov m.local_metadata_depth7 m.Ingress_var2 + add m.local_metadata_depth7 0x3 + and m.local_metadata_depth7 0x1f + LABEL_END : return +} + +table stub { + key { + } + actions { + nonDefAct + } + default_action nonDefAct args none const + size 0xf4240 +} + + +apply { + rx m.psa_ingress_input_metadata_ingress_port + mov m.psa_ingress_output_metadata_drop 0x0 + add m.local_metadata_depth1 0x7 + and m.local_metadata_depth1 0x7 + extract h.ethernet + mov m.Ingress_var1 0x8 + mov m.Ingress_var2 0x2 + mov m.Ingress_var4 m.Ingress_var3 + add m.Ingress_var4 0xfffffffffffffffd + mov m.local_metadata_depth4 m.local_metadata_depth2 + add m.local_metadata_depth4 0x1c + and m.local_metadata_depth4 0x1f + mov m.Ingress_tmp m.psa_ingress_input_metadata_ingress_port + mov m.psa_ingress_output_metadata_egress_port m.Ingress_tmp + xor m.psa_ingress_output_metadata_egress_port 0x1 + table stub + jmpneq LABEL_DROP m.psa_ingress_output_metadata_drop 0x0 + emit h.ethernet + tx m.psa_ingress_output_metadata_egress_port + LABEL_DROP : drop +} + + diff --git a/testdata/p4_16_samples_outputs/psa-variable-index.p4.spec b/testdata/p4_16_samples_outputs/psa-variable-index.p4.spec index efc7e578234..60bb2ae2002 100644 --- a/testdata/p4_16_samples_outputs/psa-variable-index.p4.spec +++ b/testdata/p4_16_samples_outputs/psa-variable-index.p4.spec @@ -80,10 +80,12 @@ apply { jmp MYIP_ACCEPT MYIP_PARSE_VLAN_TAG : extract h.vlan_tag_0 add m.local_metadata_depth 0x3 + and m.local_metadata_depth 0x3 jmpeq MYIP_PARSE_VLAN_TAG1 h.vlan_tag_0.ether_type 0x8100 jmp MYIP_ACCEPT MYIP_PARSE_VLAN_TAG1 : extract h.vlan_tag_1 add m.local_metadata_depth 0x3 + and m.local_metadata_depth 0x3 jmpeq MYIP_PARSE_VLAN_TAG2 h.vlan_tag_1.ether_type 0x8100 jmp MYIP_ACCEPT MYIP_PARSE_VLAN_TAG2 : mov m.psa_ingress_input_metadata_parser_error 0x3