17#ifndef BACKENDS_EBPF_PSA_EXTERNS_EBPFPSAHASHALGORITHM_H_
18#define BACKENDS_EBPF_PSA_EXTERNS_EBPFPSAHASHALGORITHM_H_
20#include "backends/ebpf/ebpfObject.h"
28 typedef std::vector<const IR::Expression *> ArgumentsList;
35 ArgumentsList unpackArguments(
const IR::MethodCallExpression *expr,
int dataPos);
50 : baseName(name), program(program), visitor(nullptr) {}
52 void setVisitor(
Visitor *instance) { this->visitor = instance; }
54 virtual unsigned getOutputWidth()
const {
return 0; }
60 virtual void emitAddData(
CodeBuilder *builder,
int dataPos,
61 const IR::MethodCallExpression *expr);
62 virtual void emitAddData(
CodeBuilder *builder,
const ArgumentsList &arguments) = 0;
65 virtual void emitSubtractData(
CodeBuilder *builder,
int dataPos,
66 const IR::MethodCallExpression *expr);
67 virtual void emitSubtractData(
CodeBuilder *builder,
const ArgumentsList &arguments) = 0;
69 virtual void emitGetInternalState(
CodeBuilder *builder) = 0;
70 virtual void emitSetInternalState(
CodeBuilder *builder,
71 const IR::MethodCallExpression *expr) = 0;
87 unsigned getOutputWidth()
const override {
return crcWidth; }
89 static void emitUpdateMethod(
CodeBuilder *builder,
int crcWidth);
97 void emitSubtractData(
CodeBuilder *builder,
const ArgumentsList &arguments)
override;
99 void emitGetInternalState(
CodeBuilder *builder)
override;
100 void emitSetInternalState(
CodeBuilder *builder,
const IR::MethodCallExpression *expr)
override;
113 initialValue =
"0"_cs;
116 polynomial =
"0xA001"_cs;
117 updateMethod =
"crc16_update"_cs;
118 finalizeMethod =
"crc16_finalize"_cs;
135 initialValue =
"0xffffffff"_cs;
138 polynomial =
"0xEDB88320"_cs;
139 updateMethod =
"crc32_update"_cs;
140 finalizeMethod =
"crc32_finalize"_cs;
150 void updateChecksum(
CodeBuilder *builder,
const ArgumentsList &arguments,
bool addData);
156 unsigned getOutputWidth()
const override {
return 16; }
163 void emitAddData(
CodeBuilder *builder,
const ArgumentsList &arguments)
override;
166 void emitSubtractData(
CodeBuilder *builder,
const ArgumentsList &arguments)
override;
168 void emitGetInternalState(
CodeBuilder *builder)
override;
169 void emitSetInternalState(
CodeBuilder *builder,
const IR::MethodCallExpression *expr)
override;
180 if (type == EBPFHashAlgorithmPSA::HashAlgorithm::CRC32)
182 else if (type == EBPFHashAlgorithmPSA::HashAlgorithm::CRC16)
184 else if (type == EBPFHashAlgorithmPSA::HashAlgorithm::ONES_COMPLEMENT16 ||
185 type == EBPFHashAlgorithmPSA::HashAlgorithm::TARGET_DEFAULT)
192 CRC16ChecksumAlgorithm::emitGlobals(builder);
193 CRC32ChecksumAlgorithm::emitGlobals(builder);
194 InternetChecksumAlgorithm::emitGlobals(builder);
Definition ebpfPsaHashAlgorithm.h:109
Definition ebpfPsaHashAlgorithm.h:131
Definition ebpfPsaHashAlgorithm.h:74
void emitAddData(CodeBuilder *builder, const ArgumentsList &arguments) override
Definition ebpfPsaHashAlgorithm.cpp:231
void emitVariables(CodeBuilder *builder, const IR::Declaration_Instance *decl) override
decl might be a null pointer
Definition ebpfPsaHashAlgorithm.cpp:176
Definition ebpf/codeGen.h:33
Definition ebpfPsaHashAlgorithm.h:26
virtual void emitVariables(CodeBuilder *builder, const IR::Declaration_Instance *decl)=0
decl might be a null pointer
HashAlgorithm
Keep this enum in sync with psa.p4 file.
Definition ebpfPsaHashAlgorithm.h:39
Definition ebpfPsaHashAlgorithm.h:172
Base class for EBPF objects.
Definition ebpfObject.h:31
Definition ebpfProgram.h:39
Definition ebpfPsaHashAlgorithm.h:146
void emitVariables(CodeBuilder *builder, const IR::Declaration_Instance *decl) override
decl might be a null pointer
Definition ebpfPsaHashAlgorithm.cpp:486
Definition codeGen.cpp:25