P4C
The P4 Compiler
Loading...
Searching...
No Matches
dynamic_hash.h
1#ifndef BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_DYNAMIC_HASH_H_
2#define BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_DYNAMIC_HASH_H_
3
4#include <cstdint>
5
6#include "backends/tofino/bf-utils/dynamic_hash/bfn_hash_algorithm.h"
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#define PARITY_GROUPS_DYN 16
13#define HASH_MATRIX_WIDTH_DYN 52
14#define HASH_SEED_LENGTH 64
15/* 128 crossbar bytes divided by 16 parity groups divided by 2 per byte pair */
16#define BYTE_PAIRS_PER_PARITY_GROUP 4
17
18enum ixbar_input_type { tCONST, tPHV };
19
23typedef struct hash_symmetric_info_ {
24 /* Whether this bit-range is symmetric */
25 bool is_symmetric;
26 /* The symmetric group for this hash input */
27 uint32_t sym_group;
28 /* The symmetric group which this hash input
29 * needs to be symmetrically hashed with */
30 uint32_t sib_sym_group;
31} hash_symmetric_info_t;
32
49typedef struct ixbar_input_ {
50 enum ixbar_input_type type;
51 uint32_t ixbar_bit_position;
52 uint32_t bit_size;
53 hash_symmetric_info_t symmetric_info;
54 union {
55 bool valid;
56 uint64_t constant;
57 } u;
58} ixbar_input_t;
59
68typedef struct hash_calc_output_ {
69 uint32_t p4_hash_output_bit;
70 uint32_t gfm_start_bit;
71 uint32_t bit_size;
72} hash_matrix_output_t;
73
85typedef struct hash_calc_rotate_info {
86 uint64_t rotate;
87 uint32_t num_hash_bits;
88 uint32_t *gfm_bit_posn;
89 uint32_t *p4_hash_output_bit_posn;
90} hash_calc_rotate_info_t;
91
96typedef struct ixbar_init_ {
97 ixbar_input_t *ixbar_inputs;
98 uint32_t inputs_sz;
99
100 hash_matrix_output_t *hash_matrix_outputs;
101 uint32_t outputs_sz;
102
103 uint32_t parity_group;
104} ixbar_init_t;
105
111typedef struct hash_column_ {
112 uint64_t column_value;
113 uint8_t byte_used;
114} hash_column_t;
115
121typedef struct hash_seed_ {
122 uint64_t hash_seed_value;
123 uint64_t hash_seed_used;
124} hash_seed_t;
125
128 uint32_t byte_pair_index;
129 uint32_t hash_bit;
130
131 unsigned byte0;
132 unsigned valid0;
133 unsigned byte1;
134 unsigned valid1;
135} galois_field_matrix_delta_t;
136
138typedef struct hash_seed_delta_ {
139 uint32_t hash_bit;
140 unsigned hash_seed_and_value;
141 unsigned hash_seed_or_value;
142} hash_seed_delta_t;
143
145typedef struct hash_regs_ {
146 // This field must be freed after use
147 galois_field_matrix_delta_t *galois_field_matrix_regs;
148 uint32_t gfm_sz;
149
150 // This field must be freed after use
151 hash_seed_delta_t *hash_seed_regs;
152 uint32_t hs_sz;
153} hash_regs_t;
154
170void determine_hash_matrix(const ixbar_init_t *ixbar_init, const ixbar_input_t *inputs,
171 uint32_t inputs_sz, const bfn_hash_algorithm_t *alg,
172 hash_column_t hash_matrix[PARITY_GROUPS_DYN][HASH_MATRIX_WIDTH_DYN]);
188void determine_seed(const hash_matrix_output_t *hash_matrix_outputs, uint32_t outputs_sz,
189 const ixbar_input_t *inputs, uint32_t inputs_sz, uint32_t total_input_bits,
190 const bfn_hash_algorithm_t *alg, hash_seed_t *hash_seed);
191
207void determine_tofino_regs(const ixbar_init_t *ixbar_init, const ixbar_input_t *inputs,
208 uint32_t input_sz, const bfn_hash_algorithm_t *alg,
209 hash_calc_rotate_info_t *rot_info, hash_regs_t *hash_regs);
210
211#ifdef __cplusplus
212}
213#endif
214
215#endif /* BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_DYNAMIC_HASH_H_ */
Definition dynamic_hash.h:127
Definition dynamic_hash.h:68
Definition dynamic_hash.h:85
Definition dynamic_hash.h:111
Definition dynamic_hash.h:145
Definition dynamic_hash.h:121
Definition dynamic_hash.h:138
Contains Symmetric hashing info for a hash input.
Definition dynamic_hash.h:23
Definition dynamic_hash.h:96
Definition dynamic_hash.h:49