P4C
The P4 Compiler
Loading...
Searching...
No Matches
dynamic_hash.h
1/*
2 * SPDX-FileCopyrightText: 2024 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_DYNAMIC_HASH_H_
8#define BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_DYNAMIC_HASH_H_
9
10#include <cstdint>
11
12#include "backends/tofino/bf-utils/dynamic_hash/bfn_hash_algorithm.h"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#define PARITY_GROUPS_DYN 16
19#define HASH_MATRIX_WIDTH_DYN 52
20#define HASH_SEED_LENGTH 64
21/* 128 crossbar bytes divided by 16 parity groups divided by 2 per byte pair */
22#define BYTE_PAIRS_PER_PARITY_GROUP 4
23
24enum ixbar_input_type { tCONST, tPHV };
25
29typedef struct hash_symmetric_info_ {
30 /* Whether this bit-range is symmetric */
31 bool is_symmetric;
32 /* The symmetric group for this hash input */
33 uint32_t sym_group;
34 /* The symmetric group which this hash input
35 * needs to be symmetrically hashed with */
36 uint32_t sib_sym_group;
37} hash_symmetric_info_t;
38
55typedef struct ixbar_input_ {
56 enum ixbar_input_type type;
57 uint32_t ixbar_bit_position;
58 uint32_t bit_size;
59 hash_symmetric_info_t symmetric_info;
60 union {
61 bool valid;
62 uint64_t constant;
63 } u;
64} ixbar_input_t;
65
74typedef struct hash_calc_output_ {
75 uint32_t p4_hash_output_bit;
76 uint32_t gfm_start_bit;
77 uint32_t bit_size;
78} hash_matrix_output_t;
79
91typedef struct hash_calc_rotate_info {
92 uint64_t rotate;
93 uint32_t num_hash_bits;
94 uint32_t *gfm_bit_posn;
95 uint32_t *p4_hash_output_bit_posn;
96} hash_calc_rotate_info_t;
97
102typedef struct ixbar_init_ {
103 ixbar_input_t *ixbar_inputs;
104 uint32_t inputs_sz;
105
106 hash_matrix_output_t *hash_matrix_outputs;
107 uint32_t outputs_sz;
108
109 uint32_t parity_group;
110} ixbar_init_t;
111
117typedef struct hash_column_ {
118 uint64_t column_value;
119 uint8_t byte_used;
120} hash_column_t;
121
127typedef struct hash_seed_ {
128 uint64_t hash_seed_value;
129 uint64_t hash_seed_used;
130} hash_seed_t;
131
134 uint32_t byte_pair_index;
135 uint32_t hash_bit;
136
137 unsigned byte0;
138 unsigned valid0;
139 unsigned byte1;
140 unsigned valid1;
141} galois_field_matrix_delta_t;
142
144typedef struct hash_seed_delta_ {
145 uint32_t hash_bit;
146 unsigned hash_seed_and_value;
147 unsigned hash_seed_or_value;
148} hash_seed_delta_t;
149
151typedef struct hash_regs_ {
152 // This field must be freed after use
153 galois_field_matrix_delta_t *galois_field_matrix_regs;
154 uint32_t gfm_sz;
155
156 // This field must be freed after use
157 hash_seed_delta_t *hash_seed_regs;
158 uint32_t hs_sz;
159} hash_regs_t;
160
176void determine_hash_matrix(const ixbar_init_t *ixbar_init, const ixbar_input_t *inputs,
177 uint32_t inputs_sz, const bfn_hash_algorithm_t *alg,
178 hash_column_t hash_matrix[PARITY_GROUPS_DYN][HASH_MATRIX_WIDTH_DYN]);
194void determine_seed(const hash_matrix_output_t *hash_matrix_outputs, uint32_t outputs_sz,
195 const ixbar_input_t *inputs, uint32_t inputs_sz, uint32_t total_input_bits,
196 const bfn_hash_algorithm_t *alg, hash_seed_t *hash_seed);
197
213void determine_tofino_regs(const ixbar_init_t *ixbar_init, const ixbar_input_t *inputs,
214 uint32_t input_sz, const bfn_hash_algorithm_t *alg,
215 hash_calc_rotate_info_t *rot_info, hash_regs_t *hash_regs);
216
217#ifdef __cplusplus
218}
219#endif
220
221#endif /* BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_DYNAMIC_HASH_H_ */
Definition dynamic_hash.h:133
Definition dynamic_hash.h:74
Definition dynamic_hash.h:91
Definition dynamic_hash.h:117
Definition dynamic_hash.h:151
Definition dynamic_hash.h:127
Definition dynamic_hash.h:144
Contains Symmetric hashing info for a hash input.
Definition dynamic_hash.h:29
Definition dynamic_hash.h:102
Definition dynamic_hash.h:55