nr_polar_defs.h 11.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22 23
/*!\file PHY/CODING/nrPolar_tools/nr_polar_defs.h
 * \brief
24
 * \author Raymond Knopp, Turker Yilmaz
25 26 27
 * \date 2018
 * \version 0.1
 * \company EURECOM
28
 * \email raymond.knopp@eurecom.fr, turker.yilmaz@eurecom.fr
29 30 31
 * \note
 * \warning
*/
32

Guy De Souza's avatar
Guy De Souza committed
33 34 35 36 37 38 39 40 41
#ifndef __NR_POLAR_DEFS__H__
#define __NR_POLAR_DEFS__H__

#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

42 43 44
#include "PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
yilmazt's avatar
yilmazt committed
45
#include "PHY/CODING/coding_defs.h"
46
//#include "SIMULATION/TOOLS/sim.h"
47

48 49
#define NR_POLAR_DECODER_LISTSIZE 8 //uint8_t

yilmazt's avatar
yilmazt committed
50 51 52 53 54
#define NR_POLAR_AGGREGATION_LEVEL_1_PRIME 149 //uint16_t
#define NR_POLAR_AGGREGATION_LEVEL_2_PRIME 151 //uint16_t
#define NR_POLAR_AGGREGATION_LEVEL_4_PRIME 157 //uint16_t
#define NR_POLAR_AGGREGATION_LEVEL_8_PRIME 163 //uint16_t
#define NR_POLAR_AGGREGATION_LEVEL_16_PRIME 167 //uint16_t
55

56
static const uint8_t nr_polar_subblock_interleaver_pattern[32] = {0,1,2,4,3,5,6,7,8,16,9,17,10,18,11,19,12,20,13,21,14,22,15,23,24,25,26,28,27,29,30,31};
57 58 59 60

#define Nmax 1024
#define nmax 10

61 62
#define uint128_t __uint128_t

63 64 65 66 67 68 69 70 71
typedef struct decoder_node_t_s {
  struct decoder_node_t_s *left;
  struct decoder_node_t_s *right;
  int level;
  int leaf;
  int Nv;
  int first_leaf_index;
  int all_frozen;
  int16_t *alpha;
72
  int16_t *beta;
73 74 75 76 77 78 79
} decoder_node_t;

typedef struct decoder_tree_t_s {
  decoder_node_t *root;
  int num_nodes;
} decoder_tree_t;

80
struct nrPolar_params {
81 82 83
  //messageType: 0=PBCH, 1=DCI, -1=UCI
  int idx; //idx = (messageType * messageLength * aggregation_prime);
  struct nrPolar_params *nextPtr;
84

85 86 87 88 89 90 91 92 93 94 95 96 97 98
  uint8_t n_max;
  uint8_t i_il;
  uint8_t i_seg;
  uint8_t n_pc;
  uint8_t n_pc_wm;
  uint8_t i_bil;
  uint16_t payloadBits;
  uint16_t encoderLength;
  uint8_t crcParityBits;
  uint8_t crcCorrectionBits;
  uint16_t K;
  uint16_t N;
  uint8_t n;
  uint32_t crcBit;
99

100
  uint16_t *interleaving_pattern;
101
  uint16_t *deinterleaving_pattern;
102 103 104 105 106 107 108
  uint16_t *rate_matching_pattern;
  const uint16_t *Q_0_Nminus1;
  int16_t *Q_I_N;
  int16_t *Q_F_N;
  int16_t *Q_PC_N;
  uint8_t *information_bit_pattern;
  uint16_t *channel_interleaver_pattern;
109
  //uint32_t crc_polynomial;
110

111 112 113
  uint8_t **crc_generator_matrix; //G_P
  uint8_t **G_N;
  uint64_t **G_N_tab;
114
  int groupsize;
115
  int *rm_tab;
116 117 118 119
  uint64_t cprime_tab0[32][256];
  uint64_t cprime_tab1[32][256];
  uint64_t B_tab0[32][256];
  uint64_t B_tab1[32][256];
120
  uint8_t **extended_crc_generator_matrix;
121 122 123 124 125 126 127
  //lowercase: bits, Uppercase: Bits stored in bytes
  //polar_encoder vectors
  uint8_t *nr_polar_crc;
  uint8_t *nr_polar_aPrime;
  uint8_t *nr_polar_APrime;
  uint8_t *nr_polar_D;
  uint8_t *nr_polar_E;
128

129 130 131 132 133
  //Polar Coding vectors
  uint8_t *nr_polar_A;
  uint8_t *nr_polar_CPrime;
  uint8_t *nr_polar_B;
  uint8_t *nr_polar_U;
134

135
  decoder_tree_t tree;
136 137 138
} __attribute__ ((__packed__));
typedef struct nrPolar_params t_nrPolar_params;

yilmazt's avatar
yilmazt committed
139
void polar_encoder(uint32_t *input,
140 141
                   uint32_t *output,
                   t_nrPolar_params *polarParams);
yilmazt's avatar
yilmazt committed
142 143

void polar_encoder_dci(uint32_t *in,
144 145 146
                       uint32_t *out,
                       t_nrPolar_params *polarParams,
                       uint16_t n_RNTI);
147

yilmazt's avatar
yilmazt committed
148
void polar_encoder_fast(uint64_t *A,
149 150 151
                        uint32_t *out,
                        int32_t crcmask,
                        t_nrPolar_params *polarParams);
yilmazt's avatar
yilmazt committed
152

153
int8_t polar_decoder(double *input,
154
					 uint32_t *output,
155
                     t_nrPolar_params *polarParams,
156
                     uint8_t listSize);
157

158
uint32_t polar_decoder_int16(int16_t *input,
159 160
                             uint64_t *out,
                             const t_nrPolar_params *polarParams);
161

162
int8_t polar_decoder_dci(double *input,
163 164 165 166
                         uint32_t *out,
                         t_nrPolar_params *polarParams,
                         uint8_t listSize,
                         uint16_t n_RNTI);
yilmazt's avatar
yilmazt committed
167

168 169 170 171 172 173 174 175 176 177 178
void generic_polar_decoder(const t_nrPolar_params *pp,
						   decoder_node_t *node);

void applyFtoleft(const t_nrPolar_params *pp,
				  decoder_node_t *node);

void applyGtoright(const t_nrPolar_params *pp,
				   decoder_node_t *node);

void computeBeta(const t_nrPolar_params *pp,
				 decoder_node_t *node);
179

yilmazt's avatar
yilmazt committed
180
void build_decoder_tree(t_nrPolar_params *pp);
181
void build_polar_tables(t_nrPolar_params *polarParams);
yilmazt's avatar
yilmazt committed
182
void init_polar_deinterleaver_table(t_nrPolar_params *polarParams);
Raymond Knopp's avatar
Raymond Knopp committed
183

184
void nr_polar_print_polarParams(t_nrPolar_params *polarParams);
185

186 187 188
t_nrPolar_params *nr_polar_params (int8_t messageType,
                                   uint16_t messageLength,
                                   uint8_t aggregation_level);
Guy De Souza's avatar
Guy De Souza committed
189

yilmazt's avatar
yilmazt committed
190
uint16_t nr_polar_aggregation_prime (uint8_t aggregation_level);
Guy De Souza's avatar
Guy De Souza committed
191

192
uint8_t **nr_polar_kronecker_power_matrices(uint8_t n);
Guy De Souza's avatar
Guy De Souza committed
193

194
const uint16_t *nr_polar_sequence_pattern(uint8_t n);
Guy De Souza's avatar
Guy De Souza committed
195

yilmazt's avatar
yilmazt committed
196 197 198 199 200 201
/*!@fn uint32_t nr_polar_output_length(uint16_t K, uint16_t E, uint8_t n_max)
 * @brief Computes...
 * @param K Number of bits to encode (=payloadBits+crcParityBits)
 * @param E
 * @param n_max */
uint32_t nr_polar_output_length(uint16_t K,
202 203
                                uint16_t E,
                                uint8_t n_max);
yilmazt's avatar
yilmazt committed
204 205

void nr_polar_channel_interleaver_pattern(uint16_t *cip,
206 207
    uint8_t I_BIL,
    uint16_t E);
yilmazt's avatar
yilmazt committed
208 209

void nr_polar_rate_matching_pattern(uint16_t *rmp,
210 211 212 213 214
                                    uint16_t *J,
                                    const uint8_t *P_i_,
                                    uint16_t K,
                                    uint16_t N,
                                    uint16_t E);
yilmazt's avatar
yilmazt committed
215 216

void nr_polar_rate_matching(double *input,
217 218 219 220 221
                            double *output,
                            uint16_t *rmp,
                            uint16_t K,
                            uint16_t N,
                            uint16_t E);
yilmazt's avatar
yilmazt committed
222 223

void nr_polar_rate_matching_int16(int16_t *input,
224 225 226 227 228
                                  int16_t *output,
                                  uint16_t *rmp,
                                  uint16_t K,
                                  uint16_t N,
                                  uint16_t E);
229

yilmazt's avatar
yilmazt committed
230
void nr_polar_interleaving_pattern(uint16_t K,
231 232
                                   uint8_t I_IL,
                                   uint16_t *PI_k_);
yilmazt's avatar
yilmazt committed
233 234

void nr_polar_info_bit_pattern(uint8_t *ibp,
235 236 237 238 239 240 241 242
                               int16_t *Q_I_N,
                               int16_t *Q_F_N,
                               uint16_t *J,
                               const uint16_t *Q_0_Nminus1,
                               uint16_t K,
                               uint16_t N,
                               uint16_t E,
                               uint8_t n_PC);
yilmazt's avatar
yilmazt committed
243 244

void nr_polar_info_bit_extraction(uint8_t *input,
245 246 247
                                  uint8_t *output,
                                  uint8_t *pattern,
                                  uint16_t size);
yilmazt's avatar
yilmazt committed
248

249
void nr_bit2byte_uint32_8(uint32_t *in,
250 251
                          uint16_t arraySize,
                          uint8_t *out);
yilmazt's avatar
yilmazt committed
252

253
void nr_byte2bit_uint8_32(uint8_t *in,
254 255 256 257
                          uint16_t arraySize,
                          uint32_t *out);

uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits);
yilmazt's avatar
yilmazt committed
258

259 260 261
uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits);

uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits);
yilmazt's avatar
yilmazt committed
262 263

void nr_polar_bit_insertion(uint8_t *input,
264 265 266 267 268 269
                            uint8_t *output,
                            uint16_t N,
                            uint16_t K,
                            int16_t *Q_I_N,
                            int16_t *Q_PC_N,
                            uint8_t n_PC);
yilmazt's avatar
yilmazt committed
270 271

void nr_matrix_multiplication_uint8_1D_uint8_2D(uint8_t *matrix1,
272 273 274 275
    uint8_t **matrix2,
    uint8_t *output,
    uint16_t row,
    uint16_t col);
yilmazt's avatar
yilmazt committed
276 277

uint8_t ***nr_alloc_uint8_3D_array(uint16_t xlen,
278 279
                                   uint16_t ylen,
                                   uint16_t zlen);
yilmazt's avatar
yilmazt committed
280 281

uint8_t **nr_alloc_uint8_2D_array(uint16_t xlen,
282
                                  uint16_t ylen);
yilmazt's avatar
yilmazt committed
283 284

double ***nr_alloc_double_3D_array(uint16_t xlen,
285 286
                                   uint16_t ylen,
                                   uint16_t zlen);
yilmazt's avatar
yilmazt committed
287

yilmazt's avatar
yilmazt committed
288
double **nr_alloc_double_2D_array(uint16_t xlen,
289
                                  uint16_t ylen);
yilmazt's avatar
yilmazt committed
290 291

void nr_free_double_3D_array(double ***input,
292 293
                             uint16_t xlen,
                             uint16_t ylen);
yilmazt's avatar
yilmazt committed
294 295

void nr_free_double_2D_array(double **input,
296
                             uint16_t xlen);
yilmazt's avatar
yilmazt committed
297 298

void nr_free_uint8_3D_array(uint8_t ***input,
299 300
                            uint16_t xlen,
                            uint16_t ylen);
yilmazt's avatar
yilmazt committed
301 302

void nr_free_uint8_2D_array(uint8_t **input,
303
                            uint16_t xlen);
yilmazt's avatar
yilmazt committed
304 305

void nr_sort_asc_double_1D_array_ind(double *matrix,
306 307
                                     uint8_t *ind,
                                     uint8_t len);
yilmazt's avatar
yilmazt committed
308 309

void nr_sort_asc_int16_1D_array_ind(int32_t *matrix,
310 311
                                    int *ind,
                                    int len);
yilmazt's avatar
yilmazt committed
312

313 314
void nr_free_double_2D_array(double **input, uint16_t xlen);

yilmazt's avatar
yilmazt committed
315
void updateLLR(double ***llr,
316 317 318 319 320 321 322
               uint8_t **llrU,
               uint8_t ***bit,
               uint8_t **bitU,
               uint8_t listSize,
               uint16_t row,
               uint16_t col,
               uint16_t xlen,
323
               uint8_t ylen);
yilmazt's avatar
yilmazt committed
324 325

void updateBit(uint8_t ***bit,
326 327 328 329 330 331
               uint8_t **bitU,
               uint8_t listSize,
               uint16_t row,
               uint16_t col,
               uint16_t xlen,
               uint8_t ylen);
yilmazt's avatar
yilmazt committed
332 333

void updatePathMetric(double *pathMetric,
334 335 336
                      double ***llr,
                      uint8_t listSize,
                      uint8_t bitValue,
337
                      uint16_t row);
yilmazt's avatar
yilmazt committed
338 339

void updatePathMetric2(double *pathMetric,
340 341
                       double ***llr,
                       uint8_t listSize,
342
                       uint16_t row);
yilmazt's avatar
yilmazt committed
343 344

void computeLLR(double ***llr,
345 346 347
                uint16_t row,
                uint16_t col,
                uint8_t i,
348
                uint16_t offset);
yilmazt's avatar
yilmazt committed
349 350

void updateCrcChecksum(uint8_t **crcChecksum,
351 352 353 354
                       uint8_t **crcGen,
                       uint8_t listSize,
                       uint32_t i2,
                       uint8_t len);
yilmazt's avatar
yilmazt committed
355 356

void updateCrcChecksum2(uint8_t **crcChecksum,
357 358 359 360
                        uint8_t **crcGen,
                        uint8_t listSize,
                        uint32_t i2,
                        uint8_t len);
361

yilmazt's avatar
yilmazt committed
362
//Also nr_polar_rate_matcher
yilmazt's avatar
yilmazt committed
363
static inline void nr_polar_interleaver(uint8_t *input,
364 365 366
                                        uint8_t *output,
                                        uint16_t *pattern,
                                        uint16_t size) {
367
  for (int i=0; i<size; i++) output[i]=input[pattern[i]];
368 369
}

yilmazt's avatar
yilmazt committed
370
static inline void nr_polar_deinterleaver(uint8_t *input,
371 372 373 374
										  uint8_t *output,
										  uint16_t *pattern,
										  uint16_t size) {
	for (int i=0; i<size; i++) output[pattern[i]]=input[i];
375 376
}

Guy De Souza's avatar
Guy De Souza committed
377
#endif