[GITLAB] - A technical upgrade is planned on Thursday the 1st of July at noon on our GITLAB server.

dlsch_demodulation.c 121 KB
Newer Older
1
/*******************************************************************************
ghaddab's avatar
ghaddab committed
2 3
    OpenAirInterface 
    Copyright(c) 1999 - 2014 Eurecom
4

ghaddab's avatar
ghaddab committed
5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


ghaddab's avatar
ghaddab committed
11 12 13 14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

ghaddab's avatar
ghaddab committed
16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is 
   included in this distribution in the file called "COPYING". If not, 
   see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
ghaddab's avatar
ghaddab committed
22 23 24 25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
  
ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

28
*******************************************************************************/
29 30 31 32 33

/*! \file PHY/LTE_TRANSPORT/dlsch_demodulation.c
 * \brief Top-level routines for demodulating the PDSCH physical channel from 36-211, V8.6 2009-03
 * \author R. Knopp, F. Kaltenberger,A. Bhamri, S. Aubert
 * \date 2011
34
 DEBUG * \version 0.1
35 36 37 38 39 40 41 42 43 44
 * \company Eurecom
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,ankit.bhamri@eurecom.fr,sebastien.aubert@eurecom.fr
 * \note
 * \warning
 */

#include "PHY/defs.h"
#include "PHY/extern.h"
#include "defs.h"
#include "extern.h"
45
#include "PHY/sse_intrin.h"
46 47 48 49 50 51 52 53 54 55



#ifndef USER_MODE
#define NOCYGWIN_STATIC static
#else
#define NOCYGWIN_STATIC 
#endif

//#define DEBUG_PHY 1
56

57 58 59
int avg[4];

// [MCS][i_mod (0,1,2) = (2,4,6)]
60 61 62 63
unsigned char offset_mumimo_llr_drange_fix=0;
/*
//original values from sebastion + same hand tuning
unsigned char offset_mumimo_llr_drange[29][3]={{8,8,8},{7,7,7},{7,7,7},{7,7,7},{6,6,6},{6,6,6},{6,6,6},{5,5,5},{4,4,4},{1,2,4}, // QPSK
64 65
{5,5,4},{5,5,5},{5,5,5},{3,3,3},{2,2,2},{2,2,2},{2,2,2}, // 16-QAM
{2,2,1},{3,3,3},{3,3,3},{3,3,1},{2,2,2},{2,2,2},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}; //64-QAM
66
*/
67 68 69 70 71 72 73 74
 /*
 //first optimization try
 unsigned char offset_mumimo_llr_drange[29][3]={{7, 8, 7},{6, 6, 7},{6, 6, 7},{6, 6, 6},{5, 6, 6},{5, 5, 6},{5, 5, 6},{4, 5, 4},{4, 3, 4},{3, 2, 2},{6, 5, 5},{5, 4, 4},{5, 5, 4},{3, 3, 2},{2, 2, 1},{2, 1, 1},{2, 2, 2},{3, 3, 3},{3, 3, 2},{3, 3, 2},{3, 2, 1},{2, 2, 2},{2, 2, 2},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};
 */
 //second optimization try
 /*
   unsigned char offset_mumimo_llr_drange[29][3]={{5, 8, 7},{4, 6, 8},{3, 6, 7},{7, 7, 6},{4, 7, 8},{4, 7, 4},{6, 6, 6},{3, 6, 6},{3, 6, 6},{1, 3, 4},{1, 1, 0},{3, 3, 2},{3, 4, 1},{4, 0, 1},{4, 2, 2},{3, 1, 2},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};  w
 */
75 76
unsigned char offset_mumimo_llr_drange[29][3]={{0, 6, 5},{0, 4, 5},{0, 4, 5},{0, 5, 4},{0, 5, 6},{0, 5, 3},{0, 4, 4},{0, 4, 4},{0, 3, 3},{0, 1, 2},{1, 1, 0},{1, 3, 2},{3, 4, 1},{2, 0, 0},{2, 2, 2},{1, 1, 1},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};

77

78 79
extern void print_shorts(char *s,__m128i *x);

80 81 82 83
int rx_pdsch(PHY_VARS_UE *phy_vars_ue,
             PDSCH_t type,
             unsigned char eNB_id,
             unsigned char eNB_id_i, //if this == phy_vars_ue->n_connected_eNB, we assume MU interference
gauthier's avatar
gauthier committed
84
             uint8_t subframe,
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
             unsigned char symbol,
             unsigned char first_symbol_flag,
             unsigned char dual_stream_flag,
             unsigned char i_mod,
             unsigned char harq_pid) {
  
  LTE_UE_COMMON *lte_ue_common_vars  = &phy_vars_ue->lte_ue_common_vars;
  LTE_UE_PDSCH **lte_ue_pdsch_vars;
  LTE_DL_FRAME_PARMS *frame_parms    = &phy_vars_ue->lte_frame_parms;
  PHY_MEASUREMENTS *phy_measurements = &phy_vars_ue->PHY_measurements;
  LTE_UE_DLSCH_t   **dlsch_ue;

  unsigned char aatx,aarx;    
  unsigned short nb_rb;
  int avgs, rb;  
100
  LTE_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0;
101

102 103 104 105
  switch (type) {
  case SI_PDSCH:
    lte_ue_pdsch_vars = &phy_vars_ue->lte_ue_pdsch_vars_SI[eNB_id];
    dlsch_ue          = &phy_vars_ue->dlsch_ue_SI[eNB_id];
106
    dlsch0_harq       = dlsch_ue[0]->harq_processes[harq_pid];
107 108 109 110
    break;
  case RA_PDSCH:
    lte_ue_pdsch_vars = &phy_vars_ue->lte_ue_pdsch_vars_ra[eNB_id];
    dlsch_ue          = &phy_vars_ue->dlsch_ue_ra[eNB_id];
111
    dlsch0_harq       = dlsch_ue[0]->harq_processes[harq_pid];
112 113 114 115
    break;
  case PDSCH:
    lte_ue_pdsch_vars = &phy_vars_ue->lte_ue_pdsch_vars[eNB_id];
    dlsch_ue          = phy_vars_ue->dlsch_ue[eNB_id];
116 117
    dlsch0_harq       = dlsch_ue[0]->harq_processes[harq_pid];
    dlsch1_harq       = dlsch_ue[1]->harq_processes[harq_pid];
118 119 120 121 122 123 124 125
    break;

  default:
    //msg("[PHY][UE %d][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",phy_vars_ue->frame,subframe,type);
    mac_xface->macphy_exit("");
    return(-1);
    break;
  }
126 127


128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  if (eNB_id > 2) {
    msg("dlsch_demodulation.c: Illegal eNB_id %d\n",eNB_id);
    return(-1);
  }
    
  if (!lte_ue_common_vars) {
    msg("dlsch_demodulation.c: Null lte_ue_common_vars\n");
    return(-1);
  }

  if (!dlsch_ue[0]) {
    msg("dlsch_demodulation.c: Null dlsch_ue pointer\n");
    return(-1);
  }

  if (!lte_ue_pdsch_vars) {
    msg("dlsch_demodulation.c: Null lte_ue_pdsch_vars pointer\n");
    return(-1);
  }
    
  if (!frame_parms) {
    msg("dlsch_demodulation.c: Null lte_frame_parms\n");
    return(-1);
  }
knopp's avatar
 
knopp committed
152
  //  printf("rx_dlsch subframe %d symbol %d: eNB_id %d, eNB_id_i %d, dual_stream_flag %d\n",subframe,symbol,eNB_id,eNB_id_i,dual_stream_flag); 
153 154 155 156 157 158 159 160 161 162 163
  //  symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;

  /*
    if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp)))
    pilots=1;
    else 
    pilots=0;
  */

  if (frame_parms->nb_antennas_tx_eNB>1) {
#ifdef DEBUG_DLSCH_MOD     
164
    LOG_I(PHY,"dlsch: using pmi %x (%p), rb_alloc %x\n",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),dlsch_ue[0],dlsch0_harq->rb_alloc[0]);
165 166 167 168 169
#endif
    nb_rb = dlsch_extract_rbs_dual(lte_ue_common_vars->rxdataF,
				   lte_ue_common_vars->dl_ch_estimates[eNB_id],
				   lte_ue_pdsch_vars[eNB_id]->rxdataF_ext,
				   lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext,
170
				   dlsch0_harq->pmi_alloc,
171
				   lte_ue_pdsch_vars[eNB_id]->pmi_ext,
172
				   dlsch0_harq->rb_alloc,
173 174
				   symbol,
				   subframe,
175
				   phy_vars_ue->high_speed_flag,
176 177 178 179 180 181 182 183
				   frame_parms);

    if (dual_stream_flag==1) {
      if (eNB_id_i<phy_vars_ue->n_connected_eNB)
	nb_rb = dlsch_extract_rbs_dual(lte_ue_common_vars->rxdataF,
				       lte_ue_common_vars->dl_ch_estimates[eNB_id_i],
				       lte_ue_pdsch_vars[eNB_id_i]->rxdataF_ext,
				       lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
184
				       dlsch0_harq->pmi_alloc,
185
				       lte_ue_pdsch_vars[eNB_id_i]->pmi_ext,
186
				       dlsch0_harq->rb_alloc,
187 188
				       symbol,
				       subframe,
189
				       phy_vars_ue->high_speed_flag,
190 191 192 193 194 195
				       frame_parms);
      else 
	nb_rb = dlsch_extract_rbs_dual(lte_ue_common_vars->rxdataF,
				       lte_ue_common_vars->dl_ch_estimates[eNB_id],
				       lte_ue_pdsch_vars[eNB_id_i]->rxdataF_ext,
				       lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
196
				       dlsch0_harq->pmi_alloc,
197
				       lte_ue_pdsch_vars[eNB_id_i]->pmi_ext,
198
				       dlsch0_harq->rb_alloc,
199 200
				       symbol,
				       subframe,
201
				       phy_vars_ue->high_speed_flag,
202 203 204 205 206 207 208 209
				       frame_parms);
    }
  } // if n_tx>1
  else {     
    nb_rb = dlsch_extract_rbs_single(lte_ue_common_vars->rxdataF,
				     lte_ue_common_vars->dl_ch_estimates[eNB_id],
				     lte_ue_pdsch_vars[eNB_id]->rxdataF_ext,
				     lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext,
210
				     dlsch0_harq->pmi_alloc,
211
				     lte_ue_pdsch_vars[eNB_id]->pmi_ext,
212
				     dlsch0_harq->rb_alloc,
213 214
				     symbol,
				     subframe,
215
				     phy_vars_ue->high_speed_flag,
216 217 218 219 220 221 222 223
				     frame_parms);
        
    if (dual_stream_flag==1) {
      if (eNB_id_i<phy_vars_ue->n_connected_eNB)
	nb_rb = dlsch_extract_rbs_single(lte_ue_common_vars->rxdataF,
					 lte_ue_common_vars->dl_ch_estimates[eNB_id_i],
					 lte_ue_pdsch_vars[eNB_id_i]->rxdataF_ext,
					 lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,    
224
					 dlsch0_harq->pmi_alloc,
225
					 lte_ue_pdsch_vars[eNB_id_i]->pmi_ext,
226
					 dlsch0_harq->rb_alloc,
227 228
					 symbol,
					 subframe,
229
					 phy_vars_ue->high_speed_flag,
230 231 232 233 234 235
					 frame_parms);
      else 
	nb_rb = dlsch_extract_rbs_single(lte_ue_common_vars->rxdataF,
					 lte_ue_common_vars->dl_ch_estimates[eNB_id],
					 lte_ue_pdsch_vars[eNB_id_i]->rxdataF_ext,
					 lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,    
236
					 dlsch0_harq->pmi_alloc,
237
					 lte_ue_pdsch_vars[eNB_id_i]->pmi_ext,
238
					 dlsch0_harq->rb_alloc,
239 240
					 symbol,
					 subframe,
241
					 phy_vars_ue->high_speed_flag,
242 243 244 245 246 247 248 249 250
					 frame_parms);
    }
  } //else n_tx>1
  
    //  printf("nb_rb = %d, eNB_id %d\n",nb_rb,eNB_id);
  if (nb_rb==0) {
    msg("dlsch_demodulation.c: nb_rb=0\n");
    return(-1);
  }
knopp's avatar
 
knopp committed
251
  /*
252 253
  // DL power control: Scaling of Channel estimates for PDSCH
  dlsch_scale_channel(lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext,
254 255 256 257
  frame_parms,
  dlsch_ue,
  symbol,
  nb_rb);
knopp's avatar
 
knopp committed
258
  */
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
  if (first_symbol_flag==1) {
    dlsch_channel_level(lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext,
			frame_parms,
			avg,
			symbol,
			nb_rb);
#ifdef DEBUG_PHY
    msg("[DLSCH] avg[0] %d\n",avg[0]);
#endif
      
    // the channel gain should be the effective gain of precoding + channel
    // however lets be more conservative and set maxh = nb_tx*nb_rx*max(h_i)
    // in case of precoding we add an additional factor of two for the precoding gain
    avgs = 0;
    for (aatx=0;aatx<frame_parms->nb_antennas_tx_eNB;aatx++)
      for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++)
	avgs = cmax(avgs,avg[(aatx<<1)+aarx]);
    //	avgs = cmax(avgs,avg[(aarx<<1)+aatx]);
        
    
279
    lte_ue_pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2);
280 281
    // + log2_approx(frame_parms->nb_antennas_tx_eNB-1) //-1 because log2_approx counts the number of bits
    //      + log2_approx(frame_parms->nb_antennas_rx-1);
282

283 284 285
    if ((dlsch0_harq->mimo_mode>=UNIFORM_PRECODING11) &&
	(dlsch0_harq->mimo_mode< DUALSTREAM_UNIFORM_PRECODING1) &&
	(dlsch0_harq->dl_power_off==1)) // we are in TM 6
286 287 288 289 290 291 292 293
      lte_ue_pdsch_vars[eNB_id]->log2_maxh++;

    // this version here applies the factor .5 also to the extra terms. however, it does not work so well as the one above
    /* K = Nb_rx         in TM1 
       Nb_tx*Nb_rx   in TM2,4,5
       Nb_tx^2*Nb_rx in TM6 */
    /*
      K = frame_parms->nb_antennas_rx*frame_parms->nb_antennas_tx_eNB; //that also covers TM1 since Nb_tx=1
294 295 296
      if ((dlsch0_harq->mimo_mode>=UNIFORM_PRECODING11) &&
      (dlsch0_harq->mimo_mode< DUALSTREAM_UNIFORM_PRECODING1) &&
      (dlsch0_harq->dl_power_off==1)) // we are in TM 6
297 298 299 300 301 302 303
      K *= frame_parms->nb_antennas_tx_eNB;

      lte_ue_pdsch_vars[eNB_id]->log2_maxh = (log2_approx(K*avgs)/2);
    */

#ifdef DEBUG_PHY
    msg("[DLSCH] log2_maxh = %d (%d,%d)\n",lte_ue_pdsch_vars[eNB_id]->log2_maxh,avg[0],avgs);
304
    msg("[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
305 306 307 308 309
#endif
  }
  aatx = frame_parms->nb_antennas_tx_eNB;
  aarx = frame_parms->nb_antennas_rx;

310
  if (dlsch0_harq->mimo_mode<LARGE_CDD) {// SISO or ALAMOUTI
311 312 313

    dlsch_channel_compensation(lte_ue_pdsch_vars[eNB_id]->rxdataF_ext,
			       lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext,
314 315 316
			       lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			       lte_ue_pdsch_vars[eNB_id]->dl_ch_magb0,
			       lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
317 318 319 320
			       (aatx>1) ? lte_ue_pdsch_vars[eNB_id]->rho : NULL,
			       frame_parms,
			       symbol,
			       first_symbol_flag,
321
			       get_Qm(dlsch0_harq->mcs),
322 323 324 325 326
			       nb_rb,
			       lte_ue_pdsch_vars[eNB_id]->log2_maxh,
			       phy_measurements); // log2_maxh+I0_shift
#ifdef DEBUG_PHY
    if (symbol==5)
327
      write_output("rxF_comp_d.m","rxF_c_d",&lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
328 329 330 331 332 333 334
#endif
      
    if ((dual_stream_flag==1) && 
	(eNB_id_i<phy_vars_ue->n_connected_eNB)) {
      // get MF output for interfering stream
      dlsch_channel_compensation(lte_ue_pdsch_vars[eNB_id_i]->rxdataF_ext,
				 lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
335 336 337
				 lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0,
				 lte_ue_pdsch_vars[eNB_id_i]->dl_ch_magb0,
				 lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
338 339 340 341 342 343 344 345 346 347
				 (aatx>1) ? lte_ue_pdsch_vars[eNB_id_i]->rho : NULL,
				 frame_parms,
				 symbol,
				 first_symbol_flag,
				 i_mod,
				 nb_rb,
				 lte_ue_pdsch_vars[eNB_id]->log2_maxh,
				 phy_measurements); // log2_maxh+I0_shift
#ifdef DEBUG_PHY
      if (symbol == 5) {
348 349
	write_output("rxF_comp_d.m","rxF_c_d",&lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
	write_output("rxF_comp_i.m","rxF_c_i",&lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);     
350 351 352 353 354 355 356 357 358 359 360 361 362
      }
#endif 
	
      // compute correlation between signal and interference channels
      dlsch_dual_stream_correlation(frame_parms,
				    symbol,
				    nb_rb,
				    lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext,
				    lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
				    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
				    lte_ue_pdsch_vars[eNB_id]->log2_maxh);
    }
  }
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
  else if (dlsch0_harq->mimo_mode == LARGE_CDD) {  // TM3
    //   LOG_I(PHY,"Running PDSCH RX for TM3\n");
    if (frame_parms->nb_antennas_tx_eNB == 2) {
      if (first_symbol_flag==1) {
	// effective channel of desired user is always stronger than interfering eff. channel
	dlsch_channel_level_TM3(lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext, 
				frame_parms, 
				avg, symbol, nb_rb);
	
	//	msg("llr_offset = %d\n",offset_mumimo_llr_drange[dlsch0_harq->mcs][(dlsch1_harq->mcs>>1)-1]);
	avg[0] = log2_approx(avg[0]) - 13 + offset_mumimo_llr_drange[dlsch0_harq->mcs][(get_Qm(dlsch1_harq->mcs)>>1)-1];

	lte_ue_pdsch_vars[eNB_id]->log2_maxh = cmax(avg[0],0);
	//	printf("log2_maxh =%d\n",lte_ue_pdsch_vars[eNB_id]->log2_maxh);
      }    
      dlsch_channel_compensation_TM3(frame_parms, 
				     lte_ue_pdsch_vars[eNB_id],
				     phy_measurements, 
				     eNB_id, 
				     symbol, 
				     get_Qm(dlsch0_harq->mcs), 
knopp's avatar
knopp committed
384 385
				     get_Qm(dlsch1_harq->mcs),
				     dlsch0_harq->round,
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
				     nb_rb, 
				     lte_ue_pdsch_vars[eNB_id]->log2_maxh); 
      // compute correlation between signal and interference channels
      dlsch_dual_stream_correlation(frame_parms,
				    symbol,
				    nb_rb,
				    lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext,
				    NULL,
				    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
				    lte_ue_pdsch_vars[eNB_id]->log2_maxh);
      //printf("TM3 log2_maxh : %d\n",lte_ue_pdsch_vars[eNB_id]->log2_maxh);

    }
    else {

    }
  }
  else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding, TM4 (Single-codeword)/5 (single or 2 user)/6
404 405
    //    printf("Channel compensation for precoding\n");
    //    if ((dual_stream_flag==1) && (eNB_id_i==NUMBER_OF_CONNECTED_eNB_MAX)) {
406
    if ((dual_stream_flag==1) && (eNB_id_i==phy_vars_ue->n_connected_eNB)) {  // TM5 two-user
407 408 409

      // Scale the channel estimates for interfering stream

410
      dlsch_scale_channel(lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
411 412 413
			  frame_parms,
			  dlsch_ue,
			  symbol,
414
			  nb_rb);     
415 416 417 418

      /* compute new log2_maxh for effective channel */
      if (first_symbol_flag==1) {
	// effective channel of desired user is always stronger than interfering eff. channel
419
	dlsch_channel_level_TM56(lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext, frame_parms, lte_ue_pdsch_vars[eNB_id]->pmi_ext,	avg, symbol, nb_rb);
420
	
421 422
	//    msg("llr_offset = %d\n",offset_mumimo_llr_drange[dlsch0_harq->mcs][(i_mod>>1)-1]);
	avg[0] = log2_approx(avg[0]) - 13 + offset_mumimo_llr_drange[dlsch0_harq->mcs][(i_mod>>1)-1];
423 424 425 426 427

	lte_ue_pdsch_vars[eNB_id]->log2_maxh = cmax(avg[0],0);
	//printf("log1_maxh =%d\n",lte_ue_pdsch_vars[eNB_id]->log2_maxh);
      }      

428 429 430 431 432 433 434 435 436 437 438 439 440 441
      dlsch_channel_compensation_TM56(lte_ue_pdsch_vars[eNB_id]->rxdataF_ext, 
				      lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext, 
				      lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0, 
				      lte_ue_pdsch_vars[eNB_id]->dl_ch_magb0, 
				      lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0, 
				      lte_ue_pdsch_vars[eNB_id]->pmi_ext, 
				      frame_parms, 
				      phy_measurements, 
				      eNB_id, 
				      symbol, 
				      get_Qm(dlsch0_harq->mcs), 
				      nb_rb, 
				      lte_ue_pdsch_vars[eNB_id]->log2_maxh, 
				      dlsch0_harq->dl_power_off);
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465

      // if interference source is MU interference, assume opposite precoder was used at eNB

      // calculate opposite PMI
      for (rb=0;rb<nb_rb;rb++) {
	switch(lte_ue_pdsch_vars[eNB_id]->pmi_ext[rb]) {
	case 0:
	  lte_ue_pdsch_vars[eNB_id_i]->pmi_ext[rb]=1;
	  break;
	case 1:
	  lte_ue_pdsch_vars[eNB_id_i]->pmi_ext[rb]=0;
	  break;
	case 2:
	  lte_ue_pdsch_vars[eNB_id_i]->pmi_ext[rb]=3;
	  break;
	case 3:
	  lte_ue_pdsch_vars[eNB_id_i]->pmi_ext[rb]=2;
	  break;
	}
	//	if (rb==0)
	//	  printf("pmi %d, pmi_i %d\n",lte_ue_pdsch_vars[eNB_id]->pmi_ext[rb],lte_ue_pdsch_vars[eNB_id_i]->pmi_ext[rb]);
	
      }

466 467 468 469 470 471 472 473 474 475 476 477 478 479
      dlsch_channel_compensation_TM56(lte_ue_pdsch_vars[eNB_id_i]->rxdataF_ext, 
				      lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, 
				      lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0, 
				      lte_ue_pdsch_vars[eNB_id_i]->dl_ch_magb0, 
				      lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0, 
				      lte_ue_pdsch_vars[eNB_id_i]->pmi_ext, 
				      frame_parms, 
				      phy_measurements, 
				      eNB_id_i, 
				      symbol, 
				      i_mod, 
				      nb_rb, 
				      lte_ue_pdsch_vars[eNB_id]->log2_maxh, 
				      dlsch0_harq->dl_power_off);
480 481 482
        
#ifdef DEBUG_PHY
      if (symbol==5) {
483 484
	write_output("rxF_comp_d.m","rxF_c_d",&lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
	write_output("rxF_comp_i.m","rxF_c_i",&lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);    
485 486 487 488 489 490 491
      }
#endif  

      dlsch_dual_stream_correlation(frame_parms, symbol, nb_rb, lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext, lte_ue_pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext, lte_ue_pdsch_vars[eNB_id]->log2_maxh);

    }
    else {
492
      dlsch_channel_compensation_TM56(lte_ue_pdsch_vars[eNB_id]->rxdataF_ext,
493
				      lte_ue_pdsch_vars[eNB_id]->dl_ch_estimates_ext,
494 495 496
				      lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
				      lte_ue_pdsch_vars[eNB_id]->dl_ch_magb0,
				      lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
497 498 499 500 501
				      lte_ue_pdsch_vars[eNB_id]->pmi_ext,
				      frame_parms,
				      phy_measurements,
				      eNB_id,
				      symbol,
502
				      get_Qm(dlsch0_harq->mcs),
503 504 505 506 507 508 509
				      nb_rb,
				      lte_ue_pdsch_vars[eNB_id]->log2_maxh,
				      1);
    }
  }

  //  printf("MRC\n");
510 511 512 513 514
  if (frame_parms->nb_antennas_rx > 1) {
    if (dlsch0_harq->mimo_mode == LARGE_CDD) {
      if (frame_parms->nb_antennas_tx_eNB == 2) {
	dlsch_detection_mrc(frame_parms,
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
knopp's avatar
knopp committed
515
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp1[dlsch0_harq->round],
516 517 518 519 520 521 522 523 524 525 526 527
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			    lte_ue_pdsch_vars[eNB_id]->rho,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_magb0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_mag1,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_magb1,
			    symbol,
			    nb_rb,
			    dual_stream_flag); 			    
      }
    }
    else {
528
      
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
      dlsch_detection_mrc(frame_parms,
			  lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			  lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			  lte_ue_pdsch_vars[eNB_id]->rho,
			  lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			  lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			  lte_ue_pdsch_vars[eNB_id]->dl_ch_magb0,
			  lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0,
			  lte_ue_pdsch_vars[eNB_id_i]->dl_ch_magb0,
			  symbol,
			  nb_rb,
			  dual_stream_flag); 
    }
  }
  //  printf("Combining");
  if ((dlsch0_harq->mimo_mode == SISO) ||
      ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) &&
       (dlsch0_harq->mimo_mode <= PUSCH_PRECODING0))) {

    /*
      dlsch_siso(frame_parms,
      lte_ue_pdsch_vars[eNB_id]->rxdataF_comp,
      lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp,
      symbol,
      nb_rb);
    */
  } else if (dlsch0_harq->mimo_mode == ALAMOUTI) {

    dlsch_alamouti(frame_parms,
		   lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
		   lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
		   lte_ue_pdsch_vars[eNB_id]->dl_ch_magb0,
		   symbol,
		   nb_rb);
563
          
564
  } 
565
          
566 567 568 569 570 571 572
  else if (dlsch0_harq->mimo_mode == LARGE_CDD) {
	
  }
  else {
    msg("dlsch_rx: Unknown MIMO mode\n");
    return (-1);
  }
573

574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
  //    printf("LLR");

  switch (get_Qm(dlsch0_harq->mcs)) {
  case 2 : 
    if (dlsch0_harq->mimo_mode != LARGE_CDD) { 
      if (dual_stream_flag == 0)
	dlsch_qpsk_llr(frame_parms,
		       lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
		       lte_ue_pdsch_vars[eNB_id]->llr[0],
		       symbol,first_symbol_flag,nb_rb,
		       adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
		       lte_ue_pdsch_vars[eNB_id]->llr128);
      else if (i_mod == 2) {
	dlsch_qpsk_qpsk_llr(frame_parms,
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			    lte_ue_pdsch_vars[eNB_id]->llr[0],
			    symbol,first_symbol_flag,nb_rb,
			    adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			    lte_ue_pdsch_vars[eNB_id]->llr128);
595
      }
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
      else if (i_mod == 4) { 
	dlsch_qpsk_16qam_llr(frame_parms,
			     lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			     lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			     lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0,
			     lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			     lte_ue_pdsch_vars[eNB_id]->llr[0],
			     symbol,first_symbol_flag,nb_rb,
			     adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			     lte_ue_pdsch_vars[eNB_id]->llr128);
      }
      else {
	dlsch_qpsk_64qam_llr(frame_parms,
			     lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			     lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			     lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0,
			     lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			     lte_ue_pdsch_vars[eNB_id]->llr[0],
			     symbol,first_symbol_flag,nb_rb,
			     adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			     lte_ue_pdsch_vars[eNB_id]->llr128);
	    
      }          
    }
    else { // TM3
      if (get_Qm(dlsch1_harq->mcs) == 2) {
	/*	dlsch_qpsk_llr(frame_parms,
		       lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
		       lte_ue_pdsch_vars[eNB_id]->llr[0],
		       symbol,first_symbol_flag,nb_rb,
		       adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
		       lte_ue_pdsch_vars[eNB_id]->llr128);
	*/
	dlsch_qpsk_qpsk_llr(frame_parms,
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
knopp's avatar
knopp committed
631
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp1[dlsch0_harq->round],
632 633 634 635 636 637 638 639 640
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			    lte_ue_pdsch_vars[eNB_id]->llr[0],
			    symbol,first_symbol_flag,nb_rb,
			    adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			    lte_ue_pdsch_vars[eNB_id]->llr128);
      }
      else if (get_Qm(dlsch1_harq->mcs) == 4) { 
	dlsch_qpsk_16qam_llr(frame_parms,
			     lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
knopp's avatar
knopp committed
641
			     lte_ue_pdsch_vars[eNB_id]->rxdataF_comp1[dlsch0_harq->round],
642 643 644 645 646 647 648 649 650 651
			     lte_ue_pdsch_vars[eNB_id]->dl_ch_mag1,
			     lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			     lte_ue_pdsch_vars[eNB_id]->llr[0],
			     symbol,first_symbol_flag,nb_rb,
			     adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			     lte_ue_pdsch_vars[eNB_id]->llr128);
      }
      else {
	dlsch_qpsk_64qam_llr(frame_parms,
			     lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
knopp's avatar
knopp committed
652
			     lte_ue_pdsch_vars[eNB_id]->rxdataF_comp1[dlsch0_harq->round],
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
			     lte_ue_pdsch_vars[eNB_id]->dl_ch_mag1,
			     lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			     lte_ue_pdsch_vars[eNB_id]->llr[0],
			     symbol,first_symbol_flag,nb_rb,
			     adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			     lte_ue_pdsch_vars[eNB_id]->llr128);
	
      }          
    }
    break;
  case 4 :
    if (dual_stream_flag == 0) {
      dlsch_16qam_llr(frame_parms,
		      lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
		      lte_ue_pdsch_vars[eNB_id]->llr[0],
		      lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
		      symbol,first_symbol_flag,nb_rb,
		      adjust_G2(frame_parms,dlsch0_harq->rb_alloc,4,subframe,symbol),
		      lte_ue_pdsch_vars[eNB_id]->llr128);
    }
    else if (i_mod == 2) {
      dlsch_16qam_qpsk_llr(frame_parms,
			   lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			   lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			   lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			   lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			   lte_ue_pdsch_vars[eNB_id]->llr[0],
			   symbol,first_symbol_flag,nb_rb,
			   adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			   lte_ue_pdsch_vars[eNB_id]->llr128);
    } 
    else if (i_mod == 4) {
      dlsch_16qam_16qam_llr(frame_parms,
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			    lte_ue_pdsch_vars[eNB_id]->llr[0],
			    symbol,first_symbol_flag,nb_rb,
			    adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			    lte_ue_pdsch_vars[eNB_id]->llr128);
    } else {
      dlsch_16qam_64qam_llr(frame_parms,
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			    lte_ue_pdsch_vars[eNB_id]->llr[0],
			    symbol,first_symbol_flag,nb_rb,
			    adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			    lte_ue_pdsch_vars[eNB_id]->llr128);
    }
    break;
  case 6 :
    if (dual_stream_flag == 0) {
      dlsch_64qam_llr(frame_parms,
		      lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
		      lte_ue_pdsch_vars[eNB_id]->llr[0],
		      lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
		      lte_ue_pdsch_vars[eNB_id]->dl_ch_magb0,
		      symbol,first_symbol_flag,nb_rb,
		      adjust_G2(frame_parms,dlsch0_harq->rb_alloc,6,subframe,symbol),
		      lte_ue_pdsch_vars[eNB_id]->llr128);
    }
    else if (i_mod == 2) {              
      dlsch_64qam_qpsk_llr(frame_parms,
			   lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			   lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			   lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			   lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			   lte_ue_pdsch_vars[eNB_id]->llr[0],
			   symbol,first_symbol_flag,nb_rb,
			   adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			   lte_ue_pdsch_vars[eNB_id]->llr128);
    }
    else if (i_mod == 4) {
      dlsch_64qam_16qam_llr(frame_parms,
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			    lte_ue_pdsch_vars[eNB_id]->llr[0],
			    symbol,first_symbol_flag,nb_rb,
			    adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			    lte_ue_pdsch_vars[eNB_id]->llr128);
	
    }
    else {	  
      dlsch_64qam_64qam_llr(frame_parms,
			    lte_ue_pdsch_vars[eNB_id]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id_i]->rxdataF_comp0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id_i]->dl_ch_mag0,
			    lte_ue_pdsch_vars[eNB_id]->dl_ch_rho_ext,
			    lte_ue_pdsch_vars[eNB_id]->llr[0],
			    symbol,first_symbol_flag,nb_rb,
			    adjust_G2(frame_parms,dlsch0_harq->rb_alloc,2,subframe,symbol),
			    lte_ue_pdsch_vars[eNB_id]->llr128);
    }
    break;
  default:
    msg("rx_dlsch.c : Unknown mod_order!!!!\n");
758
    return(-1);
759
    break;
760
  }
761

762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
  return(0);    
}

//==============================================================================================
// Pre-processing for LLR computation
//==============================================================================================

void dlsch_channel_compensation(int **rxdataF_ext,
                                int **dl_ch_estimates_ext,
                                int **dl_ch_mag,
                                int **dl_ch_magb,
                                int **rxdataF_comp,
                                int **rho,
                                LTE_DL_FRAME_PARMS *frame_parms,
                                unsigned char symbol,
gauthier's avatar
gauthier committed
777
                                uint8_t first_symbol_flag,
778 779 780 781 782 783 784 785
                                unsigned char mod_order,
                                unsigned short nb_rb,
                                unsigned char output_shift,
                                PHY_MEASUREMENTS *phy_measurements) {

  unsigned short rb;
  unsigned char aatx,aarx,symbol_mod,pilots=0;
  __m128i *dl_ch128,*dl_ch128_2,*dl_ch_mag128,*dl_ch_mag128b,*rxdataF128,*rxdataF_comp128,*rho128;
786
  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b;
787 788 789 790 791 792 793 794 795 796 797 798 799 800

  symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;

  if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) {
      
    if (frame_parms->mode1_flag==1) // 10 out of 12 so don't reduce size    
      nb_rb=1+(5*nb_rb/6);
    else  
      pilots=1;    
  }

  for (aatx=0;aatx<frame_parms->nb_antennas_tx_eNB;aatx++) {
    if (mod_order == 4) {
      QAM_amp128 = _mm_set1_epi16(QAM16_n1);  // 2/sqrt(10)
801
      QAM_amp128b = _mm_setzero_si128();
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
    }    
    else if (mod_order == 6) {
      QAM_amp128  = _mm_set1_epi16(QAM64_n1); // 
      QAM_amp128b = _mm_set1_epi16(QAM64_n2);
    }
    
    //    printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol);

    for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) {

      dl_ch128          = (__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*frame_parms->N_RB_DL*12];
      dl_ch_mag128      = (__m128i *)&dl_ch_mag[(aatx<<1)+aarx][symbol*frame_parms->N_RB_DL*12];
      dl_ch_mag128b     = (__m128i *)&dl_ch_magb[(aatx<<1)+aarx][symbol*frame_parms->N_RB_DL*12];
      rxdataF128        = (__m128i *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
      rxdataF_comp128   = (__m128i *)&rxdataF_comp[(aatx<<1)+aarx][symbol*frame_parms->N_RB_DL*12];


      for (rb=0;rb<nb_rb;rb++) {
	if (mod_order>2) {  
	  // get channel amplitude if not QPSK
                
	  mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]);
	  mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
                
	  mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]);
	  mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
                
	  mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
                
	  // store channel magnitude here in a new field of dlsch
                
	  dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
	  dl_ch_mag128b[0] = dl_ch_mag128[0];
	  dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128);
	  dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0],1);
                
	  dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0);
	  dl_ch_mag128b[1] = dl_ch_mag128[1];
	  dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1],QAM_amp128);
	  dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1],1);
                
	  if (pilots==0) {
	    mmtmpD0 = _mm_madd_epi16(dl_ch128[2],dl_ch128[2]);
	    mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	    mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0);
                    
	    dl_ch_mag128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1);
	    dl_ch_mag128b[2] = dl_ch_mag128[2];
                    
	    dl_ch_mag128[2] = _mm_mulhi_epi16(dl_ch_mag128[2],QAM_amp128);
	    dl_ch_mag128[2] = _mm_slli_epi16(dl_ch_mag128[2],1);	  
	  }
                
	  dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b);
	  dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1);
                
                
	  dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b);
	  dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1);
                
	  if (pilots==0) {
	    dl_ch_mag128b[2] = _mm_mulhi_epi16(dl_ch_mag128b[2],QAM_amp128b);
	    dl_ch_mag128b[2] = _mm_slli_epi16(dl_ch_mag128b[2],1);	  
	  }
	}
	
	// multiply by conjugated channel
	mmtmpD0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]);
	//	print_ints("re",&mmtmpD0);
            
	// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
	mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
	//	print_ints("im",&mmtmpD1);
	mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]);
	// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	//	print_ints("re(shift)",&mmtmpD0);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
	//	print_ints("im(shift)",&mmtmpD1);
	mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
	mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
	//       	print_ints("c0",&mmtmpD2);
	//	print_ints("c1",&mmtmpD3);
	rxdataF_comp128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
	//	print_shorts("rx:",rxdataF128);
	//	print_shorts("ch:",dl_ch128);
	//	print_shorts("pack:",rxdataF_comp128);
            
	// multiply by conjugated channel
	mmtmpD0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]);
	// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
	mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
	mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]);
	// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
	mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
	mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
            
	rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
	//	print_shorts("rx:",rxdataF128+1);
	//	print_shorts("ch:",dl_ch128+1);
	//	print_shorts("pack:",rxdataF_comp128+1);	
            
	if (pilots==0) {
	  // multiply by conjugated channel
	  mmtmpD0 = _mm_madd_epi16(dl_ch128[2],rxdataF128[2]);
	  // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
	  mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1));
	  mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
	  mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
	  mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]);
	  // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
	  mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	  mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
	  mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
	  mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
                
	  rxdataF_comp128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
	  //	print_shorts("rx:",rxdataF128+2);
	  //	print_shorts("ch:",dl_ch128+2);
	  //      	print_shorts("pack:",rxdataF_comp128+2);
                
	  dl_ch128+=3;
	  dl_ch_mag128+=3;
	  dl_ch_mag128b+=3;
	  rxdataF128+=3;
	  rxdataF_comp128+=3;
	}
	else { // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less
	  dl_ch128+=2;
	  dl_ch_mag128+=2;
	  dl_ch_mag128b+=2;
	  rxdataF128+=2;
	  rxdataF_comp128+=2;
	}
            
      }
    }
  }
  
  if (rho) {
      
      
    for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) {
      rho128        = (__m128i *)&rho[aarx][symbol*frame_parms->N_RB_DL*12];
      dl_ch128      = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
      dl_ch128_2    = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
          
      for (rb=0;rb<nb_rb;rb++) {
	// multiply by conjugated channel
	mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128_2[0]);
	//	print_ints("re",&mmtmpD0);
              
	// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
	mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
	//	print_ints("im",&mmtmpD1);
	mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[0]);
	// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	//	print_ints("re(shift)",&mmtmpD0);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
	//	print_ints("im(shift)",&mmtmpD1);
	mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
	mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
	//       	print_ints("c0",&mmtmpD2);
	//	print_ints("c1",&mmtmpD3);
	rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
              
	//print_shorts("rx:",dl_ch128_2);
	//print_shorts("ch:",dl_ch128);
	//print_shorts("pack:",rho128);
              
	// multiply by conjugated channel
	mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128_2[1]);
	// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
	mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
	mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[1]);
	// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
	mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
	mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);

	
	rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3);
	//print_shorts("rx:",dl_ch128_2+1);
	//print_shorts("ch:",dl_ch128+1);
	//print_shorts("pack:",rho128+1);	
	// multiply by conjugated channel
	mmtmpD0 = _mm_madd_epi16(dl_ch128[2],dl_ch128_2[2]);
	// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
	mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
	mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[2]);
	// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
	mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
	mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
              
	rho128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
	//print_shorts("rx:",dl_ch128_2+2);
	//print_shorts("ch:",dl_ch128+2);
	//print_shorts("pack:",rho128+2);
              
	dl_ch128+=3;
	dl_ch128_2+=3;
	rho128+=3;
              
      }	
          
      if (first_symbol_flag==1) {
	phy_measurements->rx_correlation[0][aarx] = signal_energy(&rho[aarx][symbol*frame_parms->N_RB_DL*12],rb*12);
      }           
    }      
  }

  _mm_empty();
  _m_empty();
}     

1033
void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1) {
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
  
  __m128i amp;
  amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);

  switch (pmi) {
        
  case 0 :   // +1 +1
    //    print_shorts("phase 0 :ch0",ch0);
    //    print_shorts("phase 0 :ch1",ch1);
    ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);   
    break;
  case 1 :   // +1 -1
    //    print_shorts("phase 1 :ch0",ch0);
    //    print_shorts("phase 1 :ch1",ch1);
    ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
    //    print_shorts("phase 1 :ch0-ch1",ch0);
    break;
  case 2 :   // +1 +j
    ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]);
    ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
    ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
    ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]);
        
    break;   // +1 -j
  case 3 :
    ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]);
    ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
    ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1));
    ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
    break;
  }

  ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
  ch0[0] = _mm_slli_epi16(ch0[0],1);
    
  _mm_empty();
  _m_empty();
}

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
// precoding is stream 0 .5(1,1)  .5(1,-1) .5(1,1)  .5(1,-1)
//              stream 1 .5(1,-1) .5(1,1)  .5(1,-1) .5(1,1)
// store "precoded" channel for stream 0 in ch0, stream 1 in ch1

short TM3_prec[8]__attribute__((aligned(16))) = {1,1,-1,-1,1,1,-1,-1} ;

void prec2A_TM3_128(__m128i *ch0,__m128i *ch1) {
  
  //  __m128i amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
  
  __m128i tmp0,tmp1;
  

  //  print_shorts("prec2A_TM3 ch0 (before):",ch0);
  //  print_shorts("prec2A_TM3 ch1 (before):",ch1);

  tmp0 = ch0[0];
  tmp1  = _mm_sign_epi16(ch1[0],((__m128i*)&TM3_prec)[0]);
  //  print_shorts("prec2A_TM3 ch1*s (mid):",(__m128i*)TM3_prec);

  ch0[0] = _mm_adds_epi16(ch0[0],tmp1);
  ch1[0] = _mm_subs_epi16(tmp0,tmp1);


  //  print_shorts("prec2A_TM3 ch0 (mid):",&tmp0);
  //  print_shorts("prec2A_TM3 ch1 (mid):",ch1);


  ch0[0] = _mm_srai_epi16(ch0[0],1);
  ch1[0] = _mm_srai_epi16(ch1[0],1);

  //  print_shorts("prec2A_TM3 ch0 (after):",ch0);
  //  print_shorts("prec2A_TM3 ch1 (after):",ch1);
    
  _mm_empty();
  _m_empty();
}

// pmi = 0 => stream 0 (1,1), stream 1 (1,-1)
// pmi = 1 => stream 0 (1,j), stream 2 (1,-j)

void prec2A_TM4_128(int pmi,__m128i *ch0,__m128i *ch1) {
  
  __m128i amp;
  amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
  __m128i tmp1;
  
  if (pmi == 0) {
    ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]);
    ch1[0] = _mm_subs_epi16(ch0[0],ch1[0]);
  }
  else {
    tmp1   = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]);
    tmp1   = _mm_shufflelo_epi16(tmp1,_MM_SHUFFLE(2,3,0,1));
    tmp1   = _mm_shufflehi_epi16(tmp1,_MM_SHUFFLE(2,3,0,1));
    ch0[0] = _mm_subs_epi16(ch0[0],tmp1);
    ch1[0] = _mm_subs_epi16(ch0[0],tmp1);
  }
  ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
  ch0[0] = _mm_slli_epi16(ch0[0],1);
  ch1[0] = _mm_mulhi_epi16(ch1[0],amp);
  ch1[0] = _mm_slli_epi16(ch1[0],1);

}

void dlsch_channel_compensation_TM56(int **rxdataF_ext,
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
                                     int **dl_ch_estimates_ext,
                                     int **dl_ch_mag,
                                     int **dl_ch_magb,
                                     int **rxdataF_comp,
                                     unsigned char *pmi_ext,
                                     LTE_DL_FRAME_PARMS *frame_parms,
                                     PHY_MEASUREMENTS *phy_measurements,
                                     int eNB_id,
                                     unsigned char symbol,
                                     unsigned char mod_order,
                                     unsigned short nb_rb,
                                     unsigned char output_shift,
                                     unsigned char dl_power_off) {
  
  unsigned short rb,Nre;
1154
  __m128i *dl_ch0_128,*dl_ch1_128,*dl_ch_mag128,*dl_ch_mag128b,*rxdataF128,*rxdataF_comp128;
1155 1156
  unsigned char aarx=0,symbol_mod,pilots=0;
  int precoded_signal_strength=0,rx_power_correction;
1157
  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b;
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
    
  symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
    
  if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp)))
    pilots=1;

  rx_power_correction = 1;
    
  //printf("comp prec: symbol %d, pilots %d\n",symbol, pilots);

  if (mod_order == 4) {
    QAM_amp128 = _mm_set1_epi16(QAM16_n1);
1170
    QAM_amp128b = _mm_setzero_si128();
1171 1172 1173 1174 1175 1176 1177 1178
  }
  else if (mod_order == 6) {
    QAM_amp128  = _mm_set1_epi16(QAM64_n1);
    QAM_amp128b = _mm_set1_epi16(QAM64_n2);
  }
    
  for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) {
        
1179 1180
    dl_ch0_128          = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
    dl_ch1_128          = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
        
        
    dl_ch_mag128      = (__m128i *)&dl_ch_mag[aarx][symbol*frame_parms->N_RB_DL*12];
    dl_ch_mag128b     = (__m128i *)&dl_ch_magb[aarx][symbol*frame_parms->N_RB_DL*12];
    rxdataF128        = (__m128i *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
    rxdataF_comp128   = (__m128i *)&rxdataF_comp[aarx][symbol*frame_parms->N_RB_DL*12];
        

    for (rb=0;rb<nb_rb;rb++) {
      // combine TX channels using precoder from pmi
#ifdef DEBUG_DLSCH_DEMOD
      printf("mode 6 prec: rb %d, pmi->%d\n",rb,pmi_ext[rb]);
#endif            
1194 1195
      prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128[0],&dl_ch1_128[0]);
      prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]);
1196 1197

      if (pilots==0) {
1198
	prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]); 
1199 1200 1201 1202 1203
      }

      if (mod_order>2) {  
	// get channel amplitude if not QPSK
	
1204
	mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],dl_ch0_128[0]);	
1205 1206
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
                
1207
	mmtmpD1 = _mm_madd_epi16(dl_ch0_128[1],dl_ch0_128[1]);
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
                
	mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
                
	dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
	dl_ch_mag128b[0] = dl_ch_mag128[0];
	dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128);
	dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0],1);
                
	//print_shorts("dl_ch_mag128[0]=",&dl_ch_mag128[0]);
                
	dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0);
	dl_ch_mag128b[1] = dl_ch_mag128[1];
	dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1],QAM_amp128);
	dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1],1);
                
	if (pilots==0) {
1225
	  mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2],dl_ch0_128[2]);
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
	  mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
                    
	  mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0);
                    
	  dl_ch_mag128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1);
	  dl_ch_mag128b[2] = dl_ch_mag128[2];
                    
	  dl_ch_mag128[2] = _mm_mulhi_epi16(dl_ch_mag128[2],QAM_amp128);
	  dl_ch_mag128[2] = _mm_slli_epi16(dl_ch_mag128[2],1);	  
	}
                
	dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b);
	dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1);
                
	//print_shorts("dl_ch_mag128b[0]=",&dl_ch_mag128b[0]);
                
	dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b);
	dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1);
                
	if (pilots==0) {
	  dl_ch_mag128b[2] = _mm_mulhi_epi16(dl_ch_mag128b[2],QAM_amp128b);
	  dl_ch_mag128b[2] = _mm_slli_epi16(dl_ch_mag128b[2],1);	  
	}
      }

      // MF multiply by conjugated channel
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
      mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],rxdataF128[0]);
      //	print_ints("re",&mmtmpD0);
            
      // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
      mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[0],_MM_SHUFFLE(2,3,0,1));
      mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
      //	print_ints("im",&mmtmpD1);
      mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]);
      // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
      mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
      //	print_ints("re(shift)",&mmtmpD0);
      mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
      //	print_ints("im(shift)",&mmtmpD1);
      mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
      mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
      //       	print_ints("c0",&mmtmpD2);
      //	print_ints("c1",&mmtmpD3);
      rxdataF_comp128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
      //	print_shorts("rx:",rxdataF128);
      //	print_shorts("ch:",dl_ch128);
      //	print_shorts("pack:",rxdataF_comp128);
            
      // multiply by conjugated channel
      mmtmpD0 = _mm_madd_epi16(dl_ch0_128[1],rxdataF128[1]);
      // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
      mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[1],_MM_SHUFFLE(2,3,0,1));
      mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
      mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]);
      // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
      mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
      mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
      mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
      mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
            
      rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
      //	print_shorts("rx:",rxdataF128+1);
      //	print_shorts("ch:",dl_ch128+1);
      //	print_shorts("pack:",rxdataF_comp128+1);	
            
      if (pilots==0) {
	// multiply by conjugated channel
	mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2],rxdataF128[2]);
	// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
	mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[2],_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
	mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]);
	// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
	mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
	mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
                
	rxdataF_comp128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
	//	print_shorts("rx:",rxdataF128+2);
	//	print_shorts("ch:",dl_ch128+2);
	//      	print_shorts("pack:",rxdataF_comp128+2);
                
	dl_ch0_128+=3;
	dl_ch1_128+=3;
	dl_ch_mag128+=3;
	dl_ch_mag128b+=3;
	rxdataF128+=3;
	rxdataF_comp128+=3;
      }
      else {
	dl_ch0_128+=2;
	dl_ch1_128+=2;
	dl_ch_mag128+=2;
	dl_ch_mag128b+=2;
	rxdataF128+=2;
	rxdataF_comp128+=2;
      }
    }
        
    Nre = (pilots==0) ? 12 : 8;
        
    precoded_signal_strength += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre],
						     (nb_rb*Nre))*rx_power_correction) - (phy_measurements->n0_power[aarx]));
  } // rx_antennas
    
  phy_measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength,phy_measurements->n0_power_tot);
	
  //printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol,
  //	 phy_measurements->precoded_cqi_dB[eNB_id][0]);
    
  _mm_empty();
  _m_empty();  
}    

void dlsch_channel_compensation_TM3(LTE_DL_FRAME_PARMS *frame_parms,
				    LTE_UE_PDSCH *lte_ue_pdsch_vars,
				    PHY_MEASUREMENTS *phy_measurements,
				    int eNB_id,
				    unsigned char symbol,
				    unsigned char mod_order0,
				    unsigned char mod_order1,
knopp's avatar
knopp committed
1351
				    int round,
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
				    unsigned short nb_rb,
				    unsigned char output_shift) {
  
  unsigned short rb,Nre;
  __m128i *dl_ch0_128,*dl_ch1_128,*dl_ch_mag0_128,*dl_ch_mag1_128,*dl_ch_mag0_128b,*dl_ch_mag1_128b,*rxdataF128,*rxdataF_comp0_128,*rxdataF_comp1_128;
  unsigned char aarx=0,symbol_mod,pilots=0;
  int precoded_signal_strength0=0,precoded_signal_strength1=0,rx_power_correction;

  int **rxdataF_ext           = lte_ue_pdsch_vars->rxdataF_ext;
  int **dl_ch_estimates_ext   = lte_ue_pdsch_vars->dl_ch_estimates_ext;
  int **dl_ch_mag0            = lte_ue_pdsch_vars->dl_ch_mag0;
  int **dl_ch_mag1            = lte_ue_pdsch_vars->dl_ch_mag1;
  int **dl_ch_magb0           = lte_ue_pdsch_vars->dl_ch_magb0;
  int **dl_ch_magb1           = lte_ue_pdsch_vars->dl_ch_magb1;
  int **rxdataF_comp0         = lte_ue_pdsch_vars->rxdataF_comp0;
knopp's avatar
knopp committed
1367
  int **rxdataF_comp1         = lte_ue_pdsch_vars->rxdataF_comp1[0];
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
  __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp0_128,QAM_amp0_128b,QAM_amp1_128,QAM_amp1_128b;   
    

  symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol;
    
  if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp)))
    pilots=1;

  rx_power_correction = 1;
    
  //printf("comp prec: symbol %d, pilots %d\n",symbol, pilots);

  if (mod_order0 == 4) {
    QAM_amp0_128  = _mm_set1_epi16(QAM16_n1);
1382
    QAM_amp0_128b = _mm_setzero_si128();
1383 1384 1385 1386 1387 1388 1389
  }
  else if (mod_order0 == 6) {
    QAM_amp0_128  = _mm_set1_epi16(QAM64_n1);
    QAM_amp0_128b = _mm_set1_epi16(QAM64_n2);
  }
  if (mod_order1 == 4) {
    QAM_amp1_128  = _mm_set1_epi16(QAM16_n1);
1390
    QAM_amp1_128b = _mm_setzero_si128();
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
  }
  else if (mod_order1 == 6) {
    QAM_amp1_128  = _mm_set1_epi16(QAM64_n1);
    QAM_amp1_128b = _mm_set1_epi16(QAM64_n2);
  }
    
  for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) {
        
    dl_ch0_128          = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12];
    dl_ch1_128          = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12];
        
        
    dl_ch_mag0_128      = (__m128i *)&dl_ch_mag0[aarx][symbol*frame_parms->N_RB_DL*12];
    dl_ch_mag0_128b     = (__m128i *)&dl_ch_magb0[aarx][symbol*frame_parms->N_RB_DL*12];
    dl_ch_mag1_128      = (__m128i *)&dl_ch_mag1[aarx][symbol*frame_parms->N_RB_DL*12];
    dl_ch_mag1_128b     = (__m128i *)&dl_ch_magb1[aarx][symbol*frame_parms->N_RB_DL*12];
    rxdataF128          = (__m128i *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12];
    rxdataF_comp0_128   = (__m128i *)&rxdataF_comp0[aarx][symbol*frame_parms->N_RB_DL*12];
    rxdataF_comp1_128   = (__m128i *)&rxdataF_comp1[aarx][symbol*frame_parms->N_RB_DL*12];
        

    for (rb=0;rb<nb_rb;rb++) {
      // combine TX channels using precoder from pmi

      prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]);
      prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]);

      if (pilots==0) {
	prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]); 
      }

      if (mod_order0>2) {  
	// get channel amplitude if not QPSK
	
	mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],dl_ch0_128[0]);	
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
                
	mmtmpD1 = _mm_madd_epi16(dl_ch0_128[1],dl_ch0_128[1]);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
                
	mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
                
	dl_ch_mag0_128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
	dl_ch_mag0_128b[0] = dl_ch_mag0_128[0];
	dl_ch_mag0_128[0] = _mm_mulhi_epi16(dl_ch_mag0_128[0],QAM_amp0_128);
	dl_ch_mag0_128[0] = _mm_slli_epi16(dl_ch_mag0_128[0],1);
                
	//	print_shorts("dl_ch_mag0_128[0]=",&dl_ch_mag0_128[0]);
                
	dl_ch_mag0_128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0);
	dl_ch_mag0_128b[1] = dl_ch_mag0_128[1];
	dl_ch_mag0_128[1] = _mm_mulhi_epi16(dl_ch_mag0_128[1],QAM_amp0_128);
	dl_ch_mag0_128[1] = _mm_slli_epi16(dl_ch_mag0_128[1],1);
                
	if (pilots==0) {
	  mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2],dl_ch0_128[2]);
	  mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
                    
	  mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0);
                    
	  dl_ch_mag0_128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1);
	  dl_ch_mag0_128b[2] = dl_ch_mag0_128[2];
                    
	  dl_ch_mag0_128[2] = _mm_mulhi_epi16(dl_ch_mag0_128[2],QAM_amp0_128);
	  dl_ch_mag0_128[2] = _mm_slli_epi16(dl_ch_mag0_128[2],1);	  
	}
                
	dl_ch_mag0_128b[0] = _mm_mulhi_epi16(dl_ch_mag0_128b[0],QAM_amp0_128b);
	dl_ch_mag0_128b[0] = _mm_slli_epi16(dl_ch_mag0_128b[0],1);
                
	//print_shorts("dl_ch_mag128b[0]=",&dl_ch_mag128b[0]);
                
	dl_ch_mag0_128b[1] = _mm_mulhi_epi16(dl_ch_mag0_128b[1],QAM_amp0_128b);
	dl_ch_mag0_128b[1] = _mm_slli_epi16(dl_ch_mag0_128b[1],1);
                
	if (pilots==0) {
	  dl_ch_mag0_128b[2] = _mm_mulhi_epi16(dl_ch_mag0_128b[2],QAM_amp0_128b);
	  dl_ch_mag0_128b[2] = _mm_slli_epi16(dl_ch_mag0_128b[2],1);	  
	}
      }

      if (mod_order1>2) {  
	// get channel amplitude if not QPSK
	
	mmtmpD0 = _mm_madd_epi16(dl_ch1_128[0],dl_ch1_128[0]);	
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
                
	mmtmpD1 = _mm_madd_epi16(dl_ch1_128[1],dl_ch1_128[1]);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
                
	mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1);
                
	dl_ch_mag1_128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0);
	dl_ch_mag1_128b[0] = dl_ch_mag1_128[0];
	dl_ch_mag1_128[0] = _mm_mulhi_epi16(dl_ch_mag1_128[0],QAM_amp1_128);
	dl_ch_mag1_128[0] = _mm_slli_epi16(dl_ch_mag1_128[0],1);
                
	//print_shorts("dl_ch_mag128[0]=",&dl_ch_mag128[0]);
                
	dl_ch_mag1_128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0);
	dl_ch_mag1_128b[1] = dl_ch_mag1_128[1];
	dl_ch_mag1_128[1] = _mm_mulhi_epi16(dl_ch_mag1_128[1],QAM_amp1_128);
	dl_ch_mag1_128[1] = _mm_slli_epi16(dl_ch_mag1_128[1],1);
                
	if (pilots==0) {
	  mmtmpD0 = _mm_madd_epi16(dl_ch1_128[2],dl_ch1_128[2]);
	  mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
                    
	  mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0);
                    
	  dl_ch_mag1_128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1);
	  dl_ch_mag1_128b[2] = dl_ch_mag1_128[2];
                    
	  dl_ch_mag1_128[2] = _mm_mulhi_epi16(dl_ch_mag1_128[2],QAM_amp1_128);
	  dl_ch_mag1_128[2] = _mm_slli_epi16(dl_ch_mag1_128[2],1);	  
	}
                
	dl_ch_mag1_128b[0] = _mm_mulhi_epi16(dl_ch_mag1_128b[0],QAM_amp1_128b);
	dl_ch_mag1_128b[0] = _mm_slli_epi16(dl_ch_mag1_128b[0],1);
                
	//print_shorts("dl_ch_mag128b[0]=",&dl_ch_mag128b[0]);
                
	dl_ch_mag1_128b[1] = _mm_mulhi_epi16(dl_ch_mag1_128b[1],QAM_amp1_128b);
	dl_ch_mag1_128b[1] = _mm_slli_epi16(dl_ch_mag1_128b[1],1);
                
	if (pilots==0) {
	  dl_ch_mag1_128b[2] = _mm_mulhi_epi16(dl_ch_mag1_128b[2],QAM_amp1_128b);
	  dl_ch_mag1_128b[2] = _mm_slli_epi16(dl_ch_mag1_128b[2],1);	  
	}
      }

      // layer 0
      // MF multiply by conjugated channel
      mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],rxdataF128[0]);
      //print_ints("re",&mmtmpD0);
            
      // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
      mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[0],_MM_SHUFFLE(2,3,0,1));
      mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]);
      mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]);
      //      print_ints("im",&mmtmpD1);
      // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
      mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
      //      printf("Shift: %d\n",output_shift);
      //      print_ints("re(shift)",&mmtmpD0);
      mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
      //      print_ints("im(shift)",&mmtmpD1);
      mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
      mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
      //      print_ints("c0",&mmtmpD2);
      //      print_ints("c1",&mmtmpD3);
      rxdataF_comp0_128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
      //      print_shorts("rx:",rxdataF128);
      //      print_shorts("ch:",dl_ch0_128);
      //      print_shorts("pack:",rxdataF_comp0_128);
            
      // multiply by conjugated channel
      mmtmpD0 = _mm_madd_epi16(dl_ch0_128[1],rxdataF128[1]);
      // mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
      mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[1],_MM_SHUFFLE(2,3,0,1));
      mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
      mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
      mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]);
      // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
      mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
      mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);
      mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1);
      mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1);
            
      rxdataF_comp0_128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3);
      //	print_shorts("rx:",rxdataF128+1);
      //	print_shorts("ch:",dl_ch128+1);
      //	print_shorts("pack:",rxdataF_comp128+1);	
            
      if (pilots==0) {
	// multiply by conjugated channel
	mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2],rxdataF128[2]);
	// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
	mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[2],_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1));
	mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate);
	mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]);
	// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
	mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift);
	mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift);<