3gpplte_turbo_decoder_sse_16bit.c 58.8 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_16bit.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
28

   Note: This version of the routine currently requires SSE2,SSSE3 and SSE4.1 equipped computers.  It uses 16-bit inputs for
         LLRS and uses 16-bit arithmetic for the internal computations!
29

30
31
32
33
34
35
36
37
38
39
   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)
   May 2013 Extracted 16bit code
*/

///
///

knopp's avatar
knopp committed
40
#undef __AVX2__
41
#include "PHY/sse_intrin.h"
42

43
#ifndef TEST_DEBUG
44
45
46
47
  #include "PHY/impl_defs_top.h"
  #include "PHY/defs_common.h"
  #include "PHY/CODING/coding_defs.h"
  #include "PHY/CODING/lte_interleaver_inline.h"
48
49
#else

50
51
52
53
  #include "defs.h"
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
54
55
56
#endif

#ifdef MEX
57
  #include "mex.h"
58
59
#endif

60
61
62
//#define DEBUG_LOGMAP

#ifdef DEBUG_LOGMAP
63
  #define print_shorts(s,x) fprintf(fdsse4,"%s %d,%d,%d,%d,%d,%d,%d,%d\n",s,(x)[0],(x)[1],(x)[2],(x)[3],(x)[4],(x)[5],(x)[6],(x)[7])
64
#endif
65

66
#undef __AVX2__
67

68
#ifdef DEBUG_LOGMAP
69
  FILE *fdsse4;
70
#endif
71

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

76
void log_map16(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,
77
               int offset8_flag,time_stats_t *alpha_stats,time_stats_t *beta_stats,time_stats_t *gamma_stats,time_stats_t *ext_stats);
78
79
80
81
void compute_gamma16(llr_t *m11,llr_t *m10,llr_t *systematic, channel_t *y_parity, unsigned short frame_length,unsigned char term_flag);
void compute_alpha16(llr_t *alpha,llr_t *beta, llr_t *m11,llr_t *m10, unsigned short frame_length,unsigned char F);
void compute_beta16(llr_t *alpha, llr_t *beta,llr_t *m11,llr_t *m10, unsigned short frame_length,unsigned char F,int offset8_flag);
void compute_ext16(llr_t *alpha,llr_t *beta,llr_t *m11,llr_t *m10,llr_t *extrinsic, llr_t *ap, unsigned short frame_length);
82
83


84
85
86
87
void log_map16(llr_t *systematic,
               channel_t *y_parity,
               llr_t *m11,
               llr_t *m10,
88
89
               llr_t *alpha,
               llr_t *beta,
90
               llr_t *ext,
91
92
93
94
95
96
97
               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,
98
               time_stats_t *ext_stats) {
99
#ifdef DEBUG_LOGMAP
100
  fprintf(fdsse4,"log_map, frame_length %d\n",frame_length);
101
#endif
102
103
104
105
106
107
108
109
110
111
112
113
  start_meas(gamma_stats) ;
  compute_gamma16(m11,m10,systematic,y_parity,frame_length,term_flag) ;
  stop_meas(gamma_stats);
  start_meas(alpha_stats) ;
  compute_alpha16(alpha,beta,m11,m10,frame_length,F)                  ;
  stop_meas(alpha_stats);
  start_meas(beta_stats)  ;
  compute_beta16(alpha,beta,m11,m10,frame_length,F,offset8_flag)      ;
  stop_meas(beta_stats);
  start_meas(ext_stats)   ;
  compute_ext16(alpha,beta,m11,m10,ext,systematic,frame_length)       ;
  stop_meas(ext_stats);
114
115
}

116
117
void compute_gamma16(llr_t *m11,llr_t *m10,llr_t *systematic,channel_t *y_parity,
                     unsigned short frame_length,unsigned char term_flag) {
118
  int k,K1;
119
#if defined(__x86_64__)||defined(__i386__)
120
121
122
123
  __m128i *systematic128 = (__m128i *)systematic;
  __m128i *y_parity128   = (__m128i *)y_parity;
  __m128i *m10_128        = (__m128i *)m10;
  __m128i *m11_128        = (__m128i *)m11;
124
125
126
127
128
129
#elif defined(__arm__)
  int16x8_t *systematic128  = (int16x8_t *)systematic;
  int16x8_t *y_parity128    = (int16x8_t *)y_parity;
  int16x8_t *m10_128        = (int16x8_t *)m10;
  int16x8_t *m11_128        = (int16x8_t *)m11;
#endif
130
#ifdef DEBUG_LOGMAP
131
  fprintf(fdsse4,"compute_gamma (sse_16bit), %p,%p,%p,%p,framelength %d\n",m11,m10,systematic,y_parity,frame_length);
132
#endif
133
#ifndef __AVX2__
134
  K1=frame_length>>3;
135
#else
136

137
138
139
140
  if ((frame_length&15) > 0)
    K1=(frame_length+1)>>4;
  else
    K1=frame_length>>4;
141

142
#endif
143
144

  for (k=0; k<K1; k++) {
145
#if defined(__x86_64__) || defined(__i386__)
146
#ifndef __AVX2__
147
148
    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);
149
#else
150
    ((__m256i *)m11_128)[k] = _mm256_srai_epi16(_mm256_adds_epi16(((__m256i *)systematic128)[k],((__m256i *)y_parity128)[k]),1);
151
    //    ((__m256i*)m10_128)[k] = _mm256_srai_epi16(_mm256_subs_epi16(((__m256i*)y_parity128)[k],((__m256i*)systematic128)[k]),1);
152
    ((__m256i *)m10_128)[k] = _mm256_srai_epi16(_mm256_subs_epi16(((__m256i *)systematic128)[k],((__m256i *)y_parity128)[k]),1);
153
#endif
154
155
156
157
158
#elif defined(__arm__)
    m11_128[k] = vhaddq_s16(systematic128[k],y_parity128[k]);
    m10_128[k] = vhsubq_s16(systematic128[k],y_parity128[k]);
#endif
#ifdef DEBUG_LOGMAP
159
    fprintf(fdsse4,"Loop index k %d\n", k);
160
161
162
163
    print_shorts("sys",(int16_t *)&systematic128[k]);
    print_shorts("yp",(int16_t *)&y_parity128[k]);
    print_shorts("m11",(int16_t *)&m11_128[k]);
    print_shorts("m10",(int16_t *)&m10_128[k]);
164
#endif
165
  }
166

167
  k=frame_length>>3;
168
  // Termination
169
#if defined(__x86_64__) || defined(__i386__)
170
  m11_128[k] = _mm_srai_epi16(_mm_adds_epi16(systematic128[k+term_flag],y_parity128[k]),1);
171
172
  //#ifndef __AVX2__
#if 1
173
  m10_128[k] = _mm_srai_epi16(_mm_subs_epi16(systematic128[k+term_flag],y_parity128[k]),1);
174
175
176
#else
  m10_128[k] = _mm_srai_epi16(_mm_subs_epi16(y_parity128[k],systematic128[k+term_flag]),1);
#endif
177
178
#elif defined(__arm__)
  m11_128[k] = vhaddq_s16(systematic128[k+term_flag],y_parity128[k]);
179
  m10_128[k] = vhsubq_s16(systematic128[k+term_flag],y_parity128[k]);
180
181
#endif
#ifdef DEBUG_LOGMAP
182
183
184
185
186
  fprintf(fdsse4,"Loop index k %d (term flag %d)\n", k,term_flag);
  print_shorts("sys",(int16_t *)&systematic128[k]);
  print_shorts("yp",(int16_t *)&y_parity128[k]);
  print_shorts("m11",(int16_t *)&m11_128[k]);
  print_shorts("m10",(int16_t *)&m10_128[k]);
187
#endif
188
189
190
191
}

#define L 40

192
void compute_alpha16(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,unsigned short frame_length,unsigned char F) {
193
  int k,l,l2,K1,rerun_flag=0;
194
#if defined(__x86_64__) || defined(__i386__)
195
196
197
198
  __m128i *alpha128=(__m128i *)alpha,*alpha_ptr,*m11p,*m10p;
  //#ifndef __AVX2__
#if 1
  __m128i a0,a1,a2,a3,a4,a5,a6,a7;
199
200
201
  __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;
202
203
204
205
206
207
208
#else
  __m256i *alpha256=(__m256i *)alpha,*alpha_ptr256,m11,m10;
  __m256i a01,a23,a45,a67,a02,a13,a64,a75;
  __m256i m_b01,m_b23,m_b45,m_b67,new01,new23,new45,new67;
  __m256i m11m10_256;
  __m256i alpha_max;
#endif
209
210
211
212
213
214
215
#elif defined(__arm__)
  int16x8_t *alpha128=(int16x8_t *)alpha,*alpha_ptr;
  int16x8_t a0,a1,a2,a3,a4,a5,a6,a7,*m11p,*m10p;
  int16x8_t m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
  int16x8_t new0,new1,new2,new3,new4,new5,new6,new7;
  int16x8_t alpha_max;
#endif
216
217
  l2 = L>>3;
  K1 = (frame_length>>3);
218
219
220
#ifdef DEBUG_LOGMAP
  fprintf(fdsse4,"compute_alpha (sse_16bit)\n");
#endif
221

222
  for (l=K1;; l=l2,rerun_flag=1) {
223
#if defined(__x86_64__) || defined(__i386__)
224
    alpha128 = (__m128i *)alpha;
225
    //#ifdef __AVX2__
226
227
228
#elif defined(__arm__)
    alpha128 = (int16x8_t *)alpha;
#endif
229

230
    if (rerun_flag == 0) {
231
#if defined(__x86_64__) || defined(__i386__)
232
233
234
235
236
237
238
239
      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);
240
241
242
243
244
245
246
247
248
249
250
251
#elif defined(__arm__)
      alpha128[0] = vdupq_n_s16(-MAX/2);
      alpha128[0] = vsetq_lane_s16(0,alpha128[0],0);
      alpha128[1] = vdupq_n_s16(-MAX/2);
      alpha128[2] = vdupq_n_s16(-MAX/2);
      alpha128[3] = vdupq_n_s16(-MAX/2);
      alpha128[4] = vdupq_n_s16(-MAX/2);
      alpha128[5] = vdupq_n_s16(-MAX/2);
      alpha128[6] = vdupq_n_s16(-MAX/2);
      alpha128[7] = vdupq_n_s16(-MAX/2);
#endif
#ifdef DEBUG_LOGMAP
252
      fprintf(fdsse4,"Initial alpha\n");
253
254
255
256
257
258
259
260
      print_shorts("a0",(int16_t *)&alpha128[0]);
      print_shorts("a1",(int16_t *)&alpha128[1]);
      print_shorts("a2",(int16_t *)&alpha128[2]);
      print_shorts("a3",(int16_t *)&alpha128[3]);
      print_shorts("a4",(int16_t *)&alpha128[4]);
      print_shorts("a5",(int16_t *)&alpha128[5]);
      print_shorts("a6",(int16_t *)&alpha128[6]);
      print_shorts("a7",(int16_t *)&alpha128[7]);
261
#endif
262
    } else {
263
      //set initial alpha in columns 1-7 from final alpha from last run in columns 0-6
264
#if defined(__x86_64__) || defined(__i386__)
265
266
267
268
269
270
271
272
      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);
273
#elif defined(__arm__)
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
      alpha128[0] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[frame_length],16);
      alpha128[0] = vsetq_lane_s16(alpha[8],alpha128[0],3);
      alpha128[1] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[1+frame_length],16);
      alpha128[1] = vsetq_lane_s16(alpha[24],alpha128[0],3);
      alpha128[2] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[2+frame_length],16);
      alpha128[2] = vsetq_lane_s16(alpha[40],alpha128[0],3);
      alpha128[3] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[3+frame_length],16);
      alpha128[3] = vsetq_lane_s16(alpha[56],alpha128[0],3);
      alpha128[4] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[4+frame_length],16);
      alpha128[4] = vsetq_lane_s16(alpha[72],alpha128[0],3);
      alpha128[5] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[5+frame_length],16);
      alpha128[5] = vsetq_lane_s16(alpha[88],alpha128[0],3);
      alpha128[6] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[6+frame_length],16);
      alpha128[6] = vsetq_lane_s16(alpha[104],alpha128[0],3);
      alpha128[7] = (int16x8_t)vshlq_n_s64((int64x2_t)alpha128[7+frame_length],16);
      alpha128[7] = vsetq_lane_s16(alpha[120],alpha128[0],3);
290
#endif
291
292
293
294
295
296
297
298
      // 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;
299
#ifdef DEBUG_LOGMAP
300
      fprintf(fdsse4,"Second run\n");
301
302
303
304
305
306
307
308
      print_shorts("a0",(int16_t *)&alpha128[0]);
      print_shorts("a1",(int16_t *)&alpha128[1]);
      print_shorts("a2",(int16_t *)&alpha128[2]);
      print_shorts("a3",(int16_t *)&alpha128[3]);
      print_shorts("a4",(int16_t *)&alpha128[4]);
      print_shorts("a5",(int16_t *)&alpha128[5]);
      print_shorts("a6",(int16_t *)&alpha128[6]);
      print_shorts("a7",(int16_t *)&alpha128[7]);
309
#endif
310
    }
311

312
    alpha_ptr = &alpha128[0];
313
    //#ifdef __AVX2__
314
#if defined(__x86_64__) || defined(__i386__)
315
316
    m11p = (__m128i *)m_11;
    m10p = (__m128i *)m_10;
317
#elif defined(__arm__)
318
319
    m11p = (int16x8_t *)m_11;
    m10p = (int16x8_t *)m_10;
320
#endif
321

322
    for (k=0;
323
324
         k<l;
         k++) {
325
#if defined(__x86_64__) || defined(__i386__)
326
327
      //#ifndef __AVX2__
#if 1
328
329
330
331
332
      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
333
      m_b4 = _mm_subs_epi16(a1,*m11p);  // m00=-m11
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
      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]);
      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
      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);
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#else
      a02=_mm256_load_si256(&alpha_ptr256[0]);
      a13=_mm256_load_si256(&alpha_ptr256[1]);
      a64=_mm256_load_si256(&alpha_ptr256[2]);
      a75=_mm256_load_si256(&alpha_ptr256[3]);
      m11m10_256 = _mm256_insertf128_si256(m11m10_256,*m11p,0);
      m11m10_256 = _mm256_insertf128_si256(m11m10_256,*m10p,1);
      m_b01 = _mm256_adds_epi16(a13,m11m10_256); //negative m10
      m_b23 = _mm256_subs_epi16(a75,m11m10_256); //negative m10
      m_b45 = _mm256_subs_epi16(a13,m11m10_256); //negative m10
      m_b67 = _mm256_adds_epi16(a75,m11m10_256); //negative m10
      new01 = _mm256_subs_epi16(a02,m11m10_256);  //negative m10
      new23 = _mm256_adds_epi16(a64,m11m10_256);  //negative m10
      new45 = _mm256_adds_epi16(a02,m11m10_256);  //negative m10
      new67 = _mm256_subs_epi16(a64,m11m10_256);  //negative m10
      a01   = _mm256_max_epi16(m_b01,new01);
      a23   = _mm256_max_epi16(m_b23,new23);
      a45   = _mm256_max_epi16(m_b45,new45);
      a67   = _mm256_max_epi16(m_b67,new67);
      alpha_max = _mm256_max_epi16(a01,a23);
      alpha_max = _mm256_max_epi16(alpha_max,a45);
      alpha_max = _mm256_max_epi16(alpha_max,a67);
      alpha_max = _mm256_max_epi16(alpha_max,_mm256_permutevar8x32_epi32(alpha_max,_mm256_set_epi32(3,2,1,0,7,6,5,4)));
#endif
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
#elif defined(__arm__)
      m_b0 = vqaddq_s16(alpha_ptr[1],*m11p);  // m11
      m_b4 = vqsubq_s16(alpha_ptr[1],*m11p);  // m00=-m11
      m_b1 = vqsubq_s16(alpha_ptr[3],*m10p);  // m01=-m10
      m_b5 = vqaddq_s16(alpha_ptr[3],*m10p);  // m10
      m_b2 = vqaddq_s16(alpha_ptr[5],*m10p);  // m10
      m_b6 = vqsubq_s16(alpha_ptr[5],*m10p);  // m01=-m10
      m_b3 = vqsubq_s16(alpha_ptr[7],*m11p);  // m00=-m11
      m_b7 = vqaddq_s16(alpha_ptr[7],*m11p);  // m11
      new0 = vqsubq_s16(alpha_ptr[0],*m11p);  // m00=-m11
      new4 = vqaddq_s16(alpha_ptr[0],*m11p);  // m11
      new1 = vqaddq_s16(alpha_ptr[2],*m10p);  // m10
      new5 = vqsubq_s16(alpha_ptr[2],*m10p);  // m01=-m10
      new2 = vqsubq_s16(alpha_ptr[4],*m10p);  // m01=-m10
      new6 = vqaddq_s16(alpha_ptr[4],*m10p);  // m10
      new3 = vqaddq_s16(alpha_ptr[6],*m11p);  // m11
      new7 = vqsubq_s16(alpha_ptr[6],*m11p);  // m00=-m11
      a0 = vmaxq_s16(m_b0,new0);
      a1 = vmaxq_s16(m_b1,new1);
      a2 = vmaxq_s16(m_b2,new2);
      a3 = vmaxq_s16(m_b3,new3);
      a4 = vmaxq_s16(m_b4,new4);
      a5 = vmaxq_s16(m_b5,new5);
      a6 = vmaxq_s16(m_b6,new6);
      a7 = vmaxq_s16(m_b7,new7);
      // compute and subtract maxima
      alpha_max = vmaxq_s16(a0,a1);
      alpha_max = vmaxq_s16(alpha_max,a2);
      alpha_max = vmaxq_s16(alpha_max,a3);
      alpha_max = vmaxq_s16(alpha_max,a4);
      alpha_max = vmaxq_s16(alpha_max,a5);
      alpha_max = vmaxq_s16(alpha_max,a6);
      alpha_max = vmaxq_s16(alpha_max,a7);
#endif
425
      alpha_ptr+=8;
426
      //#ifdef __AVX2__
427
      m11p++;
428
      m10p++;
429
#if defined(__x86_64__) || defined(__i386__)
430
431
      //#ifndef __AVX2__
#if 1
432
433
434
435
436
437
438
439
      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);
440
441
442
443
444
445
446
447
448
449
#else
      a01   = _mm256_subs_epi16(a01,alpha_max);
      a23   = _mm256_subs_epi16(a23,alpha_max);
      a45   = _mm256_subs_epi16(a45,alpha_max);
      a67   = _mm256_subs_epi16(a67,alpha_max);
      alpha_ptr256[0] = _mm256_permute2x128_si256(a01,a23,0x20);  //a02
      alpha_ptr256[1] = _mm256_permute2x128_si256(a01,a23,0x13);  //a13
      alpha_ptr256[2] = _mm256_permute2x128_si256(a45,a67,0x02);  //a64
      alpha_ptr256[3] = _mm256_permute2x128_si256(a45,a67,0x31);  //a75
#endif
450
451
452
453
454
455
456
457
458
459
460
#elif defined(__arm__)
      alpha_ptr[0] = vqsubq_s16(a0,alpha_max);
      alpha_ptr[1] = vqsubq_s16(a1,alpha_max);
      alpha_ptr[2] = vqsubq_s16(a2,alpha_max);
      alpha_ptr[3] = vqsubq_s16(a3,alpha_max);
      alpha_ptr[4] = vqsubq_s16(a4,alpha_max);
      alpha_ptr[5] = vqsubq_s16(a5,alpha_max);
      alpha_ptr[6] = vqsubq_s16(a6,alpha_max);
      alpha_ptr[7] = vqsubq_s16(a7,alpha_max);
#endif
#ifdef DEBUG_LOGMAP
461
      fprintf(fdsse4,"Loop index %d\n",k);
462
463
464
465
466
467
468
469
      print_shorts("mb0",(int16_t *)&m_b0);
      print_shorts("mb1",(int16_t *)&m_b1);
      print_shorts("mb2",(int16_t *)&m_b2);
      print_shorts("mb3",(int16_t *)&m_b3);
      print_shorts("mb4",(int16_t *)&m_b4);
      print_shorts("mb5",(int16_t *)&m_b5);
      print_shorts("mb6",(int16_t *)&m_b6);
      print_shorts("mb7",(int16_t *)&m_b7);
470
      fprintf(fdsse4,"Loop index %d, new\n",k);
471
472
473
474
475
476
477
478
      print_shorts("new0",(int16_t *)&new0);
      print_shorts("new1",(int16_t *)&new1);
      print_shorts("new2",(int16_t *)&new2);
      print_shorts("new3",(int16_t *)&new3);
      print_shorts("new4",(int16_t *)&new4);
      print_shorts("new5",(int16_t *)&new5);
      print_shorts("new6",(int16_t *)&new6);
      print_shorts("new7",(int16_t *)&new7);
479
      fprintf(fdsse4,"Loop index %d, after max\n",k);
480
481
482
483
484
485
486
487
      print_shorts("a0",(int16_t *)&a0);
      print_shorts("a1",(int16_t *)&a1);
      print_shorts("a2",(int16_t *)&a2);
      print_shorts("a3",(int16_t *)&a3);
      print_shorts("a4",(int16_t *)&a4);
      print_shorts("a5",(int16_t *)&a5);
      print_shorts("a6",(int16_t *)&a6);
      print_shorts("a7",(int16_t *)&a7);
488
      fprintf(fdsse4,"Loop index %d\n",k);
489
490
491
492
493
494
495
496
      print_shorts("a0",(int16_t *)&alpha_ptr[0]);
      print_shorts("a1",(int16_t *)&alpha_ptr[1]);
      print_shorts("a2",(int16_t *)&alpha_ptr[2]);
      print_shorts("a3",(int16_t *)&alpha_ptr[3]);
      print_shorts("a4",(int16_t *)&alpha_ptr[4]);
      print_shorts("a5",(int16_t *)&alpha_ptr[5]);
      print_shorts("a6",(int16_t *)&alpha_ptr[6]);
      print_shorts("a7",(int16_t *)&alpha_ptr[7]);
497
#endif
498
499
500
501
    }

    if (rerun_flag==1)
      break;
502
  }
503
504
505
}


506
void compute_beta16(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,unsigned short frame_length,unsigned char F,int offset8_flag) {
507
  int k,rerun_flag=0;
508
#if defined(__x86_64__) || defined(__i386__)
509
510
511
512
  __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;
513
  __m128i beta_max;
514
515
516
517
518
519
520
#elif defined(__arm__)
  int16x8_t m11_128,m10_128;
  int16x8_t m_b0,m_b1,m_b2,m_b3,m_b4,m_b5,m_b6,m_b7;
  int16x8_t new0,new1,new2,new3,new4,new5,new6,new7;
  int16x8_t *beta128,*alpha128,*beta_ptr;
  int16x8_t beta_max;
#endif
521
  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;
522
523
  llr_t beta0,beta1;
#ifdef DEBUG_LOGMAP
524
  fprintf(fdsse4,"compute_beta, %p,%p,%p,%p,framelength %d,F %d\n",
525
          beta,m_11,m_10,alpha,frame_length,F);
526
527
#endif
  // termination for beta initialization
528
  //  fprintf(fdsse4,"beta init: offset8 %d\n",offset8_flag);
529
  m11=(int16_t)m_11[2+frame_length];
530
531
  //#ifndef __AVX2__
#if 1
532
  m10=(int16_t)m_10[2+frame_length];
533
534
535
#else
  m10=-(int16_t)m_10[2+frame_length];
#endif
536
537
538
#ifdef DEBUG_LOGMAP
  fprintf(fdsse4,"m11,m10 %d,%d\n",m11,m10);
#endif
539
540
541
542
  beta0 = -m11;//M0T_TERM;
  beta1 = m11;//M1T_TERM;
  m11=(int16_t)m_11[1+frame_length];
  m10=(int16_t)m_10[1+frame_length];
543
544
545
#ifdef DEBUG_LOGMAP
  fprintf(fdsse4,"m11,m10 %d,%d\n",m11,m10);
#endif
546
547
548
549
550
551
  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];
552
553
554
#ifdef DEBUG_LOGMAP
  fprintf(fdsse4,"m11,m10 %d,%d\n",m11,m10);
#endif
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
  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;
  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;
  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;

579
  for (rerun_flag=0;; rerun_flag=1) {
580
#if defined(__x86_64__) || defined(__i386__)
581
582
    beta_ptr   = (__m128i *)&beta[frame_length<<3];
    alpha128   = (__m128i *)&alpha[0];
583
#elif defined(__arm__)
584
585
    beta_ptr   = (int16x8_t *)&beta[frame_length<<3];
    alpha128   = (int16x8_t *)&alpha[0];
586
#endif
587

588
589
590
591
592
593
594
595
596
    if (rerun_flag == 0) {
      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)];
597
598
#ifdef DEBUG_LOGMAP
      fprintf(fdsse4,"beta init \n");
599
600
601
602
603
604
605
606
      print_shorts("b0",(int16_t *)&beta_ptr[0]);
      print_shorts("b1",(int16_t *)&beta_ptr[1]);
      print_shorts("b2",(int16_t *)&beta_ptr[2]);
      print_shorts("b3",(int16_t *)&beta_ptr[3]);
      print_shorts("b4",(int16_t *)&beta_ptr[4]);
      print_shorts("b5",(int16_t *)&beta_ptr[5]);
      print_shorts("b6",(int16_t *)&beta_ptr[6]);
      print_shorts("b7",(int16_t *)&beta_ptr[7]);
607
#endif
608
    } else {
609
#if defined(__x86_64__) || defined(__i386__)
610
      beta128 = (__m128i *)&beta[0];
611
612
613
614
615
616
617
618
      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);
619
#elif defined(__arm__)
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
      beta128 = (int16x8_t *)&beta[0];
      beta_ptr   = (int16x8_t *)&beta[frame_length<<3];
      beta_ptr[0] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[0],16);
      beta_ptr[0] = vsetq_lane_s16(beta[3],beta_ptr[0],4);
      beta_ptr[1] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[1],16);
      beta_ptr[1] = vsetq_lane_s16(beta[11],beta_ptr[1],4);
      beta_ptr[2] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[2],16);
      beta_ptr[2] = vsetq_lane_s16(beta[19],beta_ptr[2],4);
      beta_ptr[3] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[3],16);
      beta_ptr[3] = vsetq_lane_s16(beta[27],beta_ptr[3],4);
      beta_ptr[4] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[4],16);
      beta_ptr[4] = vsetq_lane_s16(beta[35],beta_ptr[4],4);
      beta_ptr[5] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[5],16);
      beta_ptr[5] = vsetq_lane_s16(beta[43],beta_ptr[5],4);
      beta_ptr[6] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[6],16);
      beta_ptr[6] = vsetq_lane_s16(beta[51],beta_ptr[6],4);
      beta_ptr[7] = (int16x8_t)vshrq_n_s64((int64x2_t)beta128[7],16);
      beta_ptr[7] = vsetq_lane_s16(beta[59],beta_ptr[7],4);
638
639
640
#endif
#ifdef DEBUG_LOGMAP
      fprintf(fdsse4,"beta init (second run) \n");
641
642
643
644
645
646
647
648
      print_shorts("b0",(int16_t *)&beta_ptr[0]);
      print_shorts("b1",(int16_t *)&beta_ptr[1]);
      print_shorts("b2",(int16_t *)&beta_ptr[2]);
      print_shorts("b3",(int16_t *)&beta_ptr[3]);
      print_shorts("b4",(int16_t *)&beta_ptr[4]);
      print_shorts("b5",(int16_t *)&beta_ptr[5]);
      print_shorts("b6",(int16_t *)&beta_ptr[6]);
      print_shorts("b7",(int16_t *)&beta_ptr[7]);
649
#endif
650
651
    }

652
#if defined(__x86_64__) || defined(__i386__)
653
654
655
656
657
658
659
660
    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);
661
662
663
664
665
666
667
668
669
670
#elif defined(__arm__)
    beta_ptr[0] = vsetq_lane_s16(beta0_16,beta_ptr[0],7);
    beta_ptr[1] = vsetq_lane_s16(beta1_16,beta_ptr[1],7);
    beta_ptr[2] = vsetq_lane_s16(beta2_16,beta_ptr[2],7);
    beta_ptr[3] = vsetq_lane_s16(beta3_16,beta_ptr[3],7);
    beta_ptr[4] = vsetq_lane_s16(beta4_16,beta_ptr[4],7);
    beta_ptr[5] = vsetq_lane_s16(beta5_16,beta_ptr[5],7);
    beta_ptr[6] = vsetq_lane_s16(beta6_16,beta_ptr[6],7);
    beta_ptr[7] = vsetq_lane_s16(beta7_16,beta_ptr[7],7);
#endif
671
#ifdef DEBUG_LOGMAP
672
673
674
675
676
677
678
679
680
    fprintf(fdsse4,"beta init (after insert) \n");
    print_shorts("b0",(int16_t *)&beta_ptr[0]);
    print_shorts("b1",(int16_t *)&beta_ptr[1]);
    print_shorts("b2",(int16_t *)&beta_ptr[2]);
    print_shorts("b3",(int16_t *)&beta_ptr[3]);
    print_shorts("b4",(int16_t *)&beta_ptr[4]);
    print_shorts("b5",(int16_t *)&beta_ptr[5]);
    print_shorts("b6",(int16_t *)&beta_ptr[6]);
    print_shorts("b7",(int16_t *)&beta_ptr[7]);
681
#endif
682
    int loopval=((rerun_flag==0)?0:((frame_length-L)>>3));
683
684

    for (k=(frame_length>>3)-1; k>=loopval; k--) {
685
#if defined(__x86_64__) || defined(__i386__)
686
687
      m11_128=((__m128i *)m_11)[k];
      m10_128=((__m128i *)m_10)[k];
688
689
      //#ifndef __AVX2__
#if 1
690
691
692
693
      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
694
      m_b4 = _mm_adds_epi16(beta_ptr[6],m10_128);  //m10
695
696
697
698
699
700
701
702
703
704
705
      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
      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
706
#else
707
708
709
710
      b01=_mm256_load_si256(&((_m256i *)beta_ptr)[0]);
      b23=_mm256_load_si256(&((_m256i *)beta_ptr)[1]);
      b45=_mm256_load_si256(&((_m256i *)beta_ptr)[2]);
      b67=_mm256_load_si256(&((_m256i *)beta_ptr)[3]);
711
712
713
714
715
716
717
718
719
720
721
      m11m10_256 = _mm256_insertf128_si256(m11m10_256,m11_128,0);
      m11m10_256 = _mm256_insertf128_si256(m11m10_256,m10_128,1);
      m_b02 = _mm256_adds_epi16(b45,m11m10_256); //negative m10
      m_b13 = _mm256_subs_epi16(b45,m11m10_256); //negative m10
      m_b64 = _mm256_subs_epi16(b67,m11m10_256); //negative m10
      m_b75 = _mm256_adds_epi16(b67,m11m10_256); //negative m10
      new02 = _mm256_subs_epi16(b01,m11m10_256);  //negative m10
      new13 = _mm256_adds_epi16(b01,m11m10_256);  //negative m10
      new64 = _mm256_adds_epi16(b23,m11m10_256);  //negative m10
      new75 = _mm256_subs_epi16(b24,m11m10_256);  //negative m10
#endif
722
      beta_ptr-=8;
723
724
      //#ifndef __AVX2__
#if 1
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
      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);
      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);
746
      beta_ptr[6] = _mm_subs_epi16(beta_ptr[6],beta_max);
747
      beta_ptr[7] = _mm_subs_epi16(beta_ptr[7],beta_max);
748
749
750
751
752
753
754
755
756
757
758
759
760
#else
      b02   = _mm256_max_epi16(m_b02,new02);
      b13   = _mm256_max_epi16(m_b13,new13);
      b64   = _mm256_max_epi16(m_b64,new64);
      b75   = _mm256_max_epi16(m_b75,new75);
      beta_max = _mm256_max_epi16(b02,b13);
      beta_max = _mm256_max_epi16(beta_max,b64);
      beta_max = _mm256_max_epi16(beta_max,b75);
      beta_max = _mm256_max_epi16(beta_max,_mm256_permutevar8x32_epi32(betaa_max,_mm256_set_epi32(3,2,1,0,7,6,5,4)));
      b02   = _mm256_subs_epi16(b02,beta_max);
      b13   = _mm256_subs_epi16(b13,beta_max);
      b64   = _mm256_subs_epi16(b64,beta_max);
      b75   = _mm256_subs_epi16(b75,beta_max);
761
762
763
764
      ((_m256i *)beta_ptr)[0]) = _mm256_permute2x128_si256(b02,b13,0x02); //b01
      ((_m256i *)beta_ptr)[1]) = _mm256_permute2x128_si256(b02,b13,0x31); //b23
      ((_m256i *)beta_ptr)[2]) = _mm256_permute2x128_si256(b64,b75,0x13); //b45
      ((_m256i *)beta_ptr)[3]) = _mm256_permute2x128_si256(b64,b75,0x20); //b67
765
#endif
766
#elif defined(__arm__)
767
768
      m11_128=((int16x8_t *)m_11)[k];
      m10_128=((int16x8_t *)m_10)[k];
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
      m_b0 = vqaddq_s16(beta_ptr[4],m11_128);  //m11
      m_b1 = vqsubq_s16(beta_ptr[4],m11_128);  //m00
      m_b2 = vqsubq_s16(beta_ptr[5],m10_128);  //m01
      m_b3 = vqaddq_s16(beta_ptr[5],m10_128);  //m10
      m_b4 = vqaddq_s16(beta_ptr[6],m10_128);  //m10
      m_b5 = vqsubq_s16(beta_ptr[6],m10_128);  //m01
      m_b6 = vqsubq_s16(beta_ptr[7],m11_128);  //m00
      m_b7 = vqaddq_s16(beta_ptr[7],m11_128);  //m11
      new0 = vqsubq_s16(beta_ptr[0],m11_128);  //m00
      new1 = vqaddq_s16(beta_ptr[0],m11_128);  //m11
      new2 = vqaddq_s16(beta_ptr[1],m10_128);  //m10
      new3 = vqsubq_s16(beta_ptr[1],m10_128);  //m01
      new4 = vqsubq_s16(beta_ptr[2],m10_128);  //m01
      new5 = vqaddq_s16(beta_ptr[2],m10_128);  //m10
      new6 = vqaddq_s16(beta_ptr[3],m11_128);  //m11
      new7 = vqsubq_s16(beta_ptr[3],m11_128);  //m00
      beta_ptr-=8;
      beta_ptr[0] = vmaxq_s16(m_b0,new0);
      beta_ptr[1] = vmaxq_s16(m_b1,new1);
      beta_ptr[2] = vmaxq_s16(m_b2,new2);
      beta_ptr[3] = vmaxq_s16(m_b3,new3);
      beta_ptr[4] = vmaxq_s16(m_b4,new4);
      beta_ptr[5] = vmaxq_s16(m_b5,new5);
      beta_ptr[6] = vmaxq_s16(m_b6,new6);
      beta_ptr[7] = vmaxq_s16(m_b7,new7);
      beta_max = vmaxq_s16(beta_ptr[0],beta_ptr[1]);
      beta_max = vmaxq_s16(beta_max   ,beta_ptr[2]);
      beta_max = vmaxq_s16(beta_max   ,beta_ptr[3]);
      beta_max = vmaxq_s16(beta_max   ,beta_ptr[4]);
      beta_max = vmaxq_s16(beta_max   ,beta_ptr[5]);
      beta_max = vmaxq_s16(beta_max   ,beta_ptr[6]);
      beta_max = vmaxq_s16(beta_max   ,beta_ptr[7]);
      beta_ptr[0] = vqsubq_s16(beta_ptr[0],beta_max);
      beta_ptr[1] = vqsubq_s16(beta_ptr[1],beta_max);
      beta_ptr[2] = vqsubq_s16(beta_ptr[2],beta_max);
      beta_ptr[3] = vqsubq_s16(beta_ptr[3],beta_max);
      beta_ptr[4] = vqsubq_s16(beta_ptr[4],beta_max);
      beta_ptr[5] = vqsubq_s16(beta_ptr[5],beta_max);
      beta_ptr[6] = vqsubq_s16(beta_ptr[6],beta_max);
      beta_ptr[7] = vqsubq_s16(beta_ptr[7],beta_max);
#endif
810
811
812
#ifdef DEBUG_LOGMAP
      fprintf(fdsse4,"Loop index %d, mb\n",k);
      fprintf(fdsse4,"beta init (after max)\n");
813
814
815
816
817
818
819
820
      print_shorts("b0",(int16_t *)&beta_ptr[0]);
      print_shorts("b1",(int16_t *)&beta_ptr[1]);
      print_shorts("b2",(int16_t *)&beta_ptr[2]);
      print_shorts("b3",(int16_t *)&beta_ptr[3]);
      print_shorts("b4",(int16_t *)&beta_ptr[4]);
      print_shorts("b5",(int16_t *)&beta_ptr[5]);
      print_shorts("b6",(int16_t *)&beta_ptr[6]);
      print_shorts("b7",(int16_t *)&beta_ptr[7]);
821
#endif
822
823
824
825
826
827
828
    }

    if (rerun_flag==1)
      break;
  }
}

829
void compute_ext16(llr_t *alpha,llr_t *beta,llr_t *m_11,llr_t *m_10,llr_t *ext, llr_t *systematic,unsigned short frame_length) {
830
#if defined(__x86_64__) || defined(__i386__)
831
832
833
834
835
836
837
838
  __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;
839
840
841
842
843
844
845
846
847
848
#elif defined(__arm__)
  int16x8_t *alpha128=(int16x8_t *)alpha;
  int16x8_t *beta128=(int16x8_t *)beta;
  int16x8_t *m11_128,*m10_128,*ext_128;
  int16x8_t *alpha_ptr,*beta_ptr;
  int16x8_t m00_1,m00_2,m00_3,m00_4;
  int16x8_t m01_1,m01_2,m01_3,m01_4;
  int16x8_t m10_1,m10_2,m10_3,m10_4;
  int16x8_t m11_1,m11_2,m11_3,m11_4;
#endif
849
850
851
852
853
  int k;
  //
  // LLR computation, 8 consequtive bits per loop
  //
#ifdef DEBUG_LOGMAP
854
  fprintf(fdsse4,"compute_ext (sse_16bit), %p, %p, %p, %p, %p, %p ,framelength %d\n",alpha,beta,m_11,m_10,ext,systematic,frame_length);
855
856
857
858
#endif
  alpha_ptr = alpha128;
  beta_ptr = &beta128[8];

859
  for (k=0; k<(frame_length>>3); k++) {
860
#if defined(__x86_64__) || defined(__i386__)
861
862
863
    m11_128        = (__m128i *)&m_11[k<<3];
    m10_128        = (__m128i *)&m_10[k<<3];
    ext_128        = (__m128i *)&ext[k<<3];
864
    /*
865
      fprintf(fdsse4,"EXT %03d\n",k);
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
      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]);
882
    */
883
884
    //#ifndef __AVX2__
#if 1
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
    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;
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
#else
    m00_1 = _mm_adds_epi16(alpha_ptr[0],beta_ptr[0]); //ALPHA_BETA_1m00;
    m10_1 = _mm_adds_epi16(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
    m11_1 = _mm_adds_epi16(alpha_ptr[0],beta_ptr[4]); //ALPHA_BETA_1m11;
    m01_1 = _mm_adds_epi16(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
    m11_2 = _mm_adds_epi16(alpha_ptr[1],beta_ptr[0]); //ALPHA_BETA_2m11;
    m01_2 = _mm_adds_epi16(alpha_ptr[3],beta_ptr[1]); //ALPHA_BETA_2m01;
    m00_2 = _mm_adds_epi16(alpha_ptr[1],beta_ptr[4]); //ALPHA_BETA_2m00;
    m10_2 = _mm_adds_epi16(alpha_ptr[3],beta_ptr[5]); //ALPHA_BETA_2m10;
    m11_3 = _mm_adds_epi16(alpha_ptr[6],beta_ptr[3]); //ALPHA_BETA_3m11;
    m01_3 = _mm_adds_epi16(alpha_ptr[4],beta_ptr[2]); //ALPHA_BETA_3m01;
    m00_3 = _mm_adds_epi16(alpha_ptr[6],beta_ptr[7]); //ALPHA_BETA_3m00;
    m10_3 = _mm_adds_epi16(alpha_ptr[4],beta_ptr[6]); //ALPHA_BETA_3m10;
    m00_4 = _mm_adds_epi16(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
    m10_4 = _mm_adds_epi16(alpha_ptr[5],beta_ptr[2]); //ALPHA_BETA_4m10;
    m11_4 = _mm_adds_epi16(alpha_ptr[7],beta_ptr[7]); //ALPHA_BETA_4m11;
    m01_4 = _mm_adds_epi16(alpha_ptr[5],beta_ptr[6]); //ALPHA_BETA_4m01;
#endif
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
    /*
      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);
    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);
961
962
#ifdef DEBUG_LOGMAP
    fprintf(fdsse4,"ext %p\n",ext_128);
963
964
965
966
967
    print_shorts("ext:",(int16_t *)ext_128);
    print_shorts("m11:",(int16_t *)m11_128);
    print_shorts("m10:",(int16_t *)m10_128);
    print_shorts("m10_1:",(int16_t *)&m10_1);
    print_shorts("m01_1:",(int16_t *)&m01_1);
968
#endif
969
#elif defined(__arm__)
970
971
972
    m11_128        = (int16x8_t *)&m_11[k<<3];
    m10_128        = (int16x8_t *)&m_10[k<<3];
    ext_128        = (int16x8_t *)&ext[k<<3];
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
    m00_4 = vqaddq_s16(alpha_ptr[7],beta_ptr[3]); //ALPHA_BETA_4m00;
    m11_4 = vqaddq_s16(alpha_ptr[7],beta_ptr[7]); //ALPHA_BETA_4m11;
    m00_3 = vqaddq_s16(alpha_ptr[6],beta_ptr[7]); //ALPHA_BETA_3m00;
    m11_3 = vqaddq_s16(alpha_ptr[6],beta_ptr[3]); //ALPHA_BETA_3m11;
    m00_2 = vqaddq_s16(alpha_ptr[1],beta_ptr[4]); //ALPHA_BETA_2m00;
    m11_2 = vqaddq_s16(alpha_ptr[1],beta_ptr[0]); //ALPHA_BETA_2m11;
    m11_1 = vqaddq_s16(alpha_ptr[0],beta_ptr[4]); //ALPHA_BETA_1m11;
    m00_1 = vqaddq_s16(alpha_ptr[0],beta_ptr[0]); //ALPHA_BETA_1m00;
    m01_4 = vqaddq_s16(alpha_ptr[5],beta_ptr[6]); //ALPHA_BETA_4m01;
    m10_4 = vqaddq_s16(alpha_ptr[5],beta_ptr[2]); //ALPHA_BETA_4m10;
    m01_3 = vqaddq_s16(alpha_ptr[4],beta_ptr[2]); //ALPHA_BETA_3m01;
    m10_3 = vqaddq_s16(alpha_ptr[4],beta_ptr[6]); //ALPHA_BETA_3m10;
    m01_2 = vqaddq_s16(alpha_ptr[3],beta_ptr[1]); //ALPHA_BETA_2m01;
    m10_2 = vqaddq_s16(alpha_ptr[3],beta_ptr[5]); //ALPHA_BETA_2m10;
    m10_1 = vqaddq_s16(alpha_ptr[2],beta_ptr[1]); //ALPHA_BETA_1m10;
    m01_1 = vqaddq_s16(alpha_ptr[2],beta_ptr[5]); //ALPHA_BETA_1m01;
    m01_1 = vmaxq_s16(m01_1,m01_2);
    m01_1 = vmaxq_s16(m01_1,m01_3);
    m01_1 = vmaxq_s16(m01_1,m01_4);
    m00_1 = vmaxq_s16(m00_1,m00_2);
    m00_1 = vmaxq_s16(m00_1,m00_3);
    m00_1 = vmaxq_s16(m00_1,m00_4);
    m10_1 = vmaxq_s16(m10_1,m10_2);
    m10_1 = vmaxq_s16(m10_1,m10_3);
    m10_1 = vmaxq_s16(m10_1,m10_4);
    m11_1 = vmaxq_s16(m11_1,m11_2);
    m11_1 = vmaxq_s16(m11_1,m11_3);
    m11_1 = vmaxq_s16(m11_1,m11_4);
    m01_1 = vqsubq_s16(m01_1,*m10_128);
    m00_1 = vqsubq_s16(m00_1,*m11_128);
    m10_1 = vqaddq_s16(m10_1,*m10_128);
    m11_1 = vqaddq_s16(m11_1,*m11_128);
    m01_1 = vmaxq_s16(m01_1,m00_1);
    m10_1 = vmaxq_s16(m10_1,m11_1);
    *ext_128 = vqsubq_s16(m10_1,m01_1);
#endif
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
    alpha_ptr+=8;
    beta_ptr+=8;
  }
}



//int pi2[n],pi3[n+8],pi5[n+8],pi4[n+8],pi6[n+8],
int *pi2tab16[188],*pi5tab16[188],*pi4tab16[188],*pi6tab16[188];

1019
void free_td16(void) {
1020
1021
1022
  int ind;

  for (ind=0; ind<188; ind++) {
1023
1024
1025
1026
    free_and_zero(pi2tab16[ind]);
    free_and_zero(pi5tab16[ind]);
    free_and_zero(pi4tab16[ind]);
    free_and_zero(pi6tab16[ind]);
1027
  }
1028
1029
}

1030
void init_td16(void) {
1031
  int ind,i,i2,i3,j,n,pi,pi3;
1032
  short *base_interleaver;
1033

1034
  for (ind=0; ind<188; ind++) {
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
    n = f1f2mat[ind].nb_bits;
    base_interleaver=il_tb+f1f2mat[ind].beg_index;
#ifdef MEX
    // This is needed for the Mex implementation to make the memory persistent
    pi2tab16[ind] = mxMalloc((n+8)*sizeof(int));
    pi5tab16[ind] = mxMalloc((n+8)*sizeof(int));
    pi4tab16[ind] = mxMalloc((n+8)*sizeof(int));
    pi6tab16[ind] = mxMalloc((n+8)*sizeof(int));
#else
    pi2tab16[ind] = malloc((n+8)*sizeof(int));
    pi5tab16[ind] = malloc((n+8)*sizeof(int));
    pi4tab16[ind] = malloc((n+8)*sizeof(int));
    pi6tab16[ind] = malloc((n+8)*sizeof(int));
#endif

1050
    for (i=i2=0; i2<8; i2++) {
1051
      j=i2;
1052
1053
1054
1055
1056

      for (i3=0; i3<(n>>3); i3++,i++,j+=8) {
        //    if (j>=n)
        //      j-=(n-1);
        pi2tab16[ind][i]  = j;
1057
        //    fprintf(fdsse4,"pi2[%d] = %d\n",i,j);
1058
1059
      }
    }
1060
1061

    for (i=0; i<n; i++) {
1062
1063
1064
1065
1066
      pi = base_interleaver[i];//(unsigned int)threegpplte_interleaver(f1,f2,n);
      pi3 = pi2tab16[ind][pi];
      pi4tab16[ind][pi2tab16[ind][i]] = pi3;
      pi5tab16[ind][pi3] = pi2tab16[ind][i];
      pi6tab16[ind][pi] = pi2tab16[ind][i];
1067
    }
1068
1069
1070
  }
}

1071
uint8_t phy_threegpplte_turbo_decoder16(int16_t *y,
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
                                        int16_t *y2,
                                        uint8_t *decoded_bytes,
                                        uint8_t *decoded_bytes2,
                                        uint16_t n,
                                        uint8_t max_iterations,
                                        uint8_t crc_type,
                                        uint8_t F,
                                        time_stats_t *init_stats,
                                        time_stats_t *alpha_stats,
                                        time_stats_t *beta_stats,
                                        time_stats_t *gamma_stats,
                                        time_stats_t *ext_stats,
                                        time_stats_t *intl1_stats,
                                        time_stats_t *intl2_stats) {
1086
1087
1088
  /*  y is a pointer to the input
      decoded_bytes is a pointer to the decoded output
      n is the size in bits of the coded block, with the tail */
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
  llr_t systematic0[n+16] __attribute__ ((aligned(32)));
  llr_t systematic1[n+16] __attribute__ ((aligned(32)));
  llr_t systematic2[n+16] __attribute__ ((aligned(32)));
  llr_t yparity1[n+16] __attribute__ ((aligned(32)));
  llr_t yparity2[n+16] __attribute__ ((aligned(32)));
  llr_t ext[n+128] __attribute__((aligned(32)));
  llr_t ext2[n+128] __attribute__((aligned(32)));
  llr_t alpha[(n+16)*8] __attribute__ ((aligned(32)));
  llr_t beta[(n+16)*8] __attribute__ ((aligned(32)));
  llr_t m11[n+32] __attribute__ ((aligned(32)));
  llr_t m10[n+32] __attribute__ ((aligned(32)));
1100
1101
1102
1103
1104
  int *pi2_p,*pi4_p,*pi5_p,*pi6_p;
  llr_t *s,*s1,*s2,*yp1,*yp2,*yp;
  unsigned int i,j,iind;//,pi;
  unsigned char iteration_cnt=0;
  unsigned int crc,oldcrc,crc_len;
gauthier's avatar
gauthier committed
1105
  uint8_t temp;
1106
1107
#if defined(__x86_64__) || defined(__i386__)
  __m128i *yp128;
1108
  __m128i tmp={0}, zeros=_mm_setzero_si128();
1109
  __m128i tmpe;
1110
1111
#elif defined(__arm__)
  int16x8_t *yp128;
1112
  //  int16x8_t tmp128[(n+8)>>3];
1113
  int16x8_t tmp, zeros=vdupq_n_s16(0);
1114
1115
  const uint16_t __attribute__ ((aligned (16))) _Powers[8]=
  { 1, 2, 4, 8, 16, 32, 64, 128};
1116
1117
  uint16x8_t Powers= vld1q_u16(_Powers);
#endif
1118
  int offset8_flag=0;
1119
1120
1121
1122
1123
#ifdef DEBUG_LOGMAP
  fdsse4 = fopen("dump_sse4.txt","w");
  printf("tc sse4_16 (y) %p\n",y);
#endif

1124
  if (crc_type > 3) {
1125
    printf("Illegal crc length!\n");
1126
1127
1128
1129
1130
    return 255;
  }

  start_meas(init_stats);

1131
  for (iind=0; iind < 188 && f1f2mat[iind].nb_bits != n; iind++);
1132

1133
  if ( iind == 188 ) {
1134
    printf("Illegal frame length!\n");
1135
1136
    return 255;
  }
1137

1138
  switch (crc_type) {
1139
1140
1141
1142
    case CRC24_A:
    case CRC24_B:
      crc_len=3;
      break;
1143

1144
1145
1146
    case CRC16:
      crc_len=2;
      break;
1147

1148
1149
1150
    case CRC8:
      crc_len=1;
      break;
1151

1152
1153
    default:
      crc_len=3;
1154
1155
  }

1156
#if defined(__x86_64__) || defined(__i386__)
1157
  yp128 = (__m128i *)y;
1158
#elif defined(__arm__)
1159
  yp128 = (int16x8_t *)y;
1160
#endif
1161
  s = systematic0;
1162
1163
1164
1165
1166
  s1 = systematic1;
  s2 = systematic2;
  yp1 = yparity1;
  yp2 = yparity2;

1167
  for (i=0; i<n; i+=8) {
1168
1169
    pi2_p = &pi2tab16[iind][i];
    j=pi2_p[0];
1170
#if defined(__x86_64__) || defined(__i386__)