3gpplte_turbo_decoder_sse.c 92.5 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
Cedric Roux's avatar
Cedric Roux committed
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 21
 * 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
 */

22 23 24
/* file: 3gpplte_turbo_decoder_sse.c
   purpose: Routines for implementing max-logmap decoding of Turbo-coded (DLSCH) transport channels from 36-212, V8.6 2009-03
   authors: raymond.knopp@eurecom.fr, Laurent Thomas (Alcatel-Lucent)
25
   date: 21.10.2009
26 27

   Note: This routine currently requires SSE2,SSSE3 and SSE4.1 equipped computers.  IT WON'T RUN OTHERWISE!
28

29 30 31 32 33 34 35 36 37
   Changelog: 17.11.2009 FK SSE4.1 not required anymore
   Aug. 2012 new parallelization options for higher speed (8-way parallelization)
   Jan. 2013 8-bit LLR support with 16-way parallelization
   Feb. 2013 New interleaving and hard-decision optimizations (L. Thomas)
*/

///
///

38
#include "PHY/sse_intrin.h"
39

40
#ifndef TEST_DEBUG
41 42 43 44 45 46 47 48 49 50 51 52
#include "PHY/defs.h"
#include "PHY/CODING/defs.h"
#include "PHY/CODING/lte_interleaver_inline.h"
#include "extern_3GPPinterleaver.h"
#else

#include "defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#define SHUFFLE16(a,b,c,d,e,f,g,h) _mm_set_epi8(h==-1?-1:h*2+1, \
            h==-1?-1:h*2, \
            g==-1?-1:g*2+1, \
            g==-1?-1:g*2, \
            f==-1?-1:f*2+1, \
            f==-1?-1:f*2, \
            e==-1?-1:e*2+1, \
            e==-1?-1:e*2, \
            d==-1?-1:d*2+1, \
            d==-1?-1:d*2, \
            c==-1?-1:c*2+1, \
            c==-1?-1:c*2, \
            b==-1?-1:b*2+1, \
            b==-1?-1:b*2, \
            a==-1?-1:a*2+1, \
            a==-1?-1:a*2);
69 70 71 72 73 74 75





//#define DEBUG_LOGMAP

76

77 78 79 80 81
#ifdef LLR8

typedef int8_t llr_t; // internal decoder LLR data is 8-bit fixed
typedef int8_t channel_t;
#define MAX 64
82
#else
83 84 85 86 87 88 89

typedef int16_t llr_t; // internal decoder LLR data is 16-bit fixed
typedef int16_t channel_t;
#define MAX 256

#endif

90 91
void log_map (llr_t* systematic,channel_t* y_parity, llr_t* m11, llr_t* m10, llr_t *alpha, llr_t *beta, llr_t* ext,unsigned short frame_length,unsigned char term_flag,unsigned char F,int offset8_flag,
              time_stats_t *alpha_stats,time_stats_t *beta_stats,time_stats_t *gamma_stats,time_stats_t *ext_stats);
92 93 94 95 96 97
void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic, channel_t* y_parity, unsigned short frame_length,unsigned char term_flag);
void compute_alpha(llr_t*alpha,llr_t *beta, llr_t* m11,llr_t* m10, unsigned short frame_length,unsigned char F);
void compute_beta(llr_t*alpha, llr_t* beta,llr_t* m11,llr_t* m10, unsigned short frame_length,unsigned char F,int offset8_flag);
void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m11,llr_t* m10,llr_t* extrinsic, llr_t* ap, unsigned short frame_length);


98 99
void print_bytes(char *s, __m128i *x)
{
100 101 102 103

  int8_t *tempb = (int8_t *)x;

  printf("%s  : %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",s,
104 105
         tempb[0],tempb[1],tempb[2],tempb[3],tempb[4],tempb[5],tempb[6],tempb[7],
         tempb[8],tempb[9],tempb[10],tempb[11],tempb[12],tempb[13],tempb[14],tempb[15]);
106 107 108 109 110

}


void log_map(llr_t* systematic,
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
             channel_t* y_parity,
             llr_t* m11,
             llr_t* m10,
             llr_t *alpha,
             llr_t *beta,
             llr_t* ext,
             unsigned short frame_length,
             unsigned char term_flag,
             unsigned char F,
             int offset8_flag,
             time_stats_t *alpha_stats,
             time_stats_t *beta_stats,
             time_stats_t *gamma_stats,
             time_stats_t *ext_stats)
{
126 127 128 129 130

#ifdef DEBUG_LOGMAP
  msg("log_map, frame_length %d\n",frame_length);
#endif

131 132 133 134 135 136 137 138 139 140 141 142
  start_meas(gamma_stats) ;
  compute_gamma(m11,m10,systematic,y_parity,frame_length,term_flag) ;
  stop_meas(gamma_stats);
  start_meas(alpha_stats) ;
  compute_alpha(alpha,beta,m11,m10,frame_length,F)                  ;
  stop_meas(alpha_stats);
  start_meas(beta_stats)  ;
  compute_beta(alpha,beta,m11,m10,frame_length,F,offset8_flag)      ;
  stop_meas(beta_stats);
  start_meas(ext_stats)   ;
  compute_ext(alpha,beta,m11,m10,ext,systematic,frame_length)       ;
  stop_meas(ext_stats);
143 144 145 146 147


}

void compute_gamma(llr_t* m11,llr_t* m10,llr_t* systematic,channel_t* y_parity,
148
                   unsigned short frame_length,unsigned char term_flag)
149 150 151 152 153 154 155 156 157 158 159 160
{
  int k,K1;
  __m128i *systematic128 = (__m128i *)systematic;
  __m128i *y_parity128   = (__m128i *)y_parity;
  __m128i *m10_128        = (__m128i *)m10;
  __m128i *m11_128        = (__m128i *)m11;

#ifdef DEBUG_LOGMAP
  msg("compute_gamma, %p,%p,%p,%p,framelength %d\n",m11,m10,systematic,y_parity,frame_length);
#endif
#ifndef LLR8
  K1=frame_length>>3;
161 162

  for (k=0; k<K1; k++) {
163 164 165 166 167

    m11_128[k] = _mm_srai_epi16(_mm_adds_epi16(systematic128[k],y_parity128[k]),1);
    m10_128[k] = _mm_srai_epi16(_mm_subs_epi16(systematic128[k],y_parity128[k]),1);
    /*
    printf("gamma %d: s %d,%d,%d,%d,%d,%d,%d,%d\n",
168 169 170 171 172 173 174 175 176
     k,
     (int16_t)_mm_extract_epi16(systematic128[k],0),
     (int16_t)_mm_extract_epi16(systematic128[k],1),
     (int16_t)_mm_extract_epi16(systematic128[k],2),
     (int16_t)_mm_extract_epi16(systematic128[k],3),
     (int16_t)_mm_extract_epi16(systematic128[k],4),
     (int16_t)_mm_extract_epi16(systematic128[k],5),
     (int16_t)_mm_extract_epi16(systematic128[k],6),
     (int16_t)_mm_extract_epi16(systematic128[k],7));
177 178

    printf("gamma %d: yp %d,%d,%d,%d,%d,%d,%d,%d\n",
179 180 181 182 183 184 185 186 187
     k,
     (int16_t)_mm_extract_epi16(y_parity128[k],0),
     (int16_t)_mm_extract_epi16(y_parity128[k],1),
     (int16_t)_mm_extract_epi16(y_parity128[k],2),
     (int16_t)_mm_extract_epi16(y_parity128[k],3),
     (int16_t)_mm_extract_epi16(y_parity128[k],4),
     (int16_t)_mm_extract_epi16(y_parity128[k],5),
     (int16_t)_mm_extract_epi16(y_parity128[k],6),
     (int16_t)_mm_extract_epi16(y_parity128[k],7));
188 189

    printf("gamma %d: m11 %d,%d,%d,%d,%d,%d,%d,%d\n",
190 191 192 193 194 195 196 197 198
     k,
     (int16_t)_mm_extract_epi16(m11_128[k],0),
     (int16_t)_mm_extract_epi16(m11_128[k],1),
     (int16_t)_mm_extract_epi16(m11_128[k],2),
     (int16_t)_mm_extract_epi16(m11_128[k],3),
     (int16_t)_mm_extract_epi16(m11_128[k],4),
     (int16_t)_mm_extract_epi16(m11_128[k],5),
     (int16_t)_mm_extract_epi16(m11_128[k],6),
     (int16_t)_mm_extract_epi16(m11_128[k],7));
199
    printf("gamma %d: m10 %d,%d,%d,%d,%d,%d,%d,%d\n",
200 201 202 203 204 205 206 207 208
     k,
     (int16_t)_mm_extract_epi16(m10_128[k],0),
     (int16_t)_mm_extract_epi16(m10_128[k],1),
     (int16_t)_mm_extract_epi16(m10_128[k],2),
     (int16_t)_mm_extract_epi16(m10_128[k],3),
     (int16_t)_mm_extract_epi16(m10_128[k],4),
     (int16_t)_mm_extract_epi16(m10_128[k],5),
     (int16_t)_mm_extract_epi16(m10_128[k],6),
     (int16_t)_mm_extract_epi16(m10_128[k],7));
209
    */
210

211
  }
212

213 214 215 216 217 218 219
  // Termination
  m11_128[k] = _mm_srai_epi16(_mm_adds_epi16(systematic128[k+term_flag],y_parity128[k]),1);
  m10_128[k] = _mm_srai_epi16(_mm_subs_epi16(systematic128[k+term_flag],y_parity128[k]),1);

  //  printf("gamma (term): %d,%d, %d,%d, %d,%d\n",m11[k<<3],m10[k<<3],m11[1+(k<<3)],m10[1+(k<<3)],m11[2+(k<<3)],m10[2+(k<<3)]);
#else
  register __m128i sl,sh,ypl,yph; //K128=_mm_set1_epi8(-128);
220 221 222 223 224 225 226
  K1 = (frame_length>>4);

  for (k=0; k<K1; k++) {
    sl  = _mm_cvtepi8_epi16(systematic128[k]);
    sh = _mm_cvtepi8_epi16(_mm_srli_si128(systematic128[k],8));
    ypl = _mm_cvtepi8_epi16(y_parity128[k]);
    yph = _mm_cvtepi8_epi16(_mm_srli_si128(y_parity128[k],8));
227
    m11_128[k] = _mm_packs_epi16(_mm_srai_epi16(_mm_adds_epi16(sl,ypl),1),
228
                                 _mm_srai_epi16(_mm_adds_epi16(sh,yph),1));
229
    m10_128[k] = _mm_packs_epi16(_mm_srai_epi16(_mm_subs_epi16(sl,ypl),1),
230
                                 _mm_srai_epi16(_mm_subs_epi16(sh,yph),1));
231 232 233 234 235
    //    m11_128[k] = _mm_adds_epi8(systematic128[k],y_parity128[k]);
    //    m10_128[k] = _mm_subs_epi8(systematic128[k],y_parity128[k]);
    //    m11_128[k] = _mm_sub_epi8(_mm_avg_epu8(_mm_add_epi8(systematic128[k],K128),_mm_add_epi8(y_parity128[k],K128)),K128);
    //    m10_128[k] = _mm_sub_epi8(_mm_avg_epu8(_mm_add_epi8(systematic128[k],K128),_mm_add_epi8(_mm_sign_epi8(y_parity128[k],K128),K128)),K128);

236
    /*
237
    printf("gamma %d: s %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
     k,
     (int8_t)_mm_extract_epi8(systematic128[k],0),
     (int8_t)_mm_extract_epi8(systematic128[k],1),
     (int8_t)_mm_extract_epi8(systematic128[k],2),
     (int8_t)_mm_extract_epi8(systematic128[k],3),
     (int8_t)_mm_extract_epi8(systematic128[k],4),
     (int8_t)_mm_extract_epi8(systematic128[k],5),
     (int8_t)_mm_extract_epi8(systematic128[k],6),
     (int8_t)_mm_extract_epi8(systematic128[k],7),
     (int8_t)_mm_extract_epi8(systematic128[k],8),
     (int8_t)_mm_extract_epi8(systematic128[k],9),
     (int8_t)_mm_extract_epi8(systematic128[k],10),
     (int8_t)_mm_extract_epi8(systematic128[k],11),
     (int8_t)_mm_extract_epi8(systematic128[k],12),
     (int8_t)_mm_extract_epi8(systematic128[k],13),
     (int8_t)_mm_extract_epi8(systematic128[k],14),
     (int8_t)_mm_extract_epi8(systematic128[k],15));
255
    printf("gamma %d: yp %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
     k,
     (int8_t)_mm_extract_epi8(y_parity128[k],0),
     (int8_t)_mm_extract_epi8(y_parity128[k],1),
     (int8_t)_mm_extract_epi8(y_parity128[k],2),
     (int8_t)_mm_extract_epi8(y_parity128[k],3),
     (int8_t)_mm_extract_epi8(y_parity128[k],4),
     (int8_t)_mm_extract_epi8(y_parity128[k],5),
     (int8_t)_mm_extract_epi8(y_parity128[k],6),
     (int8_t)_mm_extract_epi8(y_parity128[k],7),
     (int8_t)_mm_extract_epi8(y_parity128[k],8),
     (int8_t)_mm_extract_epi8(y_parity128[k],9),
     (int8_t)_mm_extract_epi8(y_parity128[k],10),
     (int8_t)_mm_extract_epi8(y_parity128[k],11),
     (int8_t)_mm_extract_epi8(y_parity128[k],12),
     (int8_t)_mm_extract_epi8(y_parity128[k],13),
     (int8_t)_mm_extract_epi8(y_parity128[k],14),
     (int8_t)_mm_extract_epi8(y_parity128[k],15));
273
    printf("gamma %d: m11 %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
     k,
     (int8_t)_mm_extract_epi8(m11_128[k],0),
     (int8_t)_mm_extract_epi8(m11_128[k],1),
     (int8_t)_mm_extract_epi8(m11_128[k],2),
     (int8_t)_mm_extract_epi8(m11_128[k],3),
     (int8_t)_mm_extract_epi8(m11_128[k],4),
     (int8_t)_mm_extract_epi8(m11_128[k],5),
     (int8_t)_mm_extract_epi8(m11_128[k],6),
     (int8_t)_mm_extract_epi8(m11_128[k],7),
     (int8_t)_mm_extract_epi8(m11_128[k],8),
     (int8_t)_mm_extract_epi8(m11_128[k],9),
     (int8_t)_mm_extract_epi8(m11_128[k],10),
     (int8_t)_mm_extract_epi8(m11_128[k],11),
     (int8_t)_mm_extract_epi8(m11_128[k],12),
     (int8_t)_mm_extract_epi8(m11_128[k],13),
     (int8_t)_mm_extract_epi8(m11_128[k],14),
     (int8_t)_mm_extract_epi8(m11_128[k],15));
291
    printf("gamma %d: m10 %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
     k,
     (int8_t)_mm_extract_epi8(m10_128[k],0),
     (int8_t)_mm_extract_epi8(m10_128[k],1),
     (int8_t)_mm_extract_epi8(m10_128[k],2),
     (int8_t)_mm_extract_epi8(m10_128[k],3),
     (int8_t)_mm_extract_epi8(m10_128[k],4),
     (int8_t)_mm_extract_epi8(m10_128[k],5),
     (int8_t)_mm_extract_epi8(m10_128[k],6),
     (int8_t)_mm_extract_epi8(m10_128[k],7),
     (int8_t)_mm_extract_epi8(m10_128[k],8),
     (int8_t)_mm_extract_epi8(m10_128[k],9),
     (int8_t)_mm_extract_epi8(m10_128[k],10),
     (int8_t)_mm_extract_epi8(m10_128[k],11),
     (int8_t)_mm_extract_epi8(m10_128[k],12),
     (int8_t)_mm_extract_epi8(m10_128[k],13),
     (int8_t)_mm_extract_epi8(m10_128[k],14),
     (int8_t)_mm_extract_epi8(m10_128[k],15));
    */
310 311
  }

312
  // Termination
313

314 315 316 317 318 319 320 321 322 323 324 325 326
  sl  = _mm_cvtepi8_epi16(systematic128[k+term_flag]);
  sh = _mm_cvtepi8_epi16(_mm_srli_si128(systematic128[k],8));
  ypl = _mm_cvtepi8_epi16(y_parity128[k+term_flag]);
  yph = _mm_cvtepi8_epi16(_mm_srli_si128(y_parity128[k],8));
  m11_128[k] = _mm_packs_epi16(_mm_srai_epi16(_mm_adds_epi16(sl,ypl),1),
                               _mm_srai_epi16(_mm_adds_epi16(sh,yph),1));
  m10_128[k] = _mm_packs_epi16(_mm_srai_epi16(_mm_subs_epi16(sl,ypl),1),
                               _mm_srai_epi16(_mm_subs_epi16(sh,yph),1));

  //    m11_128[k] = _mm_adds_epi8(systematic128[k+term_flag],y_parity128[k]);
  //    m10_128[k] = _mm_subs_epi8(systematic128[k+term_flag],y_parity128[k]);
  //  m11_128[k] = _mm_sub_epi8(_mm_avg_epu8(_mm_add_epi8(systematic128[k+term_flag],K128),_mm_add_epi8(y_parity128[k],K128)),K128);
  //  m10_128[k] = _mm_sub_epi8(_mm_avg_epu8(_mm_add_epi8(systematic128[k+term_flag],K128),_mm_add_epi8(_mm_sign_epi8(y_parity128[k],K128),K128)),K128);
327 328 329
  /*
  printf("m11 = %p (K1 %d)\n",&m11_128[k],K1);
    printf("gamma %d: s %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
     k+term_flag,
     _mm_extract_epi8(systematic128[k+term_flag],0),
     _mm_extract_epi8(systematic128[k+term_flag],1),
     _mm_extract_epi8(systematic128[k+term_flag],2),
     _mm_extract_epi8(systematic128[k+term_flag],3),
     _mm_extract_epi8(systematic128[k+term_flag],4),
     _mm_extract_epi8(systematic128[k+term_flag],5),
     _mm_extract_epi8(systematic128[k+term_flag],6),
     _mm_extract_epi8(systematic128[k+term_flag],7),
     _mm_extract_epi8(systematic128[k+term_flag],8),
     _mm_extract_epi8(systematic128[k+term_flag],9),
     _mm_extract_epi8(systematic128[k+term_flag],10),
     _mm_extract_epi8(systematic128[k+term_flag],11),
     _mm_extract_epi8(systematic128[k+term_flag],12),
     _mm_extract_epi8(systematic128[k+term_flag],13),
     _mm_extract_epi8(systematic128[k+term_flag],14),
     _mm_extract_epi8(systematic128[k+term_flag],15));
347
    printf("gamma %d: yp %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
     k,
     _mm_extract_epi8(y_parity128[k],0),
     _mm_extract_epi8(y_parity128[k],1),
     _mm_extract_epi8(y_parity128[k],2),
     _mm_extract_epi8(y_parity128[k],3),
     _mm_extract_epi8(y_parity128[k],4),
     _mm_extract_epi8(y_parity128[k],5),
     _mm_extract_epi8(y_parity128[k],6),
     _mm_extract_epi8(y_parity128[k],7),
     _mm_extract_epi8(y_parity128[k],8),
     _mm_extract_epi8(y_parity128[k],9),
     _mm_extract_epi8(y_parity128[k],10),
     _mm_extract_epi8(y_parity128[k],11),
     _mm_extract_epi8(y_parity128[k],12),
     _mm_extract_epi8(y_parity128[k],13),
     _mm_extract_epi8(y_parity128[k],14),
     _mm_extract_epi8(y_parity128[k],15));
365
    printf("gamma %d: m11 %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
     k,
     _mm_extract_epi8(m11_128[k],0),
     _mm_extract_epi8(m11_128[k],1),
     _mm_extract_epi8(m11_128[k],2),
     _mm_extract_epi8(m11_128[k],3),
     _mm_extract_epi8(m11_128[k],4),
     _mm_extract_epi8(m11_128[k],5),
     _mm_extract_epi8(m11_128[k],6),
     _mm_extract_epi8(m11_128[k],7),
     _mm_extract_epi8(m11_128[k],8),
     _mm_extract_epi8(m11_128[k],9),
     _mm_extract_epi8(m11_128[k],10),
     _mm_extract_epi8(m11_128[k],11),
     _mm_extract_epi8(m11_128[k],12),
     _mm_extract_epi8(m11_128[k],13),
     _mm_extract_epi8(m11_128[k],14),
     _mm_extract_epi8(m11_128[k],15));
383 384 385 386
  */
#endif
  _mm_empty();
  _m_empty();
387

388 389 390 391
}

#define L 40

392 393
void compute_alpha(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,unsigned short frame_length,unsigned char F)
{
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
  int k,l,l2,K1,rerun_flag=0;
  __m128i *alpha128=(__m128i *)alpha,*alpha_ptr;
  __m128i a0,a1,a2,a3,a4,a5,a6,a7,*m11p,*m10p;
  __m128i m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
  __m128i new0,new1,new2,new3,new4,new5,new6,new7;
  __m128i alpha_max;

#ifndef LLR8
  l2 = L>>3;
  K1 = (frame_length>>3);
#else
  l2 = L>>4;
  K1 = (frame_length>>4);
#endif

409
  for (l=K1;; l=l2,rerun_flag=1) {
410 411
#ifndef LLR8
    alpha128 = (__m128i *)alpha;
412

413 414 415 416 417 418 419 420 421
    if (rerun_flag == 0) {
      alpha128[0] = _mm_set_epi16(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,0);
      alpha128[1] = _mm_set_epi16(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[2] = _mm_set_epi16(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[3] = _mm_set_epi16(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[4] = _mm_set_epi16(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[5] = _mm_set_epi16(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[6] = _mm_set_epi16(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[7] = _mm_set_epi16(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
422
    } else {
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
      //set initial alpha in columns 1-7 from final alpha from last run in columns 0-6
      alpha128[0] = _mm_slli_si128(alpha128[frame_length],2);
      alpha128[1] = _mm_slli_si128(alpha128[1+frame_length],2);
      alpha128[2] = _mm_slli_si128(alpha128[2+frame_length],2);
      alpha128[3] = _mm_slli_si128(alpha128[3+frame_length],2);
      alpha128[4] = _mm_slli_si128(alpha128[4+frame_length],2);
      alpha128[5] = _mm_slli_si128(alpha128[5+frame_length],2);
      alpha128[6] = _mm_slli_si128(alpha128[6+frame_length],2);
      alpha128[7] = _mm_slli_si128(alpha128[7+frame_length],2);
      // set initial alpha in column 0 to (0,-MAX/2,...,-MAX/2)
      alpha[8] = -MAX/2;
      alpha[16] = -MAX/2;
      alpha[24] = -MAX/2;
      alpha[32] = -MAX/2;
      alpha[40] = -MAX/2;
      alpha[48] = -MAX/2;
      alpha[56] = -MAX/2;
    }
441

442 443 444 445 446 447
    alpha_ptr = &alpha128[0];

    m11p = (__m128i*)m_11;
    m10p = (__m128i*)m_10;

    for (k=0;
448 449
         k<l;
         k++) {
450 451 452 453 454 455 456

      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
457
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
458 459 460 461 462 463 464 465 466 467 468
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
469

470 471 472 473 474 475 476 477
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
478

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);

      alpha_max = _mm_max_epi16(a0,a1);
      alpha_max = _mm_max_epi16(alpha_max,a2);
      alpha_max = _mm_max_epi16(alpha_max,a3);
      alpha_max = _mm_max_epi16(alpha_max,a4);
      alpha_max = _mm_max_epi16(alpha_max,a5);
      alpha_max = _mm_max_epi16(alpha_max,a6);
      alpha_max = _mm_max_epi16(alpha_max,a7);

      alpha_ptr+=8;
      m11p++;
498
      m10p++;
499 500 501 502 503 504 505 506 507 508 509
      alpha_ptr[0] = _mm_subs_epi16(a0,alpha_max);
      alpha_ptr[1] = _mm_subs_epi16(a1,alpha_max);
      alpha_ptr[2] = _mm_subs_epi16(a2,alpha_max);
      alpha_ptr[3] = _mm_subs_epi16(a3,alpha_max);
      alpha_ptr[4] = _mm_subs_epi16(a4,alpha_max);
      alpha_ptr[5] = _mm_subs_epi16(a5,alpha_max);
      alpha_ptr[6] = _mm_subs_epi16(a6,alpha_max);
      alpha_ptr[7] = _mm_subs_epi16(a7,alpha_max);

    }

510
    /*
511 512
       // Try this on x86-64
    for (k=0;
513 514
    k<l;
    k+=8){
515

516 517

      //      m11_0=((__m128i*)m_11)[k];
518 519 520 521 522 523 524 525 526
      //      m10_0=((__m128i*)m_10)[k];

      // 0/7
      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
527
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
528 529 530 531 532 533 534 535 536 537 538
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
539

540 541 542 543 544 545 546 547
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
548

549 550 551 552 553 554 555 556
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
557

558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
      alpha_ptr += 8;
      m11p++;
      m10p++;
      alpha_ptr[0] = a0;
      alpha_ptr[1] = a1;
      alpha_ptr[2] = a2;
      alpha_ptr[3] = a3;
      alpha_ptr[4] = a4;
      alpha_ptr[5] = a5;
      alpha_ptr[6] = a6;
      alpha_ptr[7] = a7;

      // 1/7
      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
577
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
578 579 580 581 582 583 584 585 586 587 588
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
589

590 591 592 593 594 595 596 597
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
598

599 600 601 602 603 604 605 606
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
607 608

      alpha_ptr += 8;
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
      m11p++;
      m10p++;
      alpha_ptr[0] = a0;
      alpha_ptr[1] = a1;
      alpha_ptr[2] = a2;
      alpha_ptr[3] = a3;
      alpha_ptr[4] = a4;
      alpha_ptr[5] = a5;
      alpha_ptr[6] = a6;
      alpha_ptr[7] = a7;

      // 2/7
      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
627
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
628 629 630 631 632 633 634 635 636 637 638
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
639

640 641 642 643 644 645 646 647
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
648

649 650 651 652 653 654 655 656
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
657 658

      alpha_ptr += 8;
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
      m11p++;
      m10p++;
      alpha_ptr[0] = a0;
      alpha_ptr[1] = a1;
      alpha_ptr[2] = a2;
      alpha_ptr[3] = a3;
      alpha_ptr[4] = a4;
      alpha_ptr[5] = a5;
      alpha_ptr[6] = a6;
      alpha_ptr[7] = a7;

      // 3/7
      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
677
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
678 679 680 681 682 683 684 685 686 687 688
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
689

690 691 692 693 694 695 696 697
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
698

699 700 701 702 703 704 705 706
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
707 708

      alpha_ptr += 8;
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
      m11p++;
      m10p++;
      alpha_ptr[0] = a0;
      alpha_ptr[1] = a1;
      alpha_ptr[2] = a2;
      alpha_ptr[3] = a3;
      alpha_ptr[4] = a4;
      alpha_ptr[5] = a5;
      alpha_ptr[6] = a6;
      alpha_ptr[7] = a7;

      // 4/7
      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
727
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
728 729 730 731 732 733 734 735 736 737 738
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
739

740 741 742 743 744 745 746 747
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
748

749 750 751 752 753 754 755 756
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
757 758

      alpha_ptr += 8;
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
      m11p++;
      m10p++;
      alpha_ptr[0] = a0;
      alpha_ptr[1] = a1;
      alpha_ptr[2] = a2;
      alpha_ptr[3] = a3;
      alpha_ptr[4] = a4;
      alpha_ptr[5] = a5;
      alpha_ptr[6] = a6;
      alpha_ptr[7] = a7;

      // 5/7
      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
777
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
778 779 780 781 782 783 784 785 786 787 788
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
789

790 791 792 793 794 795 796 797
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
798

799 800 801 802 803 804 805 806
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
807 808

      alpha_ptr += 8;
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
      m11p++;
      m10p++;
      alpha_ptr[0] = a0;
      alpha_ptr[1] = a1;
      alpha_ptr[2] = a2;
      alpha_ptr[3] = a3;
      alpha_ptr[4] = a4;
      alpha_ptr[5] = a5;
      alpha_ptr[6] = a6;
      alpha_ptr[7] = a7;

      // 6/7
      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
827
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
828 829 830 831 832 833 834 835 836 837 838
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
839

840 841 842 843 844 845 846 847
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
848

849 850 851 852 853 854 855 856
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
857 858

      alpha_ptr += 8;
859 860 861 862 863 864 865 866 867 868
      m11p++;
      m10p++;
      alpha_ptr[0] = a0;
      alpha_ptr[1] = a1;
      alpha_ptr[2] = a2;
      alpha_ptr[3] = a3;
      alpha_ptr[4] = a4;
      alpha_ptr[5] = a5;
      alpha_ptr[6] = a6;
      alpha_ptr[7] = a7;
869 870

    // 7/7
871 872 873 874 875 876
      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
877
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
878 879 880 881 882 883 884 885 886 887 888
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
889

890 891 892 893 894 895 896 897
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
898

899 900 901 902 903 904 905 906
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
907
    // compute and subtract maxima
908 909 910 911 912 913 914 915 916
      alpha_max = _mm_max_epi16(a0,a1);
      alpha_max = _mm_max_epi16(alpha_max,a2);
      alpha_max = _mm_max_epi16(alpha_max,a3);
      alpha_max = _mm_max_epi16(alpha_max,a4);
      alpha_max = _mm_max_epi16(alpha_max,a5);
      alpha_max = _mm_max_epi16(alpha_max,a6);
      alpha_max = _mm_max_epi16(alpha_max,a7);
      alpha_ptr += 8;
      m11p++;
917
      m10p++;
918 919 920 921 922 923 924 925 926 927 928
      alpha_ptr[0] = _mm_subs_epi16(a0,alpha_max);
      alpha_ptr[1] = _mm_subs_epi16(a1,alpha_max);
      alpha_ptr[2] = _mm_subs_epi16(a2,alpha_max);
      alpha_ptr[3] = _mm_subs_epi16(a3,alpha_max);
      alpha_ptr[4] = _mm_subs_epi16(a4,alpha_max);
      alpha_ptr[5] = _mm_subs_epi16(a5,alpha_max);
      alpha_ptr[6] = _mm_subs_epi16(a6,alpha_max);
      alpha_ptr[7] = _mm_subs_epi16(a7,alpha_max);
    }
    // fill in remainder
    for (k=0;
929 930 931
    k<(l-((l>>3)<<3));
    k++){

932 933 934 935 936 937 938

      a1=_mm_load_si128(&alpha_ptr[1]);
      a3=_mm_load_si128(&alpha_ptr[3]);
      a5=_mm_load_si128(&alpha_ptr[5]);
      a7=_mm_load_si128(&alpha_ptr[7]);

      m_b0 = _mm_adds_epi16(a1,*m11p);  // m11
939
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
940 941 942 943 944 945 946 947 948 949 950
      m_b1 = _mm_subs_epi16(a3,*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi16(a3,*m10p);  // m10
      m_b2 = _mm_adds_epi16(a5,*m10p);  // m10
      m_b6 = _mm_subs_epi16(a5,*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi16(a7,*m11p);  // m00=-m11
      m_b7 = _mm_adds_epi16(a7,*m11p);  // m11

      a0=_mm_load_si128(&alpha_ptr[0]);
      a2=_mm_load_si128(&alpha_ptr[2]);
      a4=_mm_load_si128(&alpha_ptr[4]);
      a6=_mm_load_si128(&alpha_ptr[6]);
951

952 953 954 955 956 957 958 959
      new0 = _mm_subs_epi16(a0,*m11p);  // m00=-m11
      new4 = _mm_adds_epi16(a0,*m11p);  // m11
      new1 = _mm_adds_epi16(a2,*m10p);  // m10
      new5 = _mm_subs_epi16(a2,*m10p);  // m01=-m10
      new2 = _mm_subs_epi16(a4,*m10p);  // m01=-m10
      new6 = _mm_adds_epi16(a4,*m10p);  // m10
      new3 = _mm_adds_epi16(a6,*m11p);  // m11
      new7 = _mm_subs_epi16(a6,*m11p);  // m00=-m11
960

961 962 963 964 965 966 967 968
      a0 = _mm_max_epi16(m_b0,new0);
      a1 = _mm_max_epi16(m_b1,new1);
      a2 = _mm_max_epi16(m_b2,new2);
      a3 = _mm_max_epi16(m_b3,new3);
      a4 = _mm_max_epi16(m_b4,new4);
      a5 = _mm_max_epi16(m_b5,new5);
      a6 = _mm_max_epi16(m_b6,new6);
      a7 = _mm_max_epi16(m_b7,new7);
969

970 971 972 973 974 975 976 977 978 979 980 981
      alpha_ptr += 8;
      m11p++;
      m10p++;
      alpha_ptr[0] = a0;
      alpha_ptr[1] = a1;
      alpha_ptr[2] = a2;
      alpha_ptr[3] = a3;
      alpha_ptr[4] = a4;
      alpha_ptr[5] = a5;
      alpha_ptr[6] = a6;
      alpha_ptr[7] = a7;
    }
982
    */
983 984 985 986 987 988 989 990 991 992 993 994 995 996
#else


    if (rerun_flag == 0) {

      alpha128[0] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,0);
      alpha128[1] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[2] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[3] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[4] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[5] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[6] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);
      alpha128[7] = _mm_set_epi8(-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2,-MAX/2);

997 998

    } else {
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
      alpha128[0] = _mm_slli_si128(alpha128[(K1<<3)],1);
      alpha128[1] = _mm_slli_si128(alpha128[1+(K1<<3)],1);
      alpha128[2] = _mm_slli_si128(alpha128[2+(K1<<3)],1);
      alpha128[3] = _mm_slli_si128(alpha128[3+(K1<<3)],1);
      alpha128[4] = _mm_slli_si128(alpha128[4+(K1<<3)],1);
      alpha128[5] = _mm_slli_si128(alpha128[5+(K1<<3)],1);
      alpha128[6] = _mm_slli_si128(alpha128[6+(K1<<3)],1);
      alpha128[7] = _mm_slli_si128(alpha128[7+(K1<<3)],1);
      alpha[16] =  -MAX/2;
      alpha[32] = -MAX/2;
      alpha[48] = -MAX/2;
      alpha[64] = -MAX/2;
      alpha[80] = -MAX/2;
      alpha[96] = -MAX/2;
      alpha[112] = -MAX/2;
    }
1015

1016
    alpha_ptr = &alpha128[0];
1017
    /*
1018
    printf("alpha k %d (%d) (%p)\n",0,0,alpha_ptr);
1019

1020 1021 1022 1023 1024 1025 1026
    print_bytes("a0:",&alpha_ptr[0]);
    print_bytes("a1:",&alpha_ptr[1]);
    print_bytes("a2:",&alpha_ptr[2]);
    print_bytes("a3:",&alpha_ptr[3]);
    print_bytes("a4:",&alpha_ptr[4]);
    print_bytes("a5:",&alpha_ptr[5]);
    print_bytes("a6:",&alpha_ptr[6]);
1027 1028
    print_bytes("a7:",&alpha_ptr[7]);
    */
1029 1030 1031 1032 1033

    m11p = (__m128i*)m_11;
    m10p = (__m128i*)m_10;

    for (k=0;
1034 1035 1036 1037
         k<l;
         k++) {


1038
      m_b0 = _mm_adds_epi8(alpha_ptr[1],*m11p);  // m11
1039
      m_b4 = _mm_subs_epi8(alpha_ptr[1],*m11p);  // m00=-m11
1040 1041 1042 1043 1044
      m_b1 = _mm_subs_epi8(alpha_ptr[3],*m10p);  // m01=-m10
      m_b5 = _mm_adds_epi8(alpha_ptr[3],*m10p);  // m10
      m_b2 = _mm_adds_epi8(alpha_ptr[5],*m10p);  // m10
      m_b6 = _mm_subs_epi8(alpha_ptr[5],*m10p);  // m01=-m10
      m_b3 = _mm_subs_epi8(alpha_ptr[7],*m11p);  // m00=-m11
1045 1046
      m_b7 = _mm_adds_epi8(alpha_ptr[7],*m11p);  // m11

1047 1048 1049 1050 1051 1052 1053 1054
      new0 = _mm_subs_epi8(alpha_ptr[0],*m11p);  // m00=-m11
      new4 = _mm_adds_epi8(alpha_ptr[0],*m11p);  // m11
      new1 = _mm_adds_epi8(alpha_ptr[2],*m10p);  // m10
      new5 = _mm_subs_epi8(alpha_ptr[2],*m10p);  // m01=-m10
      new2 = _mm_subs_epi8(alpha_ptr[4],*m10p);  // m01=-m10
      new6 = _mm_adds_epi8(alpha_ptr[4],*m10p);  // m10
      new3 = _mm_adds_epi8(alpha_ptr[6],*m11p);  // m11
      new7 = _mm_subs_epi8(alpha_ptr[6],*m11p);  // m00=-m11
1055

1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
      alpha_ptr += 8;
      m11p++;
      m10p++;
      alpha_ptr[0] = _mm_max_epi8(m_b0,new0);
      alpha_ptr[1] = _mm_max_epi8(m_b1,new1);
      alpha_ptr[2] = _mm_max_epi8(m_b2,new2);
      alpha_ptr[3] = _mm_max_epi8(m_b3,new3);
      alpha_ptr[4] = _mm_max_epi8(m_b4,new4);
      alpha_ptr[5] = _mm_max_epi8(m_b5,new5);
      alpha_ptr[6] = _mm_max_epi8(m_b6,new6);
      alpha_ptr[7] = _mm_max_epi8(m_b7,new7);
1067 1068


1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
      // compute and subtract maxima
      alpha_max = _mm_max_epi8(alpha_ptr[0],alpha_ptr[1]);
      alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[2]);
      alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[3]);
      alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[4]);
      alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[5]);
      alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[6]);
      alpha_max = _mm_max_epi8(alpha_max,alpha_ptr[7]);

      alpha_ptr[0] = _mm_subs_epi8(alpha_ptr[0],alpha_max);
      alpha_ptr[1] = _mm_subs_epi8(alpha_ptr[1],alpha_max);
      alpha_ptr[2] = _mm_subs_epi8(alpha_ptr[2],alpha_max);
      alpha_ptr[3] = _mm_subs_epi8(alpha_ptr[3],alpha_max);
      alpha_ptr[4] = _mm_subs_epi8(alpha_ptr[4],alpha_max);
      alpha_ptr[5] = _mm_subs_epi8(alpha_ptr[5],alpha_max);
      alpha_ptr[6] = _mm_subs_epi8(alpha_ptr[6],alpha_max);
      alpha_ptr[7] = _mm_subs_epi8(alpha_ptr[7],alpha_max);
1086
      /*
1087
      printf("alpha k %d (%d) (%p)\n",k+1,(k+1)<<4,alpha_ptr);
1088

1089 1090 1091 1092 1093 1094 1095 1096 1097
      print_bytes("m11:",&m11_0);
      print_bytes("m10:",&m10_0);
      print_bytes("a0:",&alpha_ptr[0]);
      print_bytes("a1:",&alpha_ptr[1]);
      print_bytes("a2:",&alpha_ptr[2]);
      print_bytes("a3:",&alpha_ptr[3]);
      print_bytes("a4:",&alpha_ptr[4]);
      print_bytes("a5:",&alpha_ptr[5]);
      print_bytes("a6:",&alpha_ptr[6]);
1098
      print_bytes("a7:",&alpha_ptr[7]);
1099
      */
1100 1101
    }

1102
#endif
1103

1104 1105
    if (rerun_flag==1)
      break;
1106 1107
  }

1108 1109 1110 1111 1112
  _mm_empty();
  _m_empty();
}


1113 1114 1115
void compute_beta(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned short frame_length,unsigned char F,int offset8_flag)
{

1116 1117 1118 1119 1120 1121
  int k,rerun_flag=0;
  __m128i m11_128,m10_128;
  __m128i m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
  __m128i new0,new1,new2,new3,new4,new5,new6,new7;

  __m128i *beta128,*alpha128,*beta_ptr;
1122 1123
  __m128i beta_max;
  int16_t m11,m10,beta0_16,beta1_16,beta2_16,beta3_16,beta4_16,beta5_16,beta6_16,beta7_16,beta0_2,beta1_2,beta2_2,beta3_2,beta_m;
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
  llr_t beta0,beta1;
#ifdef LLR8
  llr_t beta2,beta3,beta4,beta5,beta6,beta7;
  __m128i beta_16;

#endif

#ifdef DEBUG_LOGMAP
  msg("compute_beta, %p,%p,%p,%p,framelength %d,F %d\n",
      beta,m_11,m_10,alpha,frame_length,F);
#endif


  // termination for beta initialization

  //  printf("beta init: offset8 %d\n",offset8_flag);
  m11=(int16_t)m_11[2+frame_length];
  m10=(int16_t)m_10[2+frame_length];

  //  printf("m11,m10 %d,%d\n",m11,m10);

  beta0 = -m11;//M0T_TERM;
  beta1 = m11;//M1T_TERM;
  m11=(int16_t)m_11[1+frame_length];
  m10=(int16_t)m_10[1+frame_length];

  //  printf("m11,m10 %d,%d\n",m11,m10);

  beta0_2 = beta0-m11;//+M0T_TERM;
  beta1_2 = beta0+m11;//+M1T_TERM;
  beta2_2 = beta1+m10;//M2T_TERM;
  beta3_2 = beta1-m10;//+M3T_TERM;
  m11=(int16_t)m_11[frame_length];
  m10=(int16_t)m_10[frame_length];
  //  printf("m11,m10 %d,%d (%p)\n",m11,m10,m_11+frame_length);

  beta0_16 = beta0_2-m11;//+M0T_TERM;
  beta1_16 = beta0_2+m11;//+M1T_TERM;
  beta2_16 = beta1_2+m10;//+M2T_TERM;
  beta3_16 = beta1_2-m10;//+M3T_TERM;
  beta4_16 = beta2_2-m10;//+M4T_TERM;
  beta5_16 = beta2_2+m10;//+M5T_TERM;
  beta6_16 = beta3_2+m11;//+M6T_TERM;
  beta7_16 = beta3_2-m11;//+M7T_TERM;
1168

1169 1170 1171 1172 1173 1174 1175 1176

  beta_m = (beta0_16>beta1_16) ? beta0_16 : beta1_16;
  beta_m = (beta_m>beta2_16) ? beta_m : beta2_16;
  beta_m = (beta_m>beta3_16) ? beta_m : beta3_16;
  beta_m = (beta_m>beta4_16) ? beta_m : beta4_16;
  beta_m = (beta_m>beta5_16) ? beta_m : beta5_16;
  beta_m = (beta_m>beta6_16) ? beta_m : beta6_16;
  beta_m = (beta_m>beta7_16) ? beta_m : beta7_16;
1177

1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201

  beta0_16=beta0_16-beta_m;
  beta1_16=beta1_16-beta_m;
  beta2_16=beta2_16-beta_m;
  beta3_16=beta3_16-beta_m;
  beta4_16=beta4_16-beta_m;
  beta5_16=beta5_16-beta_m;
  beta6_16=beta6_16-beta_m;
  beta7_16=beta7_16-beta_m;

#ifdef LLR8
  beta_16 = _mm_set_epi16(beta7_16,beta6_16,beta5_16,beta4_16,beta3_16,beta2_16,beta1_16,beta0_16);
  beta_16 = _mm_packs_epi16(beta_16,beta_16);
  beta0 = _mm_extract_epi8(beta_16,0);
  beta1 = _mm_extract_epi8(beta_16,1);
  beta2 = _mm_extract_epi8(beta_16,2);
  beta3 = _mm_extract_epi8(beta_16,3);
  beta4 = _mm_extract_epi8(beta_16,4);
  beta5 = _mm_extract_epi8(beta_16,5);
  beta6 = _mm_extract_epi8(beta_16,6);
  beta7 = _mm_extract_epi8(beta_16,7);
  //  printf("beta (init)    : %d,%d,%d,%d,%d,%d,%d,%d\n",(uint8_t)beta0,(uint8_t)beta1,(uint8_t)beta2,(uint8_t)beta3,(uint8_t)beta4,(uint8_t)beta5,(uint8_t)beta6,(uint8_t)beta7);
#endif

1202
  for (rerun_flag=0;; rerun_flag=1) {
1203 1204
    beta_ptr   = (__m128i*)&beta[frame_length<<3];
    alpha128   = (__m128i*)&alpha[0];
1205

1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
    if (rerun_flag == 0) {
#ifndef LLR8
      beta_ptr[0] = alpha128[(frame_length)];
      beta_ptr[1] = alpha128[1+(frame_length)];
      beta_ptr[2] = alpha128[2+(frame_length)];
      beta_ptr[3] = alpha128[3+(frame_length)];
      beta_ptr[4] = alpha128[4+(frame_length)];
      beta_ptr[5] = alpha128[5+(frame_length)];
      beta_ptr[6] = alpha128[6+(frame_length)];
      beta_ptr[7] = alpha128[7+(frame_length)];
#else
      beta_ptr[0] = alpha128[(frame_length>>1)];
      beta_ptr[1] = alpha128[1+(frame_length>>1)];
      beta_ptr[2] = alpha128[2+(frame_length>>1)];
      beta_ptr[3] = alpha128[3+(frame_length>>1)];
      beta_ptr[4] = alpha128[4+(frame_length>>1)];
      beta_ptr[5] = alpha128[5+(frame_length>>1)];
      beta_ptr[6] = alpha128[6+(frame_length>>1)];
      beta_ptr[7] = alpha128[7+(frame_length>>1)];
#endif
1226
    } else {
1227 1228
      beta128 = (__m128i*)&beta[0];
#ifndef LLR8
1229

1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
      beta_ptr[0] = _mm_srli_si128(beta128[0],2);
      beta_ptr[1] = _mm_srli_si128(beta128[1],2);
      beta_ptr[2] = _mm_srli_si128(beta128[2],2);
      beta_ptr[3] = _mm_srli_si128(beta128[3],2);
      beta_ptr[4] = _mm_srli_si128(beta128[4],2);
      beta_ptr[5] = _mm_srli_si128(beta128[5],2);
      beta_ptr[6] = _mm_srli_si128(beta128[6],2);
      beta_ptr[7] = _mm_srli_si128(beta128[7],2);
#else
      beta_ptr[0] = _mm_srli_si128(beta128[0],1);
      beta_ptr[1] = _mm_srli_si128(beta128[1],1);
      beta_ptr[2] = _mm_srli_si128(beta128[2],1);
      beta_ptr[3] = _mm_srli_si128(beta128[3],1);
      beta_ptr[4] = _mm_srli_si128(beta128[4],1);
      beta_ptr[5] = _mm_srli_si128(beta128[5],1);
      beta_ptr[6] = _mm_srli_si128(beta128[6],1);
      beta_ptr[7] = _mm_srli_si128(beta128[7],1);
#endif
    }

1250
#ifndef LLR8
1251 1252 1253 1254 1255 1256 1257 1258
    beta_ptr[0] = _mm_insert_epi16(beta_ptr[0],beta0_16,7);
    beta_ptr[1] = _mm_insert_epi16(beta_ptr[1],beta1_16,7);
    beta_ptr[2] = _mm_insert_epi16(beta_ptr[2],beta2_16,7);
    beta_ptr[3] = _mm_insert_epi16(beta_ptr[3],beta3_16,7);
    beta_ptr[4] = _mm_insert_epi16(beta_ptr[4],beta4_16,7);
    beta_ptr[5] = _mm_insert_epi16(beta_ptr[5],beta5_16,7);
    beta_ptr[6] = _mm_insert_epi16(beta_ptr[6],beta6_16,7);
    beta_ptr[7] = _mm_insert_epi16(beta_ptr[7],beta7_16,7);
1259

1260 1261 1262 1263 1264 1265 1266 1267
    /*
      beta[7+(frame_length<<3)] = beta0_16;
      beta[15+(frame_length<<3)] = beta1_16;
      beta[23+(frame_length<<3)] = beta2_16;
      beta[31+(frame_length<<3)] = beta3_16;
      beta[39+(frame_length<<3)] = beta4_16;
      beta[47+(frame_length<<3)] = beta5_16;
      beta[55+(frame_length<<3)] = beta6_16;
1268
      beta[63+(frame_length<<3)] = beta7_16;*/
1269
#else
1270

1271 1272 1273 1274 1275 1276 1277 1278 1279
    if (offset8_flag==0) {
      beta_ptr[0] = _mm_insert_epi8(beta_ptr[0],beta0,15);
      beta_ptr[1] = _mm_insert_epi8(beta_ptr[1],beta1,15);
      beta_ptr[2] = _mm_insert_epi8(beta_ptr[2],beta2,15);
      beta_ptr[3] = _mm_insert_epi8(beta_ptr[3],beta3,15);
      beta_ptr[4] = _mm_insert_epi8(beta_ptr[4],beta4,15);
      beta_ptr[5] = _mm_insert_epi8(beta_ptr[5],beta5,15);
      beta_ptr[6] = _mm_insert_epi8(beta_ptr[6],beta6,15);
      beta_ptr[7] = _mm_insert_epi8(beta_ptr[7],beta7,15);
1280
    } else {
1281 1282

    }
1283

1284
#endif
1285 1286

#ifndef LLR8
1287
    int loopval=((rerun_flag==0)?0:((frame_length-L)>>3));
1288 1289 1290

    for (k=(frame_length>>3)-1; k>=loopval; k--) {
      m11_128=((__m128i*)m_11)[k];
1291 1292 1293 1294 1295 1296
      m10_128=((__m128i*)m_10)[k];

      m_b0 = _mm_adds_epi16(beta_ptr[4],m11_128);  //m11
      m_b1 = _mm_subs_epi16(beta_ptr[4],m11_128);  //m00
      m_b2 = _mm_subs_epi16(beta_ptr[5],m10_128);  //m01
      m_b3 = _mm_adds_epi16(beta_ptr[5],m10_128);  //m10
1297
      m_b4 = _mm_adds_epi16(beta_ptr[6],m10_128);  //m10
1298 1299 1300
      m_b5 = _mm_subs_epi16(beta_ptr[6],m10_128);  //m01
      m_b6 = _mm_subs_epi16(beta_ptr[7],m11_128);  //m00
      m_b7 = _mm_adds_epi16(beta_ptr[7],m11_128);  //m11
1301

1302 1303 1304 1305 1306 1307 1308 1309
      new0 = _mm_subs_epi16(beta_ptr[0],m11_128);  //m00
      new1 = _mm_adds_epi16(beta_ptr[0],m11_128);  //m11
      new2 = _mm_adds_epi16(beta_ptr[1],m10_128);  //m10
      new3 = _mm_subs_epi16(beta_ptr[1],m10_128);  //m01
      new4 = _mm_subs_epi16(beta_ptr[2],m10_128);  //m01
      new5 = _mm_adds_epi16(beta_ptr[2],m10_128);  //m10
      new6 = _mm_adds_epi16(beta_ptr[3],m11_128);  //m11
      new7 = _mm_subs_epi16(beta_ptr[3],m11_128);  //m00
1310

1311
      beta_ptr-=8;
1312

1313 1314 1315 1316 1317 1318 1319 1320
      beta_ptr[0] = _mm_max_epi16(m_b0,new0);
      beta_ptr[1] = _mm_max_epi16(m_b1,new1);
      beta_ptr[2] = _mm_max_epi16(m_b2,new2);
      beta_ptr[3] = _mm_max_epi16(m_b3,new3);
      beta_ptr[4] = _mm_max_epi16(m_b4,new4);
      beta_ptr[5] = _mm_max_epi16(m_b5,new5);
      beta_ptr[6] = _mm_max_epi16(m_b6,new6);
      beta_ptr[7] = _mm_max_epi16(m_b7,new7);
1321

1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
      beta_max = _mm_max_epi16(beta_ptr[0],beta_ptr[1]);
      beta_max = _mm_max_epi16(beta_max   ,beta_ptr[2]);
      beta_max = _mm_max_epi16(beta_max   ,beta_ptr[3]);
      beta_max = _mm_max_epi16(beta_max   ,beta_ptr[4]);
      beta_max = _mm_max_epi16(beta_max   ,beta_ptr[5]);
      beta_max = _mm_max_epi16(beta_max   ,beta_ptr[6]);
      beta_max = _mm_max_epi16(beta_max   ,beta_ptr[7]);

      beta_ptr[0] = _mm_subs_epi16(beta_ptr[0],beta_max);
      beta_ptr[1] = _mm_subs_epi16(beta_ptr[1],beta_max);
      beta_ptr[2] = _mm_subs_epi16(beta_ptr[2],beta_max);
      beta_ptr[3] = _mm_subs_epi16(beta_ptr[3],beta_max);
      beta_ptr[4] = _mm_subs_epi16(beta_ptr[4],beta_max);
      beta_ptr[5] = _mm_subs_epi16(beta_ptr[5],beta_max);
1336
      beta_ptr[6] = _mm_subs_epi16(beta_ptr[6],beta_max);
1337
      beta_ptr[7] = _mm_subs_epi16(beta_ptr[7],beta_max);
1338

1339 1340 1341 1342 1343 1344 1345


    }

#else
#ifdef DEBUG_LOGMAP
    printf("beta0 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
           (frame_length>>4),
           _mm_extract_epi8(beta_ptr[0],0),
           _mm_extract_epi8(beta_ptr[0],1),
           _mm_extract_epi8(beta_ptr[0],2),
           _mm_extract_epi8(beta_ptr[0],3),
           _mm_extract_epi8(beta_ptr[0],4),
           _mm_extract_epi8(beta_ptr[0],5),
           _mm_extract_epi8(beta_ptr[0],6),
           _mm_extract_epi8(beta_ptr[0],7),
           _mm_extract_epi8(beta_ptr[0],8),
           _mm_extract_epi8(beta_ptr[0],9),
           _mm_extract_epi8(beta_ptr[0],10),
           _mm_extract_epi8(beta_ptr[0],11),
           _mm_extract_epi8(beta_ptr[0],12),
           _mm_extract_epi8(beta_ptr[0],13),
           _mm_extract_epi8(beta_ptr[0],14),
           _mm_extract_epi8(beta_ptr[0],15));
1363
    printf("beta1 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
           (frame_length>>4),
           _mm_extract_epi8(beta_ptr[1],0),
           _mm_extract_epi8(beta_ptr[1],1),
           _mm_extract_epi8(beta_ptr[1],2),
           _mm_extract_epi8(beta_ptr[1],3),
           _mm_extract_epi8(beta_ptr[1],4),
           _mm_extract_epi8(beta_ptr[1],5),
           _mm_extract_epi8(beta_ptr[1],6),
           _mm_extract_epi8(beta_ptr[1],7),
           _mm_extract_epi8(beta_ptr[1],8),
           _mm_extract_epi8(beta_ptr[1],9),
           _mm_extract_epi8(beta_ptr[1],10),
           _mm_extract_epi8(beta_ptr[1],11),
           _mm_extract_epi8(beta_ptr[1],12),
           _mm_extract_epi8(beta_ptr[1],13),
           _mm_extract_epi8(beta_ptr[1],14),
           _mm_extract_epi8(beta_ptr[1],15));
1381
    printf("beta2 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
           (frame_length>>4),
           _mm_extract_epi8(beta_ptr[2],0),
           _mm_extract_epi8(beta_ptr[2],1),
           _mm_extract_epi8(beta_ptr[2],2),
           _mm_extract_epi8(beta_ptr[2],3),
           _mm_extract_epi8(beta_ptr[2],4),
           _mm_extract_epi8(beta_ptr[2],5),
           _mm_extract_epi8(beta_ptr[2],6),
           _mm_extract_epi8(beta_ptr[2],7),
           _mm_extract_epi8(beta_ptr[2],8),
           _mm_extract_epi8(beta_ptr[2],9),
           _mm_extract_epi8(beta_ptr[2],10),
           _mm_extract_epi8(beta_ptr[2],11),
           _mm_extract_epi8(beta_ptr[2],12),
           _mm_extract_epi8(beta_ptr[2],13),
           _mm_extract_epi8(beta_ptr[2],14),
           _mm_extract_epi8(beta_ptr[2],15));
1399
    printf("beta3 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
           (frame_length>>4),
           _mm_extract_epi8(beta_ptr[3],0),
           _mm_extract_epi8(beta_ptr[3],1),
           _mm_extract_epi8(beta_ptr[3],2),
           _mm_extract_epi8(beta_ptr[3],3),
           _mm_extract_epi8(beta_ptr[3],4),
           _mm_extract_epi8(beta_ptr[3],5),
           _mm_extract_epi8(beta_ptr[3],6),
           _mm_extract_epi8(beta_ptr[3],7),
           _mm_extract_epi8(beta_ptr[3],8),
           _mm_extract_epi8(beta_ptr[3],9),
           _mm_extract_epi8(beta_ptr[3],10),
           _mm_extract_epi8(beta_ptr[3],11),
           _mm_extract_epi8(beta_ptr[3],12),
           _mm_extract_epi8(beta_ptr[3],13),
           _mm_extract_epi8(beta_ptr[3],14),
           _mm_extract_epi8(beta_ptr[3],15));
1417
    printf("beta4 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
           (frame_length>>4),
           _mm_extract_epi8(beta_ptr[4],0),
           _mm_extract_epi8(beta_ptr[4],1),
           _mm_extract_epi8(beta_ptr[4],2),
           _mm_extract_epi8(beta_ptr[4],3),
           _mm_extract_epi8(beta_ptr[4],4),
           _mm_extract_epi8(beta_ptr[4],5),
           _mm_extract_epi8(beta_ptr[4],6),
           _mm_extract_epi8(beta_ptr[4],7),
           _mm_extract_epi8(beta_ptr[4],8),
           _mm_extract_epi8(beta_ptr[4],9),
           _mm_extract_epi8(beta_ptr[4],10),
           _mm_extract_epi8(beta_ptr[4],11),
           _mm_extract_epi8(beta_ptr[4],12),
           _mm_extract_epi8(beta_ptr[4],13),
           _mm_extract_epi8(beta_ptr[4],14),
           _mm_extract_epi8(beta_ptr[4],15));
1435
    printf("beta5 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452
           (frame_length>>4),
           _mm_extract_epi8(beta_ptr[5],0),
           _mm_extract_epi8(beta_ptr[5],1),
           _mm_extract_epi8(beta_ptr[5],2),
           _mm_extract_epi8(beta_ptr[5],3),
           _mm_extract_epi8(beta_ptr[5],4),
           _mm_extract_epi8(beta_ptr[5],5),
           _mm_extract_epi8(beta_ptr[5],6),
           _mm_extract_epi8(beta_ptr[5],7),
           _mm_extract_epi8(beta_ptr[5],8),
           _mm_extract_epi8(beta_ptr[5],9),
           _mm_extract_epi8(beta_ptr[5],10),
           _mm_extract_epi8(beta_ptr[5],11),
           _mm_extract_epi8(beta_ptr[5],12),
           _mm_extract_epi8(beta_ptr[5],13),
           _mm_extract_epi8(beta_ptr[5],14),
           _mm_extract_epi8(beta_ptr[5],15));
1453
    printf("beta6 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470
           (frame_length>>4),
           _mm_extract_epi8(beta_ptr[6],0),
           _mm_extract_epi8(beta_ptr[6],1),
           _mm_extract_epi8(beta_ptr[6],2),
           _mm_extract_epi8(beta_ptr[6],3),
           _mm_extract_epi8(beta_ptr[6],4),
           _mm_extract_epi8(beta_ptr[6],5),
           _mm_extract_epi8(beta_ptr[6],6),
           _mm_extract_epi8(beta_ptr[6],7),
           _mm_extract_epi8(beta_ptr[6],8),
           _mm_extract_epi8(beta_ptr[6],9),
           _mm_extract_epi8(beta_ptr[6],10),
           _mm_extract_epi8(beta_ptr[6],11),
           _mm_extract_epi8(beta_ptr[6],12),
           _mm_extract_epi8(beta_ptr[6],13),
           _mm_extract_epi8(beta_ptr[6],14),
           _mm_extract_epi8(beta_ptr[6],15));
1471
    printf("beta7 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489
           (frame_length>>4),
           _mm_extract_epi8(beta_ptr[7],0),
           _mm_extract_epi8(beta_ptr[7],1),
           _mm_extract_epi8(beta_ptr[7],2),
           _mm_extract_epi8(beta_ptr[7],3),
           _mm_extract_epi8(beta_ptr[7],4),
           _mm_extract_epi8(beta_ptr[7],5),
           _mm_extract_epi8(beta_ptr[7],6),
           _mm_extract_epi8(beta_ptr[7],7),
           _mm_extract_epi8(beta_ptr[7],8),
           _mm_extract_epi8(beta_ptr[7],9),
           _mm_extract_epi8(beta_ptr[7],10),
           _mm_extract_epi8(beta_ptr[7],11),
           _mm_extract_epi8(beta_ptr[7],12),
           _mm_extract_epi8(beta_ptr[7],13),
           _mm_extract_epi8(beta_ptr[7],14),
           _mm_extract_epi8(beta_ptr[7],15));
#endif
1490
    int loopval=(rerun_flag==0)?0:((frame_length-L)>>4);
1491
    __m128i max_val=_mm_set1_epi8(32);
1492 1493
    __m128i zeros=_mm_set1_epi8(0);

1494 1495 1496
    for (k=(frame_length>>4)-1; k>=loopval; k--) {

      m11_128=((__m128i*)m_11)[k];
1497 1498 1499
      m10_128=((__m128i*)m_10)[k];
      /*
      if ((offset8_flag==1) && (k==((frame_length>>4)-9))) {
1500 1501 1502 1503 1504 1505 1506 1507 1508
      beta_ptr[0] = _mm_insert_epi8(beta_ptr[0],beta0,15);
      beta_ptr[1] = _mm_insert_epi8(beta_ptr[1],beta1,15);
      beta_ptr[2] = _mm_insert_epi8(beta_ptr[2],beta2,15);
      beta_ptr[3] = _mm_insert_epi8(beta_ptr[3],beta3,15);
      beta_ptr[4] = _mm_insert_epi8(beta_ptr[4],beta4,15);
      beta_ptr[5] = _mm_insert_epi8(beta_ptr[5],beta5,15);
      beta_ptr[6] = _mm_insert_epi8(beta_ptr[6],beta6,15);
      beta_ptr[7] = _mm_insert_epi8(beta_ptr[7],beta7,15);
      }*/
1509 1510 1511 1512 1513 1514 1515 1516
      //      print_bytes("m11:",&m11_128);



      m_b0 = _mm_adds_epi8(beta_ptr[4],m11_128);  //m11
      m_b1 = _mm_subs_epi8(beta_ptr[4],m11_128);  //m00
      m_b2 = _mm_subs_epi8(beta_ptr[5],m10_128);  //m01
      m_b3 = _mm_adds_epi8(beta_ptr[5],m10_128);  //m10
1517
      m_b4 = _mm_adds_epi8(beta_ptr[6],m10_128);  //m10
1518 1519 1520
      m_b5 = _mm_subs_epi8(beta_ptr[6],m10_128);  //m01
      m_b6 = _mm_subs_epi8(beta_ptr[7],m11_128);  //m00
      m_b7 = _mm_adds_epi8(beta_ptr[7],m11_128);  //m11
1521

1522 1523 1524 1525 1526 1527 1528 1529
      new0 = _mm_subs_epi8(beta_ptr[0],m11_128);  //m00
      new1 = _mm_adds_epi8(beta_ptr[0],m11_128);  //m11
      new2 = _mm_adds_epi8(beta_ptr[1],m10_128);  //m10
      new3 = _mm_subs_epi8(beta_ptr[1],m10_128);  //m01
      new4 = _mm_subs_epi8(beta_ptr[2],m10_128);  //m01
      new5 = _mm_adds_epi8(beta_ptr[2],m10_128);  //m10
      new6 = _mm_adds_epi8(beta_ptr[3],m11_128);  //m11
      new7 = _mm_subs_epi8(beta_ptr[3],m11_128);  //m00
1530

1531
      beta_ptr-=8;
1532

1533 1534 1535 1536 1537 1538 1539 1540
      beta_ptr[0] = _mm_max_epi8(m_b0,new0);
      beta_ptr[1] = _mm_max_epi8(m_b1,new1);
      beta_ptr[2] = _mm_max_epi8(m_b2,new2);
      beta_ptr[3] = _mm_max_epi8(m_b3,new3);
      beta_ptr[4] = _mm_max_epi8(m_b4,new4);
      beta_ptr[5] = _mm_max_epi8(m_b5,new5);
      beta_ptr[6] = _mm_max_epi8(m_b6,new6);
      beta_ptr[7] = _mm_max_epi8(m_b7,new7);
1541

1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
      beta_max = _mm_max_epi8(beta_ptr[0],beta_ptr[1]);
      beta_max = _mm_max_epi8(beta_max   ,beta_ptr[2]);
      beta_max = _mm_max_epi8(beta_max   ,beta_ptr[3]);
      beta_max = _mm_max_epi8(beta_max   ,beta_ptr[4]);
      beta_max = _mm_max_epi8(beta_max   ,beta_ptr[5]);
      beta_max = _mm_max_epi8(beta_max   ,beta_ptr[6]);
      beta_max = _mm_max_epi8(beta_max   ,beta_ptr[7]);
      beta_ptr[0] = _mm_subs_epi8(beta_ptr[0],beta_max);
      beta_ptr[1] = _mm_subs_epi8(beta_ptr[1],beta_max);
      beta_ptr[2] = _mm_subs_epi8(beta_ptr[2],beta_max);
      beta_ptr[3] = _mm_subs_epi8(beta_ptr[3],beta_max);
      beta_ptr[4] = _mm_subs_epi8(beta_ptr[4],beta_max);
      beta_ptr[5] = _mm_subs_epi8(beta_ptr[5],beta_max);
      beta_ptr[6] = _mm_subs_epi8(beta_ptr[6],beta_max);
      beta_ptr[7] = _mm_subs_epi8(beta_ptr[7],beta_max);

      /*
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 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
      printf("beta0 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
      k,
      _mm_extract_epi8(beta_ptr[0],0),
      _mm_extract_epi8(beta_ptr[0],1),
      _mm_extract_epi8(beta_ptr[0],2),
      _mm_extract_epi8(beta_ptr[0],3),
      _mm_extract_epi8(beta_ptr[0],4),
      _mm_extract_epi8(beta_ptr[0],5),
      _mm_extract_epi8(beta_ptr[0],6),
      _mm_extract_epi8(beta_ptr[0],7),
      _mm_extract_epi8(beta_ptr[0],8),
      _mm_extract_epi8(beta_ptr[0],9),
      _mm_extract_epi8(beta_ptr[0],10),
      _mm_extract_epi8(beta_ptr[0],11),
      _mm_extract_epi8(beta_ptr[0],12),
      _mm_extract_epi8(beta_ptr[0],13),
      _mm_extract_epi8(beta_ptr[0],14),
      _mm_extract_epi8(beta_ptr[0],15));
      printf("beta1 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
      k,
      _mm_extract_epi8(beta_ptr[1],0),
      _mm_extract_epi8(beta_ptr[1],1),
      _mm_extract_epi8(beta_ptr[1],2),
      _mm_extract_epi8(beta_ptr[1],3),
      _mm_extract_epi8(beta_ptr[1],4),
      _mm_extract_epi8(beta_ptr[1],5),
      _mm_extract_epi8(beta_ptr[1],6),
      _mm_extract_epi8(beta_ptr[1],7),
      _mm_extract_epi8(beta_ptr[1],8),
      _mm_extract_epi8(beta_ptr[1],9),
      _mm_extract_epi8(beta_ptr[1],10),
      _mm_extract_epi8(beta_ptr[1],11),
      _mm_extract_epi8(beta_ptr[1],12),
      _mm_extract_epi8(beta_ptr[1],13),
      _mm_extract_epi8(beta_ptr[1],14),
      _mm_extract_epi8(beta_ptr[1],15));
      printf("beta2 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
      k,
      _mm_extract_epi8(beta_ptr[2],0),
      _mm_extract_epi8(beta_ptr[2],1),
      _mm_extract_epi8(beta_ptr[2],2),
      _mm_extract_epi8(beta_ptr[2],3),
      _mm_extract_epi8(beta_ptr[2],4),
      _mm_extract_epi8(beta_ptr[2],5),
      _mm_extract_epi8(beta_ptr[2],6),
      _mm_extract_epi8(beta_ptr[2],7),
      _mm_extract_epi8(beta_ptr[2],8),
      _mm_extract_epi8(beta_ptr[2],9),
      _mm_extract_epi8(beta_ptr[2],10),
      _mm_extract_epi8(beta_ptr[2],11),
      _mm_extract_epi8(beta_ptr[2],12),
      _mm_extract_epi8(beta_ptr[2],13),
      _mm_extract_epi8(beta_ptr[2],14),
      _mm_extract_epi8(beta_ptr[2],15));
      printf("beta3 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
      k,
      _mm_extract_epi8(beta_ptr[3],0),
      _mm_extract_epi8(beta_ptr[3],1),
      _mm_extract_epi8(beta_ptr[3],2),
      _mm_extract_epi8(beta_ptr[3],3),
      _mm_extract_epi8(beta_ptr[3],4),
      _mm_extract_epi8(beta_ptr[3],5),
      _mm_extract_epi8(beta_ptr[3],6),
      _mm_extract_epi8(beta_ptr[3],7),
      _mm_extract_epi8(beta_ptr[3],8),
      _mm_extract_epi8(beta_ptr[3],9),
      _mm_extract_epi8(beta_ptr[3],10),
      _mm_extract_epi8(beta_ptr[3],11),
      _mm_extract_epi8(beta_ptr[3],12),
      _mm_extract_epi8(beta_ptr[3],13),
      _mm_extract_epi8(beta_ptr[3],14),
      _mm_extract_epi8(beta_ptr[3],15));
      printf("beta4 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
      k,
      _mm_extract_epi8(beta_ptr[4],0),
      _mm_extract_epi8(beta_ptr[4],1),
      _mm_extract_epi8(beta_ptr[4],2),
      _mm_extract_epi8(beta_ptr[4],3),
      _mm_extract_epi8(beta_ptr[4],4),
      _mm_extract_epi8(beta_ptr[4],5),
      _mm_extract_epi8(beta_ptr[4],6),
      _mm_extract_epi8(beta_ptr[4],7),
      _mm_extract_epi8(beta_ptr[4],8),
      _mm_extract_epi8(beta_ptr[4],9),
      _mm_extract_epi8(beta_ptr[4],10),
      _mm_extract_epi8(beta_ptr[4],11),
      _mm_extract_epi8(beta_ptr[4],12),
      _mm_extract_epi8(beta_ptr[4],13),
      _mm_extract_epi8(beta_ptr[4],14),
      _mm_extract_epi8(beta_ptr[4],15));
      printf("beta5 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
      k,
      _mm_extract_epi8(beta_ptr[5],0),
      _mm_extract_epi8(beta_ptr[5],1),
      _mm_extract_epi8(beta_ptr[5],2),
      _mm_extract_epi8(beta_ptr[5],3),
      _mm_extract_epi8(beta_ptr[5],4),
      _mm_extract_epi8(beta_ptr[5],5),
      _mm_extract_epi8(beta_ptr[5],6),
      _mm_extract_epi8(beta_ptr[5],7),
      _mm_extract_epi8(beta_ptr[5],8),
      _mm_extract_epi8(beta_ptr[5],9),
      _mm_extract_epi8(beta_ptr[5],10),
      _mm_extract_epi8(beta_ptr[5],11),
      _mm_extract_epi8(beta_ptr[5],12),
      _mm_extract_epi8(beta_ptr[5],13),
      _mm_extract_epi8(beta_ptr[5],14),
      _mm_extract_epi8(beta_ptr[5],15));
      printf("beta6 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
      k,
      _mm_extract_epi8(beta_ptr[6],0),
      _mm_extract_epi8(beta_ptr[6],1),
      _mm_extract_epi8(beta_ptr[6],2),
      _mm_extract_epi8(beta_ptr[6],3),
      _mm_extract_epi8(beta_ptr[6],4),
      _mm_extract_epi8(beta_ptr[6],5),
      _mm_extract_epi8(beta_ptr[6],6),
      _mm_extract_epi8(beta_ptr[6],7),
      _mm_extract_epi8(beta_ptr[6],8),
      _mm_extract_epi8(beta_ptr[6],9),
      _mm_extract_epi8(beta_ptr[6],10),
      _mm_extract_epi8(beta_ptr[6],11),
      _mm_extract_epi8(beta_ptr[6],12),
      _mm_extract_epi8(beta_ptr[6],13),
      _mm_extract_epi8(beta_ptr[6],14),
      _mm_extract_epi8(beta_ptr[6],15));
      printf("beta7 %d:  %03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d,%03d\n",
      k,
      _mm_extract_epi8(beta_ptr[7],0),
      _mm_extract_epi8(beta_ptr[7],1),
      _mm_extract_epi8(beta_ptr[7],2),
      _mm_extract_epi8(beta_ptr[7],3),
      _mm_extract_epi8(beta_ptr[7],4),
      _mm_extract_epi8(beta_ptr[7],5),
      _mm_extract_epi8(beta_ptr[7],6),
      _mm_extract_epi8(beta_ptr[7],7),
      _mm_extract_epi8(beta_ptr[7],8),
      _mm_extract_epi8(beta_ptr[7],9),
      _mm_extract_epi8(beta_ptr[7],10),
      _mm_extract_epi8(beta_ptr[7],11),
      _mm_extract_epi8(beta_ptr[7],12),
      _mm_extract_epi8(beta_ptr[7],13),
      _mm_extract_epi8(beta_ptr[7],14),
      _mm_extract_epi8(beta_ptr[7],15));
      */

1705
    }
1706

1707
#endif
1708

1709 1710 1711
    if (rerun_flag==1)
      break;
  }
1712

1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
  _mm_empty();
  _m_empty();
}

void compute_ext(llr_t* alpha,llr_t* beta,llr_t* m_11,llr_t* m_10,llr_t* ext, llr_t* systematic,unsigned short frame_length)
{
  __m128i *alpha128=(__m128i *)alpha;
  __m128i *beta128=(__m128i *)beta;
  __m128i *m11_128,*m10_128,*ext_128;
  __m128i *alpha_ptr,*beta_ptr;
  __m128i m00_1,m00_2,m00_3,m00_4;
  __m128i m01_1,m01_2,m01_3,m01_4;
  __m128i m10_1,m10_2,m10_3,m10_4;
  __m128i m11_1,m11_2,m11_3,m11_4;
  int k;

  //
  // LLR computation, 8 consequtive bits per loop
  //

#ifdef DEBUG_LOGMAP
  msg("compute_ext, %p, %p, %p, %p, %p, %p ,framelength %d\n",alpha,beta,m_11,m_10,ext,systematic,frame_length);
#endif

  alpha_ptr = alpha128;
  beta_ptr = &beta128[8];


#ifndef LLR8
1742 1743

  for (k=0; k<(frame_length>>3); k++) {
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765

    m11_128        = (__m128i*)&m_11[k<<3];
    m10_128        = (__m128i*)&m_10[k<<3];
    ext_128        = (__m128i*)&ext[k<<3];
    /*
      printf("EXT %03d\n",k);
      print_shorts("a0:",&alpha_ptr[0]);
      print_shorts("a1:",&alpha_ptr[1]);
      print_shorts("a2:",&alpha_ptr[2]);
      print_shorts("a3:",&alpha_ptr[3]);
      print_shorts("a4:",&alpha_ptr[4]);
      print_shorts("a5:",&alpha_ptr[5]);
      print_shorts("a6:",&alpha_ptr[6]);
      print_shorts("a7:",&alpha_ptr[7]);
      print_shorts("b0:",&beta_ptr[0]);
      print_shorts("b1:",&beta_ptr[1]);
      print_shorts("b2:",&beta_ptr[2]);
      print_shorts("b3:",&beta_ptr[3]);
      print_shorts("b4:",&beta_ptr[4]);
      print_shorts("b5:",&beta_ptr[5]);
      print_shorts("b6:",&beta_ptr[6]);
      print_shorts("b7:",&beta_ptr[7]);
1766
    */
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
    m00_4 = _mm_adds_epi16(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
    m11_4 = _mm_adds_epi16(alpha_ptr[7],beta_ptr[7]); //ALPHA_BETA_4m11;
    m00_3 = _mm_adds_epi16(alpha_ptr[6],beta_ptr[7]); //ALPHA_BETA_3m00;
    m11_3 = _mm_adds_epi16(alpha_ptr[6],beta_ptr[3]); //ALPHA_BETA_3m11;
    m00_2 = _mm_adds_epi16(alpha_ptr[1],beta_ptr[4]); //ALPHA_BETA_2m00;
    m11_2 = _mm_adds_epi16(alpha_ptr[1],beta_ptr[0]); //ALPHA_BETA_2m11;
    m11_1 = _mm_adds_epi16(alpha_ptr[0],beta_ptr[4]); //ALPHA_BETA_1m11;
    m00_1 = _mm_adds_epi16(alpha_ptr[0],beta_ptr[0]); //ALPHA_BETA_1m00;
    m01_4 = _mm_adds_epi16(alpha_ptr[5],beta_ptr[6]); //ALPHA_BETA_4m01;
    m10_4 = _mm_adds_epi16(alpha_ptr[5],beta_ptr[2]); //ALPHA_BETA_4m10;
    m01_3 = _mm_adds_epi16(alpha_ptr[4],beta_ptr[2]); //ALPHA_BETA_3m01;
    m10_3 = _mm_adds_epi16(alpha_ptr[4],beta_ptr[6]); //ALPHA_BETA_3m10;
    m01_2 = _mm_adds_epi16(alpha_ptr[3],beta_ptr[1]); //ALPHA_BETA_2m01;
    m10_2 = _mm_adds_epi16(alpha_ptr[3],beta_ptr[5]); //ALPHA_BETA_2m10;
    m10_1 = _mm_adds_epi16(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
    m01_1 = _mm_adds_epi16(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
    /*
      print_shorts("m11_1:",&m11_1);
      print_shorts("m11_2:",&m11_2);
      print_shorts("m11_3:",&m11_3);
      print_shorts("m11_4:",&m11_4);
      print_shorts("m00_1:",&m00_1);
      print_shorts("m00_2:",&m00_2);
      print_shorts("m00_3:",&m00_3);
      print_shorts("m00_4:",&m00_4);
      print_shorts("m10_1:",&m10_1);
      print_shorts("m10_2:",&m10_2);
      print_shorts("m10_3:",&m10_3);
      print_shorts("m10_4:",&m10_4);
      print_shorts("m01_1:",&m01_1);
      print_shorts("m01_2:",&m01_2);
      print_shorts("m01_3:",&m01_3);
      print_shorts("m01_4:",&m01_4);
    */
    m01_1 = _mm_max_epi16(m01_1,m01_2);
    m01_1 = _mm_max_epi16(m01_1,m01_3);
    m01_1 = _mm_max_epi16(m01_1,m01_4);
    m00_1 = _mm_max_epi16(m00_1,m00_2);
    m00_1 = _mm_max_epi16(m00_1,m00_3);
    m00_1 = _mm_max_epi16(m00_1,m00_4);
    m10_1 = _mm_max_epi16(m10_1,m10_2);
    m10_1 = _mm_max_epi16(m10_1,m10_3);
    m10_1 = _mm_max_epi16(m10_1,m10_4);
    m11_1 = _mm_max_epi16(m11_1,m11_2);
    m11_1 = _mm_max_epi16(m11_1,m11_3);
    m11_1 = _mm_max_epi16(m11_1,m11_4);

    //      print_shorts("m11_1:",&m11_1);
1815

1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828
    m01_1 = _mm_subs_epi16(m01_1,*m10_128);
    m00_1 = _mm_subs_epi16(m00_1,*m11_128);
    m10_1 = _mm_adds_epi16(m10_1,*m10_128);
    m11_1 = _mm_adds_epi16(m11_1,*m11_128);

    //      print_shorts("m10_1:",&m10_1);
    //      print_shorts("m11_1:",&m11_1);
    m01_1 = _mm_max_epi16(m01_1,m00_1);
    m10_1 = _mm_max_epi16(m10_1,m11_1);
    //      print_shorts("m01_1:",&m01_1);
    //      print_shorts("m10_1:",&m10_1);

    *ext_128 = _mm_subs_epi16(m10_1,m01_1);
1829

1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844
    /*
      print_shorts("ext:",ext_128);
      print_shorts("m11:",m11_128);
      print_shorts("m10:",m10_128);
      print_shorts("m10_1:",&m10_1);
      print_shorts("m01_1:",&m01_1);
      print_shorts("syst:",systematic_128);
    */

    alpha_ptr+=8;
    beta_ptr+=8;
  }

#else

gauthier's avatar