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