dlsch_llr_computation.c 442 KB
Newer Older
1
/*
2 3 4 5
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21 22

/*! \file PHY/LTE_TRANSPORT/dlsch_llr_computation.c
23
 * \brief Top-level routines for LLR computation of the PDSCH physical channel from 36-211, V8.6 2009-03
24
 * \author R. Knopp, F. Kaltenberger,A. Bhamri, S. Aubert, S. Wagner, X Jiang
25 26 27 28 29 30 31
 * \date 2011
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,ankit.bhamri@eurecom.fr,sebastien.aubert@eurecom.fr, sebastian.wagner@eurecom.fr
 * \note
 * \warning
 */
32

33 34 35 36 37 38
#include "PHY/defs_UE.h"
#include "PHY/TOOLS/tools_defs.h"
#include "PHY/phy_extern_ue.h"
#include "transport_ue.h"
#include "PHY/LTE_TRANSPORT/transport_common_proto.h"
#include "transport_proto_ue.h"
39
#include "PHY/sse_intrin.h"
40

41 42 43
//#define DEBUG_LLR_SIC


oai's avatar
oai committed
44
int16_t zeros[8] __attribute__ ((aligned(16))) = {0,0,0,0,0,0,0,0};
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
int16_t ones[8] __attribute__ ((aligned(16))) = {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};
#if defined(__x86_64__) || defined(__i386__)
__m128i rho_rpi __attribute__ ((aligned(16)));
__m128i rho_rmi __attribute__ ((aligned(16)));
__m128i rho_rpi_1_1 __attribute__ ((aligned(16)));
__m128i rho_rpi_1_3 __attribute__ ((aligned(16)));
__m128i rho_rpi_1_5 __attribute__ ((aligned(16)));
__m128i rho_rpi_1_7 __attribute__ ((aligned(16)));
__m128i rho_rpi_3_1 __attribute__ ((aligned(16)));
__m128i rho_rpi_3_3 __attribute__ ((aligned(16)));
__m128i rho_rpi_3_5 __attribute__ ((aligned(16)));
__m128i rho_rpi_3_7 __attribute__ ((aligned(16)));
__m128i rho_rpi_5_1 __attribute__ ((aligned(16)));
__m128i rho_rpi_5_3 __attribute__ ((aligned(16)));
__m128i rho_rpi_5_5 __attribute__ ((aligned(16)));
__m128i rho_rpi_5_7 __attribute__ ((aligned(16)));
__m128i rho_rpi_7_1 __attribute__ ((aligned(16)));
__m128i rho_rpi_7_3 __attribute__ ((aligned(16)));
__m128i rho_rpi_7_5 __attribute__ ((aligned(16)));
__m128i rho_rpi_7_7 __attribute__ ((aligned(16)));
__m128i rho_rmi_1_1 __attribute__ ((aligned(16)));
__m128i rho_rmi_1_3 __attribute__ ((aligned(16)));
__m128i rho_rmi_1_5 __attribute__ ((aligned(16)));
__m128i rho_rmi_1_7 __attribute__ ((aligned(16)));
__m128i rho_rmi_3_1 __attribute__ ((aligned(16)));
__m128i rho_rmi_3_3 __attribute__ ((aligned(16)));
__m128i rho_rmi_3_5 __attribute__ ((aligned(16)));
__m128i rho_rmi_3_7 __attribute__ ((aligned(16)));
__m128i rho_rmi_5_1 __attribute__ ((aligned(16)));
__m128i rho_rmi_5_3 __attribute__ ((aligned(16)));
__m128i rho_rmi_5_5 __attribute__ ((aligned(16)));
__m128i rho_rmi_5_7 __attribute__ ((aligned(16)));
__m128i rho_rmi_7_1 __attribute__ ((aligned(16)));
__m128i rho_rmi_7_3 __attribute__ ((aligned(16)));
__m128i rho_rmi_7_5 __attribute__ ((aligned(16)));
__m128i rho_rmi_7_7 __attribute__ ((aligned(16)));

__m128i psi_r_m7_m7 __attribute__ ((aligned(16)));
__m128i psi_r_m7_m5 __attribute__ ((aligned(16)));
__m128i psi_r_m7_m3 __attribute__ ((aligned(16)));
__m128i psi_r_m7_m1 __attribute__ ((aligned(16)));
__m128i psi_r_m7_p1 __attribute__ ((aligned(16)));
__m128i psi_r_m7_p3 __attribute__ ((aligned(16)));
__m128i psi_r_m7_p5 __attribute__ ((aligned(16)));
__m128i psi_r_m7_p7 __attribute__ ((aligned(16)));
__m128i psi_r_m5_m7 __attribute__ ((aligned(16)));
__m128i psi_r_m5_m5 __attribute__ ((aligned(16)));
__m128i psi_r_m5_m3 __attribute__ ((aligned(16)));
__m128i psi_r_m5_m1 __attribute__ ((aligned(16)));
__m128i psi_r_m5_p1 __attribute__ ((aligned(16)));
__m128i psi_r_m5_p3 __attribute__ ((aligned(16)));
__m128i psi_r_m5_p5 __attribute__ ((aligned(16)));
__m128i psi_r_m5_p7 __attribute__ ((aligned(16)));
__m128i psi_r_m3_m7 __attribute__ ((aligned(16)));
__m128i psi_r_m3_m5 __attribute__ ((aligned(16)));
__m128i psi_r_m3_m3 __attribute__ ((aligned(16)));
__m128i psi_r_m3_m1 __attribute__ ((aligned(16)));
__m128i psi_r_m3_p1 __attribute__ ((aligned(16)));
__m128i psi_r_m3_p3 __attribute__ ((aligned(16)));
__m128i psi_r_m3_p5 __attribute__ ((aligned(16)));
__m128i psi_r_m3_p7 __attribute__ ((aligned(16)));
__m128i psi_r_m1_m7 __attribute__ ((aligned(16)));
__m128i psi_r_m1_m5 __attribute__ ((aligned(16)));
__m128i psi_r_m1_m3 __attribute__ ((aligned(16)));
__m128i psi_r_m1_m1 __attribute__ ((aligned(16)));
__m128i psi_r_m1_p1 __attribute__ ((aligned(16)));
__m128i psi_r_m1_p3 __attribute__ ((aligned(16)));
__m128i psi_r_m1_p5 __attribute__ ((aligned(16)));
__m128i psi_r_m1_p7 __attribute__ ((aligned(16)));
__m128i psi_r_p1_m7 __attribute__ ((aligned(16)));
__m128i psi_r_p1_m5 __attribute__ ((aligned(16)));
__m128i psi_r_p1_m3 __attribute__ ((aligned(16)));
__m128i psi_r_p1_m1 __attribute__ ((aligned(16)));
__m128i psi_r_p1_p1 __attribute__ ((aligned(16)));
__m128i psi_r_p1_p3 __attribute__ ((aligned(16)));
__m128i psi_r_p1_p5 __attribute__ ((aligned(16)));
__m128i psi_r_p1_p7 __attribute__ ((aligned(16)));
__m128i psi_r_p3_m7 __attribute__ ((aligned(16)));
__m128i psi_r_p3_m5 __attribute__ ((aligned(16)));
__m128i psi_r_p3_m3 __attribute__ ((aligned(16)));
__m128i psi_r_p3_m1 __attribute__ ((aligned(16)));
__m128i psi_r_p3_p1 __attribute__ ((aligned(16)));
__m128i psi_r_p3_p3 __attribute__ ((aligned(16)));
__m128i psi_r_p3_p5 __attribute__ ((aligned(16)));
__m128i psi_r_p3_p7 __attribute__ ((aligned(16)));
__m128i psi_r_p5_m7 __attribute__ ((aligned(16)));
__m128i psi_r_p5_m5 __attribute__ ((aligned(16)));
__m128i psi_r_p5_m3 __attribute__ ((aligned(16)));
__m128i psi_r_p5_m1 __attribute__ ((aligned(16)));
__m128i psi_r_p5_p1 __attribute__ ((aligned(16)));
__m128i psi_r_p5_p3 __attribute__ ((aligned(16)));
__m128i psi_r_p5_p5 __attribute__ ((aligned(16)));
__m128i psi_r_p5_p7 __attribute__ ((aligned(16)));
__m128i psi_r_p7_m7 __attribute__ ((aligned(16)));
__m128i psi_r_p7_m5 __attribute__ ((aligned(16)));
__m128i psi_r_p7_m3 __attribute__ ((aligned(16)));
__m128i psi_r_p7_m1 __attribute__ ((aligned(16)));
__m128i psi_r_p7_p1 __attribute__ ((aligned(16)));
__m128i psi_r_p7_p3 __attribute__ ((aligned(16)));
__m128i psi_r_p7_p5 __attribute__ ((aligned(16)));
__m128i psi_r_p7_p7 __attribute__ ((aligned(16)));

__m128i psi_i_m7_m7 __attribute__ ((aligned(16)));
__m128i psi_i_m7_m5 __attribute__ ((aligned(16)));
__m128i psi_i_m7_m3 __attribute__ ((aligned(16)));
__m128i psi_i_m7_m1 __attribute__ ((aligned(16)));
__m128i psi_i_m7_p1 __attribute__ ((aligned(16)));
__m128i psi_i_m7_p3 __attribute__ ((aligned(16)));
__m128i psi_i_m7_p5 __attribute__ ((aligned(16)));
__m128i psi_i_m7_p7 __attribute__ ((aligned(16)));
__m128i psi_i_m5_m7 __attribute__ ((aligned(16)));
__m128i psi_i_m5_m5 __attribute__ ((aligned(16)));
__m128i psi_i_m5_m3 __attribute__ ((aligned(16)));
__m128i psi_i_m5_m1 __attribute__ ((aligned(16)));
__m128i psi_i_m5_p1 __attribute__ ((aligned(16)));
__m128i psi_i_m5_p3 __attribute__ ((aligned(16)));
__m128i psi_i_m5_p5 __attribute__ ((aligned(16)));
__m128i psi_i_m5_p7 __attribute__ ((aligned(16)));
__m128i psi_i_m3_m7 __attribute__ ((aligned(16)));
__m128i psi_i_m3_m5 __attribute__ ((aligned(16)));
__m128i psi_i_m3_m3 __attribute__ ((aligned(16)));
__m128i psi_i_m3_m1 __attribute__ ((aligned(16)));
__m128i psi_i_m3_p1 __attribute__ ((aligned(16)));
__m128i psi_i_m3_p3 __attribute__ ((aligned(16)));
__m128i psi_i_m3_p5 __attribute__ ((aligned(16)));
__m128i psi_i_m3_p7 __attribute__ ((aligned(16)));
__m128i psi_i_m1_m7 __attribute__ ((aligned(16)));
__m128i psi_i_m1_m5 __attribute__ ((aligned(16)));
__m128i psi_i_m1_m3 __attribute__ ((aligned(16)));
__m128i psi_i_m1_m1 __attribute__ ((aligned(16)));
__m128i psi_i_m1_p1 __attribute__ ((aligned(16)));
__m128i psi_i_m1_p3 __attribute__ ((aligned(16)));
__m128i psi_i_m1_p5 __attribute__ ((aligned(16)));
__m128i psi_i_m1_p7 __attribute__ ((aligned(16)));
__m128i psi_i_p1_m7 __attribute__ ((aligned(16)));
__m128i psi_i_p1_m5 __attribute__ ((aligned(16)));
__m128i psi_i_p1_m3 __attribute__ ((aligned(16)));
__m128i psi_i_p1_m1 __attribute__ ((aligned(16)));
__m128i psi_i_p1_p1 __attribute__ ((aligned(16)));
__m128i psi_i_p1_p3 __attribute__ ((aligned(16)));
__m128i psi_i_p1_p5 __attribute__ ((aligned(16)));
__m128i psi_i_p1_p7 __attribute__ ((aligned(16)));
__m128i psi_i_p3_m7 __attribute__ ((aligned(16)));
__m128i psi_i_p3_m5 __attribute__ ((aligned(16)));
__m128i psi_i_p3_m3 __attribute__ ((aligned(16)));
__m128i psi_i_p3_m1 __attribute__ ((aligned(16)));
__m128i psi_i_p3_p1 __attribute__ ((aligned(16)));
__m128i psi_i_p3_p3 __attribute__ ((aligned(16)));
__m128i psi_i_p3_p5 __attribute__ ((aligned(16)));
__m128i psi_i_p3_p7 __attribute__ ((aligned(16)));
__m128i psi_i_p5_m7 __attribute__ ((aligned(16)));
__m128i psi_i_p5_m5 __attribute__ ((aligned(16)));
__m128i psi_i_p5_m3 __attribute__ ((aligned(16)));
__m128i psi_i_p5_m1 __attribute__ ((aligned(16)));
__m128i psi_i_p5_p1 __attribute__ ((aligned(16)));
__m128i psi_i_p5_p3 __attribute__ ((aligned(16)));
__m128i psi_i_p5_p5 __attribute__ ((aligned(16)));
__m128i psi_i_p5_p7 __attribute__ ((aligned(16)));
__m128i psi_i_p7_m7 __attribute__ ((aligned(16)));
__m128i psi_i_p7_m5 __attribute__ ((aligned(16)));
__m128i psi_i_p7_m3 __attribute__ ((aligned(16)));
__m128i psi_i_p7_m1 __attribute__ ((aligned(16)));
__m128i psi_i_p7_p1 __attribute__ ((aligned(16)));
__m128i psi_i_p7_p3 __attribute__ ((aligned(16)));
__m128i psi_i_p7_p5 __attribute__ ((aligned(16)));
__m128i psi_i_p7_p7 __attribute__ ((aligned(16)));

__m128i a_r_m7_m7 __attribute__ ((aligned(16)));
__m128i a_r_m7_m5 __attribute__ ((aligned(16)));
__m128i a_r_m7_m3 __attribute__ ((aligned(16)));
__m128i a_r_m7_m1 __attribute__ ((aligned(16)));
__m128i a_r_m7_p1 __attribute__ ((aligned(16)));
__m128i a_r_m7_p3 __attribute__ ((aligned(16)));
__m128i a_r_m7_p5 __attribute__ ((aligned(16)));
__m128i a_r_m7_p7 __attribute__ ((aligned(16)));
__m128i a_r_m5_m7 __attribute__ ((aligned(16)));
__m128i a_r_m5_m5 __attribute__ ((aligned(16)));
__m128i a_r_m5_m3 __attribute__ ((aligned(16)));
__m128i a_r_m5_m1 __attribute__ ((aligned(16)));
__m128i a_r_m5_p1 __attribute__ ((aligned(16)));
__m128i a_r_m5_p3 __attribute__ ((aligned(16)));
__m128i a_r_m5_p5 __attribute__ ((aligned(16)));
__m128i a_r_m5_p7 __attribute__ ((aligned(16)));
__m128i a_r_m3_m7 __attribute__ ((aligned(16)));
__m128i a_r_m3_m5 __attribute__ ((aligned(16)));
__m128i a_r_m3_m3 __attribute__ ((aligned(16)));
__m128i a_r_m3_m1 __attribute__ ((aligned(16)));
__m128i a_r_m3_p1 __attribute__ ((aligned(16)));
__m128i a_r_m3_p3 __attribute__ ((aligned(16)));
__m128i a_r_m3_p5 __attribute__ ((aligned(16)));
__m128i a_r_m3_p7 __attribute__ ((aligned(16)));
__m128i a_r_m1_m7 __attribute__ ((aligned(16)));
__m128i a_r_m1_m5 __attribute__ ((aligned(16)));
__m128i a_r_m1_m3 __attribute__ ((aligned(16)));
__m128i a_r_m1_m1 __attribute__ ((aligned(16)));
__m128i a_r_m1_p1 __attribute__ ((aligned(16)));
__m128i a_r_m1_p3 __attribute__ ((aligned(16)));
__m128i a_r_m1_p5 __attribute__ ((aligned(16)));
__m128i a_r_m1_p7 __attribute__ ((aligned(16)));
__m128i a_r_p1_m7 __attribute__ ((aligned(16)));
__m128i a_r_p1_m5 __attribute__ ((aligned(16)));
__m128i a_r_p1_m3 __attribute__ ((aligned(16)));
__m128i a_r_p1_m1 __attribute__ ((aligned(16)));
__m128i a_r_p1_p1 __attribute__ ((aligned(16)));
__m128i a_r_p1_p3 __attribute__ ((aligned(16)));
__m128i a_r_p1_p5 __attribute__ ((aligned(16)));
__m128i a_r_p1_p7 __attribute__ ((aligned(16)));
__m128i a_r_p3_m7 __attribute__ ((aligned(16)));
__m128i a_r_p3_m5 __attribute__ ((aligned(16)));
__m128i a_r_p3_m3 __attribute__ ((aligned(16)));
__m128i a_r_p3_m1 __attribute__ ((aligned(16)));
__m128i a_r_p3_p1 __attribute__ ((aligned(16)));
__m128i a_r_p3_p3 __attribute__ ((aligned(16)));
__m128i a_r_p3_p5 __attribute__ ((aligned(16)));
__m128i a_r_p3_p7 __attribute__ ((aligned(16)));
__m128i a_r_p5_m7 __attribute__ ((aligned(16)));
__m128i a_r_p5_m5 __attribute__ ((aligned(16)));
__m128i a_r_p5_m3 __attribute__ ((aligned(16)));
__m128i a_r_p5_m1 __attribute__ ((aligned(16)));
__m128i a_r_p5_p1 __attribute__ ((aligned(16)));
__m128i a_r_p5_p3 __attribute__ ((aligned(16)));
__m128i a_r_p5_p5 __attribute__ ((aligned(16)));
__m128i a_r_p5_p7 __attribute__ ((aligned(16)));
__m128i a_r_p7_m7 __attribute__ ((aligned(16)));
__m128i a_r_p7_m5 __attribute__ ((aligned(16)));
__m128i a_r_p7_m3 __attribute__ ((aligned(16)));
__m128i a_r_p7_m1 __attribute__ ((aligned(16)));
__m128i a_r_p7_p1 __attribute__ ((aligned(16)));
__m128i a_r_p7_p3 __attribute__ ((aligned(16)));
__m128i a_r_p7_p5 __attribute__ ((aligned(16)));
__m128i a_r_p7_p7 __attribute__ ((aligned(16)));

__m128i a_i_m7_m7 __attribute__ ((aligned(16)));
__m128i a_i_m7_m5 __attribute__ ((aligned(16)));
__m128i a_i_m7_m3 __attribute__ ((aligned(16)));
__m128i a_i_m7_m1 __attribute__ ((aligned(16)));
__m128i a_i_m7_p1 __attribute__ ((aligned(16)));
__m128i a_i_m7_p3 __attribute__ ((aligned(16)));
__m128i a_i_m7_p5 __attribute__ ((aligned(16)));
__m128i a_i_m7_p7 __attribute__ ((aligned(16)));
__m128i a_i_m5_m7 __attribute__ ((aligned(16)));
__m128i a_i_m5_m5 __attribute__ ((aligned(16)));
__m128i a_i_m5_m3 __attribute__ ((aligned(16)));
__m128i a_i_m5_m1 __attribute__ ((aligned(16)));
__m128i a_i_m5_p1 __attribute__ ((aligned(16)));
__m128i a_i_m5_p3 __attribute__ ((aligned(16)));
__m128i a_i_m5_p5 __attribute__ ((aligned(16)));
__m128i a_i_m5_p7 __attribute__ ((aligned(16)));
__m128i a_i_m3_m7 __attribute__ ((aligned(16)));
__m128i a_i_m3_m5 __attribute__ ((aligned(16)));
__m128i a_i_m3_m3 __attribute__ ((aligned(16)));
__m128i a_i_m3_m1 __attribute__ ((aligned(16)));
__m128i a_i_m3_p1 __attribute__ ((aligned(16)));
__m128i a_i_m3_p3 __attribute__ ((aligned(16)));
__m128i a_i_m3_p5 __attribute__ ((aligned(16)));
__m128i a_i_m3_p7 __attribute__ ((aligned(16)));
__m128i a_i_m1_m7 __attribute__ ((aligned(16)));
__m128i a_i_m1_m5 __attribute__ ((aligned(16)));
__m128i a_i_m1_m3 __attribute__ ((aligned(16)));
__m128i a_i_m1_m1 __attribute__ ((aligned(16)));
__m128i a_i_m1_p1 __attribute__ ((aligned(16)));
__m128i a_i_m1_p3 __attribute__ ((aligned(16)));
__m128i a_i_m1_p5 __attribute__ ((aligned(16)));
__m128i a_i_m1_p7 __attribute__ ((aligned(16)));
__m128i a_i_p1_m7 __attribute__ ((aligned(16)));
__m128i a_i_p1_m5 __attribute__ ((aligned(16)));
__m128i a_i_p1_m3 __attribute__ ((aligned(16)));
__m128i a_i_p1_m1 __attribute__ ((aligned(16)));
__m128i a_i_p1_p1 __attribute__ ((aligned(16)));
__m128i a_i_p1_p3 __attribute__ ((aligned(16)));
__m128i a_i_p1_p5 __attribute__ ((aligned(16)));
__m128i a_i_p1_p7 __attribute__ ((aligned(16)));
__m128i a_i_p3_m7 __attribute__ ((aligned(16)));
__m128i a_i_p3_m5 __attribute__ ((aligned(16)));
__m128i a_i_p3_m3 __attribute__ ((aligned(16)));
__m128i a_i_p3_m1 __attribute__ ((aligned(16)));
__m128i a_i_p3_p1 __attribute__ ((aligned(16)));
__m128i a_i_p3_p3 __attribute__ ((aligned(16)));
__m128i a_i_p3_p5 __attribute__ ((aligned(16)));
__m128i a_i_p3_p7 __attribute__ ((aligned(16)));
__m128i a_i_p5_m7 __attribute__ ((aligned(16)));
__m128i a_i_p5_m5 __attribute__ ((aligned(16)));
__m128i a_i_p5_m3 __attribute__ ((aligned(16)));
__m128i a_i_p5_m1 __attribute__ ((aligned(16)));
__m128i a_i_p5_p1 __attribute__ ((aligned(16)));
__m128i a_i_p5_p3 __attribute__ ((aligned(16)));
__m128i a_i_p5_p5 __attribute__ ((aligned(16)));
__m128i a_i_p5_p7 __attribute__ ((aligned(16)));
__m128i a_i_p7_m7 __attribute__ ((aligned(16)));
__m128i a_i_p7_m5 __attribute__ ((aligned(16)));
__m128i a_i_p7_m3 __attribute__ ((aligned(16)));
__m128i a_i_p7_m1 __attribute__ ((aligned(16)));
__m128i a_i_p7_p1 __attribute__ ((aligned(16)));
__m128i a_i_p7_p3 __attribute__ ((aligned(16)));
__m128i a_i_p7_p5 __attribute__ ((aligned(16)));
__m128i a_i_p7_p7 __attribute__ ((aligned(16)));

__m128i psi_a_m7_m7 __attribute__ ((aligned(16)));
__m128i psi_a_m7_m5 __attribute__ ((aligned(16)));
__m128i psi_a_m7_m3 __attribute__ ((aligned(16)));
__m128i psi_a_m7_m1 __attribute__ ((aligned(16)));
__m128i psi_a_m7_p1 __attribute__ ((aligned(16)));
__m128i psi_a_m7_p3 __attribute__ ((aligned(16)));
__m128i psi_a_m7_p5 __attribute__ ((aligned(16)));
__m128i psi_a_m7_p7 __attribute__ ((aligned(16)));
__m128i psi_a_m5_m7 __attribute__ ((aligned(16)));
__m128i psi_a_m5_m5 __attribute__ ((aligned(16)));
__m128i psi_a_m5_m3 __attribute__ ((aligned(16)));
__m128i psi_a_m5_m1 __attribute__ ((aligned(16)));
__m128i psi_a_m5_p1 __attribute__ ((aligned(16)));
__m128i psi_a_m5_p3 __attribute__ ((aligned(16)));
__m128i psi_a_m5_p5 __attribute__ ((aligned(16)));
__m128i psi_a_m5_p7 __attribute__ ((aligned(16)));
__m128i psi_a_m3_m7 __attribute__ ((aligned(16)));
__m128i psi_a_m3_m5 __attribute__ ((aligned(16)));
__m128i psi_a_m3_m3 __attribute__ ((aligned(16)));
__m128i psi_a_m3_m1 __attribute__ ((aligned(16)));
__m128i psi_a_m3_p1 __attribute__ ((aligned(16)));
__m128i psi_a_m3_p3 __attribute__ ((aligned(16)));
__m128i psi_a_m3_p5 __attribute__ ((aligned(16)));
__m128i psi_a_m3_p7 __attribute__ ((aligned(16)));
__m128i psi_a_m1_m7 __attribute__ ((aligned(16)));
__m128i psi_a_m1_m5 __attribute__ ((aligned(16)));
__m128i psi_a_m1_m3 __attribute__ ((aligned(16)));
__m128i psi_a_m1_m1 __attribute__ ((aligned(16)));
__m128i psi_a_m1_p1 __attribute__ ((aligned(16)));
__m128i psi_a_m1_p3 __attribute__ ((aligned(16)));
__m128i psi_a_m1_p5 __attribute__ ((aligned(16)));
__m128i psi_a_m1_p7 __attribute__ ((aligned(16)));
__m128i psi_a_p1_m7 __attribute__ ((aligned(16)));
__m128i psi_a_p1_m5 __attribute__ ((aligned(16)));
__m128i psi_a_p1_m3 __attribute__ ((aligned(16)));
__m128i psi_a_p1_m1 __attribute__ ((aligned(16)));
__m128i psi_a_p1_p1 __attribute__ ((aligned(16)));
__m128i psi_a_p1_p3 __attribute__ ((aligned(16)));
__m128i psi_a_p1_p5 __attribute__ ((aligned(16)));
__m128i psi_a_p1_p7 __attribute__ ((aligned(16)));
__m128i psi_a_p3_m7 __attribute__ ((aligned(16)));
__m128i psi_a_p3_m5 __attribute__ ((aligned(16)));
__m128i psi_a_p3_m3 __attribute__ ((aligned(16)));
__m128i psi_a_p3_m1 __attribute__ ((aligned(16)));
__m128i psi_a_p3_p1 __attribute__ ((aligned(16)));
__m128i psi_a_p3_p3 __attribute__ ((aligned(16)));
__m128i psi_a_p3_p5 __attribute__ ((aligned(16)));
__m128i psi_a_p3_p7 __attribute__ ((aligned(16)));
__m128i psi_a_p5_m7 __attribute__ ((aligned(16)));
__m128i psi_a_p5_m5 __attribute__ ((aligned(16)));
__m128i psi_a_p5_m3 __attribute__ ((aligned(16)));
__m128i psi_a_p5_m1 __attribute__ ((aligned(16)));
__m128i psi_a_p5_p1 __attribute__ ((aligned(16)));
__m128i psi_a_p5_p3 __attribute__ ((aligned(16)));
__m128i psi_a_p5_p5 __attribute__ ((aligned(16)));
__m128i psi_a_p5_p7 __attribute__ ((aligned(16)));
__m128i psi_a_p7_m7 __attribute__ ((aligned(16)));
__m128i psi_a_p7_m5 __attribute__ ((aligned(16)));
__m128i psi_a_p7_m3 __attribute__ ((aligned(16)));
__m128i psi_a_p7_m1 __attribute__ ((aligned(16)));
__m128i psi_a_p7_p1 __attribute__ ((aligned(16)));
__m128i psi_a_p7_p3 __attribute__ ((aligned(16)));
__m128i psi_a_p7_p5 __attribute__ ((aligned(16)));
__m128i psi_a_p7_p7 __attribute__ ((aligned(16)));

__m128i a_sq_m7_m7 __attribute__ ((aligned(16)));
__m128i a_sq_m7_m5 __attribute__ ((aligned(16)));
__m128i a_sq_m7_m3 __attribute__ ((aligned(16)));
__m128i a_sq_m7_m1 __attribute__ ((aligned(16)));
__m128i a_sq_m7_p1 __attribute__ ((aligned(16)));
__m128i a_sq_m7_p3 __attribute__ ((aligned(16)));
__m128i a_sq_m7_p5 __attribute__ ((aligned(16)));
__m128i a_sq_m7_p7 __attribute__ ((aligned(16)));
__m128i a_sq_m5_m7 __attribute__ ((aligned(16)));
__m128i a_sq_m5_m5 __attribute__ ((aligned(16)));
__m128i a_sq_m5_m3 __attribute__ ((aligned(16)));
__m128i a_sq_m5_m1 __attribute__ ((aligned(16)));
__m128i a_sq_m5_p1 __attribute__ ((aligned(16)));
__m128i a_sq_m5_p3 __attribute__ ((aligned(16)));
__m128i a_sq_m5_p5 __attribute__ ((aligned(16)));
__m128i a_sq_m5_p7 __attribute__ ((aligned(16)));
__m128i a_sq_m3_m7 __attribute__ ((aligned(16)));
__m128i a_sq_m3_m5 __attribute__ ((aligned(16)));
__m128i a_sq_m3_m3 __attribute__ ((aligned(16)));
__m128i a_sq_m3_m1 __attribute__ ((aligned(16)));
__m128i a_sq_m3_p1 __attribute__ ((aligned(16)));
__m128i a_sq_m3_p3 __attribute__ ((aligned(16)));
__m128i a_sq_m3_p5 __attribute__ ((aligned(16)));
__m128i a_sq_m3_p7 __attribute__ ((aligned(16)));
__m128i a_sq_m1_m7 __attribute__ ((aligned(16)));
__m128i a_sq_m1_m5 __attribute__ ((aligned(16)));
__m128i a_sq_m1_m3 __attribute__ ((aligned(16)));
__m128i a_sq_m1_m1 __attribute__ ((aligned(16)));
__m128i a_sq_m1_p1 __attribute__ ((aligned(16)));
__m128i a_sq_m1_p3 __attribute__ ((aligned(16)));
__m128i a_sq_m1_p5 __attribute__ ((aligned(16)));
__m128i a_sq_m1_p7 __attribute__ ((aligned(16)));
__m128i a_sq_p1_m7 __attribute__ ((aligned(16)));
__m128i a_sq_p1_m5 __attribute__ ((aligned(16)));
__m128i a_sq_p1_m3 __attribute__ ((aligned(16)));
__m128i a_sq_p1_m1 __attribute__ ((aligned(16)));
__m128i a_sq_p1_p1 __attribute__ ((aligned(16)));
__m128i a_sq_p1_p3 __attribute__ ((aligned(16)));
__m128i a_sq_p1_p5 __attribute__ ((aligned(16)));
__m128i a_sq_p1_p7 __attribute__ ((aligned(16)));
__m128i a_sq_p3_m7 __attribute__ ((aligned(16)));
__m128i a_sq_p3_m5 __attribute__ ((aligned(16)));
__m128i a_sq_p3_m3 __attribute__ ((aligned(16)));
__m128i a_sq_p3_m1 __attribute__ ((aligned(16)));
__m128i a_sq_p3_p1 __attribute__ ((aligned(16)));
__m128i a_sq_p3_p3 __attribute__ ((aligned(16)));
__m128i a_sq_p3_p5 __attribute__ ((aligned(16)));
__m128i a_sq_p3_p7 __attribute__ ((aligned(16)));
__m128i a_sq_p5_m7 __attribute__ ((aligned(16)));
__m128i a_sq_p5_m5 __attribute__ ((aligned(16)));
__m128i a_sq_p5_m3 __attribute__ ((aligned(16)));
__m128i a_sq_p5_m1 __attribute__ ((aligned(16)));
__m128i a_sq_p5_p1 __attribute__ ((aligned(16)));
__m128i a_sq_p5_p3 __attribute__ ((aligned(16)));
__m128i a_sq_p5_p5 __attribute__ ((aligned(16)));
__m128i a_sq_p5_p7 __attribute__ ((aligned(16)));
__m128i a_sq_p7_m7 __attribute__ ((aligned(16)));
__m128i a_sq_p7_m5 __attribute__ ((aligned(16)));
__m128i a_sq_p7_m3 __attribute__ ((aligned(16)));
__m128i a_sq_p7_m1 __attribute__ ((aligned(16)));
__m128i a_sq_p7_p1 __attribute__ ((aligned(16)));
__m128i a_sq_p7_p3 __attribute__ ((aligned(16)));
__m128i a_sq_p7_p5 __attribute__ ((aligned(16)));
__m128i a_sq_p7_p7 __attribute__ ((aligned(16)));

__m128i bit_met_m7_m7 __attribute__ ((aligned(16)));
__m128i bit_met_m7_m5 __attribute__ ((aligned(16)));
__m128i bit_met_m7_m3 __attribute__ ((aligned(16)));
__m128i bit_met_m7_m1 __attribute__ ((aligned(16)));
__m128i bit_met_m7_p1 __attribute__ ((aligned(16)));
__m128i bit_met_m7_p3 __attribute__ ((aligned(16)));
__m128i bit_met_m7_p5 __attribute__ ((aligned(16)));
__m128i bit_met_m7_p7 __attribute__ ((aligned(16)));
__m128i bit_met_m5_m7 __attribute__ ((aligned(16)));
__m128i bit_met_m5_m5 __attribute__ ((aligned(16)));
__m128i bit_met_m5_m3 __attribute__ ((aligned(16)));
__m128i bit_met_m5_m1 __attribute__ ((aligned(16)));
__m128i bit_met_m5_p1 __attribute__ ((aligned(16)));
__m128i bit_met_m5_p3 __attribute__ ((aligned(16)));
__m128i bit_met_m5_p5 __attribute__ ((aligned(16)));
__m128i bit_met_m5_p7 __attribute__ ((aligned(16)));
__m128i bit_met_m3_m7 __attribute__ ((aligned(16)));
__m128i bit_met_m3_m5 __attribute__ ((aligned(16)));
__m128i bit_met_m3_m3 __attribute__ ((aligned(16)));
__m128i bit_met_m3_m1 __attribute__ ((aligned(16)));
__m128i bit_met_m3_p1 __attribute__ ((aligned(16)));
__m128i bit_met_m3_p3 __attribute__ ((aligned(16)));
__m128i bit_met_m3_p5 __attribute__ ((aligned(16)));
__m128i bit_met_m3_p7 __attribute__ ((aligned(16)));
__m128i bit_met_m1_m7 __attribute__ ((aligned(16)));
__m128i bit_met_m1_m5 __attribute__ ((aligned(16)));
__m128i bit_met_m1_m3 __attribute__ ((aligned(16)));
__m128i bit_met_m1_m1 __attribute__ ((aligned(16)));
__m128i bit_met_m1_p1 __attribute__ ((aligned(16)));
__m128i bit_met_m1_p3 __attribute__ ((aligned(16)));
__m128i bit_met_m1_p5 __attribute__ ((aligned(16)));
__m128i bit_met_m1_p7 __attribute__ ((aligned(16)));
__m128i bit_met_p1_m7 __attribute__ ((aligned(16)));
__m128i bit_met_p1_m5 __attribute__ ((aligned(16)));
__m128i bit_met_p1_m3 __attribute__ ((aligned(16)));
__m128i bit_met_p1_m1 __attribute__ ((aligned(16)));
__m128i bit_met_p1_p1 __attribute__ ((aligned(16)));
__m128i bit_met_p1_p3 __attribute__ ((aligned(16)));
__m128i bit_met_p1_p5 __attribute__ ((aligned(16)));
__m128i bit_met_p1_p7 __attribute__ ((aligned(16)));
__m128i bit_met_p3_m7 __attribute__ ((aligned(16)));
__m128i bit_met_p3_m5 __attribute__ ((aligned(16)));
__m128i bit_met_p3_m3 __attribute__ ((aligned(16)));
__m128i bit_met_p3_m1 __attribute__ ((aligned(16)));
__m128i bit_met_p3_p1 __attribute__ ((aligned(16)));
__m128i bit_met_p3_p3 __attribute__ ((aligned(16)));
__m128i bit_met_p3_p5 __attribute__ ((aligned(16)));
__m128i bit_met_p3_p7 __attribute__ ((aligned(16)));
__m128i bit_met_p5_m7 __attribute__ ((aligned(16)));
__m128i bit_met_p5_m5 __attribute__ ((aligned(16)));
__m128i bit_met_p5_m3 __attribute__ ((aligned(16)));
__m128i bit_met_p5_m1 __attribute__ ((aligned(16)));
__m128i bit_met_p5_p1 __attribute__ ((aligned(16)));
__m128i bit_met_p5_p3 __attribute__ ((aligned(16)));
__m128i bit_met_p5_p5 __attribute__ ((aligned(16)));
__m128i bit_met_p5_p7 __attribute__ ((aligned(16)));
__m128i bit_met_p7_m7 __attribute__ ((aligned(16)));
__m128i bit_met_p7_m5 __attribute__ ((aligned(16)));
__m128i bit_met_p7_m3 __attribute__ ((aligned(16)));
__m128i bit_met_p7_m1 __attribute__ ((aligned(16)));
__m128i bit_met_p7_p1 __attribute__ ((aligned(16)));
__m128i bit_met_p7_p3 __attribute__ ((aligned(16)));
__m128i bit_met_p7_p5 __attribute__ ((aligned(16)));
__m128i bit_met_p7_p7 __attribute__ ((aligned(16)));

__m128i  y0_p_1_1 __attribute__ ((aligned(16)));
__m128i  y0_p_1_3 __attribute__ ((aligned(16)));
__m128i  y0_p_1_5 __attribute__ ((aligned(16)));
__m128i  y0_p_1_7 __attribute__ ((aligned(16)));
__m128i  y0_p_3_1 __attribute__ ((aligned(16)));
__m128i  y0_p_3_3 __attribute__ ((aligned(16)));
__m128i  y0_p_3_5 __attribute__ ((aligned(16)));
__m128i  y0_p_3_7 __attribute__ ((aligned(16)));
__m128i  y0_p_5_1 __attribute__ ((aligned(16)));
__m128i  y0_p_5_3 __attribute__ ((aligned(16)));
__m128i  y0_p_5_5 __attribute__ ((aligned(16)));
__m128i  y0_p_5_7 __attribute__ ((aligned(16)));
__m128i  y0_p_7_1 __attribute__ ((aligned(16)));
__m128i  y0_p_7_3 __attribute__ ((aligned(16)));
__m128i  y0_p_7_5 __attribute__ ((aligned(16)));
__m128i  y0_p_7_7 __attribute__ ((aligned(16)));
__m128i  y0_m_1_1 __attribute__ ((aligned(16)));
__m128i  y0_m_1_3 __attribute__ ((aligned(16)));
__m128i  y0_m_1_5 __attribute__ ((aligned(16)));
__m128i  y0_m_1_7 __attribute__ ((aligned(16)));
__m128i  y0_m_3_1 __attribute__ ((aligned(16)));
__m128i  y0_m_3_3 __attribute__ ((aligned(16)));
__m128i  y0_m_3_5 __attribute__ ((aligned(16)));
__m128i  y0_m_3_7 __attribute__ ((aligned(16)));
__m128i  y0_m_5_1 __attribute__ ((aligned(16)));
__m128i  y0_m_5_3 __attribute__ ((aligned(16)));
__m128i  y0_m_5_5 __attribute__ ((aligned(16)));
__m128i  y0_m_5_7 __attribute__ ((aligned(16)));
__m128i  y0_m_7_1 __attribute__ ((aligned(16)));
__m128i  y0_m_7_3 __attribute__ ((aligned(16)));
__m128i  y0_m_7_5 __attribute__ ((aligned(16)));
__m128i  y0_m_7_7 __attribute__ ((aligned(16)));

__m128i  xmm0 __attribute__ ((aligned(16)));
__m128i  xmm1 __attribute__ ((aligned(16)));
__m128i  xmm2 __attribute__ ((aligned(16)));
__m128i  xmm3 __attribute__ ((aligned(16)));
__m128i  xmm4 __attribute__ ((aligned(16)));
__m128i  xmm5 __attribute__ ((aligned(16)));
__m128i  xmm6 __attribute__ ((aligned(16)));
__m128i  xmm7 __attribute__ ((aligned(16)));
__m128i  xmm8 __attribute__ ((aligned(16)));

__m128i  y0r __attribute__ ((aligned(16)));
__m128i  y0i __attribute__ ((aligned(16)));
__m128i  y1r __attribute__ ((aligned(16)));
__m128i  y1i __attribute__ ((aligned(16)));
__m128i  y2r __attribute__ ((aligned(16)));
__m128i  y2i __attribute__ ((aligned(16)));

__m128i  logmax_num_re0 __attribute__ ((aligned(16)));
__m128i  logmax_num_im0 __attribute__ ((aligned(16)));
__m128i  logmax_den_re0 __attribute__ ((aligned(16)));
__m128i  logmax_den_im0 __attribute__ ((aligned(16)));
__m128i  logmax_num_re1 __attribute__ ((aligned(16)));
__m128i  logmax_num_im1 __attribute__ ((aligned(16)));
__m128i  logmax_den_re1 __attribute__ ((aligned(16)));
__m128i  logmax_den_im1 __attribute__ ((aligned(16)));

__m128i tmp_result  __attribute__ ((aligned(16)));
__m128i tmp_result2 __attribute__ ((aligned(16)));
__m128i tmp_result3 __attribute__ ((aligned(16)));
__m128i tmp_result4 __attribute__ ((aligned(16)));
600 601 602 603 604


//==============================================================================================
// Auxiliary Makros

605
// calculates psi_a = psi_r*a_r + psi_i*a_i
606 607 608
#define prodsum_psi_a_epi16(psi_r,a_r,psi_i,a_i,psi_a) tmp_result = _mm_mulhi_epi16(psi_r,a_r); tmp_result = _mm_slli_epi16(tmp_result,1); tmp_result2 = _mm_mulhi_epi16(psi_i,a_i); tmp_result2 = _mm_slli_epi16(tmp_result2,1); psi_a = _mm_adds_epi16(tmp_result,tmp_result2);

// calculate interference magnitude
609
#define interference_abs_epi16(psi,int_ch_mag,int_mag,c1,c2) tmp_result = _mm_cmplt_epi16(psi,int_ch_mag); tmp_result2 = _mm_xor_si128(tmp_result,(*(__m128i*)&ones[0])); tmp_result = _mm_and_si128(tmp_result,c1); tmp_result2 = _mm_and_si128(tmp_result2,c2); int_mag = _mm_or_si128(tmp_result,tmp_result2);
610 611

// calculate interference magnitude
612 613
// tmp_result = ones in shorts corr. to interval 2<=x<=4, tmp_result2 interval < 2, tmp_result3 interval 4<x<6 and tmp_result4 interval x>6
#define interference_abs_64qam_epi16(psi,int_ch_mag,int_two_ch_mag,int_three_ch_mag,a,c1,c3,c5,c7) tmp_result = _mm_cmplt_epi16(psi,int_two_ch_mag); tmp_result3 = _mm_xor_si128(tmp_result,(*(__m128i*)&ones[0])); tmp_result2 = _mm_cmplt_epi16(psi,int_ch_mag); tmp_result = _mm_xor_si128(tmp_result,tmp_result2); tmp_result4 = _mm_cmpgt_epi16(psi,int_three_ch_mag); tmp_result3 = _mm_xor_si128(tmp_result3,tmp_result4); tmp_result = _mm_and_si128(tmp_result,c3); tmp_result2 = _mm_and_si128(tmp_result2,c1); tmp_result3 = _mm_and_si128(tmp_result3,c5); tmp_result4 = _mm_and_si128(tmp_result4,c7); tmp_result = _mm_or_si128(tmp_result,tmp_result2); tmp_result3 = _mm_or_si128(tmp_result3,tmp_result4); a = _mm_or_si128(tmp_result,tmp_result3);
614

615
// calculates a_sq = int_ch_mag*(a_r^2 + a_i^2)*scale_factor
616 617 618 619 620
#define square_a_epi16(a_r,a_i,int_ch_mag,scale_factor,a_sq) tmp_result = _mm_mulhi_epi16(a_r,a_r); tmp_result = _mm_slli_epi16(tmp_result,1); tmp_result = _mm_mulhi_epi16(tmp_result,scale_factor); tmp_result = _mm_slli_epi16(tmp_result,1); tmp_result = _mm_mulhi_epi16(tmp_result,int_ch_mag); tmp_result = _mm_slli_epi16(tmp_result,1); tmp_result2 = _mm_mulhi_epi16(a_i,a_i); tmp_result2 = _mm_slli_epi16(tmp_result2,1); tmp_result2 = _mm_mulhi_epi16(tmp_result2,scale_factor); tmp_result2 = _mm_slli_epi16(tmp_result2,1); tmp_result2 = _mm_mulhi_epi16(tmp_result2,int_ch_mag); tmp_result2 = _mm_slli_epi16(tmp_result2,1); a_sq = _mm_adds_epi16(tmp_result,tmp_result2);

// calculates a_sq = int_ch_mag*(a_r^2 + a_i^2)*scale_factor for 64-QAM
#define square_a_64qam_epi16(a_r,a_i,int_ch_mag,scale_factor,a_sq)  tmp_result = _mm_mulhi_epi16(a_r,a_r); tmp_result = _mm_slli_epi16(tmp_result,1); tmp_result = _mm_mulhi_epi16(tmp_result,scale_factor); tmp_result = _mm_slli_epi16(tmp_result,3); tmp_result = _mm_mulhi_epi16(tmp_result,int_ch_mag); tmp_result = _mm_slli_epi16(tmp_result,1); tmp_result2 = _mm_mulhi_epi16(a_i,a_i); tmp_result2 = _mm_slli_epi16(tmp_result2,1); tmp_result2 = _mm_mulhi_epi16(tmp_result2,scale_factor); tmp_result2 = _mm_slli_epi16(tmp_result2,3); tmp_result2 = _mm_mulhi_epi16(tmp_result2,int_ch_mag); tmp_result2 = _mm_slli_epi16(tmp_result2,1); a_sq = _mm_adds_epi16(tmp_result,tmp_result2);

621 622 623 624
#elif defined(__arm__)

#endif

625 626 627 628 629 630 631 632 633
//==============================================================================================
// SINGLE-STREAM
//==============================================================================================

//----------------------------------------------------------------------------------------------
// QPSK
//----------------------------------------------------------------------------------------------

int dlsch_qpsk_llr(LTE_DL_FRAME_PARMS *frame_parms,
634 635 636
                   int32_t **rxdataF_comp,
                   int16_t *dlsch_llr,
                   uint8_t symbol,
637 638 639
                   uint8_t first_symbol_flag,
                   uint16_t nb_rb,
                   uint16_t pbch_pss_sss_adjust,
640
                   uint8_t beamforming_mode)
641
{
642

643
  uint32_t *rxF = (uint32_t*)&rxdataF_comp[0][((int32_t)symbol*frame_parms->N_RB_DL*12)];
644
  uint32_t *llr32;
645
  int len;
646
  uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol;
647

648
  /*
649
  if (first_symbol_flag==1) {
650 651 652
    llr32 = (uint32_t*)dlsch_llr;
  } else {
    llr32 = (uint32_t*)(*llr32p);
653
  }*/
654

655
  llr32 = (uint32_t*)dlsch_llr;
656
  if (!llr32) {
657
    LOG_E(PHY,"dlsch_qpsk_llr: llr is null, symbol %d, llr32=%p\n",symbol, llr32);
658 659
    return(-1);
  }
660 661 662


  if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) {
663
    if (frame_parms->nb_antenna_ports_eNB!=1)
664
      len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3);
665
    else
666
      len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6);
667
  } else if((beamforming_mode==7) && (frame_parms->Ncp==0) && (symbol==3 || symbol==6 || symbol==9 || symbol==12)){
668
      len = (nb_rb*9) - (3*pbch_pss_sss_adjust/4);
669
  } else if((beamforming_mode==7) && (frame_parms->Ncp==1) && (symbol==4 || symbol==7 || symbol==10)){
670 671 672
      len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3);
  } else {
    len = (nb_rb*12) - pbch_pss_sss_adjust;
673
  }
674

675

676 677
  /*
  LOG_I(PHY,"dlsch_qpsk_llr: [symb %d / FirstSym %d / Length %d]: @LLR Buff %x, @LLR Buff(symb) %x \n",
678 679 680 681
             symbol,
             first_symbol_flag,
             len,
             dlsch_llr,
682 683
             llr32);
  */
684

685 686 687
  qpsk_llr((short *)rxF,
           (short *)llr32,
           len);
688 689 690 691

  return(0);
}

692 693 694 695 696 697 698 699 700 701 702 703 704 705
void qpsk_llr(int16_t *stream0_in,
              int16_t *stream0_out,
              int length)
{
  int i;
  for (i=0; i<2*length; i++) {
    *stream0_out = *stream0_in;
    //printf("llr %d : (%d,%d)\n",i,((int16_t*)stream0_out)[0],((int16_t*)stream0_out)[1]);
    stream0_in++;
    stream0_out++;
  }

}

706
int32_t dlsch_qpsk_llr_SIC(LTE_DL_FRAME_PARMS *frame_parms,
707
                           int32_t **rxdataF_comp,
Elena Lukashova's avatar
Elena Lukashova committed
708 709
                           int32_t **sic_buffer,  //Q15
                           int32_t **rho_i,
710
                           short *dlsch_llr,
Elena Lukashova's avatar
Elena Lukashova committed
711
                           uint8_t num_pdcch_symbols,
712
                           uint16_t nb_rb,
Elena Lukashova's avatar
Elena Lukashova committed
713
                           uint8_t subframe,
714
                           uint16_t mod_order_0,
715
                           uint32_t rb_alloc)
716 717 718 719 720 721 722 723 724 725
{

  int16_t rho_amp_x0[2*frame_parms->N_RB_DL*12];
  int16_t rho_rho_amp_x0[2*frame_parms->N_RB_DL*12];
  uint16_t amp_tmp;
  uint16_t *llr16=(uint16_t*)dlsch_llr;
  int i, len,  nsymb;
  uint8_t symbol, symbol_mod;
  int len_acc=0;
  uint16_t *sic_data;
726
  uint16_t pbch_pss_sss_adjust;
727 728 729 730

  nsymb = (frame_parms->Ncp==0) ? 14:12;

  for (symbol=num_pdcch_symbols; symbol<nsymb; symbol++) {
731 732
    uint16_t *rxF = (uint16_t*)(&rxdataF_comp[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
    int16_t *rho_1=(int16_t*)(&rho_i[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
733
    sic_data = (uint16_t*)&sic_buffer[0][((int16_t)len_acc)];
734 735 736

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

737

738

739

740 741 742 743
    if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) //pilots=1
      amp_tmp=0x1fff;//dlsch0->sqrt_rho_b; already taken into account
    else //pilots=0
      amp_tmp=0x1fff;//1.5*dlsch0->sqrt_rho_a; already taken into account
744

745
    if (mod_order_0==6)
Elena Lukashova's avatar
Elena Lukashova committed
746
      amp_tmp=amp_tmp<<1; // to compensate for >> 1 shift in modulation
747 748


749
    pbch_pss_sss_adjust=adjust_G2(frame_parms,&rb_alloc,2,subframe,symbol);
750 751

    if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) {
752
      if (frame_parms->nb_antenna_ports_eNB!=1)
753 754 755 756 757 758
        len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3);
      else
        len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6);
    } else {
      len = (nb_rb*12) - pbch_pss_sss_adjust;
    }
759

760
   //  printf("dlsch_qpsk_llr: symbol %d,nb_rb %d, len %d,pbch_pss_sss_adjust %d\n",symbol,nb_rb,len,pbch_pss_sss_adjust);
761 762

    len_acc+=len; //accumulated length; this is done because in sic_buffer we have only data symbols
763

764
    multadd_complex_vector_real_scalar((int16_t *)sic_data,
Elena Lukashova's avatar
Elena Lukashova committed
765 766 767 768
                                       amp_tmp,
                                       (int16_t *)rho_amp_x0, //this is in Q13
                                       1,
                                       len);
769

770 771
    mult_cpx_vector((int16_t *)rho_1, //Q15
                    (int16_t *)rho_amp_x0, //Q13
772 773
                    (int16_t*)rho_rho_amp_x0,
                    len,
774
                    13);
775 776

#ifdef DEBUG_LLR_SIC
Mongazon's avatar
Mongazon committed
777
    LOG_M("rho_for_multipl.m","rho_for_m", rho_1,len,1,
Elena Lukashova's avatar
Elena Lukashova committed
778
     symbol==num_pdcch_symbols ? 15 :
779
     symbol==nsymb-1 ? 14 : 13);
780

Mongazon's avatar
Mongazon committed
781
    LOG_M("rho_rho_in_llr.m","rho2", rho_rho_amp_x0,len,1,
Elena Lukashova's avatar
Elena Lukashova committed
782 783
     symbol==num_pdcch_symbols ? 15 :
     symbol==nsymb-1 ? 14 : 13);
784
#endif
785

786
    sub_cpx_vector16((int16_t *)rxF,
Elena Lukashova's avatar
Elena Lukashova committed
787 788 789
                     (int16_t *)rho_rho_amp_x0,
                     //(int16_t *)clean_x1,
                     (int16_t *)rxF,
790
                     len*2);
791

792
#ifdef DEBUG_LLR_SIC
Mongazon's avatar
Mongazon committed
793 794
    LOG_M("rxFdata_comp1_after.m","rxF_a", rxF,len,1,1);
    LOG_M("rxF_comp1.m","rxF_1_comp", rxF,len,1,
795 796 797
                 symbol==num_pdcch_symbols ? 15 :
                 symbol==nsymb-1 ? 14 : 13);
#endif
798

799 800
    //this is for QPSK only!!!
    for (i=0; i<len*2; i++) {
801
      *llr16 =rxF[i];
802 803 804
      //printf("llr %d : (%d,%d)\n",i,((int16_t*)llr32)[0],((int16_t*)llr32)[1]);
      llr16++;
    }
805

806 807
  }

808
 // printf("dlsch_qpsk_llr_SIC: acc_len=%d\n",len_acc);
809 810 811 812 813

  return(0);
}


814 815 816 817 818
//----------------------------------------------------------------------------------------------
// 16-QAM
//----------------------------------------------------------------------------------------------

void dlsch_16qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
819 820 821 822
                     int32_t **rxdataF_comp,
                     int16_t *dlsch_llr,
                     int32_t **dl_ch_mag,
                     uint8_t symbol,
823
                     uint8_t first_symbol_flag,
824
                     uint16_t nb_rb,
825
                     uint16_t pbch_pss_sss_adjust,
826 827
                     int16_t **llr32p,
                     uint8_t beamforming_mode)
828
{
829 830 831
  int32_t *rxF = (int32_t*)&rxdataF_comp[0][(symbol*frame_parms->N_RB_DL*12)];
  int32_t *ch_mag = (int32_t*)&dl_ch_mag[0][(symbol*frame_parms->N_RB_DL*12)];
  int32_t *llr32;
832

833
  int len;
834 835 836
  unsigned char symbol_mod,len_mod4=0;

  if (first_symbol_flag==1) {
837
    llr32 = (int32_t*)dlsch_llr;
838
  } else {
839
    llr32 = (int32_t*)*llr32p;
840
  }
841 842 843 844

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

  if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) {
845
    if (frame_parms->nb_antenna_ports_eNB!=1)
846
      len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3);
847
    else
848 849 850 851 852
      len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6);
  } else if((beamforming_mode==7) && (frame_parms->Ncp==0) && (symbol==3 || symbol==6 || symbol==9 || symbol==12)){
      len = (nb_rb*9) - (3*pbch_pss_sss_adjust/4);
  } else if((beamforming_mode==7) && (frame_parms->Ncp==1) && (symbol==4 || symbol==7 || symbol==10)){
      len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3);
853
  } else {
854
    len = (nb_rb*12) - pbch_pss_sss_adjust;
855 856 857 858 859 860 861 862
  }

  // update output pointer according to number of REs in this symbol (<<2 because 4 bits per RE)
  if (first_symbol_flag == 1)
    *llr32p = dlsch_llr + (len<<2);
  else
    *llr32p += (len<<2);

863
 // printf("len=%d\n", len);
864
  len_mod4 = len&3;
865
 // printf("len_mod4=%d\n", len_mod4);
866
  len>>=2;  // length in quad words (4 REs)
867
 // printf("len>>=2=%d\n", len);
868 869
  len+=(len_mod4==0 ? 0 : 1);

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
  qam16_llr((short *)rxF,
            (short *)ch_mag,
            (short *)llr32,
            len);
 // printf ("This line in qam16_llr is %d.\n", __LINE__);

}

void qam16_llr(int16_t *stream0_in,
               int16_t *chan_magn,
               int16_t *llr,
               int length)
{
  int i;
  #if defined(__x86_64__) || defined(__i386__)
  __m128i *rxF_128 = (__m128i*)stream0_in;
  __m128i *ch_mag_128 = (__m128i*)chan_magn;
  __m128i llr128[2];
  int32_t *llr32 = (int32_t*) llr;
#elif defined(__arm__)
  int16x8_t *rxF_128 = (int16x8_t*)stream0_in;
  int16x8_t *ch_mag_128 = (int16x8_t*)chan_magn;
  int16x8_t xmm0;
  int16_t *llr16 = (int16_t*)llr;
#endif

 // printf ("This line in qam16_llr is %d.\n", __LINE__);

  for (i=0; i<length; i++) {
899
#if defined(__x86_64__) || defined(__i386)
900 901
   xmm0 = _mm_abs_epi16(rxF_128[i]);
   xmm0 = _mm_subs_epi16(ch_mag_128[i],xmm0);
902 903

    // lambda_1=y_R, lambda_2=|y_R|-|h|^2, lamda_3=y_I, lambda_4=|y_I|-|h|^2
904 905
    llr128[0] = _mm_unpacklo_epi32(rxF_128[i],xmm0);
    llr128[1] = _mm_unpackhi_epi32(rxF_128[i],xmm0);
906
    llr32[0] = _mm_extract_epi32(llr128[0],0); //((uint32_t *)&llr128[0])[0];
907
    llr32[1] = _mm_extract_epi32(llr128[0],1); //((uint32_t *)&llr128[0])[0];
908 909 910 911 912 913 914
    llr32[2] = _mm_extract_epi32(llr128[0],2); //((uint32_t *)&llr128[0])[2];
    llr32[3] = _mm_extract_epi32(llr128[0],3); //((uint32_t *)&llr128[0])[3];
    llr32[4] = _mm_extract_epi32(llr128[1],0); //((uint32_t *)&llr128[1])[0];
    llr32[5] = _mm_extract_epi32(llr128[1],1); //((uint32_t *)&llr128[1])[1];
    llr32[6] = _mm_extract_epi32(llr128[1],2); //((uint32_t *)&llr128[1])[2];
    llr32[7] = _mm_extract_epi32(llr128[1],3); //((uint32_t *)&llr128[1])[3];
    llr32+=8;
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
#elif defined(__arm__)
    xmm0 = vabsq_s16(rxF[i]);
    xmm0 = vqsubq_s16(ch_mag[i],xmm0);
    // lambda_1=y_R, lambda_2=|y_R|-|h|^2, lamda_3=y_I, lambda_4=|y_I|-|h|^2

    llr16[0] = vgetq_lane_s16(rxF[i],0);
    llr16[1] = vgetq_lane_s16(rxF[i],1);
    llr16[2] = vgetq_lane_s16(xmm0,0);
    llr16[3] = vgetq_lane_s16(xmm0,1);
    llr16[4] = vgetq_lane_s16(rxF[i],2);
    llr16[5] = vgetq_lane_s16(rxF[i],3);
    llr16[6] = vgetq_lane_s16(xmm0,2);
    llr16[7] = vgetq_lane_s16(xmm0,3);
    llr16[8] = vgetq_lane_s16(rxF[i],4);
    llr16[9] = vgetq_lane_s16(rxF[i],5);
    llr16[10] = vgetq_lane_s16(xmm0,4);
    llr16[11] = vgetq_lane_s16(xmm0,5);
    llr16[12] = vgetq_lane_s16(rxF[i],6);
    llr16[13] = vgetq_lane_s16(rxF[i],6);
    llr16[14] = vgetq_lane_s16(xmm0,7);
    llr16[15] = vgetq_lane_s16(xmm0,7);
    llr16+=16;
937

938 939
#endif

940
  }
941

942
#if defined(__x86_64__) || defined(__i386)
943 944
  _mm_empty();
  _m_empty();
945
#endif
946 947


948 949
}

950
void dlsch_16qam_llr_SIC (LTE_DL_FRAME_PARMS *frame_parms,
951
                          int32_t **rxdataF_comp,
Elena Lukashova's avatar
Elena Lukashova committed
952 953 954 955 956 957 958
                          int32_t **sic_buffer,  //Q15
                          int32_t **rho_i,
                          int16_t *dlsch_llr,
                          uint8_t num_pdcch_symbols,
                          int32_t **dl_ch_mag,
                          uint16_t nb_rb,
                          uint8_t subframe,
959
                          uint16_t mod_order_0,
960
                          uint32_t rb_alloc)
961
{
962 963 964 965 966 967 968 969 970 971
  int16_t rho_amp_x0[2*frame_parms->N_RB_DL*12];
  int16_t rho_rho_amp_x0[2*frame_parms->N_RB_DL*12];
  uint16_t amp_tmp;
  uint32_t *llr32=(uint32_t*)dlsch_llr;
  int i, len,  nsymb;
  uint8_t symbol, symbol_mod;
  int len_acc=0;
  uint16_t *sic_data;
  uint16_t pbch_pss_sss_adjust;
  unsigned char len_mod4=0;
972 973
  __m128i llr128[2];
  __m128i *ch_mag;
974
  nsymb = (frame_parms->Ncp==0) ? 14:12;
975

976 977 978 979
    for (symbol=num_pdcch_symbols; symbol<nsymb; symbol++) {
    uint16_t *rxF = (uint16_t*)(&rxdataF_comp[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
    int16_t *rho_1=(int16_t*)(&rho_i[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
    ch_mag = (__m128i*)(&dl_ch_mag[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
980 981
    sic_data = (uint16_t*)(&sic_buffer[0][((int16_t)len_acc)]);

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

984 985
    pbch_pss_sss_adjust=adjust_G2(frame_parms,&rb_alloc,4,subframe,symbol);

986 987
    if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) {
      amp_tmp=0x1fff;//dlsch0->sqrt_rho_b; already taken into account
988
      if (frame_parms->nb_antenna_ports_eNB!=1)
989 990 991 992 993 994 995
        len = nb_rb*8 - (2*pbch_pss_sss_adjust/3);
      else
        len = nb_rb*10 - (5*pbch_pss_sss_adjust/6);
    } else {
      amp_tmp=0x1fff;;//dlsch0->sqrt_rho_a; already taken into account
      len = nb_rb*12 - pbch_pss_sss_adjust;
    }
996

997 998
    if (mod_order_0==6)
      amp_tmp=amp_tmp<<1; // to compensate for >> 1 shift in modulation
999

1000
    len_acc+=len;
1001

1002
    multadd_complex_vector_real_scalar((int16_t *)sic_data,
Elena Lukashova's avatar
Elena Lukashova committed
1003 1004 1005 1006
                                       amp_tmp,
                                       (int16_t *)rho_amp_x0, //this is in Q13
                                       1,
                                       len);
1007

1008 1009 1010 1011 1012
     mult_cpx_vector((int16_t *)rho_1, //Q15
                    (int16_t *)rho_amp_x0, //Q13
                    (int16_t*)rho_rho_amp_x0,
                    len,
                    13);
1013

1014
     sub_cpx_vector16((int16_t *)rxF,
Elena Lukashova's avatar
Elena Lukashova committed
1015 1016 1017
                      (int16_t *)rho_rho_amp_x0,
                      //(int16_t *)clean_x1,
                      (int16_t *)rxF,
1018
                      len*2);
1019

1020 1021 1022 1023 1024
    len_mod4 = len&3;
    len>>=2;  // length in quad words (4 REs)
    len+=(len_mod4==0 ? 0 : 1);

    for (i=0; i<len; i++) {
1025

1026 1027 1028 1029 1030 1031

    __m128i *x1 = (__m128i*)rxF;//clean_x1;
//printf("%p %p %p\n", clean_x1, &clean_x1, &clean_x1[0]);
//int *a = malloc(10*sizeof(int));
//printf("%p %p\n", a, &a);
//exit(0);
1032
    xmm0 = _mm_abs_epi16(x1[i]);
1033 1034 1035
    xmm0 = _mm_subs_epi16(ch_mag[i],xmm0);

    // lambda_1=y_R, lambda_2=|y_R|-|h|^2, lamda_3=y_I, lambda_4=|y_I|-|h|^2
1036 1037
    llr128[0] = _mm_unpacklo_epi32(x1[i],xmm0);
    llr128[1] = _mm_unpackhi_epi32(x1[i],xmm0);
1038 1039 1040 1041 1042 1043 1044 1045 1046
    llr32[0] = _mm_extract_epi32(llr128[0],0); //((uint32_t *)&llr128[0])[0];
    llr32[1] = _mm_extract_epi32(llr128[0],1); //((uint32_t *)&llr128[0])[1];
    llr32[2] = _mm_extract_epi32(llr128[0],2); //((uint32_t *)&llr128[0])[2];
    llr32[3] = _mm_extract_epi32(llr128[0],3); //((uint32_t *)&llr128[0])[3];
    llr32[4] = _mm_extract_epi32(llr128[1],0); //((uint32_t *)&llr128[1])[0];
    llr32[5] = _mm_extract_epi32(llr128[1],1); //((uint32_t *)&llr128[1])[1];
    llr32[6] = _mm_extract_epi32(llr128[1],2); //((uint32_t *)&llr128[1])[2];
    llr32[7] = _mm_extract_epi32(llr128[1],3); //((uint32_t *)&llr128[1])[3];
    llr32+=8;
1047

1048 1049 1050 1051
  }
  _mm_empty();
  _m_empty();
}
1052
}
1053

1054

1055 1056 1057 1058 1059
//----------------------------------------------------------------------------------------------
// 64-QAM
//----------------------------------------------------------------------------------------------

void dlsch_64qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
1060 1061 1062 1063 1064
                     int32_t **rxdataF_comp,
                     int16_t *dlsch_llr,
                     int32_t **dl_ch_mag,
                     int32_t **dl_ch_magb,
                     uint8_t symbol,
1065
                     uint8_t first_symbol_flag,
1066
                     uint16_t nb_rb,
1067
                     uint16_t pbch_pss_sss_adjust,
1068 1069
                     //int16_t **llr_save,
                     uint32_t llr_offset,
1070
                     uint8_t beamforming_mode)
1071
{
1072 1073 1074 1075
  int32_t *rxF = (int32_t*)&rxdataF_comp[0][(symbol*frame_parms->N_RB_DL*12)];
  int32_t *ch_mag = (int32_t*)&dl_ch_mag[0][(symbol*frame_parms->N_RB_DL*12)];
  int32_t *ch_magb = (int32_t*)&dl_ch_magb[0][(symbol*frame_parms->N_RB_DL*12)];
  int len,len2;
1076 1077 1078
  unsigned char symbol_mod,len_mod4;
  short *llr;
  int16_t *llr2;
1079
  int8_t *pllr_symbol;
1080

1081
  /*
1082 1083 1084 1085
  if (first_symbol_flag==1)
    llr = dlsch_llr;
  else
    llr = *llr_save;
1086 1087 1088 1089 1090
  */
  llr = dlsch_llr;

  pllr_symbol = (int8_t*)dlsch_llr;
  pllr_symbol += llr_offset;
1091 1092 1093 1094

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

  if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) {
1095
    if (frame_parms->nb_antenna_ports_eNB!=1)
1096
      len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3);
1097
    else
1098 1099 1100 1101 1102
      len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6);
  } else if((beamforming_mode==7) && (frame_parms->Ncp==0) && (symbol==3 || symbol==6 || symbol==9 || symbol==12)){
      len = (nb_rb*9) - (3*pbch_pss_sss_adjust/4);
  } else if((beamforming_mode==7) && (frame_parms->Ncp==1) && (symbol==4 || symbol==7 || symbol==10)){
      len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3);
1103
  } else {
1104
    len = (nb_rb*12) - pbch_pss_sss_adjust;
1105 1106
  }

1107 1108 1109 1110 1111 1112 1113 1114 1115
//  printf("dlsch_64qam_llr: symbol %d,nb_rb %d, len %d,pbch_pss_sss_adjust %d\n",symbol,nb_rb,len,pbch_pss_sss_adjust);

/*  LOG_I(PHY,"dlsch_64qam_llr [symb %d / FirstSym %d / Length %d]: @LLR Buff %x \n",
             symbol,
             first_symbol_flag,
             len,
             dlsch_llr,
             pllr_symbol);*/

1116 1117 1118 1119 1120
  llr2 = llr;
  llr += (len*6);

  len_mod4 =len&3;
  len2=len>>2;  // length in quad words (4 REs)
knopp's avatar
knopp committed
1121
  len2+=((len_mod4==0)?0:1);
1122

1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
  qam64_llr((short *)rxF,
           (short *)ch_mag,
           (short *)ch_magb,
           llr2,
           len2);
}


void qam64_llr(int16_t *stream0_in,
               int16_t *chan_magn,
               int16_t *chan_magn_b,
               int16_t *llr,
               int length)
{
1137

1138
#if defined(__x86_64__) || defined(__i386__)
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
  __m128i *rxF_128 = (__m128i*)stream0_in;
  __m128i *ch_mag_128 = (__m128i*)chan_magn;
  __m128i *ch_magb_128 = (__m128i*)chan_magn_b;
#elif defined(__arm__)
  int16x8_t *rxF_128 = (int16x8_t*)stream0_in;
  int16x8_t *ch_mag_128 = (int16x8_t*)chan_magn;
  int16x8_t *ch_magb_128 = (int16x8_t*)chan_magn_b;
  int16x8_t xmm1,xmm2;
#endif


  int i;
  //int16_t *llr2;
  //llr2 = llr;

  for (i=0; i<length; i++) {

#if defined(__x86_64__) || defined(__i386__)
    xmm1 = _mm_abs_epi16(rxF_128[i]);
    xmm1 = _mm_subs_epi16(ch_mag_128[i],xmm1);
1159
    xmm2 = _mm_abs_epi16(xmm1);
1160
    xmm2 = _mm_subs_epi16(ch_magb_128[i],xmm2);
1161
#elif defined(__arm__)
1162 1163
    xmm1 = vabsq_s16(rxF_128[i]);
    xmm1 = vsubq_s16(ch_mag_128[i],xmm1);
1164
    xmm2 = vabsq_s16(xmm1);
1165
    xmm2 = vsubq_s16(ch_magb_128[i],xmm2);
1166
#endif
1167 1168
    // loop over all LLRs in quad word (24 coded bits)
    /*
1169 1170 1171 1172 1173 1174 1175 1176
      for (j=0;j<8;j+=2) {
      llr2[0] = ((short *)&rxF[i])[j];
      llr2[1] = ((short *)&rxF[i])[j+1];
      llr2[2] = ((short *)&xmm1)[j];
      llr2[3] = ((short *)&xmm1)[j+1];
      llr2[4] = ((short *)&xmm2)[j];
      llr2[5] = ((short *)&xmm2)[j+1];

Elena Lukashova's avatar
Elena Lukashova committed
1177
     llr2+=6;
1178
      }
1179
    */
1180 1181
    llr[0] = ((short *)&rxF_128[i])[0];
    llr[1] = ((short *)&rxF_128[i])[1];
1182
#if defined(__x86_64__) || defined(__i386__)
1183 1184 1185 1186
    llr[2] = _mm_extract_epi16(xmm1,0);
    llr[3] = _mm_extract_epi16(xmm1,1);//((short *)&xmm1)[j+1];
    llr[4] = _mm_extract_epi16(xmm2,0);//((short *)&xmm2)[j];
    llr[5] = _mm_extract_epi16(xmm2,1);//((short *)&xmm2)[j+1];
1187
#elif defined(__arm__)
1188 1189 1190 1191
    llr[2] = vgetq_lane_s16(xmm1,0);
    llr[3] = vgetq_lane_s16(xmm1,1);//((short *)&xmm1)[j+1];
    llr[4] = vgetq_lane_s16(xmm2,0);//((short *)&xmm2)[j];
    llr[5] = vgetq_lane_s16(xmm2,1);//((short *)&xmm2)[j+1];
1192
#endif
1193

1194 1195 1196
    llr+=6;
    llr[0] = ((short *)&rxF_128[i])[2];
    llr[1] = ((short *)&rxF_128[i])[3];
1197
#if defined(__x86_64__) || defined(__i386__)
1198 1199 1200 1201
    llr[2] = _mm_extract_epi16(xmm1,2);
    llr[3] = _mm_extract_epi16(xmm1,3);//((short *)&xmm1)[j+1];
    llr[4] = _mm_extract_epi16(xmm2,2);//((short *)&xmm2)[j];
    llr[5] = _mm_extract_epi16(xmm2,3);//((short *)&xmm2)[j+1];
1202
#elif defined(__arm__)
1203 1204 1205 1206
    llr[2] = vgetq_lane_s16(xmm1,2);
    llr[3] = vgetq_lane_s16(xmm1,3);//((short *)&xmm1)[j+1];
    llr[4] = vgetq_lane_s16(xmm2,2);//((short *)&xmm2)[j];
    llr[5] = vgetq_lane_s16(xmm2,3);//((short *)&xmm2)[j+1];
1207
#endif
1208

1209 1210 1211
    llr+=6;
    llr[0] = ((short *)&rxF_128[i])[4];
    llr[1] = ((short *)&rxF_128[i])[5];
1212
#if defined(__x86_64__) || defined(__i386__)
1213 1214 1215 1216
    llr[2] = _mm_extract_epi16(xmm1,4);
    llr[3] = _mm_extract_epi16(xmm1,5);//((short *)&xmm1)[j+1];
    llr[4] = _mm_extract_epi16(xmm2,4);//((short *)&xmm2)[j];
    llr[5] = _mm_extract_epi16(xmm2,5);//((short *)&xmm2)[j+1];
1217
#elif defined(__arm__)
1218 1219 1220 1221
    llr[2] = vgetq_lane_s16(xmm1,4);
    llr[3] = vgetq_lane_s16(xmm1,5);//((short *)&xmm1)[j+1];
    llr[4] = vgetq_lane_s16(xmm2,4);//((short *)&xmm2)[j];
    llr[5] = vgetq_lane_s16(xmm2,5);//((short *)&xmm2)[j+1];
1222
#endif
1223 1224 1225
    llr+=6;
    llr[0] = ((short *)&rxF_128[i])[6];
    llr[1] = ((short *)&rxF_128[i])[7];
1226
#if defined(__x86_64__) || defined(__i386__)
1227 1228 1229 1230
    llr[2] = _mm_extract_epi16(xmm1,6);
    llr[3] = _mm_extract_epi16(xmm1,7);//((short *)&xmm1)[j+1];
    llr[4] = _mm_extract_epi16(xmm2,6);//((short *)&xmm2)[j];
    llr[5] = _mm_extract_epi16(xmm2,7);//((short *)&xmm2)[j+1];
1231
#elif defined(__arm__)
1232 1233 1234 1235
    llr[2] = vgetq_lane_s16(xmm1,6);
    llr[3] = vgetq_lane_s16(xmm1,7);//((short *)&xmm1)[j+1];
    llr[4] = vgetq_lane_s16(xmm2,6);//((short *)&xmm2)[j];
    llr[5] = vgetq_lane_s16(xmm2,7);//((short *)&xmm2)[j+1];
1236
#endif
1237
    llr+=6;
1238 1239 1240

  }

1241
#if defined(__x86_64__) || defined(__i386__)
1242 1243
  _mm_empty();
  _m_empty();
1244
#endif
1245 1246
}

1247
void dlsch_64qam_llr_SIC(LTE_DL_FRAME_PARMS *frame_parms,
1248
                         int32_t **rxdataF_comp,
Elena Lukashova's avatar
Elena Lukashova committed
1249 1250 1251 1252 1253 1254 1255 1256
                         int32_t **sic_buffer,  //Q15
                         int32_t **rho_i,
                         int16_t *dlsch_llr,
                         uint8_t num_pdcch_symbols,
                         int32_t **dl_ch_mag,
                         int32_t **dl_ch_magb,
                         uint16_t nb_rb,
                         uint8_t subframe,
1257
                         uint16_t mod_order_0,
1258
                         uint32_t rb_alloc)
1259
{
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
  int16_t rho_amp_x0[2*frame_parms->N_RB_DL*12];
  int16_t rho_rho_amp_x0[2*frame_parms->N_RB_DL*12];
  uint16_t amp_tmp;
  uint16_t *llr32=(uint16_t*)dlsch_llr;
  int i, len,  nsymb, len2;
  uint8_t symbol, symbol_mod;
  int len_acc=0;
  uint16_t *sic_data;
  uint16_t pbch_pss_sss_adjust;
  unsigned char len_mod4=0;
1270
  uint16_t *llr2;
1271
  __m128i *ch_mag,*ch_magb;
1272

Elena Lukashova's avatar
Elena Lukashova committed
1273
  nsymb = (frame_parms->Ncp==0) ? 14:12;
1274

1275 1276 1277 1278 1279
  for (symbol=num_pdcch_symbols; symbol<nsymb; symbol++) {
    uint16_t *rxF = (uint16_t*)(&rxdataF_comp[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
    int16_t *rho_1=(int16_t*)(&rho_i[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
    ch_mag = (__m128i*)(&dl_ch_mag[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
    ch_magb = (__m128i*)(&dl_ch_magb[0][((int16_t)symbol*frame_parms->N_RB_DL*12)]);
1280 1281
    sic_data = (uint16_t*)(&sic_buffer[0][((int16_t)len_acc)]);

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

1284 1285
    pbch_pss_sss_adjust=adjust_G2(frame_parms,&rb_alloc,6,subframe,symbol);

Elena Lukashova's avatar
Elena Lukashova committed
1286
    if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) {
1287
      amp_tmp = 0x1fff;//dlsch0->sqrt_rho_b; already taken into account
1288
      if (frame_parms->nb_antenna_ports_eNB!=1)
1289 1290 1291
        len = nb_rb*8 - (2*pbch_pss_sss_adjust/3);
      else
        len = nb_rb*10 - (5*pbch_pss_sss_adjust/6);
1292
      } else {
1293 1294
        amp_tmp = 0x1fff; //dlsch0->sqrt_rho_a; already taken into account
        len = nb_rb*12 - pbch_pss_sss_adjust;
1295
      }
1296

1297 1298
    if (mod_order_0==6)
      amp_tmp=amp_tmp<<1; // to compensate for >> 1 shift in modulation
1299

1300
    len_acc+=len;
1301

1302
    multadd_complex_vector_real_scalar((int16_t *)sic_data,
Elena Lukashova's avatar
Elena Lukashova committed
1303 1304 1305 1306
                                        amp_tmp,
                                        (int16_t *)rho_amp_x0, //this is in Q13
                                        1,
                                        len);
1307

1308
    mult_cpx_vector((int16_t *)rho_1, //Q15
1309 1310 1311 1312
                    (int16_t *)rho_amp_x0, //Q13
                    (int16_t*)rho_rho_amp_x0,
                    len,
                    13);
1313

1314
    sub_cpx_vector16((int16_t *)rxF,
Elena Lukashova's avatar
Elena Lukashova committed
1315 1316 1317 1318
                      (int16_t *)rho_rho_amp_x0,
                      //(int16_t *)clean_x1,
                      (int16_t *)rxF,
                      len*2);
1319

1320 1321
    llr2 = llr32;
    llr32 += (len*6);
1322

1323 1324 1325
    len_mod4 =len&3;
    len2=len>>2;  // length in quad words (4 REs)
    len2+=(len_mod4?0:1);
1326 1327


1328

1329
    for (i=0; i<len2; i++) {
1330

1331 1332 1333 1334 1335
      __m128i *x1 = (__m128i*)rxF;
      xmm1 = _mm_abs_epi16(x1[i]);
      xmm1 = _mm_subs_epi16(ch_mag[i],xmm1);
      xmm2 = _mm_abs_epi16(xmm1);
      xmm2 = _mm_subs_epi16(ch_magb[i],xmm2);
1336

1337 1338 1339 1340 1341 1342 1343 1344 1345
      // loop over all LLRs in quad word (24 coded bits)
      /*
        for (j=0;j<8;j+=2) {
        llr2[0] = ((short *)&rxF[i])[j];
        llr2[1] = ((short *)&rxF[i])[j+1];
        llr2[2] = ((short *)&xmm1)[j];
        llr2[3] = ((short *)&xmm1)[j+1];
        llr2[4] = ((short *)&xmm2)[j];
        llr2[5] = ((short *)&xmm2)[j+1];
1346

1347 1348 1349 1350 1351 1352 1353 1354 1355
       llr2+=6;
        }
      */
      llr2[0] = ((short *)&x1[i])[0];
      llr2[1] = ((short *)&x1[i])[1];
      llr2[2] = _mm_extract_epi16(xmm1,0);
      llr2[3] = _mm_extract_epi16(xmm1,1);//((short *)&xmm1)[j+1];
      llr2[4] = _mm_extract_epi16(xmm2,0);//((short *)&xmm2)[j];
      llr2[5] = _mm_extract_epi16(xmm2,1);//((short *)&xmm2)[j+1];
1356

1357

1358 1359 1360
      llr2+=6;
      llr2[0] = ((short *)&x1[i])[2];
      llr2[1] = ((short *)&x1[i])[3];
1361

1362 1363 1364 1365
      llr2[2] = _mm_extract_epi16(xmm1,2);
      llr2[3] = _mm_extract_epi16(xmm1,3);//((short *)&xmm1)[j+1];
      llr2[4] = _mm_extract_epi16(xmm2,2);//((short *)&xmm2)[j];
      llr2[5] = _mm_extract_epi16(xmm2,3);//((short *)&xmm2)[j+1];
1366

1367 1368 1369
      llr2+=6;
      llr2[0] = ((short *)&x1[i])[4];
      llr2[1] = ((short *)&x1[i])[5];
1370

1371 1372 1373 1374
      llr2[2] = _mm_extract_epi16(xmm1,4);
      llr2[3] = _mm_extract_epi16(xmm1,5);//((short *)&xmm1)[j+1];
      llr2[4] = _mm_extract_epi16(xmm2,4);//((short *)&xmm2)[j];
      llr2[5] = _mm_extract_epi16(xmm2,5);//((short *)&xmm2)[j+1];
1375

1376 1377 1378
      llr2+=6;
      llr2[0] = ((short *)&x1[i])[6];
      llr2[1] = ((short *)&x1[i])[7];
1379

1380 1381 1382 1383
      llr2[2] = _mm_extract_epi16(xmm1,6);
      llr2[3] = _mm_extract_epi16(xmm1,7);//((short *)&xmm1)[j+1];
      llr2[4] = _mm_extract_epi16(xmm2,6);//((short *)&xmm2)[j];
      llr2[5] = _mm_extract_epi16(xmm2,7);//((short *)&xmm2)[j+1];
1384

1385
      llr2+=6;
1386

1387
    }
1388

1389 1390
 // *llr_save = llr;

1391 1392 1393
  _mm_empty();
  _m_empty();

1394
  }
1395 1396
}
//#endif
1397 1398 1399 1400 1401 1402 1403 1404
//==============================================================================================
// DUAL-STREAM
//==============================================================================================

//----------------------------------------------------------------------------------------------
// QPSK
//----------------------------------------------------------------------------------------------

1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418
#if defined(__x86_64__) || defined(__i386)
__m128i  y0r_over2 __attribute__ ((aligned(16)));
__m128i  y0i_over2 __attribute__ ((aligned(16)));
__m128i  y1r_over2 __attribute__ ((aligned(16)));
__m128i  y1i_over2 __attribute__ ((aligned(16)));

__m128i  A __attribute__ ((aligned(16)));
__m128i  B __attribute__ ((aligned(16)));
__m128i  C __attribute__ ((aligned(16)));
__m128i  D __attribute__ ((aligned(16)));
__m128i  E __attribute__ ((aligned(16)));
__m128i  F __attribute__ ((aligned(16)));
__m128i  G __attribute__ ((aligned(16)));
__m128i  H __attribute__ ((aligned(16)));
1419

1420
#endif
1421 1422 1423 1424 1425 1426 1427 1428 1429

int dlsch_qpsk_qpsk_llr(LTE_DL_FRAME_PARMS *frame_parms,
                        int **rxdataF_comp,
                        int **rxdataF_comp_i,
                        int **rho_i,
                        short *dlsch_llr,
                        unsigned char symbol,
                        unsigned char first_symbol_flag,
                        unsigned short nb_rb,
1430
                        uint16_t pbch_pss_sss_adjust,
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
                        short **llr16p)
{

  int16_t *rxF=(int16_t*)&rxdataF_comp[0][(symbol*frame_parms->N_RB_DL*12)];
  int16_t *rxF_i=(int16_t*)&rxdataF_comp_i[0][(symbol*frame_parms->N_RB_DL*12)];
  int16_t *rho=(int16_t*)&rho_i[0][(symbol*frame_parms->N_RB_DL*12)];
  int16_t *llr16;
  int len;
  uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol;

  if (first_symbol_flag == 1) {
    llr16 = (int16_t*)dlsch_llr;
  } else {
    llr16 = (int16_t*)(*llr16p);
  }

1447
  AssertFatal(llr16!=NULL,"dlsch_qpsk_qpsk_llr: llr is null, symbol %d\n",symbol);
1448 1449 1450

  if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) {
    // if symbol has pilots
1451
    if (frame_parms->nb_antenna_ports_eNB!=1)
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
      // in 2 antenna ports we have 8 REs per symbol per RB
      len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3);
    else
      // for 1 antenna port we have 10 REs per symbol per RB
      len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6);
  } else {
    // symbol has no pilots
    len = (nb_rb*12) - pbch_pss_sss_adjust;
  }

1462
  // printf("dlsch_qpsk_qpsk_llr: symbol %d,nb_rb %d, len %d,pbch_pss_sss_adjust %d\n",symbol,nb_rb,len,pbch_pss_sss_adjust);
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
  //    printf("qpsk_qpsk: len %d, llr16 %p\n",len,llr16);
  qpsk_qpsk((short *)rxF,
            (short *)rxF_i,
            (short *)llr16,
            (short *)rho,
            len);

  llr16 += (len<<1);
  *llr16p = (short *)llr16;

  return(0);
1474 1475
}

1476
//__m128i ONE_OVER_SQRT_8 __attribute__((aligned(16)));
1477 1478

void qpsk_qpsk(short *stream0_in,
1479
               short *stream1_in,
1480 1481 1482
               short *stream0_out,
               short *rho01,
               int length
Elena Lukashova's avatar
Elena Lukashova committed
1483
         )