Commit 586e279d authored by Florian Kaltenberger's avatar Florian Kaltenberger

adding ldpctest and ldpc_generate_coefficient from feature_ldpc_coding

parent 73c4672c
...@@ -142,12 +142,12 @@ int test_ldpc(short No_iteration, ...@@ -142,12 +142,12 @@ int test_ldpc(short No_iteration,
if (lift_size[i1] >= (double) block_length/Kb) if (lift_size[i1] >= (double) block_length/Kb)
{ {
Zc = lift_size[i1]; Zc = lift_size[i1];
// printf("%d\n",Zc); //printf("%d\n",Zc);
break; break;
} }
} }
printf("BG %d, Zc %d, Kb %d\n",BG, Zc, Kb); printf("ldpc_test: BG %d, Zc %d, Kb %d\n",BG, Zc, Kb);
no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*(1/((float)nom_rate/(float)denom_rate)))/Zc; no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*(1/((float)nom_rate/(float)denom_rate)))/Zc;
// printf("puncture:%d\n",no_punctured_columns); // printf("puncture:%d\n",no_punctured_columns);
removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length/((float)nom_rate/(float)denom_rate)); removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length/((float)nom_rate/(float)denom_rate));
...@@ -160,28 +160,25 @@ int test_ldpc(short No_iteration, ...@@ -160,28 +160,25 @@ int test_ldpc(short No_iteration,
//// encoder //// encoder
start_meas(&time); start_meas(&time);
if (BG==1) //if (BG==1)
ldpc_encoder(test_input, channel_input,block_length,nom_rate,denom_rate); //ldpc_encoder(test_input, channel_input,block_length,nom_rate,denom_rate);
else //else
ldpc_encoder_orig(test_input, channel_input,block_length,nom_rate,denom_rate,0); ldpc_encoder_orig(test_input, channel_input,block_length,nom_rate,denom_rate,0);
stop_meas(&time); stop_meas(&time);
start_meas(&time_optim); start_meas(&time_optim);
if (BG==1) { ldpc_encoder_optim(test_input,channel_input_optim,block_length,nom_rate,denom_rate,&tinput,&tprep,&tparity,&toutput);
ldpc_encoder_optim(test_input, channel_input_optim,block_length,nom_rate,denom_rate,&tinput,&tprep,&tparity,&toutput);
}
stop_meas(&time_optim); stop_meas(&time_optim);
if (ntrials==1)
for (i = 0; i < block_length+(nrows-no_punctured_columns) * Zc - removed_bit; i++) for (i = 0; i < block_length+(nrows-no_punctured_columns) * Zc - removed_bit; i++)
if (channel_input[i]!=channel_input_optim[i]) printf("differ in pos %d (%d,%d)\n",i, if (channel_input[i]!=channel_input_optim[i]) printf("differ in pos %d (%d,%d)\n",i,
channel_input[i], channel_input[i],
channel_input_optim[i]); channel_input_optim[i]);
//print_meas_now(&time, "", stdout); //print_meas_now(&time, "", stdout);
//for (i=0;i<25344;i++) // for (i=0;i<6400;i++)
//printf("channel_input[%d]=%d\n",i,channel_input[i]); //printf("channel_input[%d]=%d\n",i,channel_input[i]);
//printf("%d ",channel_input[i]); //printf("%d ",channel_input[i]);
if ((BG==2) && (Zc==128||Zc==256)) if ((BG==2) && (Zc==128||Zc==256))
...@@ -253,7 +250,7 @@ int test_ldpc(short No_iteration, ...@@ -253,7 +250,7 @@ int test_ldpc(short No_iteration,
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
unsigned int errors,crc_misses; unsigned int errors,crc_misses;
short block_length=22*384; // decoder supports length: 1201 -> 1280, 2401 -> 2560 short block_length=576; // decoder supports length: 1201 -> 1280, 2401 -> 2560
short No_iteration=25; short No_iteration=25;
//double rate=0.333; //double rate=0.333;
int nom_rate=1; int nom_rate=1;
...@@ -262,7 +259,9 @@ int main(int argc, char *argv[]) ...@@ -262,7 +259,9 @@ int main(int argc, char *argv[])
unsigned char qbits=4; unsigned char qbits=4;
unsigned int decoded_errors[100]; // initiate the size of matrix equivalent to size of SNR unsigned int decoded_errors[100]; // initiate the size of matrix equivalent to size of SNR
int c,i=0; int c,i=0;
int n_trials = 1; int n_trials = 1;
randominit(0); randominit(0);
while ((c = getopt (argc, argv, "q:r:s:l:n:")) != -1) while ((c = getopt (argc, argv, "q:r:s:l:n:")) != -1)
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#include <string.h> #include <string.h>
#include "Gen_shift_value.h" #include "Gen_shift_value.h"
#include "assertions.h" #include "assertions.h"
#include "defs.h"
short *choose_generator_matrix(short BG,short Zc) short *choose_generator_matrix(short BG,short Zc)
{ {
short *Gen_shift_values; short *Gen_shift_values = NULL;
if (BG==1) if (BG==1)
{ {
...@@ -329,41 +330,48 @@ short *choose_generator_matrix(short BG,short Zc) ...@@ -329,41 +330,48 @@ short *choose_generator_matrix(short BG,short Zc)
return Gen_shift_values; return Gen_shift_values;
} }
int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,short block_length,double rate,unsigned char gen_code) int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,short block_length,int nom_rate,int denom_rate,unsigned char gen_code)
{ {
unsigned char c[22*384]; //padded input, unpacked, max size unsigned char c[22*384]; //padded input, unpacked, max size
unsigned char d[68*384]; //coded output, unpacked, max size unsigned char d[68*384]; //coded output, unpacked, max size
unsigned char channel_temp,temp; unsigned char channel_temp,temp;
short *Gen_shift_values, *no_shift_values, *pointer_shift_values; short *Gen_shift_values, *no_shift_values, *pointer_shift_values;
short BG,Zc,Kb,nrows,ncols; short BG,Zc,Kb,nrows,ncols;
int i,i1,i2,i3,i4,i5,t,var,temp_prime; int i,i1,i2,i3,i4,i5,temp_prime,var;
int no_punctured_columns,removed_bit; int no_punctured_columns,removed_bit;
//Table of possible lifting sizes //Table of possible lifting sizes
short lift_size[51]= {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32,36,40,44,48,52,56,60,64,72,80,88,96,104,112,120,128,144,160,176,192,208,224,240,256,288,320,352,384}; short lift_size[51]= {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32,36,40,44,48,52,56,60,64,72,80,88,96,104,112,120,128,144,160,176,192,208,224,240,256,288,320,352,384};
int nind=0;
int indlist[1000];
int indlist2[1000];
//determine number of bits in codeword //determine number of bits in codeword
if (block_length>3840) if (block_length>3840)
{ {
BG=1; BG=1;
Kb = 22; Kb = 22;
nrows=46; //parity check bits nrows=46; //parity check bits
ncols=22; //info bits ncols=22; //info bits
} }
else if (block_length<=3840) else if (block_length<=3840)
{ {
BG=2; BG=2;
nrows=42; //parity check bits nrows=42; //parity check bits
ncols=10; // info bits ncols=10; // info bits
if (block_length>640)
Kb = 10; if (block_length>640)
else if (block_length>560) Kb = 10;
Kb = 9; else if (block_length>560)
else if (block_length>192) Kb = 9;
Kb = 8; else if (block_length>192)
else Kb = 8;
Kb = 6; else
} Kb = 6;
}
//find minimum value in all sets of lifting size //find minimum value in all sets of lifting size
Zc=0;
for (i1=0; i1 < 51; i1++) for (i1=0; i1 < 51; i1++)
{ {
if (lift_size[i1] >= (double) block_length/Kb) if (lift_size[i1] >= (double) block_length/Kb)
...@@ -373,9 +381,18 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho ...@@ -373,9 +381,18 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho
break; break;
} }
} }
if (Zc==0) {
printf("ldpc_encoder_orig: could not determine lifting size\n");
return(-1);
}
int nind=0; Gen_shift_values=choose_generator_matrix(BG,Zc);
int indlist[1000]; if (Gen_shift_values==NULL) {
printf("ldpc_encoder_orig: could not find generator matrix\n");
return(-1);
}
//printf("ldpc_encoder_orig: BG %d, Zc %d, Kb %d\n",BG, Zc, Kb);
// load base graph of generator matrix // load base graph of generator matrix
if (BG==1) if (BG==1)
...@@ -388,20 +405,20 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho ...@@ -388,20 +405,20 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho
no_shift_values=(short *) no_shift_values_BG2; no_shift_values=(short *) no_shift_values_BG2;
pointer_shift_values=(short *) pointer_shift_values_BG2; pointer_shift_values=(short *) pointer_shift_values_BG2;
} }
Gen_shift_values=choose_generator_matrix(BG,Zc);
// calculate number of punctured bits
no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*3)/Zc; no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*3)/Zc;
removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*3); removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(block_length*3);
//printf("%d\n",no_punctured_columns); //printf("%d\n",no_punctured_columns);
//printf("%d\n",removed_bit); //printf("%d\n",removed_bit);
// unpack input // unpack input
memset(c,0,sizeof(unsigned char) * Kb * Zc); memset(c,0,sizeof(unsigned char) * ncols * Zc);
memset(d,0,sizeof(unsigned char) * nrows * Zc);
for (i=0; i<block_length; i++) for (i=0; i<block_length; i++)
{ {
c[i] = test_input[i/8]<<(i%8); //c[i] = test_input[i/8]<<(i%8);
c[i]=c[i]>>7&1; //c[i]=c[i]>>7&1;
c[i]=(test_input[i/8]&(1<<(i&7)))>>(i&7);
} }
// parity check part // parity check part
...@@ -409,16 +426,23 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho ...@@ -409,16 +426,23 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho
if (gen_code==1) if (gen_code==1)
{ {
char fname[100]; char fname[100];
sprintf(fname,"ldpc%d_byte.c",Zc); sprintf(fname,"ldpc_BG%d_Zc%d_byte.c",BG,Zc);
FILE *fd=fopen(fname,"w"); FILE *fd=fopen(fname,"w");
AssertFatal(fd!=NULL,"cannot open %s\n",fname);
sprintf(fname,"ldpc_BG%d_Zc%d_16bit.c",BG,Zc);
FILE *fd2=fopen(fname,"w");
AssertFatal(fd2!=NULL,"cannot open %s\n",fname);
int shift; int shift;
char data_type[100]; char data_type[100];
char xor_command[100]; char xor_command[100];
int mask; int mask;
AssertFatal(fd!=NULL,"cannot open %s\n",fname);
fprintf(fd,"#include \"PHY/sse_intrin.h\"\n"); fprintf(fd,"#include \"PHY/sse_intrin.h\"\n");
fprintf(fd2,"#include \"PHY/sse_intrin.h\"\n");
if ((Zc&31)==0) { if ((Zc&31)==0) {
shift=5; // AVX2 - 256-bit SIMD shift=5; // AVX2 - 256-bit SIMD
...@@ -436,7 +460,7 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho ...@@ -436,7 +460,7 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho
else if ((Zc&7)==0) { else if ((Zc&7)==0) {
shift=3; // MMX - 64-bit SIMD shift=3; // MMX - 64-bit SIMD
mask=7; mask=7;
strcpy(data_type,"__m64i"); strcpy(data_type,"__m64");
strcpy(xor_command,"_mm_xor_si64"); strcpy(xor_command,"_mm_xor_si64");
} }
else { else {
...@@ -445,49 +469,56 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho ...@@ -445,49 +469,56 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho
strcpy(data_type,"uint8_t"); strcpy(data_type,"uint8_t");
strcpy(xor_command,"scalar_xor"); strcpy(xor_command,"scalar_xor");
fprintf(fd,"#define scalar_xor(a,b) ((a)^(b))\n"); fprintf(fd,"#define scalar_xor(a,b) ((a)^(b))\n");
fprintf(fd2,"#define scalar_xor(a,b) ((a)^(b))\n");
} }
fprintf(fd,"// generated code for Zc=%d, byte encoding\n",Zc); fprintf(fd,"// generated code for Zc=%d, byte encoding\n",Zc);
fprintf(fd,"static inline void ldpc%d_byte(uint8_t *c,uint8_t *d) {\n",Zc); fprintf(fd2,"// generated code for Zc=%d, 16bit encoding\n",Zc);
fprintf(fd,"static inline void ldpc_BG%d_Zc%d_byte(uint8_t *c,uint8_t *d) {\n",BG,Zc);
fprintf(fd2,"static inline void ldpc_BG%d_Zc%d_16bit(uint16_t *c,uint16_t *d) {\n",BG,Zc);
fprintf(fd," %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type); fprintf(fd," %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
fprintf(fd2," %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
fprintf(fd," %s *c2,*d2;\n\n",data_type); fprintf(fd," %s *c2,*d2;\n\n",data_type);
fprintf(fd2," %s *c2,*d2;\n\n",data_type);
fprintf(fd," int i2;\n"); fprintf(fd," int i2;\n");
fprintf(fd2," int i2;\n");
fprintf(fd," for (i2=0; i2<%d; i2++) {\n",Zc>>shift); fprintf(fd," for (i2=0; i2<%d; i2++) {\n",Zc>>shift);
fprintf(fd2," for (i2=0; i2<%d; i2++) {\n",Zc>>(shift-1));
for (i2=0; i2 < 1; i2++) for (i2=0; i2 < 1; i2++)
{ {
t=Kb*Zc+i2; //t=Kb*Zc+i2;
//rotate matrix here
for (i5=0; i5 < Kb; i5++)
{
temp = c[i5*Zc];
memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(unsigned char));
c[i5*Zc+Zc-1] = temp;
}
// calculate each row in base graph // calculate each row in base graph
fprintf(fd," c2=&csimd[i2];\n"); fprintf(fd," c2=&csimd[i2];\n");
fprintf(fd," d2=&dsimd[i2];\n"); fprintf(fd," d2=&dsimd[i2];\n");
fprintf(fd2," c2=&csimd[i2];\n");
fprintf(fd2," d2=&dsimd[i2];\n");
for (i1=0; i1 < nrows; i1++)
for (i1=0; i1 < nrows-no_punctured_columns; i1++)
{ {
channel_temp=0; channel_temp=0;
fprintf(fd,"\n//row: %d\n",i1); fprintf(fd,"\n//row: %d\n",i1);
fprintf(fd2,"\n//row: %d\n",i1);
fprintf(fd," d2[%d]=",(Zc*i1)>>shift); fprintf(fd," d2[%d]=",(Zc*i1)>>shift);
fprintf(fd2," d2[%d]=",(Zc*i1)>>(shift-1));
nind=0; nind=0;
for (i3=0; i3 < Kb; i3++) for (i3=0; i3 < ncols; i3++)
{ {
temp_prime=i1 * ncols + i3; temp_prime=i1 * ncols + i3;
for (i4=0; i4 < no_shift_values[temp_prime]; i4++) for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
{ {
var=(int)((i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc)/Zc); var=(int)((i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc)/Zc);
int index =var*2*Zc + (i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc) % Zc; int index =var*2*Zc + (i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc) % Zc;
indlist[nind++] = ((index&mask)*((2*Zc)>>shift)*Kb)+(index>>shift); indlist[nind] = ((index&mask)*((2*Zc)>>shift)*Kb)+(index>>shift);
indlist2[nind++] = ((index&(mask>>1))*((2*Zc)>>(shift-1))*Kb)+(index>>(shift-1));
} }
...@@ -495,60 +526,59 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho ...@@ -495,60 +526,59 @@ int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,sho
} }
for (i4=0;i4<nind-1;i4++) { for (i4=0;i4<nind-1;i4++) {
fprintf(fd,"%s(c2[%d],",xor_command,indlist[i4]); fprintf(fd,"%s(c2[%d],",xor_command,indlist[i4]);
fprintf(fd2,"%s(c2[%d],",xor_command,indlist2[i4]);
} }
fprintf(fd,"c2[%d]",indlist[i4]); fprintf(fd,"c2[%d]",indlist[i4]);
for (i4=0;i4<nind-1;i4++) fprintf(fd,")"); fprintf(fd2,"c2[%d]",indlist2[i4]);
for (i4=0;i4<nind-1;i4++) { fprintf(fd,")"); fprintf(fd2,")"); }
fprintf(fd,";\n"); fprintf(fd,";\n");
d[t+i1*Zc]=channel_temp; fprintf(fd2,";\n");
//channel_input[t+i1*Zc]=channel_temp;
} }
fprintf(fd," }\n}\n"); fprintf(fd," }\n}\n");
fprintf(fd2," }\n}\n");
} }
fclose(fd); fclose(fd);
fclose(fd2);
} }
else if(gen_code==0) else if(gen_code==0)
{ {
for (i2=0; i2 < Zc; i2++) { for (i2=0; i2 < Zc; i2++)
//t=Kb*Zc+i2;
//rotate matrix here
for (i5=0; i5 < Kb; i5++)
{ {
temp = c[i5*Zc]; //t=Kb*Zc+i2;
memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(unsigned char));
c[i5*Zc+Zc-1] = temp;
}
// calculate each row in base graph //rotate matrix here
for (i1=0; i1 < nrows-no_punctured_columns; i1++) for (i5=0; i5 < Kb; i5++)
{ {
channel_temp=0; temp = c[i5*Zc];
if (gen_code) { memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(unsigned char));
printf("//row: %d\n",i1); c[i5*Zc+Zc-1] = temp;
printf("d[i2+%d*Zc]=",i1);
} }
for (i3=0; i3 < Kb; i3++)
// calculate each row in base graph
for (i1=0; i1 < nrows-no_punctured_columns; i1++)
{ {
temp_prime=i1 * ncols + i3; channel_temp=0;
for (i4=0; i4 < no_shift_values[temp_prime]; i4++) for (i3=0; i3 < Kb; i3++)
{ {
channel_temp = channel_temp ^ c[ i3*Zc + Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ] ]; temp_prime=i1 * ncols + i3;
if (gen_code)
printf("c[%d]^", i3*Zc + Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ] ); for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
{
channel_temp = channel_temp ^ c[ i3*Zc + Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ] ];
}
} }
d[i2+i1*Zc]=channel_temp;
//channel_input[t+i1*Zc]=channel_temp;
} }
if (gen_code)
printf("\n");
d[i2+i1*Zc]=channel_temp;
//channel_input[t+i1*Zc]=channel_temp;
} }
}
} }
// information part and puncture columns // information part and puncture columns
memcpy(&channel_input[0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char)); memcpy(&channel_input[0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char));
memcpy(&channel_input[block_length-2*Zc], &d[Kb*Zc], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char)); memcpy(&channel_input[block_length-2*Zc], &d[0], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char));
//memcpy(channel_input,c,Kb*Zc*sizeof(unsigned char)); //memcpy(channel_input,c,Kb*Zc*sizeof(unsigned char));
return 0; return 0;
} }
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