Debian Codegraph @

src/sw_stats_striped_neon_128_16.c

raw symbols SCIP
1 /**
2 * @file
3 *
4 * @author [email protected]
5 *
6 * Copyright (c) 2015 Battelle Memorial Institute.
7 */
8 #include "config.h"
9
10 #include <stdint.h>
11 #include <stdlib.h>
12
13
14
15 #include "parasail.h"
16 #include "parasail/memory.h"
17 #include "parasail/internal_neon.h"
18
19 #define FASTSTATS
20
21 #define SWAP(A,B) { simde__m128i* tmp = A; A = B; B = tmp; }
22 #define SWAP3(A,B,C) { simde__m128i* tmp = A; A = B; B = C; C = tmp; }
23
24 #define NEG_INF INT16_MIN
25
26
27 #ifdef PARASAIL_TABLE
28 static inline void arr_store(
29 int *array,
30 simde__m128i vH,
31 int32_t t,
32 int32_t seglen,
33 int32_t d,
34 int32_t dlen,
35 int32_t bias)
36 {
37 array[1LL*(0*seglen+t)*dlen + d] = (int16_t)simde_mm_extract_epi16(vH, 0) - bias;
38 array[1LL*(1*seglen+t)*dlen + d] = (int16_t)simde_mm_extract_epi16(vH, 1) - bias;
39 array[1LL*(2*seglen+t)*dlen + d] = (int16_t)simde_mm_extract_epi16(vH, 2) - bias;
40 array[1LL*(3*seglen+t)*dlen + d] = (int16_t)simde_mm_extract_epi16(vH, 3) - bias;
41 array[1LL*(4*seglen+t)*dlen + d] = (int16_t)simde_mm_extract_epi16(vH, 4) - bias;
42 array[1LL*(5*seglen+t)*dlen + d] = (int16_t)simde_mm_extract_epi16(vH, 5) - bias;
43 array[1LL*(6*seglen+t)*dlen + d] = (int16_t)simde_mm_extract_epi16(vH, 6) - bias;
44 array[1LL*(7*seglen+t)*dlen + d] = (int16_t)simde_mm_extract_epi16(vH, 7) - bias;
45 }
46 #endif
47
48 #ifdef PARASAIL_ROWCOL
49 static inline void arr_store_col(
50 int *col,
51 simde__m128i vH,
52 int32_t t,
53 int32_t seglen,
54 int32_t bias)
55 {
56 col[0*seglen+t] = (int16_t)simde_mm_extract_epi16(vH, 0) - bias;
57 col[1*seglen+t] = (int16_t)simde_mm_extract_epi16(vH, 1) - bias;
58 col[2*seglen+t] = (int16_t)simde_mm_extract_epi16(vH, 2) - bias;
59 col[3*seglen+t] = (int16_t)simde_mm_extract_epi16(vH, 3) - bias;
60 col[4*seglen+t] = (int16_t)simde_mm_extract_epi16(vH, 4) - bias;
61 col[5*seglen+t] = (int16_t)simde_mm_extract_epi16(vH, 5) - bias;
62 col[6*seglen+t] = (int16_t)simde_mm_extract_epi16(vH, 6) - bias;
63 col[7*seglen+t] = (int16_t)simde_mm_extract_epi16(vH, 7) - bias;
64 }
65 #endif
66
67 #ifdef PARASAIL_TABLE
68 #define FNAME parasail_sw_stats_table_striped_neon_128_16
69 #define PNAME parasail_sw_stats_table_striped_profile_neon_128_16
70 #define INAME PNAME
71 #define STATIC
72 #else
73 #ifdef PARASAIL_ROWCOL
74 #define FNAME parasail_sw_stats_rowcol_striped_neon_128_16
75 #define PNAME parasail_sw_stats_rowcol_striped_profile_neon_128_16
76 #define INAME PNAME
77 #define STATIC
78 #else
79 #define FNAME parasail_sw_stats_striped_neon_128_16
80 #ifdef FASTSTATS
81 #define PNAME parasail_sw_stats_striped_profile_neon_128_16_internal
82 #define INAME parasail_sw_stats_striped_profile_neon_128_16
83 #define STATIC static
84 #else
85 #define PNAME parasail_sw_stats_striped_profile_neon_128_16
86 #define INAME PNAME
87 #define STATIC
88 #endif
89 #endif
90 #endif
91
92 parasail_result_t* FNAME(
93 const char * const restrict s1, const int s1Len,
94 const char * const restrict s2, const int s2Len,
95 const int open, const int gap, const parasail_matrix_t *matrix)
96 {
97 /* declare local variables */
98 parasail_profile_t *profile = NULL;
99 parasail_result_t *result = NULL;
100
101 /* validate inputs */
102 PARASAIL_CHECK_NULL(s2);
103 PARASAIL_CHECK_GT0(s2Len);
104 PARASAIL_CHECK_GE0(open);
105 PARASAIL_CHECK_GE0(gap);
106 PARASAIL_CHECK_NULL(matrix);
107 if (matrix->type == PARASAIL_MATRIX_TYPE_PSSM) {
108 PARASAIL_CHECK_NULL_PSSM_STATS(s1);
109 }
110 else {
111 PARASAIL_CHECK_NULL(s1);
112 PARASAIL_CHECK_GT0(s1Len);
113 }
114
115 /* initialize local variables */
116 profile = parasail_profile_create_stats_neon_128_16(s1, s1Len, matrix);
117 if (!profile) return NULL;
118 result = INAME(profile, s2, s2Len, open, gap);
119
120 parasail_profile_free(profile);
121
122 return result;
123 }
124
125 STATIC parasail_result_t* PNAME(
126 const parasail_profile_t * const restrict profile,
127 const char * const restrict s2, const int s2Len,
128 const int open, const int gap)
129 {
130 /* declare local variables */
131 int32_t i = 0;
132 int32_t j = 0;
133 int32_t k = 0;
134 int32_t end_query = 0;
135 int32_t end_ref = 0;
136 int32_t s1Len = 0;
137 const parasail_matrix_t *matrix = NULL;
138 int32_t segWidth = 0;
139 int32_t segLen = 0;
140 #ifdef PARASAIL_ROWCOL
141 int32_t offset = 0;
142 int32_t position = 0;
143 #endif
144 simde__m128i* restrict vProfile = NULL;
145 simde__m128i* restrict vProfileM = NULL;
146 simde__m128i* restrict vProfileS = NULL;
147 simde__m128i* restrict pvHStore = NULL;
148 simde__m128i* restrict pvHLoad = NULL;
149 simde__m128i* restrict pvHMStore = NULL;
150 simde__m128i* restrict pvHMLoad = NULL;
151 simde__m128i* restrict pvHSStore = NULL;
152 simde__m128i* restrict pvHSLoad = NULL;
153 simde__m128i* restrict pvHLStore = NULL;
154 simde__m128i* restrict pvHLLoad = NULL;
155 simde__m128i* restrict pvE = NULL;
156 simde__m128i* restrict pvEM = NULL;
157 simde__m128i* restrict pvES = NULL;
158 simde__m128i* restrict pvEL = NULL;
159 simde__m128i* restrict pvHMax = NULL;
160 simde__m128i* restrict pvHMMax = NULL;
161 simde__m128i* restrict pvHSMax = NULL;
162 simde__m128i* restrict pvHLMax = NULL;
163 simde__m128i vGapO;
164 simde__m128i vGapE;
165 simde__m128i vZero;
166 simde__m128i vOne;
167 int16_t bias = 0;
168 int16_t score = 0;
169 int16_t matches = 0;
170 int16_t similar = 0;
171 int16_t length = 0;
172 simde__m128i vBias;
173 simde__m128i vBias1;
174 simde__m128i vMaxH;
175 simde__m128i vMaxHUnit;
176 simde__m128i insert_mask;
177 simde__m128i vSaturationCheckMax;
178 simde__m128i vPosLimit;
179 int16_t maxp = 0;
180 parasail_result_t *result = NULL;
181
182 /* validate inputs */
183 PARASAIL_CHECK_NULL(profile);
184 PARASAIL_CHECK_NULL(profile->profile16.score);
185 PARASAIL_CHECK_NULL(profile->matrix);
186 PARASAIL_CHECK_GT0(profile->s1Len);
187 PARASAIL_CHECK_NULL(s2);
188 PARASAIL_CHECK_GT0(s2Len);
189 PARASAIL_CHECK_GE0(open);
190 PARASAIL_CHECK_GE0(gap);
191
192 /* initialize stack variables */
193 i = 0;
194 j = 0;
195 k = 0;
196 end_query = 0;
197 end_ref = 0;
198 s1Len = profile->s1Len;
199 matrix = profile->matrix;
200 segWidth = 8; /* number of values in vector unit */
201 segLen = (s1Len + segWidth - 1) / segWidth;
202 #ifdef PARASAIL_ROWCOL
203 offset = (s1Len - 1) % segLen;
204 position = (segWidth - 1) - (s1Len - 1) / segLen;
205 #endif
206 vProfile = (simde__m128i*)profile->profile16.score;
207 vProfileM = (simde__m128i*)profile->profile16.matches;
208 vProfileS = (simde__m128i*)profile->profile16.similar;
209 vGapO = simde_mm_set1_epi16(open);
210 vGapE = simde_mm_set1_epi16(gap);
211 vZero = simde_mm_setzero_si128();
212 vOne = simde_mm_set1_epi16(1);
213 bias = INT16_MIN;
214 score = bias;
215 matches = bias;
216 similar = bias;
217 length = bias;
218 vBias = simde_mm_set1_epi16(bias);
219 vBias1 = simde_mm_adds_epi16(vBias,vOne);
220 vMaxH = vBias;
221 vMaxHUnit = vBias;
222 insert_mask = simde_mm_cmpgt_epi16(
223 simde_mm_set_epi16(0,0,0,0,0,0,0,1),
224 vZero);
225 vSaturationCheckMax = vBias;
226 vPosLimit = simde_mm_set1_epi16(INT16_MAX);
227 maxp = INT16_MAX - (int16_t)(matrix->max+1);
228
229 /* initialize result */
230 #ifdef PARASAIL_TABLE
231 result = parasail_result_new_table3(segLen*segWidth, s2Len);
232 #else
233 #ifdef PARASAIL_ROWCOL
234 result = parasail_result_new_rowcol3(segLen*segWidth, s2Len);
235 #else
236 result = parasail_result_new_stats();
237 #endif
238 #endif
239 if (!result) return NULL;
240
241 /* set known flags */
242 result->flag |= PARASAIL_FLAG_SW | PARASAIL_FLAG_STRIPED
243 | PARASAIL_FLAG_STATS
244 | PARASAIL_FLAG_BITS_16 | PARASAIL_FLAG_LANES_8;
245 #ifdef PARASAIL_TABLE
246 result->flag |= PARASAIL_FLAG_TABLE;
247 #endif
248 #ifdef PARASAIL_ROWCOL
249 result->flag |= PARASAIL_FLAG_ROWCOL;
250 #endif
251
252 /* initialize heap variables */
253 pvHStore = parasail_memalign_simde__m128i(16, segLen);
254 pvHLoad = parasail_memalign_simde__m128i(16, segLen);
255 pvHMStore = parasail_memalign_simde__m128i(16, segLen);
256 pvHMLoad = parasail_memalign_simde__m128i(16, segLen);
257 pvHSStore = parasail_memalign_simde__m128i(16, segLen);
258 pvHSLoad = parasail_memalign_simde__m128i(16, segLen);
259 pvHLStore = parasail_memalign_simde__m128i(16, segLen);
260 pvHLLoad = parasail_memalign_simde__m128i(16, segLen);
261 pvE = parasail_memalign_simde__m128i(16, segLen);
262 pvEM = parasail_memalign_simde__m128i(16, segLen);
263 pvES = parasail_memalign_simde__m128i(16, segLen);
264 pvEL = parasail_memalign_simde__m128i(16, segLen);
265 pvHMax = parasail_memalign_simde__m128i(16, segLen);
266 pvHMMax = parasail_memalign_simde__m128i(16, segLen);
267 pvHSMax = parasail_memalign_simde__m128i(16, segLen);
268 pvHLMax = parasail_memalign_simde__m128i(16, segLen);
269
270 /* validate heap variables */
271 if (!pvHStore) return NULL;
272 if (!pvHLoad) return NULL;
273 if (!pvHMStore) return NULL;
274 if (!pvHMLoad) return NULL;
275 if (!pvHSStore) return NULL;
276 if (!pvHSLoad) return NULL;
277 if (!pvHLStore) return NULL;
278 if (!pvHLLoad) return NULL;
279 if (!pvE) return NULL;
280 if (!pvEM) return NULL;
281 if (!pvES) return NULL;
282 if (!pvEL) return NULL;
283 if (!pvHMax) return NULL;
284 if (!pvHMMax) return NULL;
285 if (!pvHSMax) return NULL;
286 if (!pvHLMax) return NULL;
287
288 parasail_memset_simde__m128i(pvHStore, vBias, segLen);
289 parasail_memset_simde__m128i(pvHMStore, vBias, segLen);
290 parasail_memset_simde__m128i(pvHSStore, vBias, segLen);
291 parasail_memset_simde__m128i(pvHLStore, vBias, segLen);
292 parasail_memset_simde__m128i(pvE, vBias, segLen);
293 parasail_memset_simde__m128i(pvEM, vBias, segLen);
294 parasail_memset_simde__m128i(pvES, vBias, segLen);
295 parasail_memset_simde__m128i(pvEL, vBias1, segLen);
296
297 /* outer loop over database sequence */
298 for (j=0; j<s2Len; ++j) {
299 simde__m128i vEF_opn;
300 simde__m128i vE;
301 simde__m128i vE_ext;
302 simde__m128i vEM;
303 simde__m128i vES;
304 simde__m128i vEL;
305 simde__m128i vF;
306 simde__m128i vF_ext;
307 simde__m128i vFM;
308 simde__m128i vFS;
309 simde__m128i vFL;
310 simde__m128i vH;
311 simde__m128i vH_dag;
312 simde__m128i vHM;
313 simde__m128i vHS;
314 simde__m128i vHL;
315 const simde__m128i* vP = NULL;
316 const simde__m128i* vPM = NULL;
317 const simde__m128i* vPS = NULL;
318
319 /* Initialize F value to 0. Any errors to vH values will be
320 * corrected in the Lazy_F loop. */
321 vF = vBias;
322 vFM = vBias;
323 vFS = vBias;
324 vFL = vBias1;
325
326 /* load final segment of pvHStore and shift left by 2 bytes */
327 vH = simde_mm_load_si128(&pvHStore[segLen - 1]);
328 vHM = simde_mm_load_si128(&pvHMStore[segLen - 1]);
329 vHS = simde_mm_load_si128(&pvHSStore[segLen - 1]);
330 vHL = simde_mm_load_si128(&pvHLStore[segLen - 1]);
331 vH = simde_mm_slli_si128(vH, 2);
332 vHM = simde_mm_slli_si128(vHM, 2);
333 vHS = simde_mm_slli_si128(vHS, 2);
334 vHL = simde_mm_slli_si128(vHL, 2);
335 vH = simde_mm_blendv_epi8(vH, vBias, insert_mask);
336 vHM = simde_mm_blendv_epi8(vHM, vBias, insert_mask);
337 vHS = simde_mm_blendv_epi8(vHS, vBias, insert_mask);
338 vHL = simde_mm_blendv_epi8(vHL, vBias, insert_mask);
339
340 /* Correct part of the vProfile */
341 vP = vProfile + matrix->mapper[(unsigned char)s2[j]] * segLen;
342 vPM = vProfileM + matrix->mapper[(unsigned char)s2[j]] * segLen;
343 vPS = vProfileS + matrix->mapper[(unsigned char)s2[j]] * segLen;
344
345 if (end_ref == j-2) {
346 /* Swap in the max buffer. */
347 SWAP3(pvHMax, pvHLoad, pvHStore)
348 SWAP3(pvHMMax, pvHMLoad, pvHMStore)
349 SWAP3(pvHSMax, pvHSLoad, pvHSStore)
350 SWAP3(pvHLMax, pvHLLoad, pvHLStore)
351 }
352 else {
353 /* Swap the 2 H buffers. */
354 SWAP(pvHLoad, pvHStore)
355 SWAP(pvHMLoad, pvHMStore)
356 SWAP(pvHSLoad, pvHSStore)
357 SWAP(pvHLLoad, pvHLStore)
358 }
359
360 /* inner loop to process the query sequence */
361 for (i=0; i<segLen; ++i) {
362 simde__m128i cond_zero;
363 simde__m128i case1;
364 simde__m128i case2;
365
366 vE = simde_mm_load_si128(pvE+ i);
367 vEM = simde_mm_load_si128(pvEM+ i);
368 vES = simde_mm_load_si128(pvES+ i);
369 vEL = simde_mm_load_si128(pvEL+ i);
370
371 /* Get max from vH, vE and vF. */
372 vH_dag = simde_mm_adds_epi16(vH, simde_mm_load_si128(vP + i));
373 /*vH = simde_mm_max_epi16(vH_dag, vBias);*/
374 vH = simde_mm_max_epi16(vH_dag, vE);
375 vH = simde_mm_max_epi16(vH, vF);
376 /* Save vH values. */
377 simde_mm_store_si128(pvHStore + i, vH);
378 cond_zero = simde_mm_cmpeq_epi16(vH, vBias);
379
380 case1 = simde_mm_cmpeq_epi16(vH, vH_dag);
381 case2 = simde_mm_cmpeq_epi16(vH, vF);
382
383 /* calculate vM */
384 vHM = simde_mm_blendv_epi8(
385 simde_mm_blendv_epi8(vEM, vFM, case2),
386 simde_mm_adds_epi16(vHM, simde_mm_load_si128(vPM + i)), case1);
387 vHM = simde_mm_blendv_epi8(vHM, vBias, cond_zero);
388 simde_mm_store_si128(pvHMStore + i, vHM);
389
390 /* calculate vS */
391 vHS = simde_mm_blendv_epi8(
392 simde_mm_blendv_epi8(vES, vFS, case2),
393 simde_mm_adds_epi16(vHS, simde_mm_load_si128(vPS + i)), case1);
394 vHS = simde_mm_blendv_epi8(vHS, vBias, cond_zero);
395 simde_mm_store_si128(pvHSStore + i, vHS);
396
397 /* calculate vL */
398 vHL = simde_mm_blendv_epi8(
399 simde_mm_blendv_epi8(vEL, vFL, case2),
400 simde_mm_adds_epi16(vHL, vOne), case1);
401 vHL = simde_mm_blendv_epi8(vHL, vBias, cond_zero);
402 simde_mm_store_si128(pvHLStore + i, vHL);
403
404 vSaturationCheckMax = simde_mm_max_epi16(vSaturationCheckMax, vHM);
405 vSaturationCheckMax = simde_mm_max_epi16(vSaturationCheckMax, vHS);
406 vSaturationCheckMax = simde_mm_max_epi16(vSaturationCheckMax, vHL);
407 #ifdef PARASAIL_TABLE
408 arr_store(result->stats->tables->matches_table, vHM, i, segLen, j, s2Len, bias);
409 arr_store(result->stats->tables->similar_table, vHS, i, segLen, j, s2Len, bias);
410 arr_store(result->stats->tables->length_table, vHL, i, segLen, j, s2Len, bias);
411 arr_store(result->stats->tables->score_table, vH, i, segLen, j, s2Len, bias);
412 #endif
413 vMaxH = simde_mm_max_epi16(vH, vMaxH);
414 vEF_opn = simde_mm_subs_epi16(vH, vGapO);
415
416 /* Update vE value. */
417 vE_ext = simde_mm_subs_epi16(vE, vGapE);
418 vE = simde_mm_max_epi16(vEF_opn, vE_ext);
419 case1 = simde_mm_cmpgt_epi16(vEF_opn, vE_ext);
420 vEM = simde_mm_blendv_epi8(vEM, vHM, case1);
421 vES = simde_mm_blendv_epi8(vES, vHS, case1);
422 vEL = simde_mm_blendv_epi8(
423 simde_mm_adds_epi16(vEL, vOne),
424 simde_mm_adds_epi16(vHL, vOne),
425 case1);
426 simde_mm_store_si128(pvE + i, vE);
427 simde_mm_store_si128(pvEM + i, vEM);
428 simde_mm_store_si128(pvES + i, vES);
429 simde_mm_store_si128(pvEL + i, vEL);
430
431 /* Update vF value. */
432 vF_ext = simde_mm_subs_epi16(vF, vGapE);
433 vF = simde_mm_max_epi16(vEF_opn, vF_ext);
434 case1 = simde_mm_cmpgt_epi16(vEF_opn, vF_ext);
435 vFM = simde_mm_blendv_epi8(vFM, vHM, case1);
436 vFS = simde_mm_blendv_epi8(vFS, vHS, case1);
437 vFL = simde_mm_blendv_epi8(
438 simde_mm_adds_epi16(vFL, vOne),
439 simde_mm_adds_epi16(vHL, vOne),
440 case1);
441
442 /* Load the next vH. */
443 vH = simde_mm_load_si128(pvHLoad + i);
444 vHM = simde_mm_load_si128(pvHMLoad + i);
445 vHS = simde_mm_load_si128(pvHSLoad + i);
446 vHL = simde_mm_load_si128(pvHLLoad + i);
447 }
448
449 /* Lazy_F loop: has been revised to disallow adjecent insertion and
450 * then deletion, so don't update E(i, i), learn from SWPS3 */
451 for (k=0; k<segWidth; ++k) {
452 simde__m128i vHp = simde_mm_load_si128(&pvHLoad[segLen - 1]);
453 vHp = simde_mm_slli_si128(vHp, 2);
454 vF = simde_mm_slli_si128(vF, 2);
455 vFM = simde_mm_slli_si128(vFM, 2);
456 vFS = simde_mm_slli_si128(vFS, 2);
457 vFL = simde_mm_slli_si128(vFL, 2);
458 vHp = simde_mm_blendv_epi8(vHp, vBias, insert_mask);
459 vF = simde_mm_blendv_epi8(vF, vBias, insert_mask);
460 vFM = simde_mm_blendv_epi8(vFM, vBias, insert_mask);
461 vFS = simde_mm_blendv_epi8(vFS, vBias, insert_mask);
462 vFL = simde_mm_blendv_epi8(vFL, vBias1, insert_mask);
463 for (i=0; i<segLen; ++i) {
464 simde__m128i case1;
465 simde__m128i case2;
466 simde__m128i cond;
467
468 vHp = simde_mm_adds_epi16(vHp, simde_mm_load_si128(vP + i));
469 vH = simde_mm_load_si128(pvHStore + i);
470 vH = simde_mm_max_epi16(vH, vF);
471 simde_mm_store_si128(pvHStore + i, vH);
472 case1 = simde_mm_cmpeq_epi16(vH, vHp);
473 case2 = simde_mm_cmpeq_epi16(vH, vF);
474 cond = simde_mm_andnot_si128(case1, case2);
475
476 /* calculate vM */
477 vHM = simde_mm_load_si128(pvHMStore + i);
478 vHM = simde_mm_blendv_epi8(vHM, vFM, cond);
479 simde_mm_store_si128(pvHMStore + i, vHM);
480
481 /* calculate vS */
482 vHS = simde_mm_load_si128(pvHSStore + i);
483 vHS = simde_mm_blendv_epi8(vHS, vFS, cond);
484 simde_mm_store_si128(pvHSStore + i, vHS);
485
486 /* calculate vL */
487 vHL = simde_mm_load_si128(pvHLStore + i);
488 vHL = simde_mm_blendv_epi8(vHL, vFL, cond);
489 simde_mm_store_si128(pvHLStore + i, vHL);
490
491 vSaturationCheckMax = simde_mm_max_epi16(vSaturationCheckMax, vHM);
492 vSaturationCheckMax = simde_mm_max_epi16(vSaturationCheckMax, vHS);
493 vSaturationCheckMax = simde_mm_max_epi16(vSaturationCheckMax, vHL);
494 #ifdef PARASAIL_TABLE
495 arr_store(result->stats->tables->matches_table, vHM, i, segLen, j, s2Len, bias);
496 arr_store(result->stats->tables->similar_table, vHS, i, segLen, j, s2Len, bias);
497 arr_store(result->stats->tables->length_table, vHL, i, segLen, j, s2Len, bias);
498 arr_store(result->stats->tables->score_table, vH, i, segLen, j, s2Len, bias);
499 #endif
500 vMaxH = simde_mm_max_epi16(vH, vMaxH);
501 /* Update vF value. */
502 vEF_opn = simde_mm_subs_epi16(vH, vGapO);
503 vF_ext = simde_mm_subs_epi16(vF, vGapE);
504 if (! simde_mm_movemask_epi8(
505 simde_mm_or_si128(
506 simde_mm_cmpgt_epi16(vF_ext, vEF_opn),
507 simde_mm_and_si128(
508 simde_mm_cmpeq_epi16(vF_ext, vEF_opn),
509 simde_mm_cmpgt_epi16(vF_ext, vBias)))))
510 goto end;
511 /*vF = simde_mm_max_epi16(vEF_opn, vF_ext);*/
512 vF = vF_ext;
513 cond = simde_mm_cmpgt_epi16(vEF_opn, vF_ext);
514 vFM = simde_mm_blendv_epi8(vFM, vHM, cond);
515 vFS = simde_mm_blendv_epi8(vFS, vHS, cond);
516 vFL = simde_mm_blendv_epi8(
517 simde_mm_adds_epi16(vFL, vOne),
518 simde_mm_adds_epi16(vHL, vOne),
519 cond);
520 vHp = simde_mm_load_si128(pvHLoad + i);
521 }
522 }
523 end:
524 {
525 }
526
527 #ifdef PARASAIL_ROWCOL
528 /* extract last value from the column */
529 {
530 vH = simde_mm_load_si128(pvHStore + offset);
531 vHM = simde_mm_load_si128(pvHMStore + offset);
532 vHS = simde_mm_load_si128(pvHSStore + offset);
533 vHL = simde_mm_load_si128(pvHLStore + offset);
534 for (k=0; k<position; ++k) {
535 vH = simde_mm_slli_si128(vH, 2);
536 vHM = simde_mm_slli_si128(vHM, 2);
537 vHS = simde_mm_slli_si128(vHS, 2);
538 vHL = simde_mm_slli_si128(vHL, 2);
539 }
540 result->stats->rowcols->score_row[j] = (int16_t) simde_mm_extract_epi16 (vH, 7) - bias;
541 result->stats->rowcols->matches_row[j] = (int16_t) simde_mm_extract_epi16 (vHM, 7) - bias;
542 result->stats->rowcols->similar_row[j] = (int16_t) simde_mm_extract_epi16 (vHS, 7) - bias;
543 result->stats->rowcols->length_row[j] = (int16_t) simde_mm_extract_epi16 (vHL, 7) - bias;
544 }
545 #endif
546
547 {
548 simde__m128i vCompare = simde_mm_cmpgt_epi16(vMaxH, vMaxHUnit);
549 if (simde_mm_movemask_epi8(vCompare)) {
550 score = simde_mm_hmax_epi16(vMaxH);
551 /* if score has potential to overflow, abort early */
552 if (score > maxp) {
553 result->flag |= PARASAIL_FLAG_SATURATED;
554 break;
555 }
556 vMaxHUnit = simde_mm_set1_epi16(score);
557 end_ref = j;
558 }
559 }
560 }
561
562 #ifdef PARASAIL_ROWCOL
563 for (i=0; i<segLen; ++i) {
564 simde__m128i vH = simde_mm_load_si128(pvHStore+i);
565 simde__m128i vHM = simde_mm_load_si128(pvHMStore+i);
566 simde__m128i vHS = simde_mm_load_si128(pvHSStore+i);
567 simde__m128i vHL = simde_mm_load_si128(pvHLStore+i);
568 arr_store_col(result->stats->rowcols->score_col, vH, i, segLen, bias);
569 arr_store_col(result->stats->rowcols->matches_col, vHM, i, segLen, bias);
570 arr_store_col(result->stats->rowcols->similar_col, vHS, i, segLen, bias);
571 arr_store_col(result->stats->rowcols->length_col, vHL, i, segLen, bias);
572 }
573 #endif
574
575 if (score == INT16_MAX
576 || simde_mm_movemask_epi8(simde_mm_cmpeq_epi16(vSaturationCheckMax,vPosLimit))) {
577 result->flag |= PARASAIL_FLAG_SATURATED;
578 }
579
580 if (parasail_result_is_saturated(result)) {
581 score = 0;
582 end_query = 0;
583 end_ref = 0;
584 matches = 0;
585 similar = 0;
586 length = 0;
587 }
588 else {
589 if (end_ref == j-1) {
590 /* end_ref was the last store column */
591 SWAP(pvHMax, pvHStore)
592 SWAP(pvHMMax, pvHMStore)
593 SWAP(pvHSMax, pvHSStore)
594 SWAP(pvHLMax, pvHLStore)
595 }
596 else if (end_ref == j-2) {
597 /* end_ref was the last load column */
598 SWAP(pvHMax, pvHLoad)
599 SWAP(pvHMMax, pvHMLoad)
600 SWAP(pvHSMax, pvHSLoad)
601 SWAP(pvHLMax, pvHLLoad)
602 }
603 /* Trace the alignment ending position on read. */
604 {
605 int16_t *t = (int16_t*)pvHMax;
606 int16_t *m = (int16_t*)pvHMMax;
607 int16_t *s = (int16_t*)pvHSMax;
608 int16_t *l = (int16_t*)pvHLMax;
609 int32_t column_len = segLen * segWidth;
610 end_query = s1Len;
611 for (i = 0; i<column_len; ++i, ++t, ++m, ++s, ++l) {
612 if (*t == score) {
613 int32_t temp = i / segWidth + i % segWidth * segLen;
614 if (temp < end_query) {
615 end_query = temp;
616 matches = *m;
617 similar = *s;
618 length = *l;
619 }
620 }
621 }
622 }
623 }
624
625 result->score = score - bias;
626 result->end_query = end_query;
627 result->end_ref = end_ref;
628 result->stats->matches = matches - bias;
629 result->stats->similar = similar - bias;
630 result->stats->length = length - bias;
631
632 parasail_free(pvHLMax);
633 parasail_free(pvHSMax);
634 parasail_free(pvHMMax);
635 parasail_free(pvHMax);
636 parasail_free(pvEL);
637 parasail_free(pvES);
638 parasail_free(pvEM);
639 parasail_free(pvE);
640 parasail_free(pvHLLoad);
641 parasail_free(pvHLStore);
642 parasail_free(pvHSLoad);
643 parasail_free(pvHSStore);
644 parasail_free(pvHMLoad);
645 parasail_free(pvHMStore);
646 parasail_free(pvHLoad);
647 parasail_free(pvHStore);
648
649 return result;
650 }
651
652 #ifdef FASTSTATS
653 #ifdef PARASAIL_TABLE
654 #else
655 #ifdef PARASAIL_ROWCOL
656 #else
657 #include <assert.h>
658 parasail_result_t* INAME(
659 const parasail_profile_t * const restrict profile,
660 const char * const restrict s2, const int s2Len,
661 const int open, const int gap)
662 {
663 const char *s1 = profile->s1;
664 const parasail_matrix_t *matrix = profile->matrix;
665
666 /* find the end loc first with the faster implementation */
667 parasail_result_t *result = parasail_sw_striped_profile_neon_128_16(profile, s2, s2Len, open, gap);
668 if (!parasail_result_is_saturated(result)) {
669 #if 0
670 int s1Len_new = 0;
671 int s2Len_new = 0;
672 char *s1_new = NULL;
673 char *s2_new = NULL;
674 parasail_profile_t *profile_new = NULL;
675 parasail_result_t *result_new = NULL;
676 int s1_begin = 0;
677 int s2_begin = 0;
678 int s1Len_final = 0;
679 int s2Len_final = 0;
680 parasail_profile_t *profile_final = NULL;
681 parasail_result_t *result_final = NULL;
682
683 /* using the end loc and the non-stats version of the function,
684 * reverse the inputs and find the beg loc */
685 s1Len_new = result->end_query+1;
686 s2Len_new = result->end_ref+1;
687 s1_new = parasail_reverse(s1, s1Len_new);
688 s2_new = parasail_reverse(s2, s2Len_new);
689 profile_new = parasail_profile_create_neon_128_16(
690 s1_new, s1Len_new, matrix);
691 profile_new->stop = result->score;
692 result_new = parasail_sw_striped_profile_neon_128_16(
693 profile_new, s2_new, s2Len_new, open, gap);
694
695 /* using both the beg and end loc, call the original stats func */
696 s1_begin = s1Len_new - result_new->end_query - 1;
697 s2_begin = s2Len_new - result_new->end_ref - 1;
698 s1Len_final = s1Len_new - s1_begin;
699 s2Len_final = s2Len_new - s2_begin;
700 assert(s1_begin >= 0);
701 assert(s2_begin >= 0);
702 assert(s1Len_new > s1_begin);
703 assert(s2Len_new > s2_begin);
704 profile_final = parasail_profile_create_stats_neon_128_16(
705 &s1[s1_begin], s1Len_final, matrix);
706 result_final = PNAME(
707 profile_final, &s2[s2_begin], s2Len_final, open, gap);
708
709 /* clean up all the temporary profiles, sequences, and results */
710 free(s1_new);
711 free(s2_new);
712 parasail_profile_free(profile_new);
713 parasail_profile_free(profile_final);
714 parasail_result_free(result);
715 parasail_result_free(result_new);
716
717 /* correct the end locations before returning */
718 result_final->end_query = s1Len_new-1;
719 result_final->end_ref = s2Len_new-1;
720 return result_final;
721 #else
722 int s1Len_new = 0;
723 int s2Len_new = 0;
724 parasail_profile_t *profile_final = NULL;
725 parasail_result_t *result_final = NULL;
726
727 /* using the end loc, call the original stats function */
728 s1Len_new = result->end_query+1;
729 s2Len_new = result->end_ref+1;
730 profile_final = parasail_profile_create_stats_neon_128_16(
731 s1, s1Len_new, matrix);
732 result_final = PNAME(
733 profile_final, s2, s2Len_new, open, gap);
734
735 /* clean up all the temporary profiles, sequences, and results */
736 parasail_profile_free(profile_final);
737 parasail_result_free(result);
738
739 /* correct the end locations before returning */
740 result_final->end_query = s1Len_new-1;
741 result_final->end_ref = s2Len_new-1;
742 return result_final;
743 #endif
744 }
745 else {
746 return result;
747 }
748 }
749 #endif
750 #endif
751 #endif
752
753