Commit 8b8e6e12 authored by Raymond Knopp's avatar Raymond Knopp

new data strucure for list management (decoding ok)

parent 720d0d31
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance: * For more information about the OpenAirInterface (OAI) Software Alliance
* contact@openairinterface.org * contact@openairinterface.org
*/ */
...@@ -56,9 +56,9 @@ int8_t polar_decoder( ...@@ -56,9 +56,9 @@ int8_t polar_decoder(
decoder_list_t dlist[2*listSize]; decoder_list_t dlist[2*listSize];
for ( int i=0;i<2*listSize;i++) { for ( int i=0;i<2*listSize;i++) {
dlist[i].bit = nr_alloc_uint8_t_2D_array((polarParams->n+1), polarParams->N); // dlist[i].bit = nr_alloc_uint8_t_2D_array((polarParams->n+1), polarParams->N);
dlist[i].llr = nr_alloc_double_2D_array((polarParams->n+1), polarParams->N); // dlist[i].llr = nr_alloc_double_2D_array((polarParams->n+1), polarParams->N);
dlist[i].crcChecksum = malloc(sizeof(uint8_t)*polarParams->crcParityBits); //dlist[i].crcChecksum = malloc(sizeof(uint8_t)*polarParams->crcParityBits);
for (int j=0; j< polarParams->n+1; j++) { for (int j=0; j< polarParams->n+1; j++) {
memset((void*)&dlist[i].bit[j][0],0,sizeof(uint8_t)*polarParams->N); memset((void*)&dlist[i].bit[j][0],0,sizeof(uint8_t)*polarParams->N);
memset((void*)&dlist[i].llr[j][0],0,sizeof(double)*polarParams->N); memset((void*)&dlist[i].llr[j][0],0,sizeof(double)*polarParams->N);
...@@ -115,7 +115,7 @@ int8_t polar_decoder( ...@@ -115,7 +115,7 @@ int8_t polar_decoder(
stop_meas(init); stop_meas(init);
start_meas(polar_rate_matching); start_meas(polar_rate_matching);
double *d_tilde = malloc(sizeof(double) * polarParams->N); double d_tilde[polarParams->N];// = malloc(sizeof(double) * polarParams->N);
nr_polar_rate_matching(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength); nr_polar_rate_matching(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength);
memcpy((void*)&dlist[0].llr[polarParams->n][0],(void*)&d_tilde[0],sizeof(double)*polarParams->N); memcpy((void*)&dlist[0].llr[polarParams->n][0],(void*)&d_tilde[0],sizeof(double)*polarParams->N);
stop_meas(polar_rate_matching); stop_meas(polar_rate_matching);
...@@ -126,8 +126,6 @@ int8_t polar_decoder( ...@@ -126,8 +126,6 @@ int8_t polar_decoder(
start_meas(decoding); start_meas(decoding);
uint32_t nonFrozenBit=0; uint32_t nonFrozenBit=0;
uint8_t currentListSize=1; uint8_t currentListSize=1;
uint8_t decoderIterationCheck=0;
int16_t checkCrcBits=-1;
uint8_t copyIndex=0; uint8_t copyIndex=0;
decoder_list_t *sorted_dlist[2*listSize]; decoder_list_t *sorted_dlist[2*listSize];
...@@ -161,17 +159,14 @@ int8_t polar_decoder( ...@@ -161,17 +159,14 @@ int8_t polar_decoder(
bitUpdated[currentBit][0]=1; bitUpdated[currentBit][0]=1;
updateCrcChecksum(sorted_dlist, extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits); updateCrcChecksum(sorted_dlist, extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits);
} else { } else {
start_meas(path_metric); start_meas(path_metric);
updatePathMetric2(sorted_dlist, currentListSize, currentBit, pathMetricAppr); updatePathMetric2(sorted_dlist, currentListSize, currentBit, pathMetricAppr);
stop_meas(path_metric); stop_meas(path_metric);
start_meas(sorting); start_meas(sorting);
for (int i = 0; i < currentListSize; i++) { for (int i = 0; i < currentListSize; i++) {
for (int k = 0; k < (polarParams->n+1); k++) { for (int k = 0; k < (polarParams->n+1); k++) {
/*
for (int j = 0; j < polarParams->N; j++) {
bit[i+currentListSize][k][j]=bit[i][k][j];
llr[i+currentListSize][k][j]=llr[i][k][j];
}*/
memcpy((void*)&sorted_dlist[i+currentListSize]->bit[k][0],(void*)&sorted_dlist[i]->bit[k][0],sizeof(uint8_t)*polarParams->N); memcpy((void*)&sorted_dlist[i+currentListSize]->bit[k][0],(void*)&sorted_dlist[i]->bit[k][0],sizeof(uint8_t)*polarParams->N);
memcpy((void*)&sorted_dlist[i+currentListSize]->llr[k][0],(void*)&sorted_dlist[i]->llr[k][0],sizeof(double)*polarParams->N); memcpy((void*)&sorted_dlist[i+currentListSize]->llr[k][0],(void*)&sorted_dlist[i]->llr[k][0],sizeof(double)*polarParams->N);
} }
...@@ -181,7 +176,7 @@ int8_t polar_decoder( ...@@ -181,7 +176,7 @@ int8_t polar_decoder(
sorted_dlist[i]->bit[0][currentBit]=0; sorted_dlist[i]->bit[0][currentBit]=0;
sorted_dlist[i+currentListSize]->crcState=sorted_dlist[i]->crcState; sorted_dlist[i+currentListSize]->crcState=sorted_dlist[i]->crcState;
} }
for (int i = currentListSize; i < 2*currentListSize; i++) sorted_dlist[i]->bit[currentBit]=1; for (int i = currentListSize; i < 2*currentListSize; i++) sorted_dlist[i]->bit[0][currentBit]=1;
bitUpdated[currentBit][0]=1; bitUpdated[currentBit][0]=1;
updateCrcChecksum2(sorted_dlist,extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits); updateCrcChecksum2(sorted_dlist,extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits);
currentListSize*=2; currentListSize*=2;
...@@ -194,133 +189,26 @@ int8_t polar_decoder( ...@@ -194,133 +189,26 @@ int8_t polar_decoder(
} }
nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize);
currentListSize = listSize; currentListSize = listSize;
} for (uint8_t i = 0; i < 2*listSize; i++) {
stop_meas(sorting); sorted_dlist[i] = &dlist[listIndex[i]];
/*
//sort listIndex[listSize, ..., 2*listSize-1] in descending order.
uint8_t swaps, tempInd;
for (uint8_t i = 0; i < listSize; i++) {
swaps = 0;
for (uint8_t j = listSize; j < (2*listSize - i) - 1; j++) {
if (listIndex[j+1] > listIndex[j]) {
tempInd = listIndex[j];
listIndex[j] = listIndex[j + 1];
listIndex[j + 1] = tempInd;
swaps++;
}
}
if (swaps == 0)
break;
}
//First, backup the best "listSize" number of entries.
for (int k=(listSize-1); k>0; k--) {
for (int j=0; j<(polarParams->n+1); j++) {
//for (int i=0; i<polarParams->N; i++) {
// bit[listIndex[(2*listSize-1)-k]][j][i]=bit[listIndex[k]][j][i];
// llr[listIndex[(2*listSize-1)-k]][j][i]=llr[listIndex[k]][j][i];
// }
memcpy((void*)&bit[listIndex[(2*listSize-1)-k]][j][0],
(void*)&bit[listIndex[k]][j][0],
sizeof(uint8_t)*polarParams->N);
memcpy((void*)&llr[listIndex[(2*listSize-1)-k]][j][0],
(void*)&llr[listIndex[k]][j][0],
sizeof(double)*polarParams->N);
}
}
for (int k=(listSize-1); k>0; k--) {
for (int i = 0; i < polarParams->crcParityBits; i++) {
crcChecksum[i][listIndex[(2*listSize-1)-k]] = crcChecksum[i][listIndex[k]];
}
}
for (int k=(listSize-1); k>0; k--) crcState[listIndex[(2*listSize-1)-k]]=crcState[listIndex[k]];
//Copy the best "listSize" number of entries to the first indices.
for (int k = 0; k < listSize; k++) {
if (k > listIndex[k]) {
copyIndex = listIndex[(2*listSize-1)-k];
} else { //Use the backup.
copyIndex = listIndex[k];
}
if (copyIndex!=k) {
for (int j = 0; j < (polarParams->n + 1); j++) {
//for (int i = 0; i < polarParams->N; i++) {
// bit[k][j][i] = bit[copyIndex][j][i];
// llr[k][j][i] = llr[copyIndex][j][i];
// }
memcpy((void*)&bit[k][j][0],(void*)&bit[copyIndex][j][0],sizeof(uint8_t)*polarParams->N);
memcpy((void*)&llr[k][j][0],(void*)&llr[copyIndex][j][0],sizeof(double)*polarParams->N);
}
}
}
for (int k = 0; k < listSize; k++) {
if (k > listIndex[k]) {
copyIndex = listIndex[(2*listSize-1)-k];
} else { //Use the backup.
copyIndex = listIndex[k];
}
for (int i = 0; i < polarParams->crcParityBits; i++) {
crcChecksum[i][k]=crcChecksum[i][copyIndex];
}
}
for (int k = 0; k < listSize; k++) {
if (k > listIndex[k]) {
copyIndex = listIndex[(2*listSize-1)-k];
} else { //Use the backup.
copyIndex = listIndex[k];
}
crcState[k]=crcState[copyIndex];
}
currentListSize = listSize;
}*/
}
for (int i=0; i<polarParams->crcParityBits; i++) {
if (last1ind[i]==nonFrozenBit) {
checkCrcBits=i;
break;
} }
} }
stop_meas(sorting);
if ( checkCrcBits > (-1) ) {
for (uint8_t i = 0; i < currentListSize; i++) {
if (dlist[i].crcChecksum[checkCrcBits]==1) {
dlist[i].crcState=0; //0=False, 1=True
}
}
} }
for (uint8_t i = 0; i < currentListSize; i++) decoderIterationCheck+=sorted_dlist[i]->crcState;
if (decoderIterationCheck==0) {
//perror("[SCL polar decoder] All list entries have failed the CRC checks.");
free(d_tilde);
for (int i=0;i<2*listSize;i++) {
// printf("error: Freeing dlist[%d].bit %p\n",i,dlist[i].bit);
nr_free_uint8_t_2D_array(dlist[i].bit, (polarParams->n+1));
// printf("error: Freeing dlist[%d].llr %p\n",i,dlist[i].bit);
nr_free_double_2D_array(dlist[i].llr, (polarParams->n+1));
free(dlist[i].crcChecksum);
}
stop_meas(decoding);
return(-1);
}
nonFrozenBit++; nonFrozenBit++;
decoderIterationCheck=0;
checkCrcBits=-1;
}
} }
for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; }
nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize);
for (uint8_t i = 0; i < fmin(listSize, (pow(2,polarParams->crcCorrectionBits)) ); i++) { for (uint8_t i = 0; i < fmin(listSize, (pow(2,polarParams->crcCorrectionBits)) ); i++) {
if ( dlist[i].crcState == 1 ) { // printf("list index %d :",i);
for (int j = 0; j < polarParams->N; j++) polarParams->nr_polar_u[j]=dlist[listIndex[i]].bit[0][j]; // for (int j=0;j<polarParams->crcParityBits;j++) printf("%d",sorted_dlist[i]->crcChecksum[j]);
// printf(" => %d (%f)\n",sorted_dlist[i]->crcState,sorted_dlist[i]->pathMetric);
int crcState = 1;
for (int j=0;j<polarParams->crcParityBits;j++) if (sorted_dlist[i]->crcChecksum[j]!=0) crcState=0;
if (crcState == 1) {
for (int j = 0; j < polarParams->N; j++) polarParams->nr_polar_u[j]=sorted_dlist[i]->bit[0][j];
start_meas(bit_extraction); start_meas(bit_extraction);
//Extract the information bits (û to ĉ) //Extract the information bits (û to ĉ)
...@@ -337,13 +225,14 @@ int8_t polar_decoder( ...@@ -337,13 +225,14 @@ int8_t polar_decoder(
} }
} }
free(d_tilde); // free(d_tilde);
/*
for (int i=0;i<2*listSize;i++) { for (int i=0;i<2*listSize;i++) {
// printf("correct: Freeing dlist[%d].bit %p\n",i,dlist[i].bit); // printf("correct: Freeing dlist[%d].bit %p\n",i,dlist[i].bit);
nr_free_uint8_t_2D_array(dlist[i].bit, (polarParams->n+1)); nr_free_uint8_t_2D_array(dlist[i].bit, (polarParams->n+1));
nr_free_double_2D_array(dlist[i].llr, (polarParams->n+1)); nr_free_double_2D_array(dlist[i].llr, (polarParams->n+1));
free(dlist[i].crcChecksum); free(dlist[i].crcChecksum);
} }*/
nr_free_uint8_t_2D_array(extended_crc_generator_matrix, polarParams->K); nr_free_uint8_t_2D_array(extended_crc_generator_matrix, polarParams->K);
nr_free_uint8_t_2D_array(tempECGM, polarParams->K); nr_free_uint8_t_2D_array(tempECGM, polarParams->K);
stop_meas(decoding); stop_meas(decoding);
......
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
//#define SHOWCOMP 1 //#define SHOWCOMP 1
inline void computeLLR(double **llr, uint16_t row, uint16_t col, inline void computeLLR(double llr[1+nmax][Nmax], uint16_t row, uint16_t col,
uint16_t offset, uint8_t approximation) __attribute__((always_inline)); uint16_t offset, uint8_t approximation) __attribute__((always_inline));
inline void computeLLR(double **llr, uint16_t row, uint16_t col, inline void computeLLR(double llr[1+nmax][Nmax], uint16_t row, uint16_t col,
uint16_t offset, uint8_t approximation) { uint16_t offset, uint8_t approximation) {
double a; double a;
......
...@@ -130,12 +130,14 @@ void nr_free_uint8_t_3D_array(uint8_t ***input, uint16_t xlen, uint16_t ylen); ...@@ -130,12 +130,14 @@ void nr_free_uint8_t_3D_array(uint8_t ***input, uint16_t xlen, uint16_t ylen);
void nr_free_uint8_t_2D_array(uint8_t **input, uint16_t xlen); void nr_free_uint8_t_2D_array(uint8_t **input, uint16_t xlen);
void nr_free_double_2D_array(double **input, uint16_t xlen); void nr_free_double_2D_array(double **input, uint16_t xlen);
#define Nmax 1024
#define nmax 10
typedef struct decoder_list_s { typedef struct decoder_list_s {
uint8_t **bit; uint8_t bit[1+nmax][Nmax];
double **llr; double llr[1+nmax][Nmax];
uint8_t *crcChecksum; uint8_t crcChecksum[24];
uint8_t crcState; uint8_t crcState;
double pathMetric; double pathMetric;
......
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