remove usage of undefined var in polar and memory leaks
This commit is contained in:
committed by
Robert Schmidt
parent
51625f3c8f
commit
be314a9770
@@ -160,7 +160,7 @@ if (logFlag){
|
||||
|
||||
uint8_t testArrayLength = ceil(testLength / 32.0);
|
||||
uint8_t coderArrayLength = ceil(coderLength / 32.0);
|
||||
uint32_t testInput[testArrayLength]; //generate randomly
|
||||
uint32_t testInput[min(2,testArrayLength)]; //generate randomly
|
||||
uint32_t encoderOutput[coderArrayLength];
|
||||
uint32_t estimatedOutput[testArrayLength]; //decoder output
|
||||
memset(testInput,0,sizeof(uint32_t) * testArrayLength);
|
||||
|
||||
@@ -39,19 +39,40 @@
|
||||
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
|
||||
#include "assertions.h"
|
||||
|
||||
static inline void updateCrcChecksum2(int xlen,
|
||||
int ylen,
|
||||
uint8_t crcChecksum[xlen][ylen],
|
||||
int gxlen,
|
||||
int gylen,
|
||||
uint8_t crcGen[gxlen][gylen],
|
||||
uint8_t listSize,
|
||||
uint32_t i2,
|
||||
uint8_t len)
|
||||
{
|
||||
for (uint8_t i = 0; i < listSize; i++) {
|
||||
for (uint8_t j = 0; j < len; j++) {
|
||||
crcChecksum[j][i+listSize] = ( (crcChecksum[j][i] + crcGen[i2][j]) % 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int8_t polar_decoder(double *input,
|
||||
uint32_t *out,
|
||||
const t_nrPolar_params *polarParams,
|
||||
uint8_t listSize)
|
||||
{
|
||||
//Assumes no a priori knowledge.
|
||||
uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize);
|
||||
uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
|
||||
uint8_t **llrUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
|
||||
double ***llr = nr_alloc_double_3D_array(polarParams->N, (polarParams->n+1), 2*listSize);
|
||||
uint8_t **crcChecksum = nr_alloc_uint8_2D_array(polarParams->crcParityBits, 2*listSize);
|
||||
double *pathMetric = malloc(sizeof(double)*(2*listSize));
|
||||
uint8_t *crcState = malloc(sizeof(uint8_t)*(2*listSize)); //0=False, 1=True
|
||||
uint8_t bit[polarParams->N][polarParams->n+1][2*listSize];
|
||||
memset(bit,0,sizeof bit);
|
||||
uint8_t bitUpdated[polarParams->N][polarParams->n+1]; //0=False, 1=True
|
||||
memset(bitUpdated,0,sizeof bitUpdated);
|
||||
uint8_t llrUpdated[polarParams->N][polarParams->n+1]; //0=False, 1=True
|
||||
memset(llrUpdated,0,sizeof llrUpdated);
|
||||
double llr[polarParams->N][polarParams->n+1][2*listSize];
|
||||
uint8_t crcChecksum[polarParams->crcParityBits][2*listSize];
|
||||
memset(crcChecksum,0,sizeof crcChecksum);
|
||||
double pathMetric[2*listSize];
|
||||
uint8_t crcState[2*listSize]; //0=False, 1=True
|
||||
|
||||
for (int i=0; i<(2*listSize); i++) {
|
||||
pathMetric[i] = 0;
|
||||
@@ -63,13 +84,8 @@ int8_t polar_decoder(double *input,
|
||||
bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2);
|
||||
}
|
||||
|
||||
uint8_t **extended_crc_generator_matrix = malloc(polarParams->K * sizeof(uint8_t *)); //G_P3
|
||||
uint8_t **tempECGM = malloc(polarParams->K * sizeof(uint8_t *)); //G_P2
|
||||
|
||||
for (int i = 0; i < polarParams->K; i++) {
|
||||
extended_crc_generator_matrix[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t));
|
||||
tempECGM[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t));
|
||||
}
|
||||
uint8_t extended_crc_generator_matrix[polarParams->K][polarParams->crcParityBits]; //G_P3
|
||||
uint8_t tempECGM[polarParams->K][polarParams->crcParityBits]; //G_P2
|
||||
|
||||
for (int i=0; i<polarParams->payloadBits; i++) {
|
||||
for (int j=0; j<polarParams->crcParityBits; j++) {
|
||||
@@ -102,7 +118,7 @@ int8_t polar_decoder(double *input,
|
||||
}
|
||||
}
|
||||
|
||||
double *d_tilde = malloc(sizeof(double) * polarParams->N);
|
||||
double d_tilde[polarParams->N];
|
||||
nr_polar_rate_matching(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength);
|
||||
|
||||
for (int j = 0; j < polarParams->N; j++) llr[j][polarParams->n][0]=d_tilde[j];
|
||||
@@ -117,12 +133,12 @@ int8_t polar_decoder(double *input,
|
||||
uint8_t listIndex[2*listSize], copyIndex;
|
||||
|
||||
for (uint16_t currentBit=0; currentBit<polarParams->N; currentBit++) {
|
||||
updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1));
|
||||
updateLLR(currentListSize, currentBit, 0, polarParams->N, polarParams->n+1, 2*listSize, llr, llrUpdated, bit, bitUpdated);
|
||||
|
||||
if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit.
|
||||
updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit);
|
||||
updatePathMetric(pathMetric, currentListSize, 0, currentBit, polarParams->N, polarParams->n+1, 2*listSize, llr);
|
||||
} else { //Information or CRC bit.
|
||||
updatePathMetric2(pathMetric, llr, currentListSize, currentBit);
|
||||
updatePathMetric2(pathMetric, currentListSize, currentBit, polarParams->N, polarParams->n+1, 2*listSize, llr);
|
||||
|
||||
for (int i = 0; i < currentListSize; i++) {
|
||||
for (int j = 0; j < polarParams->N; j++) {
|
||||
@@ -141,7 +157,9 @@ int8_t polar_decoder(double *input,
|
||||
for (int i = currentListSize; i < 2*currentListSize; i++) bit[currentBit][0][i]=1;
|
||||
|
||||
bitUpdated[currentBit][0]=1;
|
||||
updateCrcChecksum2(crcChecksum, extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits);
|
||||
updateCrcChecksum2(polarParams->crcParityBits, 2*listSize, crcChecksum,
|
||||
polarParams->K, polarParams->crcParityBits, extended_crc_generator_matrix,
|
||||
currentListSize, nonFrozenBit, polarParams->crcParityBits);
|
||||
currentListSize*=2;
|
||||
|
||||
//Keep only the best "listSize" number of entries.
|
||||
@@ -246,12 +264,12 @@ int8_t polar_decoder(double *input,
|
||||
|
||||
if (decoderIterationCheck==0) {
|
||||
//perror("[SCL polar decoder] All list entries have failed the CRC checks.");
|
||||
free(d_tilde);
|
||||
free(pathMetric);
|
||||
free(crcState);
|
||||
nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1));
|
||||
nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1));
|
||||
nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits);
|
||||
//free(d_tilde);
|
||||
//free(pathMetric);
|
||||
//free(crcState);
|
||||
//nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1));
|
||||
//nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1));
|
||||
//nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits);
|
||||
free(tempECGM);
|
||||
return(-1);
|
||||
}
|
||||
@@ -282,14 +300,6 @@ int8_t polar_decoder(double *input,
|
||||
}
|
||||
}
|
||||
|
||||
free(d_tilde);
|
||||
free(pathMetric);
|
||||
free(crcState);
|
||||
nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1));
|
||||
nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1));
|
||||
nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits);
|
||||
nr_free_uint8_2D_array(extended_crc_generator_matrix, polarParams->K);
|
||||
nr_free_uint8_2D_array(tempECGM, polarParams->K);
|
||||
/*
|
||||
* Return bits.
|
||||
*/
|
||||
@@ -302,13 +312,17 @@ int8_t polar_decoder_dci(double *input,
|
||||
const t_nrPolar_params *polarParams,
|
||||
uint8_t listSize,
|
||||
uint16_t n_RNTI) {
|
||||
uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize);
|
||||
uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
|
||||
uint8_t **llrUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
|
||||
double ***llr = nr_alloc_double_3D_array(polarParams->N, (polarParams->n+1), 2*listSize);
|
||||
uint8_t **crcChecksum = nr_alloc_uint8_2D_array(polarParams->crcParityBits, 2*listSize);
|
||||
double *pathMetric = malloc(sizeof(double)*(2*listSize));
|
||||
uint8_t *crcState = malloc(sizeof(uint8_t)*(2*listSize)); //0=False, 1=True
|
||||
uint8_t bit[polarParams->N][polarParams->n+1][2*listSize];
|
||||
memset(bit,0,sizeof bit);
|
||||
uint8_t bitUpdated[polarParams->N][polarParams->n+1]; //0=False, 1=True
|
||||
memset(bitUpdated,0,sizeof bitUpdated);
|
||||
uint8_t llrUpdated[polarParams->N][polarParams->n+1]; //0=False, 1=True
|
||||
memset(llrUpdated,0,sizeof llrUpdated);
|
||||
double llr[polarParams->N][polarParams->n+1][2*listSize];
|
||||
uint8_t crcChecksum[polarParams->crcParityBits][2*listSize];
|
||||
memset(crcChecksum,0,sizeof crcChecksum);
|
||||
double pathMetric[2*listSize];
|
||||
uint8_t crcState[2*listSize]; //0=False, 1=True
|
||||
uint8_t extended_crc_scrambling_pattern[polarParams->crcParityBits];
|
||||
|
||||
for (int i=0; i<(2*listSize); i++) {
|
||||
@@ -321,13 +335,8 @@ int8_t polar_decoder_dci(double *input,
|
||||
bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2);
|
||||
}
|
||||
|
||||
uint8_t **extended_crc_generator_matrix = malloc(polarParams->K * sizeof(uint8_t *)); //G_P3: K-by-P
|
||||
uint8_t **tempECGM = malloc(polarParams->K * sizeof(uint8_t *)); //G_P2: K-by-P
|
||||
|
||||
for (int i = 0; i < polarParams->K; i++) {
|
||||
extended_crc_generator_matrix[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t));
|
||||
tempECGM[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t));
|
||||
}
|
||||
uint8_t extended_crc_generator_matrix[polarParams->K][polarParams->crcParityBits]; //G_P3: K-by-P
|
||||
uint8_t tempECGM[polarParams->K][polarParams->crcParityBits]; //G_P2: K-by-P
|
||||
|
||||
for (int i=0; i<polarParams->payloadBits; i++) {
|
||||
for (int j=0; j<polarParams->crcParityBits; j++) {
|
||||
@@ -366,17 +375,19 @@ int8_t polar_decoder_dci(double *input,
|
||||
extended_crc_scrambling_pattern[i]=(n_RNTI>>(23-i))&1;
|
||||
}
|
||||
|
||||
double *d_tilde = malloc(sizeof(double) * polarParams->N);
|
||||
double d_tilde[polarParams->N];
|
||||
nr_polar_rate_matching(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength);
|
||||
|
||||
for (int j = 0; j < polarParams->N; j++) llr[j][polarParams->n][0]=d_tilde[j];
|
||||
for (int j = 0; j < polarParams->N; j++)
|
||||
llr[j][polarParams->n][0]=d_tilde[j];
|
||||
|
||||
/*
|
||||
* SCL polar decoder.
|
||||
*/
|
||||
|
||||
for (int i=0; i<polarParams->crcParityBits; i++) {
|
||||
for (int j=0; j<polarParams->crcParityBits; j++) crcChecksum[i][0]=crcChecksum[i][0]+polarParams->crc_generator_matrix[j][i];
|
||||
for (int j=0; j<polarParams->crcParityBits; j++)
|
||||
crcChecksum[i][0]=crcChecksum[i][0]+polarParams->crc_generator_matrix[j][i];
|
||||
|
||||
crcChecksum[i][0]=(crcChecksum[i][0]%2);
|
||||
}
|
||||
@@ -388,12 +399,12 @@ int8_t polar_decoder_dci(double *input,
|
||||
uint8_t listIndex[2*listSize], copyIndex;
|
||||
|
||||
for (uint16_t currentBit=0; currentBit<polarParams->N; currentBit++) {
|
||||
updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1));
|
||||
updateLLR(currentListSize, currentBit, 0, polarParams->N, polarParams->n+1, 2*listSize, llr, llrUpdated, bit, bitUpdated);
|
||||
|
||||
if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit.
|
||||
updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit);
|
||||
updatePathMetric(pathMetric, currentListSize, 0, currentBit,polarParams->N, polarParams->n+1, 2*listSize, llr);
|
||||
} else { //Information or CRC bit.
|
||||
updatePathMetric2(pathMetric, llr, currentListSize, currentBit);
|
||||
updatePathMetric2(pathMetric, currentListSize, currentBit, polarParams->N, polarParams->n+1, 2*listSize, llr);
|
||||
|
||||
for (int i = 0; i < currentListSize; i++) {
|
||||
for (int j = 0; j < polarParams->N; j++) {
|
||||
@@ -412,7 +423,9 @@ int8_t polar_decoder_dci(double *input,
|
||||
for (int i = currentListSize; i < 2*currentListSize; i++) bit[currentBit][0][i]=1;
|
||||
|
||||
bitUpdated[currentBit][0]=1;
|
||||
updateCrcChecksum2(crcChecksum, extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits);
|
||||
updateCrcChecksum2(polarParams->crcParityBits, 2*listSize, crcChecksum,
|
||||
polarParams->K, polarParams->crcParityBits, extended_crc_generator_matrix,
|
||||
currentListSize, nonFrozenBit, polarParams->crcParityBits);
|
||||
currentListSize*=2;
|
||||
|
||||
//Keep only the best "listSize" number of entries.
|
||||
@@ -513,16 +526,17 @@ int8_t polar_decoder_dci(double *input,
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < currentListSize; i++) decoderIterationCheck+=crcState[i];
|
||||
for (uint8_t i = 0; i < currentListSize; i++)
|
||||
decoderIterationCheck+=crcState[i];
|
||||
|
||||
if (decoderIterationCheck==0) {
|
||||
//perror("[SCL polar decoder] All list entries have failed the CRC checks.");
|
||||
free(d_tilde);
|
||||
free(pathMetric);
|
||||
free(crcState);
|
||||
nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1));
|
||||
nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1));
|
||||
nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits);
|
||||
//free(d_tilde);
|
||||
//free(pathMetric);
|
||||
//free(crcState);
|
||||
//nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1));
|
||||
//nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1));
|
||||
//nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits);
|
||||
free(tempECGM);
|
||||
return(-1);
|
||||
}
|
||||
@@ -553,14 +567,6 @@ int8_t polar_decoder_dci(double *input,
|
||||
}
|
||||
}
|
||||
|
||||
free(d_tilde);
|
||||
free(pathMetric);
|
||||
free(crcState);
|
||||
nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1));
|
||||
nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1));
|
||||
nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits);
|
||||
nr_free_uint8_2D_array(extended_crc_generator_matrix, polarParams->K);
|
||||
nr_free_uint8_2D_array(tempECGM, polarParams->K);
|
||||
/*
|
||||
* Return bits.
|
||||
*/
|
||||
|
||||
@@ -36,51 +36,25 @@
|
||||
|
||||
//#define DEBUG_NEW_IMPL 1
|
||||
|
||||
void updateLLR(double ***llr,
|
||||
uint8_t **llrU,
|
||||
uint8_t ***bit,
|
||||
uint8_t **bitU,
|
||||
uint8_t listSize,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint16_t xlen,
|
||||
uint8_t ylen)
|
||||
{
|
||||
uint16_t offset = (xlen/(pow(2,(ylen-col-1))));
|
||||
for (uint8_t i=0; i<listSize; i++) {
|
||||
if (( (row) % (2*offset) ) >= offset ) {
|
||||
if(bitU[row-offset][col]==0) updateBit(bit, bitU, listSize, (row-offset), col, xlen, ylen);
|
||||
if(llrU[row-offset][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, (row-offset), (col+1), xlen, ylen);
|
||||
if(llrU[row][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, row, (col+1), xlen, ylen);
|
||||
llr[row][col][i] = (pow((-1),bit[row-offset][col][i])*llr[row-offset][col+1][i]) + llr[row][col+1][i];
|
||||
} else {
|
||||
if(llrU[row][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, row, (col+1), xlen, ylen);
|
||||
if(llrU[row+offset][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, (row+offset), (col+1), xlen, ylen);
|
||||
computeLLR(llr, row, col, i, offset);
|
||||
}
|
||||
}
|
||||
llrU[row][col]=1;
|
||||
|
||||
// printf("LLR (a %f, b %f): llr[%d][%d] %f\n",32*a,32*b,col,row,32*llr[col][row]);
|
||||
}
|
||||
|
||||
void updateBit(uint8_t ***bit,
|
||||
uint8_t **bitU,
|
||||
uint8_t listSize,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint16_t xlen,
|
||||
uint8_t ylen)
|
||||
static inline void updateBit(uint8_t listSize,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint16_t xlen,
|
||||
uint8_t ylen,
|
||||
int zlen,
|
||||
uint8_t bit[xlen][ylen][zlen],
|
||||
uint8_t bitU[xlen][ylen])
|
||||
{
|
||||
uint16_t offset = ( xlen/(pow(2,(ylen-col))) );
|
||||
|
||||
for (uint8_t i=0; i<listSize; i++) {
|
||||
if (( (row) % (2*offset) ) >= offset ) {
|
||||
if (bitU[row][col-1]==0) updateBit(bit, bitU, listSize, row, (col-1), xlen, ylen);
|
||||
if (bitU[row][col-1]==0) updateBit(listSize, row, (col-1), xlen, ylen, zlen, bit, bitU);
|
||||
bit[row][col][i] = bit[row][col-1][i];
|
||||
} else {
|
||||
if (bitU[row][col-1]==0) updateBit(bit, bitU, listSize, row, (col-1), xlen, ylen);
|
||||
if (bitU[row+offset][col-1]==0) updateBit(bit, bitU, listSize, (row+offset), (col-1), xlen, ylen);
|
||||
if (bitU[row][col-1]==0) updateBit(listSize, row, (col-1), xlen, ylen, zlen, bit, bitU);
|
||||
if (bitU[row+offset][col-1]==0) updateBit(listSize, (row+offset), (col-1), xlen, ylen, zlen, bit, bitU);
|
||||
bit[row][col][i] = ( (bit[row][col-1][i]+bit[row+offset][col-1][i]) % 2);
|
||||
}
|
||||
}
|
||||
@@ -88,11 +62,60 @@ void updateBit(uint8_t ***bit,
|
||||
bitU[row][col]=1;
|
||||
}
|
||||
|
||||
static inline void computeLLR(uint16_t row,
|
||||
uint16_t col,
|
||||
uint8_t i,
|
||||
uint16_t offset,
|
||||
int xlen,
|
||||
int ylen,
|
||||
int zlen,
|
||||
double llr[xlen][ylen][zlen])
|
||||
{
|
||||
double a = llr[row][col + 1][i];
|
||||
double b = llr[row + offset][col + 1][i];
|
||||
llr[row][col][i] = log((exp(a + b) + 1) / (exp(a) + exp(b))); //eq. (8a)
|
||||
}
|
||||
|
||||
|
||||
void updateLLR(uint8_t listSize,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint16_t xlen,
|
||||
uint8_t ylen,
|
||||
int zlen,
|
||||
double llr[xlen][ylen][zlen],
|
||||
uint8_t llrU[xlen][ylen],
|
||||
uint8_t bit[xlen][ylen][zlen],
|
||||
uint8_t bitU[xlen][ylen]
|
||||
)
|
||||
{
|
||||
uint16_t offset = (xlen/(pow(2,(ylen-col-1))));
|
||||
for (uint8_t i=0; i<listSize; i++) {
|
||||
if (( (row) % (2*offset) ) >= offset ) {
|
||||
if(bitU[row-offset][col]==0) updateBit(listSize, (row-offset), col, xlen, ylen, zlen, bit, bitU);
|
||||
if(llrU[row-offset][col+1]==0) updateLLR(listSize, (row-offset), (col+1), xlen, ylen, zlen, llr, llrU, bit, bitU );
|
||||
if(llrU[row][col+1]==0) updateLLR(listSize, row, (col+1), xlen, ylen, zlen, llr, llrU, bit, bitU);
|
||||
llr[row][col][i] = (pow((-1),bit[row-offset][col][i])*llr[row-offset][col+1][i]) + llr[row][col+1][i];
|
||||
} else {
|
||||
if(llrU[row][col+1]==0) updateLLR(listSize, row, (col+1), xlen, ylen, zlen, llr, llrU, bit, bitU );
|
||||
if(llrU[row+offset][col+1]==0) updateLLR(listSize, (row+offset), (col+1), xlen, ylen, zlen, llr, llrU, bit, bitU );
|
||||
computeLLR(row, col, i, offset, xlen, ylen, zlen, llr);
|
||||
}
|
||||
}
|
||||
llrU[row][col]=1;
|
||||
|
||||
// printf("LLR (a %f, b %f): llr[%d][%d] %f\n",32*a,32*b,col,row,32*llr[col][row]);
|
||||
}
|
||||
|
||||
void updatePathMetric(double *pathMetric,
|
||||
double ***llr,
|
||||
uint8_t listSize,
|
||||
uint8_t bitValue,
|
||||
uint16_t row)
|
||||
uint8_t listSize,
|
||||
uint8_t bitValue,
|
||||
uint16_t row,
|
||||
int xlen,
|
||||
int ylen,
|
||||
int zlen,
|
||||
double llr[xlen][ylen][zlen]
|
||||
)
|
||||
{
|
||||
int8_t multiplier = (2*bitValue) - 1;
|
||||
for (uint8_t i=0; i<listSize; i++)
|
||||
@@ -101,11 +124,14 @@ void updatePathMetric(double *pathMetric,
|
||||
}
|
||||
|
||||
void updatePathMetric2(double *pathMetric,
|
||||
double ***llr,
|
||||
uint8_t listSize,
|
||||
uint16_t row)
|
||||
uint8_t listSize,
|
||||
uint16_t row,
|
||||
int xlen,
|
||||
int ylen,
|
||||
int zlen,
|
||||
double llr[xlen][ylen][zlen])
|
||||
{
|
||||
double *tempPM = malloc(sizeof(double) * listSize);
|
||||
double tempPM[listSize];
|
||||
memcpy(tempPM, pathMetric, (sizeof(double) * listSize));
|
||||
|
||||
uint8_t bitValue = 0;
|
||||
@@ -118,48 +144,8 @@ void updatePathMetric2(double *pathMetric,
|
||||
for (uint8_t i = listSize; i < 2*listSize; i++)
|
||||
pathMetric[i] = tempPM[(i-listSize)] + log(1 + exp(multiplier * llr[row][0][(i-listSize)])); //eq. (11b)
|
||||
|
||||
free(tempPM);
|
||||
}
|
||||
|
||||
void computeLLR(double ***llr,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint8_t i,
|
||||
uint16_t offset)
|
||||
{
|
||||
double a = llr[row][col + 1][i];
|
||||
double b = llr[row + offset][col + 1][i];
|
||||
llr[row][col][i] = log((exp(a + b) + 1) / (exp(a) + exp(b))); //eq. (8a)
|
||||
}
|
||||
|
||||
void updateCrcChecksum(uint8_t **crcChecksum,
|
||||
uint8_t **crcGen,
|
||||
uint8_t listSize,
|
||||
uint32_t i2,
|
||||
uint8_t len)
|
||||
{
|
||||
for (uint8_t i = 0; i < listSize; i++) {
|
||||
for (uint8_t j = 0; j < len; j++) {
|
||||
crcChecksum[j][i] = ( (crcChecksum[j][i] + crcGen[i2][j]) % 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateCrcChecksum2(uint8_t **crcChecksum,
|
||||
uint8_t **crcGen,
|
||||
uint8_t listSize,
|
||||
uint32_t i2,
|
||||
uint8_t len)
|
||||
{
|
||||
for (uint8_t i = 0; i < listSize; i++) {
|
||||
for (uint8_t j = 0; j < len; j++) {
|
||||
crcChecksum[j][i+listSize] = ( (crcChecksum[j][i] + crcGen[i2][j]) % 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
decoder_node_t *new_decoder_node(int first_leaf_index, int level) {
|
||||
|
||||
decoder_node_t *node=(decoder_node_t *)malloc(sizeof(decoder_node_t));
|
||||
|
||||
@@ -278,34 +278,6 @@ void nr_matrix_multiplication_uint8_1D_uint8_2D(uint8_t *matrix1,
|
||||
uint16_t row,
|
||||
uint16_t col);
|
||||
|
||||
uint8_t ***nr_alloc_uint8_3D_array(uint16_t xlen,
|
||||
uint16_t ylen,
|
||||
uint16_t zlen);
|
||||
|
||||
uint8_t **nr_alloc_uint8_2D_array(uint16_t xlen,
|
||||
uint16_t ylen);
|
||||
|
||||
double ***nr_alloc_double_3D_array(uint16_t xlen,
|
||||
uint16_t ylen,
|
||||
uint16_t zlen);
|
||||
|
||||
double **nr_alloc_double_2D_array(uint16_t xlen,
|
||||
uint16_t ylen);
|
||||
|
||||
void nr_free_double_3D_array(double ***input,
|
||||
uint16_t xlen,
|
||||
uint16_t ylen);
|
||||
|
||||
void nr_free_double_2D_array(double **input,
|
||||
uint16_t xlen);
|
||||
|
||||
void nr_free_uint8_3D_array(uint8_t ***input,
|
||||
uint16_t xlen,
|
||||
uint16_t ylen);
|
||||
|
||||
void nr_free_uint8_2D_array(uint8_t **input,
|
||||
uint16_t xlen);
|
||||
|
||||
void nr_sort_asc_double_1D_array_ind(double *matrix,
|
||||
uint8_t *ind,
|
||||
uint8_t len);
|
||||
@@ -316,52 +288,33 @@ void nr_sort_asc_int16_1D_array_ind(int32_t *matrix,
|
||||
|
||||
void nr_free_double_2D_array(double **input, uint16_t xlen);
|
||||
|
||||
void updateLLR(double ***llr,
|
||||
uint8_t **llrU,
|
||||
uint8_t ***bit,
|
||||
uint8_t **bitU,
|
||||
uint8_t listSize,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint16_t xlen,
|
||||
uint8_t ylen);
|
||||
|
||||
void updateBit(uint8_t ***bit,
|
||||
uint8_t **bitU,
|
||||
uint8_t listSize,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint16_t xlen,
|
||||
uint8_t ylen);
|
||||
|
||||
void updateLLR(uint8_t listSize,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint16_t xlen,
|
||||
uint8_t ylen,
|
||||
int zlen,
|
||||
double llr[xlen][ylen][zlen],
|
||||
uint8_t llrU[xlen][ylen],
|
||||
uint8_t bit[xlen][ylen][zlen],
|
||||
uint8_t bitU[xlen][ylen]
|
||||
);
|
||||
void updatePathMetric(double *pathMetric,
|
||||
double ***llr,
|
||||
uint8_t listSize,
|
||||
uint8_t bitValue,
|
||||
uint16_t row);
|
||||
|
||||
uint8_t listSize,
|
||||
uint8_t bitValue,
|
||||
uint16_t row,
|
||||
int xlen,
|
||||
int ylen,
|
||||
int zlen,
|
||||
double llr[xlen][ylen][zlen]
|
||||
);
|
||||
void updatePathMetric2(double *pathMetric,
|
||||
double ***llr,
|
||||
uint8_t listSize,
|
||||
uint16_t row);
|
||||
|
||||
void computeLLR(double ***llr,
|
||||
uint16_t row,
|
||||
uint16_t col,
|
||||
uint8_t i,
|
||||
uint16_t offset);
|
||||
|
||||
void updateCrcChecksum(uint8_t **crcChecksum,
|
||||
uint8_t **crcGen,
|
||||
uint8_t listSize,
|
||||
uint32_t i2,
|
||||
uint8_t len);
|
||||
|
||||
void updateCrcChecksum2(uint8_t **crcChecksum,
|
||||
uint8_t **crcGen,
|
||||
uint8_t listSize,
|
||||
uint32_t i2,
|
||||
uint8_t len);
|
||||
uint8_t listSize,
|
||||
uint16_t row,
|
||||
int xlen,
|
||||
int ylen,
|
||||
int zlen,
|
||||
double llr[xlen][ylen][zlen]);
|
||||
|
||||
//Also nr_polar_rate_matcher
|
||||
static inline void nr_polar_interleaver(uint8_t *input,
|
||||
|
||||
@@ -43,163 +43,6 @@ void nr_matrix_multiplication_uint8_1D_uint8_2D(uint8_t *matrix1, uint8_t **matr
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ***nr_alloc_uint8_3D_array(uint16_t xlen, uint16_t ylen, uint16_t zlen) {
|
||||
uint8_t ***output;
|
||||
int i, j;
|
||||
|
||||
if ((output = malloc(xlen * sizeof(*output))) == NULL) {
|
||||
perror("[nr_alloc_uint8_3D_array] Problem at 1D allocation");
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < xlen; i++)
|
||||
output[i] = NULL;
|
||||
|
||||
|
||||
for (i = 0; i < xlen; i++)
|
||||
if ((output[i] = malloc(ylen * sizeof *output[i])) == NULL) {
|
||||
perror("[nr_alloc_uint8_3D_array] Problem at 2D allocation");
|
||||
nr_free_uint8_3D_array(output, xlen, ylen);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < xlen; i++)
|
||||
for (j = 0; j < ylen; j++)
|
||||
output[i][j] = NULL;
|
||||
|
||||
|
||||
for (i = 0; i < xlen; i++)
|
||||
for (j = 0; j < ylen; j++)
|
||||
if ((output[i][j] = malloc(zlen * sizeof *output[i][j])) == NULL) {
|
||||
perror("[nr_alloc_uint8_3D_array] Problem at 3D allocation");
|
||||
nr_free_uint8_3D_array(output, xlen, ylen);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
uint8_t **nr_alloc_uint8_2D_array(uint16_t xlen, uint16_t ylen) {
|
||||
uint8_t **output;
|
||||
int i, j;
|
||||
|
||||
if ((output = malloc(xlen * sizeof(*output))) == NULL) {
|
||||
perror("[nr_alloc_uint8_2D_array] Problem at 1D allocation");
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < xlen; i++)
|
||||
output[i] = NULL;
|
||||
|
||||
|
||||
for (i = 0; i < xlen; i++)
|
||||
if ((output[i] = malloc(ylen * sizeof *output[i])) == NULL) {
|
||||
perror("[nr_alloc_uint8_2D_array] Problem at 2D allocation");
|
||||
nr_free_uint8_2D_array(output, xlen);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < xlen; i++)
|
||||
for (j = 0; j < ylen; j++)
|
||||
output[i][j] = 0;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
double ***nr_alloc_double_3D_array(uint16_t xlen, uint16_t ylen, uint16_t zlen) {
|
||||
double ***output;
|
||||
int i, j;
|
||||
|
||||
if ((output = malloc(xlen * sizeof(*output))) == NULL) {
|
||||
perror("[nr_alloc_double_3D_array] Problem at 1D allocation");
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < xlen; i++)
|
||||
output[i] = NULL;
|
||||
|
||||
|
||||
for (i = 0; i < xlen; i++)
|
||||
if ((output[i] = malloc(ylen * sizeof *output[i])) == NULL) {
|
||||
perror("[nr_alloc_double_3D_array] Problem at 2D allocation");
|
||||
nr_free_double_3D_array(output, xlen, ylen);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < xlen; i++)
|
||||
for (j = 0; j < ylen; j++)
|
||||
output[i][j] = NULL;
|
||||
|
||||
|
||||
for (i = 0; i < xlen; i++)
|
||||
for (j = 0; j < ylen; j++)
|
||||
if ((output[i][j] = malloc(zlen * sizeof *output[i][j])) == NULL) {
|
||||
perror("[nr_alloc_double_3D_array] Problem at 3D allocation");
|
||||
nr_free_double_3D_array(output, xlen, ylen);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
double **nr_alloc_double_2D_array(uint16_t xlen, uint16_t ylen) {
|
||||
double **output;
|
||||
int i, j;
|
||||
|
||||
if ((output = malloc(xlen * sizeof(*output))) == NULL) {
|
||||
perror("[nr_alloc_double_3D_array] Problem at 1D allocation");
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < xlen; i++)
|
||||
output[i] = NULL;
|
||||
|
||||
|
||||
for (i = 0; i < xlen; i++)
|
||||
if ((output[i] = malloc(ylen * sizeof *output[i])) == NULL) {
|
||||
perror("[nr_alloc_double_2D_array] Problem at 2D allocation");
|
||||
nr_free_double_2D_array(output, xlen);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < xlen; i++)
|
||||
for (j = 0; j < ylen; j++)
|
||||
output[i][j] = 0;
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void nr_free_double_3D_array(double ***input, uint16_t xlen, uint16_t ylen) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < xlen; i++) {
|
||||
for (j = 0; j < ylen; j++) {
|
||||
free(input[i][j]);
|
||||
}
|
||||
free(input[i]);
|
||||
}
|
||||
free(input);
|
||||
}
|
||||
|
||||
void nr_free_double_2D_array(double **input, uint16_t xlen) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < xlen; i++) {
|
||||
free(input[i]);
|
||||
}
|
||||
free(input);
|
||||
}
|
||||
|
||||
void nr_free_uint8_3D_array(uint8_t ***input, uint16_t xlen, uint16_t ylen) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < xlen; i++) {
|
||||
for (j = 0; j < ylen; j++) {
|
||||
free(input[i][j]);
|
||||
}
|
||||
free(input[i]);
|
||||
}
|
||||
free(input);
|
||||
}
|
||||
|
||||
void nr_free_uint8_2D_array(uint8_t **input, uint16_t xlen) {
|
||||
for (int i = 0; i < xlen; i++) free(input[i]);
|
||||
free(input);
|
||||
}
|
||||
|
||||
// Modified Bubble Sort.
|
||||
void nr_sort_asc_double_1D_array_ind(double *matrix, uint8_t *ind, uint8_t len) {
|
||||
int swaps;
|
||||
|
||||
Reference in New Issue
Block a user