From fd5a124c84ed643d94173596c44a9a37e4e27cbb Mon Sep 17 00:00:00 2001 From: laurent Date: Mon, 13 Feb 2023 20:09:13 +0100 Subject: [PATCH] try to make a piece of code a bit more decent, no functional change --- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 319 +++++++----------- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 4 - 2 files changed, 128 insertions(+), 195 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index e88a71c1db..5a0136e4b6 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -1683,34 +1683,27 @@ void nr_dlsch_detection_mrc(uint32_t rx_size_symbol, * Compute the complex addition x=x+y * * */ -void nr_a_sum_b(__m128i *input_x, - __m128i *input_y, - unsigned short nb_rb) +void nr_a_sum_b(c16_t *input_x, c16_t *input_y, unsigned short nb_rb) { unsigned short rb; + __m128i *x = (__m128i *)input_x; + __m128i *y = (__m128i *)input_y; for (rb=0; rb 0, ""); if(size==1) { - nr_element_sign(a44[0],//a - ad_bc,//b + nr_element_sign(a44[0][0], // a + ad_bc, // b nb_rb, sign); } else { int16_t k, rr[size - 1], cc[size - 1]; - sub_matrix = (int32_t **)malloc16_clear((size - 1) * (size - 1) * sizeof(int32_t *)); - for (int rtx = 0; rtx < (size - 1); rtx++) { // row - for (int ctx = 0; ctx < (size - 1); ctx++) { // column - sub_matrix[ctx * (size - 1) + rtx] = (int32_t *)malloc16_clear(12 * nb_rb * sizeof(int32_t)); - } - } + c16_t outtemp[12 * nb_rb] __attribute__((aligned(32))); + c16_t outtemp1[12 * nb_rb] __attribute__((aligned(32))); + c16_t *sub_matrix[size - 1][size - 1]; for (int rtx=0;rtx 0); if(size==1) { - return((double complex)a44_cpx[0]*sign); + return (a44_cpx[0][0] * sign); }else { + double complex sub_matrix[size - 1][size - 1]; + int16_t k, rr[size - 1], cc[size - 1]; outtemp1 = 0; for (int rtx=0;rtx 1); int16_t k,rr[size-1],cc[size-1]; if(flag) {//fixed point SIMD calc. //Allocate the submatrix elements - int32_t **sub_matrix; - sub_matrix = (int32_t **)malloc16_clear( (size-1)*(size-1)*sizeof(int32_t *) ); - for (int rtx=0;rtx<(size-1);rtx++) {//row - for (int ctx=0;ctx<(size-1);ctx++) {//column - sub_matrix[ctx*(size-1)+rtx] = (int32_t *)malloc16_clear( 12*nb_rb*sizeof(int32_t) ); - } - } + c16_t sub_matrix_data[size - 1][size - 1][12 * nb_rb]; + memset(sub_matrix_data, 0, sizeof(sub_matrix_data)); + c16_t *sub_matrix[size - 1][size - 1]; + for (int rtx = 0; rtx < (size - 1); rtx++) + for (int ctx = 0; ctx < (size - 1); ctx++) + sub_matrix[ctx][rtx] = sub_matrix_data[ctx][rtx]; //Compute Matrix determinant - nr_determin(a44,// - ad_bc,//determinant - size,//size + nr_determin(size, + a44, // + ad_bc, // determinant nb_rb, +1, shift0); @@ -1941,39 +1913,36 @@ uint8_t nr_matrix_inverse(int32_t **a44,//Input matrix//conjH_H_elements[0] //fill out the sub matrix corresponds to this element for (int ridx=0;ridx<(size-1);ridx++) for (int cidx=0;cidx<(size-1);cidx++) - sub_matrix[cidx*(size-1)+ridx]= (int32_t *)&a44[cc[cidx]*size+rr[ridx]][0]; + memcpy(sub_matrix[cidx][ridx], a44[cc[cidx]][rr[ridx]], sizeof(sub_matrix_data[cidx][ridx])); - nr_determin(sub_matrix, - inv_H_h_H[rtx*size+ctx],//out transpose - size-1,//size + nr_determin(size - 1, // size + sub_matrix, + inv_H_h_H[rtx][ctx], // out transpose nb_rb, - ((rtx&1)==1?-1:1)*((ctx&1)==1?-1:1), + ((rtx & 1) == 1 ? -1 : 1) * ((ctx & 1) == 1 ? -1 : 1), shift0); - //printf("H_h_H(r%d,c%d)=%d+j%d --> inv_H_h_H(%d,%d) = %d+j%d \n",rtx,ctx,((short *)a44[ctx*size+rtx])[0],((short *)a44[ctx*size+rtx])[1],ctx,rtx,((short *)inv_H_h_H[rtx*size+ctx])[0],((short *)inv_H_h_H[rtx*size+ctx])[1]); } } - _mm_empty(); - _m_empty(); } else {//floating point calc. //Allocate the submatrix elements - double complex sub_matrix_cpx[(size-1)*(size-1)]; + double complex sub_matrix_cpx[size - 1][size - 1]; //Convert the IQ samples (in Q15 format) to float complex - double complex a44_cpx[size*size]; - double complex inv_H_h_H_cpx[size*size]; + double complex a44_cpx[size][size]; + double complex inv_H_h_H_cpx[size][size]; double complex determin_cpx; for (int i=0; i<12*nb_rb; i++) { //Convert Q15 to floating point for (int rtx=0;rtx inv_H_h_H(%d,%d) = %lf+j%lf \n",rtx,ctx,creal(a44_cpx[ctx*size+rtx]),cimag(a44_cpx[ctx*size+rtx]),ctx,rtx,creal(inv_H_h_H_cpx[rtx*size+ctx]),cimag(inv_H_h_H_cpx[rtx*size+ctx])); - if (creal(inv_H_h_H_cpx[rtx*size+ctx])>0) - ((short *) inv_H_h_H[rtx*size+ctx])[i<<1] = (short) ((creal(inv_H_h_H_cpx[rtx*size+ctx])*(1<<(shift0-1)))+0.5);//Convert to Q 18 + if (creal(inv_H_h_H_cpx[rtx][ctx]) > 0) + inv_H_h_H[rtx][ctx][i].r = (short)((creal(inv_H_h_H_cpx[rtx][ctx]) * (1 << (shift0 - 1))) + 0.5); // Convert to Q 18 else - ((short *) inv_H_h_H[rtx*size+ctx])[i<<1] = (short) ((creal(inv_H_h_H_cpx[rtx*size+ctx])*(1<<(shift0-1)))-0.5);// + inv_H_h_H[rtx][ctx][i].r = (short)((creal(inv_H_h_H_cpx[rtx][ctx]) * (1 << (shift0 - 1))) - 0.5); // - if (cimag(inv_H_h_H_cpx[rtx*size+ctx])>0) - ((short *) inv_H_h_H[rtx*size+ctx])[(i<<1)+1] = (short) ((cimag(inv_H_h_H_cpx[rtx*size+ctx])*(1<<(shift0-1)))+0.5);// + if (cimag(inv_H_h_H_cpx[rtx][ctx]) > 0) + inv_H_h_H[rtx][ctx][i].i = (short)((cimag(inv_H_h_H_cpx[rtx][ctx]) * (1 << (shift0 - 1))) + 0.5); // else - ((short *) inv_H_h_H[rtx*size+ctx])[(i<<1)+1] = (short) ((cimag(inv_H_h_H_cpx[rtx*size+ctx])*(1<<(shift0-1)))-0.5);// + inv_H_h_H[rtx][ctx][i].i = (short)((cimag(inv_H_h_H_cpx[rtx][ctx]) * (1 << (shift0 - 1))) - 0.5); // //if (i<4) printf("inv_H_h_H_FP(%d,%d)= %d+j%d \n",ctx,rtx, ((short *) inv_H_h_H[rtx*size+ctx])[i<<1],((short *) inv_H_h_H[rtx*size+ctx])[(i<<1)+1]); } @@ -2090,20 +2059,17 @@ uint8_t nr_zero_forcing_rx(uint32_t rx_size_symbol, int length) { int *ch0r, *ch0c; - int32_t ***conjH_H_elements; uint32_t nb_rb_0 = length/12 + ((length%12)?1:0); - int32_t determ_fin[12*nb_rb_0] __attribute__((aligned(32))); + c16_t determ_fin[12 * nb_rb_0] __attribute__((aligned(32))); ///Allocate H^*H matrix elements and sub elements - conjH_H_elements = (int32_t ***)malloc16_clear(n_rx * sizeof(int32_t **)); - for (int aarx = 0; aarx < n_rx; aarx++) { - conjH_H_elements[aarx] = (int32_t **)malloc16_clear(n_tx * n_tx * sizeof(int32_t *)); - for (int rtx = 0; rtx < n_tx; rtx++) { // row - for (int ctx = 0; ctx < n_tx; ctx++) { // column - conjH_H_elements[aarx][ctx * n_tx + rtx] = (int32_t *)malloc16_clear(12 * nb_rb_0 * sizeof(int32_t)); - } - } - } + c16_t conjH_H_elements_data[n_rx][n_tx][n_tx][12 * nb_rb_0]; + memset(conjH_H_elements_data, 0, sizeof(conjH_H_elements_data)); + c16_t *conjH_H_elements[n_rx][n_tx][n_tx]; + for (int aarx = 0; aarx < n_rx; aarx++) + for (int rtx = 0; rtx < n_tx; rtx++) + for (int ctx = 0; ctx < n_tx; ctx++) + conjH_H_elements[aarx][rtx][ctx] = conjH_H_elements_data[aarx][rtx][ctx]; //Compute H^*H matrix elements and sub elements:(1/2^log2_maxh)*conjH_H_elements for (int rtx=0;rtx