Commit 061fb00f authored by knopp's avatar knopp

added new polar decoder implementation

parent 7aad1584
......@@ -1123,6 +1123,7 @@ set(PHY_POLARSRC
${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion.c
${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_channel_interleaver_pattern.c
# ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_crc.c
# ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/decoder_K56_N512_E864.c
${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_info_bit_pattern.c
${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c
......
......@@ -43,8 +43,9 @@ int main(int argc, char *argv[]) {
double timeEncoderCumulative = 0, timeDecoderCumulative = 0;
uint8_t decoderListSize = 8, pathMetricAppr = 0; //0 --> eq. (8a) and (11b), 1 --> eq. (9) and (12)
int generate_optim_code=0;
while ((arguments = getopt (argc, argv, "s:d:f:m:i:l:a:h:q")) != -1)
while ((arguments = getopt (argc, argv, "s:d:f:m:i:l:a:h:qg")) != -1)
switch (arguments)
{
case 's':
......@@ -80,6 +81,13 @@ int main(int argc, char *argv[]) {
decoder_int8=1;
break;
case 'g':
generate_optim_code=1;
iterations=1;
SNRstart=-6.0;
SNRstop =-6.0;
decoder_int8=1;
break;
case 'h':
printf("./polartest -s SNRstart -d SNRinc -f SNRstop -m [0=DCI|1=PBCH|2=UCI] -i iterations -l decoderListSize -a pathMetricAppr\n");
exit(-1);
......@@ -141,12 +149,18 @@ int main(int argc, char *argv[]) {
t_nrPolar_params nrPolar_params;
nr_polar_init(&nrPolar_params, polarMessageType);
nr_polar_llrtableinit();
if (generate_optim_code==1) nrPolar_params.decoder_kernel = NULL;
// We assume no a priori knowledge available about the payload.
double aPrioriArray[nrPolar_params.payloadBits];
for (int i=0; i<=nrPolar_params.payloadBits; i++) aPrioriArray[i] = NAN;
printf("SNRstart %f, SNRstop %f,, SNRinc %f\n",SNRstart,SNRstop,SNRinc);
for (SNR = SNRstart; SNR <= SNRstop; SNR += SNRinc) {
printf("SNR %f\n",SNR);
SNR_lin = pow(10, SNR/10);
for (itr = 1; itr <= iterations; itr++) {
......@@ -165,20 +179,29 @@ int main(int argc, char *argv[]) {
modulatedInput[i]=(-1)/sqrt(2);
channelOutput[i] = modulatedInput[i] + (gaussdouble(0.0,1.0) * (1/sqrt(2*SNR_lin)));
if (decoder_int8==1) {
if (channelOutput[i] > 1024) channelOutput_int8[i] = 32768;
else if (channelOutput[i] < -1023) channelOutput_int8[i] = -32767;
else channelOutput_int8[i] = (int16_t) (32*channelOutput[i]);
if (channelOutput[i] > 15) channelOutput_int8[i] = 127;
else if (channelOutput[i] < -16) channelOutput_int8[i] = -128;
else channelOutput_int8[i] = (int16_t) (8*channelOutput[i]);
}
}
start_meas(&timeDecoder);
if (decoder_int8==0) decoderState = polar_decoder(channelOutput, estimatedOutput, &nrPolar_params, decoderListSize, aPrioriArray, pathMetricAppr,&polar_decoder_init,&polar_rate_matching,&decoding,&bit_extraction,&deinterleaving,&sorting,&path_metric,&update_LLR);
if (decoder_int8==0)
decoderState = polar_decoder(channelOutput, estimatedOutput, &nrPolar_params,
decoderListSize, aPrioriArray, pathMetricAppr,
&polar_decoder_init,&polar_rate_matching,&decoding,
&bit_extraction,&deinterleaving,&sorting,&path_metric,&update_LLR);
else
decoderState = polar_decoder_int8(channelOutput_int8, estimatedOutput, &nrPolar_params, decoderListSize, &polar_decoder_init,&polar_rate_matching,&decoding,&bit_extraction,&deinterleaving,&sorting,&path_metric,&update_LLR);
decoderState = polar_decoder_int8_new(channelOutput_int8, estimatedOutput, &nrPolar_params,
decoderListSize, &polar_decoder_init,&polar_rate_matching,
&decoding,&bit_extraction,&deinterleaving,
&sorting,&path_metric,&update_LLR,
generate_optim_code);
stop_meas(&timeDecoder);
//calculate errors
if (decoderState==-1) {
blockErrorState=-1;
......
......@@ -62,6 +62,11 @@ uint32_t poly24c = 0xB2B11700; //101100101011000100010111 -> D^24...
polarParams->nr_polar_u = malloc(sizeof(uint8_t) * polarParams->N); //Decoder: nr_polar_uHat
polarParams->nr_polar_cPrime = malloc(sizeof(uint8_t) * polarParams->K); //Decoder: nr_polar_cHat
polarParams->nr_polar_b = malloc(sizeof(uint8_t) * polarParams->K); //Decoder: nr_polar_bHat
polarParams->decoder_kernel = NULL;//polar_decoder_K56_N512_E864;
} else if (messageType == 2) { //UCI
polarParams->payloadBits = NR_POLAR_PUCCH_PAYLOAD_BITS; //A depends on what they carry...
polarParams->encoderLength = NR_POLAR_PUCCH_E ; //E depends on other standards 6.3.1.4
......@@ -131,6 +136,7 @@ uint32_t poly24c = 0xB2B11700; //101100101011000100010111 -> D^24...
polarParams->nr_polar_u = malloc(sizeof(uint8_t) * polarParams->N); //Decoder: nr_polar_uHat
polarParams->nr_polar_cPrime = malloc(sizeof(uint8_t) * polarParams->K); //Decoder: nr_polar_cHat
polarParams->nr_polar_b = malloc(sizeof(uint8_t) * polarParams->K); //Decoder: nr_polar_bHat
}
polarParams->crcCorrectionBits = NR_POLAR_CRC_ERROR_CORRECTION_BITS;
......@@ -161,5 +167,38 @@ uint32_t poly24c = 0xB2B11700; //101100101011000100010111 -> D^24...
nr_polar_channel_interleaver_pattern(polarParams->channel_interleaver_pattern,
polarParams->i_bil, polarParams->encoderLength);
polarParams->extended_crc_generator_matrix = malloc(polarParams->K * sizeof(uint8_t *)); //G_P3
uint8_t tempECGM[polarParams->K][polarParams->crcParityBits];
for (int i = 0; i < polarParams->K; i++){
polarParams->extended_crc_generator_matrix[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t));
}
for (int i=0; i<polarParams->payloadBits; i++) {
for (int j=0; j<polarParams->crcParityBits; j++) {
tempECGM[i][j]=polarParams->crc_generator_matrix[i][j];
}
}
for (int i=polarParams->payloadBits; i<polarParams->K; i++) {
for (int j=0; j<polarParams->crcParityBits; j++) {
if( (i-polarParams->payloadBits) == j ){
tempECGM[i][j]=1;
} else {
tempECGM[i][j]=0;
}
}
}
for (int i=0; i<polarParams->K; i++) {
for (int j=0; j<polarParams->crcParityBits; j++) {
polarParams->extended_crc_generator_matrix[i][j]=tempECGM[polarParams->interleaving_pattern[i]][j];
}
}
build_decoder_tree(polarParams);
printf("decoder tree nodes %d\n",polarParams->tree.num_nodes);
free(J);
}
......@@ -29,7 +29,6 @@
#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
#include "PHY/TOOLS/time_meas.h"
#define SHOWCOMP 1
int8_t polar_decoder(
double *input,
......@@ -50,31 +49,6 @@ int8_t polar_decoder(
start_meas(init);
uint8_t **bitUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
uint8_t **llrUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
decoder_list_t dlist[2*listSize];
for ( int i=0;i<2*listSize;i++) {
// 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].crcChecksum = malloc(sizeof(uint8_t)*polarParams->crcParityBits);
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].llr[j][0],0,sizeof(double)*polarParams->N);
}
for (int j=0;j<polarParams->crcParityBits;j++) dlist[i].crcChecksum[j] = 0;
dlist[i].pathMetric = 0;
}
for (int i=0; i<polarParams->N; i++) {
memset((void *)&llrUpdated[i][0],0,sizeof(uint8_t)*polarParams->n);
memset((void *)&bitUpdated[i][0],0,sizeof(uint8_t)*polarParams->n);
llrUpdated[i][polarParams->n]=1;
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++){
......@@ -102,6 +76,31 @@ int8_t polar_decoder(
extended_crc_generator_matrix[i][j]=tempECGM[polarParams->interleaving_pattern[i]][j];
}
}
uint8_t **bitUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
uint8_t **llrUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
decoder_list_t dlist[2*listSize];
for ( int i=0;i<2*listSize;i++) {
// 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].crcChecksum = malloc(sizeof(uint8_t)*polarParams->crcParityBits);
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].llr[j][0],0,sizeof(double)*polarParams->N);
}
for (int j=0;j<polarParams->crcParityBits;j++) dlist[i].crcChecksum[j] = 0;
dlist[i].pathMetric = 0;
}
for (int i=0; i<polarParams->N; i++) {
memset((void *)&llrUpdated[i][0],0,sizeof(uint8_t)*polarParams->n);
memset((void *)&bitUpdated[i][0],0,sizeof(uint8_t)*polarParams->n);
llrUpdated[i][polarParams->n]=1;
bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2);
}
stop_meas(init);
start_meas(polar_rate_matching);
......@@ -155,6 +154,7 @@ int8_t polar_decoder(
start_meas(sorting);
if (currentListSize <= listSize/2) {
// until listsize is full we need to copy bit and LLR arrays to new entries
// below we only copy the ones we need to keep for sure
......@@ -290,92 +290,8 @@ int8_t polar_decoder(
}
#define decoder_int8_A(sorted_dlist,currentListSize,polarParams) {for (int i = 0; i < currentListSize; i++) { \
for (int k = 0; k < (polarParams->n+1); k++) { \
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(int16_t)*polarParams->N);}}}
#define decoder_int8_B(sorted_dlist,currentListSize) {for (int i = 0; i < currentListSize; i++) {sorted_dlist[i]->bit[0][currentBit]=0;sorted_dlist[i+currentListSize]->bit[0][currentBit]=1;}}
void inline decoder_int8_C(decoder_list_int8_t *sorted_dlist[],
t_nrPolar_params *polarParams,
int currentBit,
int currentListSize,
int listSize) {
int32_t pathMetric[2*listSize];
decoder_list_int8_t *temp_dlist[2*listSize];
int listIndex[2*listSize];
int listIndex2[2*listSize];
for (int i = 0; i < currentListSize; i++) {
listIndex[i]=i;
pathMetric[i] = sorted_dlist[i]->pathMetric;
}
nr_sort_asc_int16_1D_array_ind(pathMetric, listIndex, currentListSize);
for (int i=0;i<currentListSize;i++) {
listIndex2[listIndex[i]] = i;
}
// copy the llr/bit arrays that are needed
for (int i = 0; i < listSize; i++) {
// printf("listIndex[%d] %d\n",i,listIndex[i]);
if ((listIndex2[i+listSize]<listSize) && (listIndex2[i]<listSize)) { // both '0' and '1' path metrics are to be kept
// do memcpy of LLR and Bit arrays
for (int k = 0; k < (polarParams->n+1); k++) {
memcpy((void*)&sorted_dlist[i+listSize]->bit[k][0],
(void*)&sorted_dlist[i]->bit[k][0],
sizeof(uint8_t)*polarParams->N);
memcpy((void*)&sorted_dlist[i+listSize]->llr[k][0],
(void*)&sorted_dlist[i]->llr[k][0],
sizeof(int16_t)*polarParams->N);
}
sorted_dlist[i]->bit[0][currentBit]=0;
sorted_dlist[i+listSize]->bit[0][currentBit]=1;
}
else if (listIndex2[i+listSize]<listSize) { // only '1' path metric is to be kept
// just change the current bit from '0' to '1'
for (int k = 0; k < (polarParams->n+1); k++) {
memcpy((void*)&sorted_dlist[i+listSize]->bit[k][0],
(void*)&sorted_dlist[i]->bit[k][0],
sizeof(uint8_t)*polarParams->N);
memcpy((void*)&sorted_dlist[i+listSize]->llr[k][0],
(void*)&sorted_dlist[i]->llr[k][0],
sizeof(int16_t)*polarParams->N);
}
sorted_dlist[i+listSize]->bit[0][currentBit]=1;
/*
decoder_list_t *tmp = sorted_dlist[i+listSize];
sorted_dlist[i+listSize] = sorted_dlist[i];
sorted_dlist[i+listSize]->pathMetric = tmp->pathMetric;
sorted_dlist[i+listSize]->bit[0][currentBit]=1;
memcpy((void*)&sorted_dlist[i+listSize]->crcChecksum[0],
(void*)&tmp->crcChecksum[0],
24*sizeof(uint8_t));*/
}
}
for (int i = 0; i < 2*listSize; i++) {
temp_dlist[i] = sorted_dlist[i];
}
for (int i = 0; i < 2*listSize; i++) {
// printf("i %d => %d\n",i,listIndex[i]);
sorted_dlist[i] = temp_dlist[listIndex[i]];
}
}
int8_t polar_decoder_int8(int16_t *input,
uint8_t *output,
t_nrPolar_params *polarParams,
......@@ -387,16 +303,22 @@ int8_t polar_decoder_int8(int16_t *input,
time_stats_t *deinterleaving,
time_stats_t *sorting,
time_stats_t *path_metric,
time_stats_t *update_LLR)
time_stats_t *update_LLR,
int generate_optim_code)
{
start_meas(init);
uint8_t **bitUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
uint8_t **llrUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
uint8_t **bitUpdated;
uint8_t **llrUpdated;
if (generate_optim_code == 1 || polarParams->decoder_kernel==NULL) {
bitUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
llrUpdated = nr_alloc_uint8_t_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True
}
decoder_list_int8_t dlist[2*listSize];
start_meas(init);
for ( int i=0;i<2*listSize;i++) {
// dlist[i].bit = nr_alloc_uint8_t_2D_array((polarParams->n+1), polarParams->N);
......@@ -409,48 +331,28 @@ int8_t polar_decoder_int8(int16_t *input,
for (int j=0;j<polarParams->crcParityBits;j++) dlist[i].crcChecksum[j] = 0;
dlist[i].pathMetric = 0;
}
stop_meas(init);
for (int i=0; i<polarParams->N; i++) {
memset((void *)&llrUpdated[i][0],0,sizeof(uint8_t)*polarParams->n);
memset((void *)&bitUpdated[i][0],0,sizeof(uint8_t)*polarParams->n);
llrUpdated[i][polarParams->n]=1;
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));
}
for (int i=0; i<polarParams->payloadBits; i++) {
for (int j=0; j<polarParams->crcParityBits; j++) {
tempECGM[i][j]=polarParams->crc_generator_matrix[i][j];
}
}
for (int i=polarParams->payloadBits; i<polarParams->K; i++) {
for (int j=0; j<polarParams->crcParityBits; j++) {
if( (i-polarParams->payloadBits) == j ){
tempECGM[i][j]=1;
} else {
tempECGM[i][j]=0;
}
if (generate_optim_code == 1 || polarParams->decoder_kernel==NULL) {
for (int i=0; i<polarParams->N; i++) {
memset((void *)&llrUpdated[i][0],0,sizeof(uint8_t)*polarParams->n);
memset((void *)&bitUpdated[i][0],0,sizeof(uint8_t)*polarParams->n);
llrUpdated[i][polarParams->n]=1;
bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2);
}
}
for (int i=0; i<polarParams->K; i++) {
for (int j=0; j<polarParams->crcParityBits; j++) {
extended_crc_generator_matrix[i][j]=tempECGM[polarParams->interleaving_pattern[i]][j];
}
}
stop_meas(init);
start_meas(polar_rate_matching);
int16_t d_tilde[polarParams->N];// = malloc(sizeof(double) * polarParams->N);
nr_polar_rate_matching_int8(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength);
for (int i=0;i<polarParams->N;i++) {
if (d_tilde[i]<-128) d_tilde[i]=-128;
else if (d_tilde[i]>127) d_tilde[i]=128;
}
memcpy((void*)&dlist[0].llr[polarParams->n][0],(void*)&d_tilde[0],sizeof(int16_t)*polarParams->N);
stop_meas(polar_rate_matching);
......@@ -464,70 +366,81 @@ int8_t polar_decoder_int8(int16_t *input,
decoder_list_int8_t *sorted_dlist[2*listSize];
for (uint8_t i = 0; i < 2*listSize; i++) sorted_dlist[i] = &dlist[i];
char fname[100];
FILE *fd;
if (generate_optim_code==1) {
sprintf(fname,"decoder_K%d_N%d_E%d.c",polarParams->K,polarParams->N,polarParams->encoderLength);
if ((fd=fopen(fname,"w"))==NULL) {printf("Cannot open %s\n",fname); exit(-1);}
fprintf(fd,"#include \"nr_polar_defs.h\"\n");
fprintf(fd,"void polar_decoder_K%d_N%d_E%d(t_nrPolar_params *polarParams,decoder_list_int8_t **sorted_dlist) {\n",
polarParams->K,polarParams->N,polarParams->encoderLength);
fprintf(fd,"int16_t mask,absllr;\n");
}
for (uint16_t currentBit=0; currentBit<polarParams->N; currentBit++){
// printf("***************** BIT %d (currentListSize %d, information_bit_pattern %d)\n",
// currentBit,currentListSize,polarParams->information_bit_pattern[currentBit]);
start_meas(update_LLR);
updateLLR_int8(sorted_dlist, llrUpdated, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1));
stop_meas(update_LLR);
if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit.
updatePathMetric0_int8(sorted_dlist,currentListSize, currentBit); //approximation=0 --> 11b, approximation=1 --> 12
} else { //Information or CRC bit.
start_meas(path_metric);
updatePathMetric2_int8(sorted_dlist, currentListSize, currentBit);
stop_meas(path_metric);
if (polarParams->decoder_kernel) polarParams->decoder_kernel(polarParams,sorted_dlist);
else {
for (uint16_t currentBit=0; currentBit<polarParams->N; currentBit++){
printf("***************** BIT %d (currentListSize %d, information_bit_pattern %d)\n",
currentBit,currentListSize,polarParams->information_bit_pattern[currentBit]);
start_meas(sorting);
start_meas(update_LLR);
updateLLR_int8(sorted_dlist, llrUpdated, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1),generate_optim_code,fd);
stop_meas(update_LLR);
if (currentListSize <= listSize/2) {
// until listsize is full we need to copy bit and LLR arrays to new entries
// below we only copy the ones we need to keep for sure
decoder_int8_A(sorted_dlist,currentListSize,polarParams);
#ifdef SHOWCOMP
printf("decoder_int8_A(sorted_dlist,%d,polarParams);\n",currentListSize);
#endif
}
decoder_int8_B(sorted_dlist,currentListSize);
#ifdef SHOWCOMP
printf("decoder_int8_B(sorted_dlist,%d);\n",currentListSize);
#endif
if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit.
updatePathMetric0_int8(sorted_dlist,currentListSize, currentBit,generate_optim_code,fd); //approximation=0 --> 11b, approximation=1 --> 12
} else { //Information or CRC bit.
start_meas(path_metric);
updatePathMetric2_int8(sorted_dlist, currentListSize, currentBit,generate_optim_code,fd);
stop_meas(path_metric);
bitUpdated[currentBit][0]=1;
updateCrcChecksum2_int8(sorted_dlist,extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits);
currentListSize*=2;
//Keep only the best "listSize" number of entries.
if (currentListSize > listSize) {
decoder_int8_C(sorted_dlist,
polarParams,
currentBit,
currentListSize,
listSize);
#ifdef SHOWCOMP
printf("decoder_int8_C(sorted_dlist,polarParams,%d,%d,%d);\n",currentBit,currentListSize,listSize);
#endif
currentListSize = listSize;
start_meas(sorting);
if (currentListSize <= listSize/2) {
// until listsize is full we need to copy bit and LLR arrays to new entries
// below we only copy the ones we need to keep for sure
decoder_int8_A(sorted_dlist,currentListSize,polarParams);
if (generate_optim_code == 1) fprintf(fd,"decoder_int8_A(sorted_dlist,%d,polarParams);\n",currentListSize);
}
decoder_int8_B(sorted_dlist,currentBit,currentListSize);
if (generate_optim_code == 1) fprintf(fd,"decoder_int8_B(sorted_dlist,%d,%d);\n",currentBit,currentListSize);
bitUpdated[currentBit][0]=1;
updateCrcChecksum2_int8(sorted_dlist,polarParams->extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits,generate_optim_code,fd);
currentListSize*=2;
//Keep only the best "listSize" number of entries.
if (currentListSize > listSize) {
decoder_int8_C(sorted_dlist,
polarParams,
currentBit,
currentListSize,
listSize);
if (generate_optim_code == 1) fprintf(fd,"decoder_int8_C(sorted_dlist,polarParams,%d,%d,%d);\n",currentBit,currentListSize,listSize);
currentListSize = listSize;
}
stop_meas(sorting);
nonFrozenBit++;
}
stop_meas(sorting);
nonFrozenBit++;
}
}
}
if (generate_optim_code==1) fprintf(fd,"}\n");
for (uint8_t i = 0; i < fmin(listSize, (pow(2,polarParams->crcCorrectionBits)) ); i++) {
// printf("list index %d :",i);
// 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);
// printf("list index %d / %d :",i,listSize);
// for (int j=0;j<polarParams->crcParityBits;j++) printf("%d",sorted_dlist[i]->crcChecksum[j]);
// printf(" => (%d)\n",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) {
......@@ -556,8 +469,69 @@ int8_t polar_decoder_int8(int16_t *input,
nr_free_double_2D_array(dlist[i].llr, (polarParams->n+1));
free(dlist[i].crcChecksum);
}*/
nr_free_uint8_t_2D_array(extended_crc_generator_matrix, polarParams->K);
nr_free_uint8_t_2D_array(tempECGM, polarParams->K);
stop_meas(decoding);
return(0);
}
int8_t polar_decoder_int8_new(int16_t *input,
uint8_t *output,
t_nrPolar_params *polarParams,
uint8_t listSize,
time_stats_t *init,
time_stats_t *polar_rate_matching,
time_stats_t *decoding,
time_stats_t *bit_extraction,
time_stats_t *deinterleaving,
time_stats_t *sorting,
time_stats_t *path_metric,
time_stats_t *update_LLR,
int generate_optim_code)
{
start_meas(init);
stop_meas(init);
start_meas(polar_rate_matching);
int16_t d_tilde[polarParams->N];// = malloc(sizeof(double) * polarParams->N);
nr_polar_rate_matching_int8(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength);
for (int i=0;i<polarParams->N;i++) {
if (d_tilde[i]<-128) d_tilde[i]=-128;
else if (d_tilde[i]>127) d_tilde[i]=128;
}
memcpy((void*)&polarParams->tree.root->alpha[0],(void*)&d_tilde[0],sizeof(int16_t)*polarParams->N);
stop_meas(polar_rate_matching);
/*
* SCL polar decoder.
*/
start_meas(decoding);
generic_polar_decoder(polarParams,polarParams->tree.root);
start_meas(bit_extraction);
//Extract the information bits (û to ĉ)
nr_polar_info_bit_extraction(polarParams->nr_polar_u, polarParams->nr_polar_cPrime, polarParams->information_bit_pattern, polarParams->N);
stop_meas(bit_extraction);
//Deinterleaving (ĉ to b)
start_meas(deinterleaving);
nr_polar_deinterleaver(polarParams->nr_polar_cPrime, polarParams->nr_polar_b, polarParams->interleaving_pattern, polarParams->K);
stop_meas(deinterleaving);
//Remove the CRC (â)
for (int j = 0; j < polarParams->payloadBits; j++) output[j]=polarParams->nr_polar_b[j];
// free(d_tilde);
/*
for (int i=0;i<2*listSize;i++) {
// 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_double_2D_array(dlist[i].llr, (polarParams->n+1));
free(dlist[i].crcChecksum);
}*/
stop_meas(decoding);
return(0);
}
......@@ -19,8 +19,9 @@
* contact@openairinterface.org
*/
#include "PHY/impl_defs_top.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
#define SHOWCOMP 1
#include "PHY/sse_intrin.h"
inline void computeLLR(double llr[1+nmax][Nmax], uint16_t row, uint16_t col,
uint16_t offset, uint8_t approximation) __attribute__((always_inline));
......@@ -45,40 +46,28 @@ inline void computeLLR(double llr[1+nmax][Nmax], uint16_t row, uint16_t col,
// printf("LLR (a %f, b %f): llr[%d][%d] %f\n",32*a,32*b,col,row,32*llr[col][row]);
}
inline void computeLLR_int8(decoder_list_int8_t **dlist,int i, uint16_t row, uint16_t col,
uint16_t offset) __attribute__((always_inline));
inline void computeLLR_int8(decoder_list_int8_t **dlist,int i, uint16_t row, uint16_t col,
uint16_t offset) {
int16_t llrtab[256][256];
int16_t a;
int16_t b;
int16_t absA,absB;
int16_t maska,maskb;
int16_t minabs;
// int16_t **llr=dlist[i]->llr;
void nr_polar_llrtableinit() {
int16_t absA,absB;
int16_t maska,maskb;
int16_t minabs;
#ifdef SHOWCOMP
printf("computeLLR_int8(sorted_dlist,%d,%d,%d);\n",i,row,col,offset);
#endif
a = dlist[i]->llr[col + 1][row];
b = dlist[i]->llr[col+1][row + offset];
// printf("LLR: a %d, b %d\n",a,b);
maska = a>>15;
maskb = b>>15;
absA = (a+maska)^maska;
absB = (b+maskb)^maskb;
// printf("LLR: absA %d, absB %d\n",absA,absB);
minabs = absA<absB ? absA : absB;
if ((maska^maskb) == 0)
dlist[i]->llr[col][row] = minabs;
else
dlist[i]->llr[col][row] = -minabs;
// printf("LLR (a %d, b %d): llr[%d][%d] %d\n",a,b,col,row,llr[col][row]);
for (int a=-128;a<128;a++) {
for (int b=-128;b<128;b++) {
absA=abs(a);
absB=abs(b);
minabs = absA<absB ? absA:absB;
if ((a<0 && b<0) || (a>=0 && b>=0)) llrtab[a+128][b+128] = minabs;
else llrtab[a+128][b+128] = -minabs;
}
}
}
void updateLLR(decoder_list_t **dlist,uint8_t **llrU, uint8_t **bitU,
uint8_t listSize, uint16_t row, uint16_t col, uint16_t xlen, uint8_t ylen, uint8_t approximation) {
uint16_t offset = (xlen/(1<<(ylen-col-1)));
if (( (row) % (2*offset) ) >= offset ) {
if (bitU[row-offset][col]==0) updateBit(dlist, bitU, listSize, (