Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
Signed-off-by: Komal, Jain <[email protected]>
  • Loading branch information
komaljai committed Oct 24, 2024
1 parent e7cf274 commit 3b7e031
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 96 deletions.
1 change: 0 additions & 1 deletion backends/tc/ebpfCodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ class EBPFControlPNA : public EBPF::EBPFControlPSA {
}
EBPFHashPNA *getHash(cstring name) const {
auto result = ::P4::get(pna_hashes, name);
BUG_CHECK(result != nullptr, "No hash named %1%", name);
return result;
}
void emitExternDefinition(EBPF::CodeBuilder *builder) {
Expand Down
6 changes: 5 additions & 1 deletion backends/tc/tcExterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,11 @@ void EBPFHashPNA::calculateHash(EBPF::CodeBuilder *builder, const IR::MethodCall
}

void CRCChecksumAlgorithmPNA::emitGet(EBPF::CodeBuilder *builder) {
builder->appendFormat("%s", registerVar.c_str());
if (crcWidth == 16) {
builder->appendFormat("%s", registerVar.c_str());
} else {
builder->appendFormat("%s ^ 0xFFFFFFFF", registerVar.c_str());
}
}

void CRCChecksumAlgorithmPNA::emitAddData(EBPF::CodeBuilder *builder, int dataPos,
Expand Down
4 changes: 3 additions & 1 deletion backends/tc/tcExterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ class CRCChecksumAlgorithmPNA : public EBPF::CRCChecksumAlgorithm {
public:
CRCChecksumAlgorithmPNA(const EBPF::EBPFProgram *program, cstring name, int width)
: EBPF::CRCChecksumAlgorithm(program, name, width) {
BUG_CHECK(width == 16 || width == 32, "Must be 16 bits width or 32 bits width.");
initialValue = "0"_cs;
}
void emitGet(EBPF::CodeBuilder *builder) override;
void emitAddData(EBPF::CodeBuilder *builder, const ArgumentsList &arguments,
const IR::MethodCallExpression *expr);
void emitAddData(EBPF::CodeBuilder *builder, int dataPos, const IR::MethodCallExpression *expr);
void emitAddData(EBPF::CodeBuilder *builder, int dataPos,
const IR::MethodCallExpression *expr) override;
};

class EBPFDigestPNA : public EBPF::EBPFDigestPSA {
Expand Down
92 changes: 0 additions & 92 deletions testdata/p4tc_samples_outputs/digest_parser_meta_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,95 +66,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;
}
2 changes: 1 addition & 1 deletion testdata/p4tc_samples_outputs/hash_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
bpf_p4tc_ext_hash_crc32(&hdr->crc.f3, sizeof(hdr->crc.f3), ingress_h_reg);
bpf_p4tc_ext_hash_crc32(&hdr->crc.f4, sizeof(hdr->crc.f4), ingress_h_reg);
hdr->crc.crc = /* h_0.get_hash({hdr->crc.f1, hdr->crc.f2, hdr->crc.f3, hdr->crc.f4}) */
ingress_h_reg;
ingress_h_reg ^ 0xFFFFFFFF;
}
}
{
Expand Down

0 comments on commit 3b7e031

Please sign in to comment.