Commit 5344e567 authored by Raymond Knopp's avatar Raymond Knopp

intermediate commit of list decoding extension

parent cc4182a3
......@@ -372,21 +372,18 @@ int main(int argc, char *argv[]) {
printf("estimatedOutput: [0]->0x%08x\n", estimatedOutput[0]);*/
//calculate errors
if (decoderState!=0) {
blockErrorState=-1;
nBitError=-1;
} else {
for (int j = 0; j < currentPtr->payloadBits; j++) {
if (((estimatedOutput[0]>>j) & 1) != ((testInput[0]>>j) & 1)) nBitError++;
// printf("bit %d: %d => %d\n",j,(testInput[0]>>j)&1,(estimatedOutput[0]>>j)&1);
}
if (nBitError>0) {
for (int j = 0; j < currentPtr->payloadBits; j++) {
if (((estimatedOutput[0]>>j) & 1) != ((testInput[0]>>j) & 1)) {
nBitError++;
printf("bit %d: %d => %d\n",j,(testInput[0]>>j)&1,(estimatedOutput[0]>>j)&1);
}
}
if (nBitError>0) {
blockErrorState=1;
// printf("Error: Input %x, Output %x\n",testInput[0],estimatedOutput[0]);
}
printf("Error: Input %x, Output %x\n",testInput[0],estimatedOutput[0]);
}
//Iteration times are in microseconds.
timeEncoderCumulative+=(timeEncoder.diff/(cpu_freq_GHz*1000.0));
......
......@@ -1153,6 +1153,8 @@ void init_polar_deinterleaver_table(t_nrPolar_params *polarParams) {
}
}
uint64_t Cprimetest;
uint32_t polar_decoder_int16(int16_t *input,
uint64_t *out,
const t_nrPolar_params *polarParams) {
......@@ -1166,20 +1168,17 @@ uint32_t polar_decoder_int16(int16_t *input,
memcpy((void *)&polarParams->tree.root->alpha[0],(void *)&d_tilde[0],sizeof(int16_t)*polarParams->N);
for (int iter=0;iter<4;iter++) {
generic_polar_decoder(polarParams,polarParams->tree.root,1);
generic_polar_decoder(polarParams,polarParams->tree.root);
//Extract the information bits (û to ĉ)
uint64_t Cprime[4]={0,0,0,0};
uint64_t B[4]={0,0,0,0};
for (int i=0;i<polarParams->K;i++) Cprime[i>>6] = Cprime[i>>6] | ((uint64_t)polarParams->nr_polar_U[polarParams->Q_I_N[i]])<<(i&63);
printf("iter %d : Cprime %llx|%llx\n",
iter,Cprime[1],Cprime[0]);
//Deinterleaving (ĉ to b)
uint8_t *Cprimebyte = (uint8_t*)Cprime;
if (polarParams->K<65) {
//Extract the information bits (û to ĉ)
uint64_t Cprime[4]={0,0,0,0};
uint64_t B[4]={0,0,0,0};
for (int i=0;i<polarParams->K;i++) Cprime[i>>6] = Cprime[i>>6] | ((uint64_t)polarParams->nr_polar_U[polarParams->Q_I_N[i]])<<(i&63);
//Deinterleaving (ĉ to b)
uint8_t *Cprimebyte = (uint8_t*)Cprime;
if (polarParams->K<65) {
B[0] = polarParams->B_tab0[0][Cprimebyte[0]] |
polarParams->B_tab0[1][Cprimebyte[1]] |
polarParams->B_tab0[2][Cprimebyte[2]] |
......@@ -1199,80 +1198,48 @@ uint32_t polar_decoder_int16(int16_t *input,
}
int len=polarParams->payloadBits;
//int len_mod64=len&63;
int crclen = polarParams->crcParityBits;
uint64_t rxcrc=B[0]&((1<<crclen)-1);
uint32_t crc;
uint64_t Ar;
AssertFatal(len<65,"A must be less than 65 bits\n");
if (len<=32) {
Ar = (uint32_t)(B[0]>>crclen);
uint8_t A32_flip[4];
uint32_t Aprime= (uint32_t)(Ar<<(32-len));
A32_flip[0]=((uint8_t*)&Aprime)[3];
A32_flip[1]=((uint8_t*)&Aprime)[2];
A32_flip[2]=((uint8_t*)&Aprime)[1];
A32_flip[3]=((uint8_t*)&Aprime)[0];
crc = (uint64_t)(crc24c(A32_flip,len)>>8);
}
else if (len<=64) {
Ar = (B[0]>>crclen) | (B[1]<<(64-crclen));;
uint8_t A64_flip[8];
uint64_t Aprime= (uint32_t)(Ar<<(64-len));
A64_flip[0]=((uint8_t*)&Aprime)[7];
A64_flip[1]=((uint8_t*)&Aprime)[6];
A64_flip[2]=((uint8_t*)&Aprime)[5];
A64_flip[3]=((uint8_t*)&Aprime)[4];
A64_flip[4]=((uint8_t*)&Aprime)[3];
A64_flip[5]=((uint8_t*)&Aprime)[2];
A64_flip[6]=((uint8_t*)&Aprime)[1];
A64_flip[7]=((uint8_t*)&Aprime)[0];
crc = (uint64_t)(crc24c(A64_flip,len)>>8);
}
//#if 0
//#endif
out[0]=Ar;
printf("iter %d : A %llx B %llx|%llx Cprime %llx|%llx (crc %x,rxcrc %llx %d)\n",
iter,Ar,
B[1],B[0],Cprime[1],Cprime[0],crc,
rxcrc,polarParams->payloadBits);
if (crc==rxcrc) return(0);
int32_t avg_llr=0,llr_tmp;
for (int i=0;i<polarParams->N;i++) {
llr_tmp = abs(polarParams->tree.root->softbeta[i]);
avg_llr += llr_tmp;
}
avg_llr/=polarParams->N;
int shift = log2_approx(avg_llr) - 3;
printf("iter %d: avg_llr %d shift %d\n",iter,avg_llr,shift);
// for (int i=0;i<polarParams->N;i++) printf("i %d: alpha %d, beta %d\n",i,polarParams->tree.root->alpha[i],polarParams->tree.root->softbeta[i]);
/* for (int i=0; i<polarParams->N; i++) {
if (polarParams->tree.root->softbeta[i]<-128) polarParams->tree.root->alpha[i]=-128;
else if (polarParams->tree.root->softbeta[i]>127) polarParams->tree.root->alpha[i]=127;
else polarParams->tree.root->alpha[i]=polarParams->tree.root->softbeta[i];
}*/
for (int i=0;i<polarParams->N;i++) {
if ((polarParams->tree.root->alpha[i] * (polarParams->tree.root->softbeta[i])) < 0 ) printf("i %d: alpha %d => %d\n",i,polarParams->tree.root->alpha[i],polarParams->tree.root->softbeta[i]>>shift);
polarParams->tree.root->alpha[i] = polarParams->tree.root->softbeta[i]>>shift;
}
//for (int i=0;i<polarParams->N;i++) printf("i %d: %d => %d\n",i,polarParams->tree.root->alpha[i],d_tilde[i]);;
int len=polarParams->payloadBits;
//int len_mod64=len&63;
int crclen = polarParams->crcParityBits;
uint64_t rxcrc=B[0]&((1<<crclen)-1);
uint32_t crc;
uint64_t Ar;
AssertFatal(len<65,"A must be less than 65 bits\n");
if (len<=32) {
Ar = (uint32_t)(B[0]>>crclen);
uint8_t A32_flip[4];
uint32_t Aprime= (uint32_t)(Ar<<(32-len));
A32_flip[0]=((uint8_t*)&Aprime)[3];
A32_flip[1]=((uint8_t*)&Aprime)[2];
A32_flip[2]=((uint8_t*)&Aprime)[1];
A32_flip[3]=((uint8_t*)&Aprime)[0];
crc = (uint64_t)(crc24c(A32_flip,len)>>8);
}
else if (len<=64) {
Ar = (B[0]>>crclen) | (B[1]<<(64-crclen));;
uint8_t A64_flip[8];
uint64_t Aprime= (uint32_t)(Ar<<(64-len));
A64_flip[0]=((uint8_t*)&Aprime)[7];
A64_flip[1]=((uint8_t*)&Aprime)[6];
A64_flip[2]=((uint8_t*)&Aprime)[5];
A64_flip[3]=((uint8_t*)&Aprime)[4];
A64_flip[4]=((uint8_t*)&Aprime)[3];
A64_flip[5]=((uint8_t*)&Aprime)[2];
A64_flip[6]=((uint8_t*)&Aprime)[1];
A64_flip[7]=((uint8_t*)&Aprime)[0];
crc = (uint64_t)(crc24c(A64_flip,len)>>8);
}
return(-1);
//#if 0
//#endif
out[0]=Ar;
if (crc!=rxcrc) printf("CRC mismatch: A %llx B %llx|%llx Cprime %llx|%llx (crc %x,rxcrc %llx %d)\n",
Ar,
B[1],B[0],Cprime[1],Cprime[0],crc,
rxcrc,polarParams->payloadBits);
return(crc^rxcrc);
}
......@@ -206,7 +206,6 @@ decoder_node_t *new_decoder_node(int first_leaf_index,int level) {
node->all_frozen=0;
node->alpha = (int16_t*)malloc16(node->Nv*sizeof(int16_t));
node->beta = (int16_t*)malloc16(node->Nv*sizeof(int16_t));
node->softbeta = (int16_t*)malloc16(node->Nv*sizeof(int16_t));
memset((void*)node->beta,-1,node->Nv*sizeof(int16_t));
......@@ -384,17 +383,36 @@ void applyFtoleft(t_nrPolar_params *pp,decoder_node_t *node) {
}
if (node->Nv == 2) { // apply hard decision on left node
betal[0] = (alpha_l[0]>0) ? -1 : 1;
node->left->softbeta[0] = alpha_l[0];
#ifdef DEBUG_NEW_IMPL
printf("betal[0] %d (%p), softbeta %d \n",betal[0],&betal[0],node->left->softbeta[0]);
printf("betal[0] %d (%p)\n",betal[0],&betal[0]);
#endif
// pp->nr_polar_U[node->first_leaf_index] = (1+betal[0])>>1;
int bi = node->left->bit_bitindex;
int ne1 = pp->tree.num_entries;
int16_t abs_alpha = ((alpha_l[0]>0) ? alpha_l[0] : -alpha_l[0]);
if (pp->tree.num_entries < pp->tree.list_size) {
// update list for SC hard-decision
for (int i=0;i<pp->tree.num_entries;i++) pp->tree.decoderout[i][bi>>6] |= (((1+betal[0])>>1)<<(bi&63));
// update list for flipped SC hard-decision
int ne2=pp->tree.num_entries<<1;
if (ne2 > pp->tree.list_size) ne2 = pp->tree.list_size;
for (int i=pp->tree.num_entries;i<ne2;i++) {
pp->tree.decoderout[i][bi>>6] = pp->tree.decoderout[i-pp->tree.num_entries][bi>>6] ^ (((uint64_t)1)<<(bi&63));
pp->tree.PM[i] = pp->tree.PM[i-pp->tree.num_entries] - abs_alpha;
}
}
for (int i=0;i<pp->tree.num_entries-(ne2-pp->tree.num_entries);i++) update_min(pp->tree,abs_alpha);
#ifdef DEBUG_NEW_IMPL
int j;
printf("Setting bit %d (%d) to %d (LLR %d)\n",node->first_leaf_index,bit_index,(betal[0]+1)>>1,alpha_l[0]);
#endif
pp->nr_polar_U[node->first_leaf_index] = (1+betal[0])>>1;
//#ifdef DEBUG_NEW_IMPL
printf("Setting bit %d to %d (LLR %d)\n",node->first_leaf_index,(betal[0]+1)>>1,alpha_l[0]);
//#endif
}
}
else for (int i=0;i<node->Nv/2;i++) node->left->softbeta[i]=32767;
}
void applyGtoright(t_nrPolar_params *pp,decoder_node_t *node) {
......@@ -458,10 +476,11 @@ void applyGtoright(t_nrPolar_params *pp,decoder_node_t *node) {
}
if (node->Nv == 2) { // apply hard decision on right node
betar[0] = (alpha_r[0]>0) ? -1 : 1;
node->right->softbeta[0] = alpha_r[0];
pp->nr_polar_U[node->first_leaf_index+1] = (1+betar[0])>>1;
//#ifdef DEBUG_NEW_IMPL
printf("Setting bit %d to %d (LLR %d)\n",node->first_leaf_index+1,(betar[0]+1)>>1,alpha_r[0]);
int j;
for (j=0;j<pp->K;j++) if (pp->Q_I_N[j] == (node->first_leaf_index+1)) break;
printf("Setting bit %d (%d) to %d (LLR %d)\n",node->first_leaf_index+1,j,(betar[0]+1)>>1,alpha_r[0]);
//#endif
}
}
......@@ -473,14 +492,11 @@ int16_t all1[16] = {1,1,1,1,
1,1,1,1,
1,1,1,1};
void computeBeta(t_nrPolar_params *pp,decoder_node_t *node, int do_softbeta) {
void computeBeta(t_nrPolar_params *pp,decoder_node_t *node) {
int16_t *betav = node->beta;
int16_t *betal = node->left->beta;
int16_t *betar = node->right->beta;
int16_t *softbetav = node->softbeta;
int16_t *softbetal = node->left->softbeta;
int16_t *softbetar = node->right->softbeta;
#ifdef DEBUG_NEW_IMPL
printf("Computing beta @ level %d first_leaf_index %d (all_frozen %d)\n",node->level,node->first_leaf_index,node->left->all_frozen);
......@@ -532,42 +548,21 @@ void computeBeta(t_nrPolar_params *pp,decoder_node_t *node, int do_softbeta) {
memcpy((void*)&betav[node->Nv/2],betar,(node->Nv/2)*sizeof(int16_t));
// softbeta computation
if (do_softbeta==1) {
int16_t a,b,absa,absb,maska,maskb,minabs;
for (int i=0;i<node->Nv/2;i++) {
a=softbetal[i];
b=softbetar[i];
maska=a>>15;
maskb=b>>15;
absa=(a+maska)^maska;
absb=(b+maskb)^maskb;
minabs = absa<absb ? absa : absb;
softbetav[i] = (maska^maskb)!=0 ? -minabs : minabs;
#ifdef DEBUG_NEW_IMPL
printf("Nv %d, first_leaf %d: beta_v[%d] %d (%d,%d) softbetav[%d] %d (%d,%d)\n",node->Nv,node->first_leaf_index,i,betav[i],betal[i],betar[i],i,softbetav[i],a,b);
#endif
}
memcpy((void*)&softbetav[node->Nv/2],(void*)softbetar,sizeof(int16_t)*node->Nv/2);
}
}
void generic_polar_decoder(t_nrPolar_params *pp,decoder_node_t *node, int do_softbeta) {
void generic_polar_decoder(t_nrPolar_params *pp,decoder_node_t *node) {
// Apply F to left
applyFtoleft(pp,node);
// if left is not a leaf recurse down to the left
if (node->left->leaf==0) generic_polar_decoder(pp,node->left,do_softbeta);
if (node->left->leaf==0) generic_polar_decoder(pp,node->left);
applyGtoright(pp,node);
if (node->right->leaf==0) generic_polar_decoder(pp,node->right,do_softbeta);
if (node->right->leaf==0) generic_polar_decoder(pp,node->right);
computeBeta(pp,node,do_softbeta);
computeBeta(pp,node);
}
......@@ -68,14 +68,20 @@ typedef struct decoder_node_t_s {
int Nv;
int first_leaf_index;
int all_frozen;
int bit_index;
int16_t *alpha;
int16_t *beta;
int16_t *softbeta;
} decoder_node_t;
#define LISTSIZE_MAX 8
typedef struct decoder_tree_t_s {
decoder_node_t *root;
int num_nodes;
int list_size;
int32_t PM[LISTSIZE_MAX];
uint64_t decoderout[LISTSIZE_MAX][4];
int numentries;
int minentry;
} decoder_tree_t;
struct nrPolar_params {
......@@ -186,7 +192,7 @@ int8_t polar_decoder_dci(double *input,
uint16_t n_RNTI);
void generic_polar_decoder(t_nrPolar_params *,
decoder_node_t *,int);
decoder_node_t *);
void build_decoder_tree(t_nrPolar_params *pp);
void build_polar_tables(t_nrPolar_params *polarParams);
......
......@@ -412,6 +412,7 @@ void build_polar_tables(t_nrPolar_params *polarParams) {
polarParams->rm_tab[tcnt] = polarParams->rate_matching_pattern[outpos]>>shift;
}
void polar_encoder_fast(uint64_t *A,
uint32_t *out,
int32_t crcmask,
......@@ -484,7 +485,7 @@ void polar_encoder_fast(uint64_t *A,
}
}
//#ifdef DEBUG_POLAR_ENCODER
#ifdef DEBUG_POLAR_ENCODER
if (polarParams->K<65)
printf("A %llx B %llx Cprime %llx (payload bits %d,crc %x)\n",
......@@ -510,7 +511,7 @@ void polar_encoder_fast(uint64_t *A,
crc24c((uint8_t *)A,bitlen)>>8);
}
//#endif
#endif
/* printf("Bbytes : %x.%x.%x.%x.%x.%x.%x.%x\n",Bbyte[0],Bbyte[1],Bbyte[2],Bbyte[3],Bbyte[4],Bbyte[5],Bbyte[6],Bbyte[7]);
printf("%llx,%llx,%llx,%llx,%llx,%llx,%llx,%llx\n",polarParams->cprime_tab[0][Bbyte[0]] ,
polarParams->cprime_tab[1][Bbyte[1]] ,
......
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