From e7cf27428eff01478b350fa43975410cb0b343b4 Mon Sep 17 00:00:00 2001 From: "Komal, Jain" Date: Thu, 17 Oct 2024 04:35:50 +0530 Subject: [PATCH] Implementation of Hash Extern Signed-off-by: Komal, Jain --- backends/tc/ebpfCodeGen.cpp | 170 ++------------- backends/tc/ebpfCodeGen.h | 51 +---- backends/tc/tcExterns.cpp | 66 ++++++ backends/tc/tcExterns.h | 23 +++ p4include/tc/pna.p4 | 4 +- testdata/p4tc_samples/hash.p4 | 116 +++++++++++ testdata/p4tc_samples/hash1.p4 | 5 +- .../add_entry_1_example_parser.h | 92 --------- .../add_entry_3_example_parser.h | 92 --------- .../add_entry_example_parser.h | 92 --------- .../p4tc_samples_outputs/calculator_parser.h | 92 --------- .../p4tc_samples_outputs/checksum_parser.h | 92 --------- .../const_entries_range_mask_parser.h | 92 --------- .../default_action_example_01_parser.h | 92 --------- .../default_action_example_parser.h | 92 --------- .../default_action_with_param_01_parser.h | 92 --------- .../default_action_with_param_parser.h | 92 --------- .../default_hit_const_example_parser.h | 92 --------- .../p4tc_samples_outputs/digest_01_parser.h | 92 --------- testdata/p4tc_samples_outputs/digest_parser.h | 92 --------- .../direct_counter_example_parser.h | 92 --------- .../direct_meter_color_parser.h | 92 --------- .../direct_meter_parser.h | 92 --------- .../drop_packet_example_parser.h | 92 --------- .../global_action_example_01_parser.h | 92 --------- .../global_action_example_02_parser.h | 92 --------- testdata/p4tc_samples_outputs/hash.json | 6 + testdata/p4tc_samples_outputs/hash.p4-stderr | 0 testdata/p4tc_samples_outputs/hash.template | 7 + .../hash1_control_blocks.c | 16 +- testdata/p4tc_samples_outputs/hash1_parser.h | 92 --------- .../hash_control_blocks.c | 194 ++++++++++++++++++ testdata/p4tc_samples_outputs/hash_parser.c | 115 +++++++++++ testdata/p4tc_samples_outputs/hash_parser.h | 80 ++++++++ .../indirect_counter_01_example_parser.h | 92 --------- .../internetchecksum_01_parser.h | 92 --------- testdata/p4tc_samples_outputs/ipip_parser.h | 92 --------- .../is_host_port_parser.h | 92 --------- .../p4tc_samples_outputs/is_net_port_parser.h | 92 --------- .../p4tc_samples_outputs/matchtype_parser.h | 92 --------- .../p4tc_samples_outputs/meter_color_parser.h | 92 --------- testdata/p4tc_samples_outputs/meter_parser.h | 92 --------- .../mix_matchtype_example_parser.h | 92 --------- .../multiple_tables_example_01_parser.h | 92 --------- .../multiple_tables_example_02_parser.h | 92 --------- .../name_annotation_example_parser.h | 92 --------- .../no_table_example_parser.h | 92 --------- .../noaction_example_01_parser.h | 92 --------- .../noaction_example_02_parser.h | 92 --------- .../nummask_annotation_example_parser.h | 92 --------- .../send_to_port_example_parser.h | 92 --------- .../set_entry_timer_example_parser.h | 92 --------- .../simple_exact_example_parser.h | 92 --------- .../simple_extern_example_parser.h | 92 --------- .../simple_lpm_example_parser.h | 92 --------- .../simple_ternary_example_parser.h | 92 --------- .../size_param_example_parser.h | 92 --------- .../tc_may_override_example_01_parser.h | 92 --------- .../tc_may_override_example_02_parser.h | 92 --------- .../tc_may_override_example_03_parser.h | 92 --------- .../tc_may_override_example_04_parser.h | 92 --------- .../tc_may_override_example_05_parser.h | 92 --------- .../tc_may_override_example_06_parser.h | 92 --------- .../tc_may_override_example_07_parser.h | 92 --------- .../tc_may_override_example_08_parser.h | 92 --------- .../tc_may_override_example_09_parser.h | 92 --------- .../tc_type_annotation_example_parser.h | 92 --------- .../test_ipv6_example_parser.h | 92 --------- 68 files changed, 642 insertions(+), 5179 deletions(-) create mode 100644 testdata/p4tc_samples/hash.p4 create mode 100644 testdata/p4tc_samples_outputs/hash.json create mode 100644 testdata/p4tc_samples_outputs/hash.p4-stderr create mode 100755 testdata/p4tc_samples_outputs/hash.template create mode 100644 testdata/p4tc_samples_outputs/hash_control_blocks.c create mode 100644 testdata/p4tc_samples_outputs/hash_parser.c create mode 100644 testdata/p4tc_samples_outputs/hash_parser.h diff --git a/backends/tc/ebpfCodeGen.cpp b/backends/tc/ebpfCodeGen.cpp index 17fdfe0e31..de0e4b596c 100644 --- a/backends/tc/ebpfCodeGen.cpp +++ b/backends/tc/ebpfCodeGen.cpp @@ -248,7 +248,6 @@ void PNAArchTC::emitHeader(EBPF::CodeBuilder *builder) const { emitP4TCFilterFields(builder); // BPF map definitions. emitInstances(builder); - EBPFHashAlgorithmTypeFactoryPNA::instance()->emitGlobals(builder); } // =====================TCIngressPipelinePNA============================= @@ -1394,6 +1393,11 @@ bool ConvertToEBPFParserPNA::preorder(const IR::P4ValueSet *pvs) { return false; } +void EBPFControlPNA::emit(EBPF::CodeBuilder *builder) { + for (auto h : pna_hashes) h.second->emitVariables(builder); + EBPF::EBPFControl::emit(builder); +} + // =====================ConvertToEBPFControlPNA============================= bool ConvertToEBPFControlPNA::preorder(const IR::ControlBlock *ctrl) { control = new EBPFControlPNA(program, ctrl, parserHeaders); @@ -1491,8 +1495,8 @@ bool ConvertToEBPFControlPNA::preorder(const IR::ExternBlock *instance) { cstring name = EBPF::EBPFObject::externalName(di); cstring typeName = instance->type->getName().name; if (typeName == "Hash") { - auto hash = new EBPF::EBPFHashPSA(program, di, name); - control->hashes.emplace(name, hash); + auto hash = new EBPFHashPNA(program, di, name); + control->pna_hashes.emplace(name, hash); } else if (typeName == "Register") { auto reg = new EBPFRegisterPNA(program, name, di, control->codeGen); control->pna_registers.emplace(name, reg); @@ -2009,7 +2013,7 @@ void ControlBodyTranslatorPNA::processMethod(const P4::ExternMethod *method) { pna_meter->emitExecute(builder, method, this, nullptr); return; } else if (declType->name.name == "Hash") { - auto hash = control->to()->getHash(name); + auto hash = pnaControl->getHash(name); hash->processMethod(builder, method->method->name.name, method->expr, this); return; } else { @@ -2048,7 +2052,7 @@ bool ControlBodyTranslatorPNA::preorder(const IR::AssignmentStatement *a) { return false; } else if (ext->originalExternType->name.name == "Hash") { cstring name = EBPF::EBPFObject::externalName(ext->object); - auto hash = control->to()->getHash(name); + auto hash = pnaControl->getHash(name); // Before assigning a value to a left expression we have to calculate a hash. // Then the hash value is stored in a registerVar variable. hash->calculateHash(builder, ext->expr, this); @@ -2380,160 +2384,16 @@ void DeparserHdrEmitTranslatorPNA::emitField(EBPF::CodeBuilder *builder, cstring EBPF::EBPFHashAlgorithmPSA *EBPFHashAlgorithmTypeFactoryPNA::create( int type, const EBPF::EBPFProgram *program, cstring name) { - if (type == EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::ONES_COMPLEMENT16 || - type == EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::TARGET_DEFAULT) { + if (type == EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::CRC16) { + return new CRCChecksumAlgorithmPNA(program, name, 16); + } else if (type == EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::CRC32) { + return new CRCChecksumAlgorithmPNA(program, name, 32); + } else if (type == EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::ONES_COMPLEMENT16 || + type == EBPF::EBPFHashAlgorithmPSA::HashAlgorithm::TARGET_DEFAULT) { return new InternetChecksumAlgorithmPNA(program, name); } return nullptr; } -void CRCChecksumAlgorithmPNA::emitUpdateMethod(EBPF::CodeBuilder *builder, int crcWidth) { - // Note that this update method is optimized for our CRC16 and CRC32, custom - // version may require other method of update. When data_size <= 64 bits, - // applies host byte order for input data, otherwise network byte order is expected. - if (crcWidth == 16) { - // This function calculates CRC16 by definition, it is bit by bit. If input data has more - // than 64 bit, the outer loop process bytes in network byte order - data pointer is - // incremented. For data shorter than or equal 64 bits, bytes are processed in little endian - // byte order - data pointer is decremented by outer loop in this case. - // There is no need for lookup table. - const char *code = - "static __always_inline\n" - "void crc16_update(u16 * reg, const u8 * data, " - "u16 data_size, const u16 poly) {\n" - " if (data_size <= 8)\n" - " data += data_size - 1;\n" - " #pragma clang loop unroll(full)\n" - " for (u16 i = 0; i < data_size; i++) {\n" - " bpf_trace_message(\"CRC16: data byte: %x\\n\", *data);\n" - " *reg ^= *data;\n" - " for (u8 bit = 0; bit < 8; bit++) {\n" - " *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1;\n" - " }\n" - " if (data_size <= 8)\n" - " data--;\n" - " else\n" - " data++;\n" - " }\n" - "}"; - builder->appendLine(code); - } else if (crcWidth == 32) { - // This function calculates CRC32 using two optimisations: slice-by-8 and Standard - // Implementation. Both algorithms have to properly handle byte order depending on data - // length. There are four cases which must be handled: - // 1. Data size below 8 bytes - calculated using Standard Implementation in little endian - // byte order. - // 2. Data size equal to 8 bytes - calculated using slice-by-8 in little endian byte order. - // 3. Data size more than 8 bytes and multiply of 8 bytes - calculated using slice-by-8 in - // big endian byte order. - // 4. Data size more than 8 bytes and not multiply of 8 bytes - calculated using slice-by-8 - // and Standard Implementation both in big endian byte order. - // Lookup table is necessary for both algorithms. - const char *code = - "static __always_inline\n" - "void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) {\n" - " u32* current = (u32*) data;\n" - " u32 index = 0;\n" - " u32 lookup_key = 0;\n" - " u32 lookup_value = 0;\n" - " u32 lookup_value1 = 0;\n" - " u32 lookup_value2 = 0;\n" - " u32 lookup_value3 = 0;\n" - " u32 lookup_value4 = 0;\n" - " u32 lookup_value5 = 0;\n" - " u32 lookup_value6 = 0;\n" - " u32 lookup_value7 = 0;\n" - " u32 lookup_value8 = 0;\n" - " u16 tmp = 0;\n" - " if (crc32_table != NULL) {\n" - " for (u16 i = data_size; i >= 8; i -= 8) {\n" - " /* Vars one and two will have swapped byte order if data_size == 8 */\n" - " if (data_size == 8) current = (u32 *)(data + 4);\n" - " bpf_trace_message(\"CRC32: data dword: %x\\n\", *current);\n" - " u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ " - "*reg;\n" - " bpf_trace_message(\"CRC32: data dword: %x\\n\", *current);\n" - " u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++);\n" - " lookup_key = (one & 0x000000FF);\n" - " lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)];\n" - " lookup_key = (one >> 8) & 0x000000FF;\n" - " lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)];\n" - " lookup_key = (one >> 16) & 0x000000FF;\n" - " lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)];\n" - " lookup_key = one >> 24;\n" - " lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))];\n" - " lookup_key = (two & 0x000000FF);\n" - " lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)];\n" - " lookup_key = (two >> 8) & 0x000000FF;\n" - " lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)];\n" - " lookup_key = (two >> 16) & 0x000000FF;\n" - " lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)];\n" - " lookup_key = two >> 24;\n" - " lookup_value1 = crc32_table[(u8)(lookup_key)];\n" - " *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^\n" - " lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1;\n" - " tmp += 8;\n" - " }\n" - " volatile int std_algo_lookup_key = 0;\n" - " if (data_size < 8) {\n" - // Standard Implementation for little endian byte order - " unsigned char *currentChar = (unsigned char *) current;\n" - " currentChar += data_size - 1;\n" - " for (u16 i = tmp; i < data_size; i++) {\n" - " bpf_trace_message(\"CRC32: data byte: %x\\n\", *currentChar);\n" - " std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--);\n" - " if (std_algo_lookup_key >= 0) {\n" - " lookup_value = " - "crc32_table[(u8)(std_algo_lookup_key & 255)];\n" - " }\n" - " *reg = ((*reg) >> 8) ^ lookup_value;\n" - " }\n" - " } else {\n" - // Standard Implementation for big endian byte order - " /* Consume data not processed by slice-by-8 algorithm above, " - "these data are in network byte order */\n" - " unsigned char *currentChar = (unsigned char *) current;\n" - " for (u16 i = tmp; i < data_size; i++) {\n" - " bpf_trace_message(\"CRC32: data byte: %x\\n\", *currentChar);\n" - " std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++);\n" - " if (std_algo_lookup_key >= 0) {\n" - " lookup_value = " - "crc32_table[(u8)(std_algo_lookup_key & 255)];\n" - " }\n" - " *reg = ((*reg) >> 8) ^ lookup_value;\n" - " }\n" - " }\n" - " }\n" - "}"; - builder->appendLine(code); - } -} - -// ===========================CRC16ChecksumAlgorithmPNA=========================== - -void CRC16ChecksumAlgorithmPNA::emitGlobals(EBPF::CodeBuilder *builder) { - CRCChecksumAlgorithmPNA::emitUpdateMethod(builder, 16); - - const char *code = - "static __always_inline " - "u16 crc16_finalize(u16 reg) {\n" - " return reg;\n" - "}"; - builder->appendLine(code); -} - -// ===========================CRC32ChecksumAlgorithmPNA=========================== - -void CRC32ChecksumAlgorithmPNA::emitGlobals(EBPF::CodeBuilder *builder) { - CRCChecksumAlgorithmPNA::emitUpdateMethod(builder, 32); - - const char *code = - "static __always_inline " - "u32 crc32_finalize(u32 reg) {\n" - " return reg ^ 0xFFFFFFFF;\n" - "}"; - builder->appendLine(code); -} - } // namespace P4::TC diff --git a/backends/tc/ebpfCodeGen.h b/backends/tc/ebpfCodeGen.h index c72ad33d58..3c45ae1f4b 100644 --- a/backends/tc/ebpfCodeGen.h +++ b/backends/tc/ebpfCodeGen.h @@ -28,6 +28,7 @@ using namespace P4::literals; class ConvertToBackendIR; class EBPFPnaParser; class EBPFRegisterPNA; +class EBPFHashPNA; // Similar to class PSAEbpfGenerator in backends/ebpf/psa/ebpfPsaGen.h @@ -279,6 +280,7 @@ class EBPFControlPNA : public EBPF::EBPFControlPSA { public: bool addExternDeclaration = false; std::map pna_registers; + std::map pna_hashes; EBPFControlPNA(const EBPF::EBPFProgram *program, const IR::ControlBlock *control, const IR::Parameter *parserHeaders) @@ -289,6 +291,11 @@ class EBPFControlPNA : public EBPF::EBPFControlPSA { BUG_CHECK(result != nullptr, "No register named %1%", name); return result; } + 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) { if (addExternDeclaration) { builder->emitIndent(); @@ -300,6 +307,7 @@ class EBPFControlPNA : public EBPF::EBPFControlPSA { } } void emitTableTypes(EBPF::CodeBuilder *builder) { EBPF::EBPFControl::emitTableTypes(builder); } + void emit(EBPF::CodeBuilder *builder); }; // Similar to class ConvertToEBPFControlPSA in backends/ebpf/psa/ebpfPsaGen.h @@ -415,44 +423,6 @@ class DeparserHdrEmitTranslatorPNA : public EBPF::DeparserPrepareBufferTranslato unsigned alignment, EBPF::EBPFType *type, bool isMAC); }; -class CRCChecksumAlgorithmPNA : public EBPF::CRCChecksumAlgorithm { - public: - CRCChecksumAlgorithmPNA(const EBPF::EBPFProgram *program, cstring name, int width) - : EBPF::CRCChecksumAlgorithm(program, name, width) {} - - static void emitUpdateMethod(EBPF::CodeBuilder *builder, int crcWidth); -}; - -class CRC16ChecksumAlgorithmPNA : public CRCChecksumAlgorithmPNA { - public: - CRC16ChecksumAlgorithmPNA(const EBPF::EBPFProgram *program, cstring name) - : CRCChecksumAlgorithmPNA(program, name, 16) { - initialValue = "0"_cs; - // We use a 0x8005 polynomial. - // 0xA001 comes from 0x8005 value bits reflection. - polynomial = "0xA001"_cs; - updateMethod = "crc16_update"_cs; - finalizeMethod = "crc16_finalize"_cs; - } - - static void emitGlobals(EBPF::CodeBuilder *builder); -}; - -class CRC32ChecksumAlgorithmPNA : public CRCChecksumAlgorithmPNA { - public: - CRC32ChecksumAlgorithmPNA(const EBPF::EBPFProgram *program, cstring name) - : CRCChecksumAlgorithmPNA(program, name, 32) { - initialValue = "0xffffffff"_cs; - // We use a 0x04C11DB7 polynomial. - // 0xEDB88320 comes from 0x04C11DB7 value bits reflection. - polynomial = "0xEDB88320"_cs; - updateMethod = "crc32_update"_cs; - finalizeMethod = "crc32_finalize"_cs; - } - - static void emitGlobals(EBPF::CodeBuilder *builder); -}; - class EBPFHashAlgorithmTypeFactoryPNA : public EBPF::EBPFHashAlgorithmTypeFactoryPSA { public: static EBPFHashAlgorithmTypeFactoryPNA *instance() { @@ -460,11 +430,6 @@ class EBPFHashAlgorithmTypeFactoryPNA : public EBPF::EBPFHashAlgorithmTypeFactor return &factory; } - void emitGlobals(EBPF::CodeBuilder *builder) { - CRC16ChecksumAlgorithmPNA::emitGlobals(builder); - CRC32ChecksumAlgorithmPNA::emitGlobals(builder); - } - EBPF::EBPFHashAlgorithmPSA *create(int type, const EBPF::EBPFProgram *program, cstring name); }; diff --git a/backends/tc/tcExterns.cpp b/backends/tc/tcExterns.cpp index 089a4cea89..c607f9998b 100644 --- a/backends/tc/tcExterns.cpp +++ b/backends/tc/tcExterns.cpp @@ -453,6 +453,72 @@ void EBPFDigestPNA::emitInitializer(EBPF::CodeBuilder *builder) const { builder->newline(); } +void EBPFHashPNA::emitVariables(EBPF::CodeBuilder *builder) { + if (engine) { + engine->emitVariables(builder, declaration); + } +} + +void EBPFHashPNA::processMethod(EBPF::CodeBuilder *builder, cstring method, + const IR::MethodCallExpression *expr, Visitor *visitor) { + engine->setVisitor(visitor); + + if (method == "get_hash") { + BUG_CHECK(expr->arguments->size() == 1 || expr->arguments->size() == 3, + "Expected 1 or 3 arguments: %1%", expr); + engine->emitGet(builder); + } else { + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call %1%", expr); + } +} + +void EBPFHashPNA::calculateHash(EBPF::CodeBuilder *builder, const IR::MethodCallExpression *expr, + Visitor *visitor) { + engine->setVisitor(visitor); + engine->emitClear(builder); + engine->emitAddData(builder, expr->arguments->size() == 3 ? 1 : 0, expr); + builder->newline(); +} + +void CRCChecksumAlgorithmPNA::emitGet(EBPF::CodeBuilder *builder) { + builder->appendFormat("%s", registerVar.c_str()); +} + +void CRCChecksumAlgorithmPNA::emitAddData(EBPF::CodeBuilder *builder, int dataPos, + const IR::MethodCallExpression *expr) { + emitAddData(builder, unpackArguments(expr, dataPos), expr); +} + +void CRCChecksumAlgorithmPNA::emitAddData(EBPF::CodeBuilder *builder, + const ArgumentsList &arguments, + const IR::MethodCallExpression *expr) { + cstring kfunc; + if (crcWidth == 16) { + kfunc = expr->arguments->size() == 3 ? "bpf_p4tc_ext_hash_base_crc16"_cs + : "bpf_p4tc_ext_hash_crc16"_cs; + } else { + kfunc = expr->arguments->size() == 3 ? "bpf_p4tc_ext_hash_base_crc32"_cs + : "bpf_p4tc_ext_hash_crc32"_cs; + } + for (auto field : arguments) { + builder->newline(); + builder->emitIndent(); + builder->appendFormat("%s(&", kfunc); + visitor->visit(field); + builder->append(", sizeof("); + visitor->visit(field); + if (expr->arguments->size() == 3) { + builder->append("), "); + visitor->visit(expr->arguments->at(0)); + builder->append(", "); + visitor->visit(expr->arguments->at(2)); + builder->appendFormat(", %s);", registerVar); + } else { + builder->appendFormat("), %s);", registerVar); + } + } +} + void EBPFDigestPNA::emitPushElement(EBPF::CodeBuilder *builder, const IR::Expression *elem, Inspector *codegen) const { emitInitializer(builder); diff --git a/backends/tc/tcExterns.h b/backends/tc/tcExterns.h index 5116d81d42..e26e65f1a8 100644 --- a/backends/tc/tcExterns.h +++ b/backends/tc/tcExterns.h @@ -177,6 +177,29 @@ class EBPFInternetChecksumPNA : public EBPFChecksumPNA { const IR::MethodCallExpression *expr, Visitor *visitor) override; }; +class EBPFHashPNA : public EBPFChecksumPNA { + public: + EBPFHashPNA(const EBPF::EBPFProgram *program, const IR::Declaration_Instance *block, + cstring name) + : EBPFChecksumPNA(program, block, name) {} + void processMethod(EBPF::CodeBuilder *builder, cstring method, + const IR::MethodCallExpression *expr, Visitor *visitor) override; + void calculateHash(EBPF::CodeBuilder *builder, const IR::MethodCallExpression *expr, + Visitor *visitor); + void emitVariables(EBPF::CodeBuilder *builder); +}; +class CRCChecksumAlgorithmPNA : public EBPF::CRCChecksumAlgorithm { + public: + CRCChecksumAlgorithmPNA(const EBPF::EBPFProgram *program, cstring name, int width) + : EBPF::CRCChecksumAlgorithm(program, name, 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); +}; + class EBPFDigestPNA : public EBPF::EBPFDigestPSA { const ConvertToBackendIR *tcIR; cstring externName; diff --git a/p4include/tc/pna.p4 b/p4include/tc/pna.p4 index 6c1efe2b1b..9e2914cd95 100644 --- a/p4include/tc/pna.p4 +++ b/p4include/tc/pna.p4 @@ -350,7 +350,7 @@ extern Hash { /// Compute the hash for data. /// @param data The data over which to calculate the hash. /// @return The hash value. - O get_hash(in D data); + @tc_md_exec O get_hash(in D data); /// Compute the hash for data, with modulo by max, then add base. /// @param base Minimum return value. @@ -362,7 +362,7 @@ extern Hash { /// limit their choice to such values if they wish to /// maximize portability. /// @return (base + (h % max)) where h is the hash value. - O get_hash(in T base, in D data, in T max); + @tc_md_exec O get_hash(in T base, in D data, in T max); } // END:Hash_extern diff --git a/testdata/p4tc_samples/hash.p4 b/testdata/p4tc_samples/hash.p4 new file mode 100644 index 0000000000..aa08fd4abe --- /dev/null +++ b/testdata/p4tc_samples/hash.p4 @@ -0,0 +1,116 @@ +/* -*- P4_16 -*- */ + +#include +#include + +#define PORT_TABLE_SIZE 262144 + +/* + * Standard ethernet header + */ +header ethernet_t { + @tc_type ("macaddr") bit<48> dstAddr; + @tc_type ("macaddr") bit<48> srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + @tc_type ("ipv4") bit<32> srcAddr; + @tc_type ("ipv4") bit<32> dstAddr; +} + +header crc_t { + bit<4> f1; + bit<4> f2; + bit<32> f3; + bit<32> f4; + + bit<32> crc; +} + +struct my_ingress_headers_t { + ethernet_t ethernet; + ipv4_t ipv4; + crc_t crc; +} + +/****** G L O B A L I N G R E S S M E T A D A T A *********/ + +struct my_ingress_metadata_t { +} + +struct empty_metadata_t { +} + +/*********************** P A R S E R **************************/ + +parser Ingress_Parser( + packet_in pkt, + out my_ingress_headers_t hdr, + inout my_ingress_metadata_t meta, + in pna_main_parser_input_metadata_t istd) +{ + const bit<16> ETHERTYPE_IPV4 = 0x0800; + + state start { + transition parse_ethernet; + } + state parse_ethernet { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + ETHERTYPE_IPV4 : parse_ipv4; + default : reject; + } + } + state parse_ipv4 { + pkt.extract(hdr.crc); + transition accept; + } +} + +/***************** M A T C H - A C T I O N *********************/ + +control ingress( + inout my_ingress_headers_t hdr, + inout my_ingress_metadata_t meta, + in pna_main_input_metadata_t istd, + inout pna_main_output_metadata_t ostd +) +{ + Hash>(PNA_HashAlgorithm_t.CRC32) h; + apply { + hdr.crc.crc = h.get_hash({hdr.crc.f1, hdr.crc.f2, hdr.crc.f3, hdr.crc.f4}); + } +} + +/********************* D E P A R S E R ************************/ + +control Ingress_Deparser( + packet_out pkt, + inout my_ingress_headers_t hdr, + in my_ingress_metadata_t meta, + in pna_main_output_metadata_t ostd) +{ + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.crc); + } +} + +/************ F I N A L P A C K A G E ******************************/ + +PNA_NIC( + Ingress_Parser(), + ingress(), + Ingress_Deparser() +) main; diff --git a/testdata/p4tc_samples/hash1.p4 b/testdata/p4tc_samples/hash1.p4 index 2d92548057..36e4927d41 100644 --- a/testdata/p4tc_samples/hash1.p4 +++ b/testdata/p4tc_samples/hash1.p4 @@ -88,9 +88,10 @@ control ingress( ) { Hash>(PNA_HashAlgorithm_t.CRC16) h; - + const bit<16> base = 15; + const bit<16> max = 32; apply { - hdr.crc.crc = h.get_hash({hdr.crc.f1, hdr.crc.f2, hdr.crc.f3, hdr.crc.f4}); + hdr.crc.crc = h.get_hash(base, {hdr.crc.f1, hdr.crc.f2, hdr.crc.f3, hdr.crc.f4}, max); } } diff --git a/testdata/p4tc_samples_outputs/add_entry_1_example_parser.h b/testdata/p4tc_samples_outputs/add_entry_1_example_parser.h index eb0351243e..6e42437522 100644 --- a/testdata/p4tc_samples_outputs/add_entry_1_example_parser.h +++ b/testdata/p4tc_samples_outputs/add_entry_1_example_parser.h @@ -65,95 +65,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/add_entry_3_example_parser.h b/testdata/p4tc_samples_outputs/add_entry_3_example_parser.h index eb0351243e..6e42437522 100644 --- a/testdata/p4tc_samples_outputs/add_entry_3_example_parser.h +++ b/testdata/p4tc_samples_outputs/add_entry_3_example_parser.h @@ -65,95 +65,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/add_entry_example_parser.h b/testdata/p4tc_samples_outputs/add_entry_example_parser.h index c3b7c46eb9..929d5e054a 100644 --- a/testdata/p4tc_samples_outputs/add_entry_example_parser.h +++ b/testdata/p4tc_samples_outputs/add_entry_example_parser.h @@ -65,95 +65,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/calculator_parser.h b/testdata/p4tc_samples_outputs/calculator_parser.h index ba89b9929a..1645fd4515 100644 --- a/testdata/p4tc_samples_outputs/calculator_parser.h +++ b/testdata/p4tc_samples_outputs/calculator_parser.h @@ -56,95 +56,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/checksum_parser.h b/testdata/p4tc_samples_outputs/checksum_parser.h index 3e5caec29f..300b4de819 100644 --- a/testdata/p4tc_samples_outputs/checksum_parser.h +++ b/testdata/p4tc_samples_outputs/checksum_parser.h @@ -79,95 +79,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/const_entries_range_mask_parser.h b/testdata/p4tc_samples_outputs/const_entries_range_mask_parser.h index 9ec0cd912f..2f2e0fa612 100644 --- a/testdata/p4tc_samples_outputs/const_entries_range_mask_parser.h +++ b/testdata/p4tc_samples_outputs/const_entries_range_mask_parser.h @@ -47,95 +47,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/default_action_example_01_parser.h b/testdata/p4tc_samples_outputs/default_action_example_01_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/default_action_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/default_action_example_01_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/default_action_example_parser.h b/testdata/p4tc_samples_outputs/default_action_example_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/default_action_example_parser.h +++ b/testdata/p4tc_samples_outputs/default_action_example_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.h b/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.h +++ b/testdata/p4tc_samples_outputs/default_action_with_param_01_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_parser.h b/testdata/p4tc_samples_outputs/default_action_with_param_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/default_action_with_param_parser.h +++ b/testdata/p4tc_samples_outputs/default_action_with_param_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/default_hit_const_example_parser.h b/testdata/p4tc_samples_outputs/default_hit_const_example_parser.h index d0f8789a8f..352d0815e9 100644 --- a/testdata/p4tc_samples_outputs/default_hit_const_example_parser.h +++ b/testdata/p4tc_samples_outputs/default_hit_const_example_parser.h @@ -75,95 +75,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/digest_01_parser.h b/testdata/p4tc_samples_outputs/digest_01_parser.h index cc42507e0b..6cb04fcdf9 100644 --- a/testdata/p4tc_samples_outputs/digest_01_parser.h +++ b/testdata/p4tc_samples_outputs/digest_01_parser.h @@ -67,95 +67,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/digest_parser.h b/testdata/p4tc_samples_outputs/digest_parser.h index cc42507e0b..6cb04fcdf9 100644 --- a/testdata/p4tc_samples_outputs/digest_parser.h +++ b/testdata/p4tc_samples_outputs/digest_parser.h @@ -67,95 +67,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/direct_counter_example_parser.h b/testdata/p4tc_samples_outputs/direct_counter_example_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/direct_counter_example_parser.h +++ b/testdata/p4tc_samples_outputs/direct_counter_example_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/direct_meter_color_parser.h b/testdata/p4tc_samples_outputs/direct_meter_color_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/direct_meter_color_parser.h +++ b/testdata/p4tc_samples_outputs/direct_meter_color_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/direct_meter_parser.h b/testdata/p4tc_samples_outputs/direct_meter_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/direct_meter_parser.h +++ b/testdata/p4tc_samples_outputs/direct_meter_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/drop_packet_example_parser.h b/testdata/p4tc_samples_outputs/drop_packet_example_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/drop_packet_example_parser.h +++ b/testdata/p4tc_samples_outputs/drop_packet_example_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/global_action_example_01_parser.h b/testdata/p4tc_samples_outputs/global_action_example_01_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/global_action_example_01_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/global_action_example_02_parser.h b/testdata/p4tc_samples_outputs/global_action_example_02_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_02_parser.h +++ b/testdata/p4tc_samples_outputs/global_action_example_02_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/hash.json b/testdata/p4tc_samples_outputs/hash.json new file mode 100644 index 0000000000..729e3eb033 --- /dev/null +++ b/testdata/p4tc_samples_outputs/hash.json @@ -0,0 +1,6 @@ +{ + "schema_version" : "1.0.0", + "pipeline_name" : "hash", + "externs" : [], + "tables" : [] +} \ No newline at end of file diff --git a/testdata/p4tc_samples_outputs/hash.p4-stderr b/testdata/p4tc_samples_outputs/hash.p4-stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testdata/p4tc_samples_outputs/hash.template b/testdata/p4tc_samples_outputs/hash.template new file mode 100755 index 0000000000..9e26b290fb --- /dev/null +++ b/testdata/p4tc_samples_outputs/hash.template @@ -0,0 +1,7 @@ +#!/bin/bash -x + +set -e + +: "${TC:="tc"}" +$TC p4template create pipeline/hash numtables 0 +$TC p4template update pipeline/hash state ready \ No newline at end of file diff --git a/testdata/p4tc_samples_outputs/hash1_control_blocks.c b/testdata/p4tc_samples_outputs/hash1_control_blocks.c index 7e851732e3..c243f6d9ab 100644 --- a/testdata/p4tc_samples_outputs/hash1_control_blocks.c +++ b/testdata/p4tc_samples_outputs/hash1_control_blocks.c @@ -33,15 +33,13 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head u8 hit; { ingress_h_reg = 0; - { - u8 ingress_h_tmp = 0; - ingress_h_tmp = (hdr->crc.f1 << 4) | (hdr->crc.f2 << 0); - crc16_update(&ingress_h_reg, &ingress_h_tmp, 1, 0xA001); - crc16_update(&ingress_h_reg, (u8 *) &(hdr->crc.f3), 4, 0xA001); - crc16_update(&ingress_h_reg, (u8 *) &(hdr->crc.f4), 4, 0xA001); - } - hdr->crc.crc = /* h_0.get_hash({hdr->crc.f1, hdr->crc.f2, hdr->crc.f3, hdr->crc.f4}) */ -crc16_finalize(ingress_h_reg); + + bpf_p4tc_ext_hash_base_crc16(&hdr->crc.f1, sizeof(hdr->crc.f1), 15, 32, ingress_h_reg); + bpf_p4tc_ext_hash_base_crc16(&hdr->crc.f2, sizeof(hdr->crc.f2), 15, 32, ingress_h_reg); + bpf_p4tc_ext_hash_base_crc16(&hdr->crc.f3, sizeof(hdr->crc.f3), 15, 32, ingress_h_reg); + bpf_p4tc_ext_hash_base_crc16(&hdr->crc.f4, sizeof(hdr->crc.f4), 15, 32, ingress_h_reg); + hdr->crc.crc = /* h_0.get_hash(15, {hdr->crc.f1, hdr->crc.f2, hdr->crc.f3, hdr->crc.f4}, 32) */ +ingress_h_reg; } } { diff --git a/testdata/p4tc_samples_outputs/hash1_parser.h b/testdata/p4tc_samples_outputs/hash1_parser.h index 42a9f99a83..94841425a8 100644 --- a/testdata/p4tc_samples_outputs/hash1_parser.h +++ b/testdata/p4tc_samples_outputs/hash1_parser.h @@ -78,95 +78,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/hash_control_blocks.c b/testdata/p4tc_samples_outputs/hash_control_blocks.c new file mode 100644 index 0000000000..d208b44851 --- /dev/null +++ b/testdata/p4tc_samples_outputs/hash_control_blocks.c @@ -0,0 +1,194 @@ +#include "hash_parser.h" +struct p4tc_filter_fields p4tc_filter_fields; + +struct internal_metadata { + __u16 pkt_ether_type; +} __attribute__((aligned(4))); + + +static __always_inline int process(struct __sk_buff *skb, struct my_ingress_headers_t *hdr, struct pna_global_metadata *compiler_meta__) +{ + struct hdr_md *hdrMd; + + unsigned ebpf_packetOffsetInBits_save = 0; + ParserError_t ebpf_errorCode = NoError; + void* pkt = ((void*)(long)skb->data); + u8* hdr_start = pkt; + void* ebpf_packetEnd = ((void*)(long)skb->data_end); + u32 ebpf_zero = 0; + u32 ebpf_one = 1; + unsigned char ebpf_byte; + u32 pkt_len = skb->len; + + struct my_ingress_metadata_t *meta; + hdrMd = BPF_MAP_LOOKUP_ELEM(hdr_md_cpumap, &ebpf_zero); + if (!hdrMd) + return TC_ACT_SHOT; + unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits; + hdr_start = pkt + BYTES(ebpf_packetOffsetInBits); + hdr = &(hdrMd->cpumap_hdr); + meta = &(hdrMd->cpumap_usermeta); +{ + u32 ingress_h_reg = 0; + u8 hit; + { + ingress_h_reg = 0; + + bpf_p4tc_ext_hash_crc32(&hdr->crc.f1, sizeof(hdr->crc.f1), ingress_h_reg); + bpf_p4tc_ext_hash_crc32(&hdr->crc.f2, sizeof(hdr->crc.f2), ingress_h_reg); + 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; + } + } + { +{ +; + ; + } + + if (compiler_meta__->drop) { + return TC_ACT_SHOT; + } + int outHeaderLength = 0; + if (hdr->ethernet.ebpf_valid) { + outHeaderLength += 112; + } +; if (hdr->crc.ebpf_valid) { + outHeaderLength += 104; + } +; + int outHeaderOffset = BYTES(outHeaderLength) - (hdr_start - (u8*)pkt); + if (outHeaderOffset != 0) { + int returnCode = 0; + returnCode = bpf_skb_adjust_room(skb, outHeaderOffset, 1, 0); + if (returnCode) { + return TC_ACT_SHOT; + } + } + pkt = ((void*)(long)skb->data); + ebpf_packetEnd = ((void*)(long)skb->data_end); + ebpf_packetOffsetInBits = 0; + if (hdr->ethernet.ebpf_valid) { + if (ebpf_packetEnd < pkt + BYTES(ebpf_packetOffsetInBits + 112)) { + return TC_ACT_SHOT; + } + + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[4]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 4, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[5]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 5, (ebpf_byte)); + ebpf_packetOffsetInBits += 48; + + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[4]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 4, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[5]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 5, (ebpf_byte)); + ebpf_packetOffsetInBits += 48; + + hdr->ethernet.etherType = bpf_htons(hdr->ethernet.etherType); + ebpf_byte = ((char*)(&hdr->ethernet.etherType))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.etherType))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + } +; if (hdr->crc.ebpf_valid) { + if (ebpf_packetEnd < pkt + BYTES(ebpf_packetOffsetInBits + 104)) { + return TC_ACT_SHOT; + } + + ebpf_byte = ((char*)(&hdr->crc.f1))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 4, 4, (ebpf_byte >> 0)); + ebpf_packetOffsetInBits += 4; + + ebpf_byte = ((char*)(&hdr->crc.f2))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 4, 0, (ebpf_byte >> 0)); + ebpf_packetOffsetInBits += 4; + + hdr->crc.f3 = htonl(hdr->crc.f3); + ebpf_byte = ((char*)(&hdr->crc.f3))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.f3))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.f3))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.f3))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_packetOffsetInBits += 32; + + hdr->crc.f4 = htonl(hdr->crc.f4); + ebpf_byte = ((char*)(&hdr->crc.f4))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.f4))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.f4))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.f4))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_packetOffsetInBits += 32; + + hdr->crc.crc = htonl(hdr->crc.crc); + ebpf_byte = ((char*)(&hdr->crc.crc))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.crc))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.crc))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->crc.crc))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_packetOffsetInBits += 32; + + } +; + } + return -1; +} +SEC("p4tc/main") +int tc_ingress_func(struct __sk_buff *skb) { + struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb; + if (compiler_meta__->pass_to_kernel == true) return TC_ACT_OK; + compiler_meta__->drop = false; + if (!compiler_meta__->recirculated) { + compiler_meta__->mark = 153; + struct internal_metadata *md = (struct internal_metadata *)(unsigned long)skb->data_meta; + if ((void *) ((struct internal_metadata *) md + 1) <= (void *)(long)skb->data) { + __u16 *ether_type = (__u16 *) ((void *) (long)skb->data + 12); + if ((void *) ((__u16 *) ether_type + 1) > (void *) (long) skb->data_end) { + return TC_ACT_SHOT; + } + *ether_type = md->pkt_ether_type; + } + } + struct hdr_md *hdrMd; + struct my_ingress_headers_t *hdr; + int ret = -1; + ret = process(skb, (struct my_ingress_headers_t *) hdr, compiler_meta__); + if (ret != -1) { + return ret; + } + if (!compiler_meta__->drop && compiler_meta__->egress_port == 0) { + compiler_meta__->pass_to_kernel = true; + return bpf_redirect(skb->ifindex, BPF_F_INGRESS); + } + return bpf_redirect(compiler_meta__->egress_port, 0); +} +char _license[] SEC("license") = "GPL"; diff --git a/testdata/p4tc_samples_outputs/hash_parser.c b/testdata/p4tc_samples_outputs/hash_parser.c new file mode 100644 index 0000000000..481f9d942c --- /dev/null +++ b/testdata/p4tc_samples_outputs/hash_parser.c @@ -0,0 +1,115 @@ +#include "hash_parser.h" + +struct p4tc_filter_fields p4tc_filter_fields; + +static __always_inline int run_parser(struct __sk_buff *skb, struct my_ingress_headers_t *hdr, struct pna_global_metadata *compiler_meta__) +{ + struct hdr_md *hdrMd; + + unsigned ebpf_packetOffsetInBits_save = 0; + ParserError_t ebpf_errorCode = NoError; + void* pkt = ((void*)(long)skb->data); + u8* hdr_start = pkt; + void* ebpf_packetEnd = ((void*)(long)skb->data_end); + u32 ebpf_zero = 0; + u32 ebpf_one = 1; + unsigned char ebpf_byte; + u32 pkt_len = skb->len; + + struct my_ingress_metadata_t *meta; + + hdrMd = BPF_MAP_LOOKUP_ELEM(hdr_md_cpumap, &ebpf_zero); + if (!hdrMd) + return TC_ACT_SHOT; + __builtin_memset(hdrMd, 0, sizeof(struct hdr_md)); + + unsigned ebpf_packetOffsetInBits = 0; + hdr = &(hdrMd->cpumap_hdr); + meta = &(hdrMd->cpumap_usermeta); + { + goto start; + parse_ipv4: { +/* extract(hdr->crc) */ + if ((u8*)ebpf_packetEnd < hdr_start + BYTES(104 + 0)) { + ebpf_errorCode = PacketTooShort; + goto reject; + } + + hdr->crc.f1 = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)) >> 4) & EBPF_MASK(u8, 4)); + ebpf_packetOffsetInBits += 4; + + hdr->crc.f2 = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits))) & EBPF_MASK(u8, 4)); + ebpf_packetOffsetInBits += 4; + + hdr->crc.f3 = (u32)((load_word(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 32; + + hdr->crc.f4 = (u32)((load_word(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 32; + + hdr->crc.crc = (u32)((load_word(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 32; + + + hdr->crc.ebpf_valid = 1; + hdr_start += BYTES(104); + +; + goto accept; + } + start: { +/* extract(hdr->ethernet) */ + if ((u8*)ebpf_packetEnd < hdr_start + BYTES(112 + 0)) { + ebpf_errorCode = PacketTooShort; + goto reject; + } + + __builtin_memcpy(&hdr->ethernet.dstAddr, pkt + BYTES(ebpf_packetOffsetInBits), 6); + ebpf_packetOffsetInBits += 48; + + __builtin_memcpy(&hdr->ethernet.srcAddr, pkt + BYTES(ebpf_packetOffsetInBits), 6); + ebpf_packetOffsetInBits += 48; + + hdr->ethernet.etherType = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + + hdr->ethernet.ebpf_valid = 1; + hdr_start += BYTES(112); + +; + u16 select_0; + select_0 = hdr->ethernet.etherType; + if (select_0 == 0x800)goto parse_ipv4; + if ((select_0 & 0x0) == (0x0 & 0x0))goto reject; + else goto reject; + } + + reject: { + if (ebpf_errorCode == 0) { + return TC_ACT_SHOT; + } + compiler_meta__->parser_error = ebpf_errorCode; + goto accept; + } + + } + + accept: + hdrMd->ebpf_packetOffsetInBits = ebpf_packetOffsetInBits; + return -1; +} + +SEC("p4tc/parse") +int tc_parse_func(struct __sk_buff *skb) { + struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb; + struct hdr_md *hdrMd; + struct my_ingress_headers_t *hdr; + int ret = -1; + ret = run_parser(skb, (struct my_ingress_headers_t *) hdr, compiler_meta__); + if (ret != -1) { + return ret; + } + return TC_ACT_PIPE; + } +char _license[] SEC("license") = "GPL"; diff --git a/testdata/p4tc_samples_outputs/hash_parser.h b/testdata/p4tc_samples_outputs/hash_parser.h new file mode 100644 index 0000000000..893d160819 --- /dev/null +++ b/testdata/p4tc_samples_outputs/hash_parser.h @@ -0,0 +1,80 @@ +#include "ebpf_kernel.h" + +#include +#include +#include "pna.h" + +#define EBPF_MASK(t, w) ((((t)(1)) << (w)) - (t)1) +#define BYTES(w) ((w) / 8) +#define write_partial(a, w, s, v) do { *((u8*)a) = ((*((u8*)a)) & ~(EBPF_MASK(u8, w) << s)) | (v << s) ; } while (0) +#define write_byte(base, offset, v) do { *(u8*)((base) + (offset)) = (v); } while (0) +#define bpf_trace_message(fmt, ...) + + +struct ethernet_t { + u64 dstAddr; /* bit<48> */ + u64 srcAddr; /* bit<48> */ + u16 etherType; /* bit<16> */ + u8 ebpf_valid; +}; +struct ipv4_t { + u8 version; /* bit<4> */ + u8 ihl; /* bit<4> */ + u8 diffserv; /* bit<8> */ + u16 totalLen; /* bit<16> */ + u16 identification; /* bit<16> */ + u8 flags; /* bit<3> */ + u16 fragOffset; /* bit<13> */ + u8 ttl; /* bit<8> */ + u8 protocol; /* bit<8> */ + u16 hdrChecksum; /* bit<16> */ + u32 srcAddr; /* bit<32> */ + u32 dstAddr; /* bit<32> */ + u8 ebpf_valid; +}; +struct crc_t { + u8 f1; /* bit<4> */ + u8 f2; /* bit<4> */ + u32 f3; /* bit<32> */ + u32 f4; /* bit<32> */ + u32 crc; /* bit<32> */ + u8 ebpf_valid; +}; +struct my_ingress_headers_t { + struct ethernet_t ethernet; /* ethernet_t */ + struct ipv4_t ipv4; /* ipv4_t */ + struct crc_t crc; /* crc_t */ +}; +struct my_ingress_metadata_t { +}; +struct empty_metadata_t { +}; +struct tuple_0 { + u8 f0; /* bit<4> */ + u8 f1; /* bit<4> */ + u32 f2; /* bit<32> */ + u32 f3; /* bit<32> */ +}; + +struct hdr_md { + struct my_ingress_headers_t cpumap_hdr; + struct my_ingress_metadata_t cpumap_usermeta; + unsigned ebpf_packetOffsetInBits; + __u8 __hook; +}; + +struct p4tc_filter_fields { + __u32 pipeid; + __u32 handle; + __u32 classid; + __u32 chain; + __u32 blockid; + __be16 proto; + __u16 prio; +}; + +REGISTER_START() +REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) +BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) +REGISTER_END() + diff --git a/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h +++ b/testdata/p4tc_samples_outputs/indirect_counter_01_example_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/internetchecksum_01_parser.h b/testdata/p4tc_samples_outputs/internetchecksum_01_parser.h index 849fc36394..aa9b19c0bf 100644 --- a/testdata/p4tc_samples_outputs/internetchecksum_01_parser.h +++ b/testdata/p4tc_samples_outputs/internetchecksum_01_parser.h @@ -85,95 +85,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/ipip_parser.h b/testdata/p4tc_samples_outputs/ipip_parser.h index 20fb054f05..48b48ac494 100644 --- a/testdata/p4tc_samples_outputs/ipip_parser.h +++ b/testdata/p4tc_samples_outputs/ipip_parser.h @@ -65,95 +65,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/is_host_port_parser.h b/testdata/p4tc_samples_outputs/is_host_port_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/is_host_port_parser.h +++ b/testdata/p4tc_samples_outputs/is_host_port_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/is_net_port_parser.h b/testdata/p4tc_samples_outputs/is_net_port_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/is_net_port_parser.h +++ b/testdata/p4tc_samples_outputs/is_net_port_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/matchtype_parser.h b/testdata/p4tc_samples_outputs/matchtype_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/matchtype_parser.h +++ b/testdata/p4tc_samples_outputs/matchtype_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/meter_color_parser.h b/testdata/p4tc_samples_outputs/meter_color_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/meter_color_parser.h +++ b/testdata/p4tc_samples_outputs/meter_color_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/meter_parser.h b/testdata/p4tc_samples_outputs/meter_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/meter_parser.h +++ b/testdata/p4tc_samples_outputs/meter_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.h b/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.h +++ b/testdata/p4tc_samples_outputs/mix_matchtype_example_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.h b/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.h index 5c8a19c1a8..0bb6fe0e1e 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_01_parser.h @@ -75,95 +75,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.h b/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.h index 5c8a19c1a8..0bb6fe0e1e 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.h +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_02_parser.h @@ -75,95 +75,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/name_annotation_example_parser.h b/testdata/p4tc_samples_outputs/name_annotation_example_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/name_annotation_example_parser.h +++ b/testdata/p4tc_samples_outputs/name_annotation_example_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/no_table_example_parser.h b/testdata/p4tc_samples_outputs/no_table_example_parser.h index b65ae62b59..75006eeeca 100644 --- a/testdata/p4tc_samples_outputs/no_table_example_parser.h +++ b/testdata/p4tc_samples_outputs/no_table_example_parser.h @@ -69,95 +69,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/noaction_example_01_parser.h b/testdata/p4tc_samples_outputs/noaction_example_01_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/noaction_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/noaction_example_01_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/noaction_example_02_parser.h b/testdata/p4tc_samples_outputs/noaction_example_02_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/noaction_example_02_parser.h +++ b/testdata/p4tc_samples_outputs/noaction_example_02_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.h b/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.h index d0f8789a8f..352d0815e9 100644 --- a/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.h +++ b/testdata/p4tc_samples_outputs/nummask_annotation_example_parser.h @@ -75,95 +75,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/send_to_port_example_parser.h b/testdata/p4tc_samples_outputs/send_to_port_example_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/send_to_port_example_parser.h +++ b/testdata/p4tc_samples_outputs/send_to_port_example_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.h b/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.h +++ b/testdata/p4tc_samples_outputs/set_entry_timer_example_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/simple_exact_example_parser.h b/testdata/p4tc_samples_outputs/simple_exact_example_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/simple_exact_example_parser.h +++ b/testdata/p4tc_samples_outputs/simple_exact_example_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/simple_extern_example_parser.h b/testdata/p4tc_samples_outputs/simple_extern_example_parser.h index 808992488d..06164768de 100644 --- a/testdata/p4tc_samples_outputs/simple_extern_example_parser.h +++ b/testdata/p4tc_samples_outputs/simple_extern_example_parser.h @@ -67,95 +67,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/simple_lpm_example_parser.h b/testdata/p4tc_samples_outputs/simple_lpm_example_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/simple_lpm_example_parser.h +++ b/testdata/p4tc_samples_outputs/simple_lpm_example_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/simple_ternary_example_parser.h b/testdata/p4tc_samples_outputs/simple_ternary_example_parser.h index 7c722359cc..a4fbecb227 100644 --- a/testdata/p4tc_samples_outputs/simple_ternary_example_parser.h +++ b/testdata/p4tc_samples_outputs/simple_ternary_example_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/size_param_example_parser.h b/testdata/p4tc_samples_outputs/size_param_example_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/size_param_example_parser.h +++ b/testdata/p4tc_samples_outputs/size_param_example_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.h index 7a99d4144a..8f8fb971a5 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_01_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_02_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_03_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.h index 743fd5363a..9d708e2b8f 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_04_parser.h @@ -62,95 +62,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.h index 3b6f75c598..239070ea8a 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_05_parser.h @@ -62,95 +62,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.h index d8475cf311..f1ae281121 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_06_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.h index 7a99d4144a..8f8fb971a5 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_07_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.h index 7a99d4144a..8f8fb971a5 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_08_parser.h @@ -63,95 +63,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.h b/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.h index 90ff839fc9..74b1b65a62 100644 --- a/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.h +++ b/testdata/p4tc_samples_outputs/tc_may_override_example_09_parser.h @@ -62,95 +62,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.h b/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.h index 54a8b788e1..4206db4108 100644 --- a/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.h +++ b/testdata/p4tc_samples_outputs/tc_type_annotation_example_parser.h @@ -61,95 +61,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -} diff --git a/testdata/p4tc_samples_outputs/test_ipv6_example_parser.h b/testdata/p4tc_samples_outputs/test_ipv6_example_parser.h index 2a658bc386..8d20a6e6c7 100644 --- a/testdata/p4tc_samples_outputs/test_ipv6_example_parser.h +++ b/testdata/p4tc_samples_outputs/test_ipv6_example_parser.h @@ -72,95 +72,3 @@ REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) REGISTER_END() -static __always_inline -void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { - if (data_size <= 8) - data += data_size - 1; - #pragma clang loop unroll(full) - for (u16 i = 0; i < data_size; i++) { - bpf_trace_message("CRC16: data byte: %x\n", *data); - *reg ^= *data; - for (u8 bit = 0; bit < 8; bit++) { - *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; - } - if (data_size <= 8) - data--; - else - data++; - } -} -static __always_inline u16 crc16_finalize(u16 reg) { - return reg; -} -static __always_inline -void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { - u32* current = (u32*) data; - u32 index = 0; - u32 lookup_key = 0; - u32 lookup_value = 0; - u32 lookup_value1 = 0; - u32 lookup_value2 = 0; - u32 lookup_value3 = 0; - u32 lookup_value4 = 0; - u32 lookup_value5 = 0; - u32 lookup_value6 = 0; - u32 lookup_value7 = 0; - u32 lookup_value8 = 0; - u16 tmp = 0; - if (crc32_table != NULL) { - for (u16 i = data_size; i >= 8; i -= 8) { - /* Vars one and two will have swapped byte order if data_size == 8 */ - if (data_size == 8) current = (u32 *)(data + 4); - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; - bpf_trace_message("CRC32: data dword: %x\n", *current); - u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); - lookup_key = (one & 0x000000FF); - lookup_value8 = crc32_table[(u16)(1792 + (u8)lookup_key)]; - lookup_key = (one >> 8) & 0x000000FF; - lookup_value7 = crc32_table[(u16)(1536 + (u8)lookup_key)]; - lookup_key = (one >> 16) & 0x000000FF; - lookup_value6 = crc32_table[(u16)(1280 + (u8)lookup_key)]; - lookup_key = one >> 24; - lookup_value5 = crc32_table[(u16)(1024 + (u8)(lookup_key))]; - lookup_key = (two & 0x000000FF); - lookup_value4 = crc32_table[(u16)(768 + (u8)lookup_key)]; - lookup_key = (two >> 8) & 0x000000FF; - lookup_value3 = crc32_table[(u16)(512 + (u8)lookup_key)]; - lookup_key = (two >> 16) & 0x000000FF; - lookup_value2 = crc32_table[(u16)(256 + (u8)lookup_key)]; - lookup_key = two >> 24; - lookup_value1 = crc32_table[(u8)(lookup_key)]; - *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ - lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; - tmp += 8; - } - volatile int std_algo_lookup_key = 0; - if (data_size < 8) { - unsigned char *currentChar = (unsigned char *) current; - currentChar += data_size - 1; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } else { - /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ - unsigned char *currentChar = (unsigned char *) current; - for (u16 i = tmp; i < data_size; i++) { - bpf_trace_message("CRC32: data byte: %x\n", *currentChar); - std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); - if (std_algo_lookup_key >= 0) { - lookup_value = crc32_table[(u8)(std_algo_lookup_key & 255)]; - } - *reg = ((*reg) >> 8) ^ lookup_value; - } - } - } -} -static __always_inline u32 crc32_finalize(u32 reg) { - return reg ^ 0xFFFFFFFF; -}