Commit be314a97 authored by Laurent THOMAS's avatar Laurent THOMAS Committed by Robert Schmidt

remove usage of undefined var in polar and memory leaks

parent 51625f3c
...@@ -160,7 +160,7 @@ if (logFlag){ ...@@ -160,7 +160,7 @@ if (logFlag){
uint8_t testArrayLength = ceil(testLength / 32.0); uint8_t testArrayLength = ceil(testLength / 32.0);
uint8_t coderArrayLength = ceil(coderLength / 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 encoderOutput[coderArrayLength];
uint32_t estimatedOutput[testArrayLength]; //decoder output uint32_t estimatedOutput[testArrayLength]; //decoder output
memset(testInput,0,sizeof(uint32_t) * testArrayLength); memset(testInput,0,sizeof(uint32_t) * testArrayLength);
......
...@@ -36,63 +36,86 @@ ...@@ -36,63 +36,86 @@
//#define DEBUG_NEW_IMPL 1 //#define DEBUG_NEW_IMPL 1
void updateLLR(double ***llr,
uint8_t **llrU, static inline void updateBit(uint8_t listSize,
uint8_t ***bit, uint16_t row,
uint8_t **bitU, uint16_t col,
uint8_t listSize, uint16_t xlen,
uint16_t row, uint8_t ylen,
uint16_t col, int zlen,
uint16_t xlen, uint8_t bit[xlen][ylen][zlen],
uint8_t ylen) uint8_t bitU[xlen][ylen])
{ {
uint16_t offset = (xlen/(pow(2,(ylen-col-1)))); uint16_t offset = ( xlen/(pow(2,(ylen-col))) );
for (uint8_t i=0; i<listSize; i++) { for (uint8_t i=0; i<listSize; i++) {
if (( (row) % (2*offset) ) >= offset ) { if (( (row) % (2*offset) ) >= offset ) {
if(bitU[row-offset][col]==0) updateBit(bit, bitU, listSize, (row-offset), col, xlen, ylen); if (bitU[row][col-1]==0) updateBit(listSize, row, (col-1), xlen, ylen, zlen, bit, bitU);
if(llrU[row-offset][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, (row-offset), (col+1), xlen, ylen); bit[row][col][i] = bit[row][col-1][i];
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 { } else {
if(llrU[row][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, row, (col+1), xlen, ylen); if (bitU[row][col-1]==0) updateBit(listSize, row, (col-1), xlen, ylen, zlen, bit, bitU);
if(llrU[row+offset][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, (row+offset), (col+1), xlen, ylen); if (bitU[row+offset][col-1]==0) updateBit(listSize, (row+offset), (col-1), xlen, ylen, zlen, bit, bitU);
computeLLR(llr, row, col, i, offset); bit[row][col][i] = ( (bit[row][col-1][i]+bit[row+offset][col-1][i]) % 2);
} }
} }
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]); bitU[row][col]=1;
} }
void updateBit(uint8_t ***bit, static inline void computeLLR(uint16_t row,
uint8_t **bitU, uint16_t col,
uint8_t listSize, uint8_t i,
uint16_t row, uint16_t offset,
uint16_t col, int xlen,
uint16_t xlen, int ylen,
uint8_t ylen) int zlen,
double llr[xlen][ylen][zlen])
{ {
uint16_t offset = ( xlen/(pow(2,(ylen-col))) ); 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++) { for (uint8_t i=0; i<listSize; i++) {
if (( (row) % (2*offset) ) >= offset ) { if (( (row) % (2*offset) ) >= offset ) {
if (bitU[row][col-1]==0) updateBit(bit, bitU, listSize, row, (col-1), xlen, ylen); if(bitU[row-offset][col]==0) updateBit(listSize, (row-offset), col, xlen, ylen, zlen, bit, bitU);
bit[row][col][i] = bit[row][col-1][i]; 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 { } else {
if (bitU[row][col-1]==0) updateBit(bit, bitU, listSize, row, (col-1), xlen, ylen); if(llrU[row][col+1]==0) updateLLR(listSize, row, (col+1), xlen, ylen, zlen, llr, llrU, bit, bitU );
if (bitU[row+offset][col-1]==0) updateBit(bit, bitU, listSize, (row+offset), (col-1), xlen, ylen); if(llrU[row+offset][col+1]==0) updateLLR(listSize, (row+offset), (col+1), xlen, ylen, zlen, llr, llrU, bit, bitU );
bit[row][col][i] = ( (bit[row][col-1][i]+bit[row+offset][col-1][i]) % 2); computeLLR(row, col, i, offset, xlen, ylen, zlen, llr);
} }
} }
llrU[row][col]=1;
bitU[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, void updatePathMetric(double *pathMetric,
double ***llr, uint8_t listSize,
uint8_t listSize, uint8_t bitValue,
uint8_t bitValue, uint16_t row,
uint16_t row) int xlen,
int ylen,
int zlen,
double llr[xlen][ylen][zlen]
)
{ {
int8_t multiplier = (2*bitValue) - 1; int8_t multiplier = (2*bitValue) - 1;
for (uint8_t i=0; i<listSize; i++) for (uint8_t i=0; i<listSize; i++)
...@@ -101,11 +124,14 @@ void updatePathMetric(double *pathMetric, ...@@ -101,11 +124,14 @@ void updatePathMetric(double *pathMetric,
} }
void updatePathMetric2(double *pathMetric, void updatePathMetric2(double *pathMetric,
double ***llr, uint8_t listSize,
uint8_t listSize, uint16_t row,
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)); memcpy(tempPM, pathMetric, (sizeof(double) * listSize));
uint8_t bitValue = 0; uint8_t bitValue = 0;
...@@ -118,48 +144,8 @@ void updatePathMetric2(double *pathMetric, ...@@ -118,48 +144,8 @@ void updatePathMetric2(double *pathMetric,
for (uint8_t i = listSize; i < 2*listSize; i++) 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) 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 *new_decoder_node(int first_leaf_index, int level) {
decoder_node_t *node=(decoder_node_t *)malloc(sizeof(decoder_node_t)); 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, ...@@ -278,34 +278,6 @@ void nr_matrix_multiplication_uint8_1D_uint8_2D(uint8_t *matrix1,
uint16_t row, uint16_t row,
uint16_t col); 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, void nr_sort_asc_double_1D_array_ind(double *matrix,
uint8_t *ind, uint8_t *ind,
uint8_t len); uint8_t len);
...@@ -316,52 +288,33 @@ void nr_sort_asc_int16_1D_array_ind(int32_t *matrix, ...@@ -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 nr_free_double_2D_array(double **input, uint16_t xlen);
void updateLLR(double ***llr, void updateLLR(uint8_t listSize,
uint8_t **llrU, uint16_t row,
uint8_t ***bit, uint16_t col,
uint8_t **bitU, uint16_t xlen,
uint8_t listSize, uint8_t ylen,
uint16_t row, int zlen,
uint16_t col, double llr[xlen][ylen][zlen],
uint16_t xlen, uint8_t llrU[xlen][ylen],
uint8_t ylen); uint8_t bit[xlen][ylen][zlen],
uint8_t bitU[xlen][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 updatePathMetric(double *pathMetric, void updatePathMetric(double *pathMetric,
double ***llr, uint8_t listSize,
uint8_t listSize, uint8_t bitValue,
uint8_t bitValue, uint16_t row,
uint16_t row); int xlen,
int ylen,
int zlen,
double llr[xlen][ylen][zlen]
);
void updatePathMetric2(double *pathMetric, void updatePathMetric2(double *pathMetric,
double ***llr, uint8_t listSize,
uint8_t listSize, uint16_t row,
uint16_t row); int xlen,
int ylen,
void computeLLR(double ***llr, int zlen,
uint16_t row, double llr[xlen][ylen][zlen]);
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);
//Also nr_polar_rate_matcher //Also nr_polar_rate_matcher
static inline void nr_polar_interleaver(uint8_t *input, 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 ...@@ -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. // Modified Bubble Sort.
void nr_sort_asc_double_1D_array_ind(double *matrix, uint8_t *ind, uint8_t len) { void nr_sort_asc_double_1D_array_ind(double *matrix, uint8_t *ind, uint8_t len) {
int swaps; int swaps;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment