19#ifndef BF_P4C_MAU_HASH_FUNCTION_H_
20#define BF_P4C_MAU_HASH_FUNCTION_H_
30 enum { IDENTITY, CSUM, XOR, CRC, RANDOM } type = IDENTITY;
37 uint64_t final_xor = 0;
40 return type == a.type && size == a.size && msb == a.msb && reverse == a.reverse &&
41 poly == a.poly && init == a.init && final_xor == a.final_xor;
43 bool operator!=(
const HashFunction &a)
const {
return !(*
this == a); }
46 bool setup(
const IR::Expression *exp);
47 bool convertPolynomialExtern(
const IR::GlobalRef *);
58 bool size_from_algorithm()
const {
59 if (type == CRC)
return true;
62 bool ordered()
const {
return type != RANDOM; }
64 std::string name()
const {
65 std::string algo_name =
"";
66 if (type == IDENTITY) {
67 algo_name =
"identity";
68 }
else if (type == CRC) {
69 algo_name =
"crc_" + std::to_string(size);
70 }
else if (type == RANDOM) {
72 }
else if (type == XOR) {
78 std::string algo_type()
const {
79 std::string algo_type =
"";
80 if (type == IDENTITY) {
81 algo_type =
"identity";
82 }
else if (type == CRC) {
84 }
else if (type == RANDOM) {
86 }
else if (type == XOR) {
93 const IR::MethodCallExpression *hash_to_mce(
const IR::Expression *);
94 uint64_t toKoopman(uint64_t poly, uint32_t width);
100 friend std::ostream &operator<<(std::ostream &,
const HashFunction &);
103 static const IR::Expression *convertHashAlgorithmExtern(
Util::SourceInfo srcInfo,
106 static const IR::Expression *convertHashAlgorithmInner(
Util::SourceInfo srcInfo,
107 IR::ID algorithm,
bool msb,
bool extend,
109 const std::string &alg_name);
114 case IR::MAU::HashFunction::IDENTITY:
117 case IR::MAU::HashFunction::CSUM:
118 out <<
"csum" << h.size;
120 case IR::MAU::HashFunction::XOR:
121 out <<
"xor" << h.size;
123 case IR::MAU::HashFunction::CRC:
124 out <<
"crc(0x" << std::hex << h.poly;
125 if (h.init) out <<
" init=0x" << std::hex << h.init;
127 if (h.final_xor) out <<
"^" << std::hex << h.final_xor;
129 case IR::MAU::HashFunction::RANDOM:
133 out <<
"invalid(0x" << std::hex << h.type <<
")";
Definition json_generator.h:36
Definition json_loader.h:38
Definition source_file.h:125
The namespace encapsulating IR node classes.
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition hash_function.h:28
static const IR::Expression * convertHashAlgorithmBFN(Util::SourceInfo srcInfo, IR::ID algorithm)
Definition hash_function.cpp:172
bool setup(const IR::Expression *exp)
Definition hash_function.cpp:404
Definition bfn_hash_algorithm.h:385