diff --git a/backends/tc/ebpfCodeGen.h b/backends/tc/ebpfCodeGen.h index 3c45ae1f4b..12cfabe8ec 100644 --- a/backends/tc/ebpfCodeGen.h +++ b/backends/tc/ebpfCodeGen.h @@ -293,7 +293,6 @@ class EBPFControlPNA : public EBPF::EBPFControlPSA { } EBPFHashPNA *getHash(cstring name) const { auto result = ::P4::get(pna_hashes, name); - BUG_CHECK(result != nullptr, "No hash named %1%", name); return result; } void emitExternDefinition(EBPF::CodeBuilder *builder) { diff --git a/backends/tc/tcExterns.cpp b/backends/tc/tcExterns.cpp index c607f9998b..ea9b4ec974 100644 --- a/backends/tc/tcExterns.cpp +++ b/backends/tc/tcExterns.cpp @@ -481,7 +481,11 @@ void EBPFHashPNA::calculateHash(EBPF::CodeBuilder *builder, const IR::MethodCall } void CRCChecksumAlgorithmPNA::emitGet(EBPF::CodeBuilder *builder) { - builder->appendFormat("%s", registerVar.c_str()); + if (crcWidth == 16) { + builder->appendFormat("%s", registerVar.c_str()); + } else { + builder->appendFormat("%s ^ 0xFFFFFFFF", registerVar.c_str()); + } } void CRCChecksumAlgorithmPNA::emitAddData(EBPF::CodeBuilder *builder, int dataPos, diff --git a/backends/tc/tcExterns.h b/backends/tc/tcExterns.h index e26e65f1a8..0cc14e9e42 100644 --- a/backends/tc/tcExterns.h +++ b/backends/tc/tcExterns.h @@ -192,12 +192,14 @@ class CRCChecksumAlgorithmPNA : public EBPF::CRCChecksumAlgorithm { public: CRCChecksumAlgorithmPNA(const EBPF::EBPFProgram *program, cstring name, int width) : EBPF::CRCChecksumAlgorithm(program, name, width) { + BUG_CHECK(width == 16 || width == 32, "Must be 16 bits width or 32 bits width."); initialValue = "0"_cs; } void emitGet(EBPF::CodeBuilder *builder) override; void emitAddData(EBPF::CodeBuilder *builder, const ArgumentsList &arguments, const IR::MethodCallExpression *expr); - void emitAddData(EBPF::CodeBuilder *builder, int dataPos, const IR::MethodCallExpression *expr); + void emitAddData(EBPF::CodeBuilder *builder, int dataPos, + const IR::MethodCallExpression *expr) override; }; class EBPFDigestPNA : public EBPF::EBPFDigestPSA { diff --git a/testdata/p4tc_samples_outputs/hash_control_blocks.c b/testdata/p4tc_samples_outputs/hash_control_blocks.c index d208b44851..9a924b31d5 100644 --- a/testdata/p4tc_samples_outputs/hash_control_blocks.c +++ b/testdata/p4tc_samples_outputs/hash_control_blocks.c @@ -39,7 +39,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head bpf_p4tc_ext_hash_crc32(&hdr->crc.f3, sizeof(hdr->crc.f3), ingress_h_reg); bpf_p4tc_ext_hash_crc32(&hdr->crc.f4, sizeof(hdr->crc.f4), ingress_h_reg); hdr->crc.crc = /* h_0.get_hash({hdr->crc.f1, hdr->crc.f2, hdr->crc.f3, hdr->crc.f4}) */ -ingress_h_reg; +ingress_h_reg ^ 0xFFFFFFFF; } } {