Debian Codegraph @

src/sw_diag_neon_128_8.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 <stdlib.h>
11
12
13
14 #include "parasail.h"
15 #include "parasail/memory.h"
16 #include "parasail/internal_neon.h"
17
18
19
20 #ifdef PARASAIL_TABLE
21 static inline void arr_store_si128(
22 int *array,
23 simde__m128i vWH,
24 int32_t i,
25 int32_t s1Len,
26 int32_t j,
27 int32_t s2Len)
28 {
29 if (0 <= i+0 && i+0 < s1Len && 0 <= j-0 && j-0 < s2Len) {
30 array[1LL*(i+0)*s2Len + (j-0)] = (int8_t)simde_mm_extract_epi8(vWH, 15);
31 }
32 if (0 <= i+1 && i+1 < s1Len && 0 <= j-1 && j-1 < s2Len) {
33 array[1LL*(i+1)*s2Len + (j-1)] = (int8_t)simde_mm_extract_epi8(vWH, 14);
34 }
35 if (0 <= i+2 && i+2 < s1Len && 0 <= j-2 && j-2 < s2Len) {
36 array[1LL*(i+2)*s2Len + (j-2)] = (int8_t)simde_mm_extract_epi8(vWH, 13);
37 }
38 if (0 <= i+3 && i+3 < s1Len && 0 <= j-3 && j-3 < s2Len) {
39 array[1LL*(i+3)*s2Len + (j-3)] = (int8_t)simde_mm_extract_epi8(vWH, 12);
40 }
41 if (0 <= i+4 && i+4 < s1Len && 0 <= j-4 && j-4 < s2Len) {
42 array[1LL*(i+4)*s2Len + (j-4)] = (int8_t)simde_mm_extract_epi8(vWH, 11);
43 }
44 if (0 <= i+5 && i+5 < s1Len && 0 <= j-5 && j-5 < s2Len) {
45 array[1LL*(i+5)*s2Len + (j-5)] = (int8_t)simde_mm_extract_epi8(vWH, 10);
46 }
47 if (0 <= i+6 && i+6 < s1Len && 0 <= j-6 && j-6 < s2Len) {
48 array[1LL*(i+6)*s2Len + (j-6)] = (int8_t)simde_mm_extract_epi8(vWH, 9);
49 }
50 if (0 <= i+7 && i+7 < s1Len && 0 <= j-7 && j-7 < s2Len) {
51 array[1LL*(i+7)*s2Len + (j-7)] = (int8_t)simde_mm_extract_epi8(vWH, 8);
52 }
53 if (0 <= i+8 && i+8 < s1Len && 0 <= j-8 && j-8 < s2Len) {
54 array[1LL*(i+8)*s2Len + (j-8)] = (int8_t)simde_mm_extract_epi8(vWH, 7);
55 }
56 if (0 <= i+9 && i+9 < s1Len && 0 <= j-9 && j-9 < s2Len) {
57 array[1LL*(i+9)*s2Len + (j-9)] = (int8_t)simde_mm_extract_epi8(vWH, 6);
58 }
59 if (0 <= i+10 && i+10 < s1Len && 0 <= j-10 && j-10 < s2Len) {
60 array[1LL*(i+10)*s2Len + (j-10)] = (int8_t)simde_mm_extract_epi8(vWH, 5);
61 }
62 if (0 <= i+11 && i+11 < s1Len && 0 <= j-11 && j-11 < s2Len) {
63 array[1LL*(i+11)*s2Len + (j-11)] = (int8_t)simde_mm_extract_epi8(vWH, 4);
64 }
65 if (0 <= i+12 && i+12 < s1Len && 0 <= j-12 && j-12 < s2Len) {
66 array[1LL*(i+12)*s2Len + (j-12)] = (int8_t)simde_mm_extract_epi8(vWH, 3);
67 }
68 if (0 <= i+13 && i+13 < s1Len && 0 <= j-13 && j-13 < s2Len) {
69 array[1LL*(i+13)*s2Len + (j-13)] = (int8_t)simde_mm_extract_epi8(vWH, 2);
70 }
71 if (0 <= i+14 && i+14 < s1Len && 0 <= j-14 && j-14 < s2Len) {
72 array[1LL*(i+14)*s2Len + (j-14)] = (int8_t)simde_mm_extract_epi8(vWH, 1);
73 }
74 if (0 <= i+15 && i+15 < s1Len && 0 <= j-15 && j-15 < s2Len) {
75 array[1LL*(i+15)*s2Len + (j-15)] = (int8_t)simde_mm_extract_epi8(vWH, 0);
76 }
77 }
78 #endif
79
80 #ifdef PARASAIL_ROWCOL
81 static inline void arr_store_rowcol(
82 int *row,
83 int *col,
84 simde__m128i vWH,
85 int32_t i,
86 int32_t s1Len,
87 int32_t j,
88 int32_t s2Len)
89 {
90 if (i+0 == s1Len-1 && 0 <= j-0 && j-0 < s2Len) {
91 row[j-0] = (int8_t)simde_mm_extract_epi8(vWH, 15);
92 }
93 if (j-0 == s2Len-1 && 0 <= i+0 && i+0 < s1Len) {
94 col[(i+0)] = (int8_t)simde_mm_extract_epi8(vWH, 15);
95 }
96 if (i+1 == s1Len-1 && 0 <= j-1 && j-1 < s2Len) {
97 row[j-1] = (int8_t)simde_mm_extract_epi8(vWH, 14);
98 }
99 if (j-1 == s2Len-1 && 0 <= i+1 && i+1 < s1Len) {
100 col[(i+1)] = (int8_t)simde_mm_extract_epi8(vWH, 14);
101 }
102 if (i+2 == s1Len-1 && 0 <= j-2 && j-2 < s2Len) {
103 row[j-2] = (int8_t)simde_mm_extract_epi8(vWH, 13);
104 }
105 if (j-2 == s2Len-1 && 0 <= i+2 && i+2 < s1Len) {
106 col[(i+2)] = (int8_t)simde_mm_extract_epi8(vWH, 13);
107 }
108 if (i+3 == s1Len-1 && 0 <= j-3 && j-3 < s2Len) {
109 row[j-3] = (int8_t)simde_mm_extract_epi8(vWH, 12);
110 }
111 if (j-3 == s2Len-1 && 0 <= i+3 && i+3 < s1Len) {
112 col[(i+3)] = (int8_t)simde_mm_extract_epi8(vWH, 12);
113 }
114 if (i+4 == s1Len-1 && 0 <= j-4 && j-4 < s2Len) {
115 row[j-4] = (int8_t)simde_mm_extract_epi8(vWH, 11);
116 }
117 if (j-4 == s2Len-1 && 0 <= i+4 && i+4 < s1Len) {
118 col[(i+4)] = (int8_t)simde_mm_extract_epi8(vWH, 11);
119 }
120 if (i+5 == s1Len-1 && 0 <= j-5 && j-5 < s2Len) {
121 row[j-5] = (int8_t)simde_mm_extract_epi8(vWH, 10);
122 }
123 if (j-5 == s2Len-1 && 0 <= i+5 && i+5 < s1Len) {
124 col[(i+5)] = (int8_t)simde_mm_extract_epi8(vWH, 10);
125 }
126 if (i+6 == s1Len-1 && 0 <= j-6 && j-6 < s2Len) {
127 row[j-6] = (int8_t)simde_mm_extract_epi8(vWH, 9);
128 }
129 if (j-6 == s2Len-1 && 0 <= i+6 && i+6 < s1Len) {
130 col[(i+6)] = (int8_t)simde_mm_extract_epi8(vWH, 9);
131 }
132 if (i+7 == s1Len-1 && 0 <= j-7 && j-7 < s2Len) {
133 row[j-7] = (int8_t)simde_mm_extract_epi8(vWH, 8);
134 }
135 if (j-7 == s2Len-1 && 0 <= i+7 && i+7 < s1Len) {
136 col[(i+7)] = (int8_t)simde_mm_extract_epi8(vWH, 8);
137 }
138 if (i+8 == s1Len-1 && 0 <= j-8 && j-8 < s2Len) {
139 row[j-8] = (int8_t)simde_mm_extract_epi8(vWH, 7);
140 }
141 if (j-8 == s2Len-1 && 0 <= i+8 && i+8 < s1Len) {
142 col[(i+8)] = (int8_t)simde_mm_extract_epi8(vWH, 7);
143 }
144 if (i+9 == s1Len-1 && 0 <= j-9 && j-9 < s2Len) {
145 row[j-9] = (int8_t)simde_mm_extract_epi8(vWH, 6);
146 }
147 if (j-9 == s2Len-1 && 0 <= i+9 && i+9 < s1Len) {
148 col[(i+9)] = (int8_t)simde_mm_extract_epi8(vWH, 6);
149 }
150 if (i+10 == s1Len-1 && 0 <= j-10 && j-10 < s2Len) {
151 row[j-10] = (int8_t)simde_mm_extract_epi8(vWH, 5);
152 }
153 if (j-10 == s2Len-1 && 0 <= i+10 && i+10 < s1Len) {
154 col[(i+10)] = (int8_t)simde_mm_extract_epi8(vWH, 5);
155 }
156 if (i+11 == s1Len-1 && 0 <= j-11 && j-11 < s2Len) {
157 row[j-11] = (int8_t)simde_mm_extract_epi8(vWH, 4);
158 }
159 if (j-11 == s2Len-1 && 0 <= i+11 && i+11 < s1Len) {
160 col[(i+11)] = (int8_t)simde_mm_extract_epi8(vWH, 4);
161 }
162 if (i+12 == s1Len-1 && 0 <= j-12 && j-12 < s2Len) {
163 row[j-12] = (int8_t)simde_mm_extract_epi8(vWH, 3);
164 }
165 if (j-12 == s2Len-1 && 0 <= i+12 && i+12 < s1Len) {
166 col[(i+12)] = (int8_t)simde_mm_extract_epi8(vWH, 3);
167 }
168 if (i+13 == s1Len-1 && 0 <= j-13 && j-13 < s2Len) {
169 row[j-13] = (int8_t)simde_mm_extract_epi8(vWH, 2);
170 }
171 if (j-13 == s2Len-1 && 0 <= i+13 && i+13 < s1Len) {
172 col[(i+13)] = (int8_t)simde_mm_extract_epi8(vWH, 2);
173 }
174 if (i+14 == s1Len-1 && 0 <= j-14 && j-14 < s2Len) {
175 row[j-14] = (int8_t)simde_mm_extract_epi8(vWH, 1);
176 }
177 if (j-14 == s2Len-1 && 0 <= i+14 && i+14 < s1Len) {
178 col[(i+14)] = (int8_t)simde_mm_extract_epi8(vWH, 1);
179 }
180 if (i+15 == s1Len-1 && 0 <= j-15 && j-15 < s2Len) {
181 row[j-15] = (int8_t)simde_mm_extract_epi8(vWH, 0);
182 }
183 if (j-15 == s2Len-1 && 0 <= i+15 && i+15 < s1Len) {
184 col[(i+15)] = (int8_t)simde_mm_extract_epi8(vWH, 0);
185 }
186 }
187 #endif
188
189 #ifdef PARASAIL_TABLE
190 #define FNAME parasail_sw_table_diag_neon_128_8
191 #else
192 #ifdef PARASAIL_ROWCOL
193 #define FNAME parasail_sw_rowcol_diag_neon_128_8
194 #else
195 #define FNAME parasail_sw_diag_neon_128_8
196 #endif
197 #endif
198
199 parasail_result_t* FNAME(
200 const char * const restrict _s1, const int _s1Len,
201 const char * const restrict _s2, const int s2Len,
202 const int open, const int gap, const parasail_matrix_t *matrix)
203 {
204 /* declare local variables */
205 int32_t N = 0;
206 int32_t PAD = 0;
207 int32_t PAD2 = 0;
208 int32_t s1Len = 0;
209 int32_t s1Len_PAD = 0;
210 int32_t s2Len_PAD = 0;
211 int8_t * restrict s1 = NULL;
212 int8_t * restrict s2B = NULL;
213 int8_t * restrict _H_pr = NULL;
214 int8_t * restrict _F_pr = NULL;
215 int8_t * restrict s2 = NULL;
216 int8_t * restrict H_pr = NULL;
217 int8_t * restrict F_pr = NULL;
218 parasail_result_t *result = NULL;
219 int32_t i = 0;
220 int32_t j = 0;
221 int32_t end_query = 0;
222 int32_t end_ref = 0;
223 int8_t NEG_LIMIT = 0;
224 int8_t POS_LIMIT = 0;
225 int8_t score = 0;
226 simde__m128i vNegLimit;
227 simde__m128i vPosLimit;
228 simde__m128i vSaturationCheckMin;
229 simde__m128i vSaturationCheckMax;
230 simde__m128i vNegInf;
231 simde__m128i vNegInf0;
232 simde__m128i vOpen;
233 simde__m128i vGap;
234 simde__m128i vZero;
235 simde__m128i vOne16;
236 simde__m128i vNegOne16;
237 simde__m128i vN16;
238 simde__m128i vILo16;
239 simde__m128i vIHi16;
240 simde__m128i vJresetLo16;
241 simde__m128i vJresetHi16;
242 simde__m128i vMaxH;
243 simde__m128i vEndILo;
244 simde__m128i vEndIHi;
245 simde__m128i vEndJLo;
246 simde__m128i vEndJHi;
247 simde__m128i vILimit16;
248 simde__m128i vJLimit16;
249
250 /* validate inputs */
251 PARASAIL_CHECK_NULL(_s2);
252 PARASAIL_CHECK_GT0(s2Len);
253 PARASAIL_CHECK_GE0(open);
254 PARASAIL_CHECK_GE0(gap);
255 PARASAIL_CHECK_NULL(matrix);
256 if (matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) {
257 PARASAIL_CHECK_NULL(_s1);
258 PARASAIL_CHECK_GT0(_s1Len);
259 }
260
261 /* initialize stack variables */
262 N = 16; /* number of values in vector */
263 PAD = N-1;
264 PAD2 = PAD*2;
265 s1Len = matrix->type == PARASAIL_MATRIX_TYPE_SQUARE ? _s1Len : matrix->length;
266 s1Len_PAD = s1Len+PAD;
267 s2Len_PAD = s2Len+PAD;
268 i = 0;
269 j = 0;
270 end_query = 0;
271 end_ref = 0;
272 NEG_LIMIT = (-open < matrix->min ? INT8_MIN + open : INT8_MIN - matrix->min) + 1;
273 POS_LIMIT = INT8_MAX - matrix->max - 1;
274 score = NEG_LIMIT;
275 vNegLimit = simde_mm_set1_epi8(NEG_LIMIT);
276 vPosLimit = simde_mm_set1_epi8(POS_LIMIT);
277 vSaturationCheckMin = vPosLimit;
278 vSaturationCheckMax = vNegLimit;
279 vNegInf = simde_mm_set1_epi8(NEG_LIMIT);
280 vNegInf0 = simde_mm_srli_si128(vNegInf, 1); /* shift in a 0 */
281 vOpen = simde_mm_set1_epi8(open);
282 vGap = simde_mm_set1_epi8(gap);
283 vZero = simde_mm_set1_epi8(0);
284 vOne16 = simde_mm_set1_epi16(1);
285 vNegOne16 = simde_mm_set1_epi16(-1);
286 vN16 = simde_mm_set1_epi16(N);
287 vILo16 = simde_mm_set_epi16(8,9,10,11,12,13,14,15);
288 vIHi16 = simde_mm_set_epi16(0,1,2,3,4,5,6,7);
289 vJresetLo16 = simde_mm_set_epi16(-8,-9,-10,-11,-12,-13,-14,-15);
290 vJresetHi16 = simde_mm_set_epi16(0,-1,-2,-3,-4,-5,-6,-7);
291 vMaxH = vNegInf;
292 vEndILo = vNegInf;
293 vEndIHi = vNegInf;
294 vEndJLo = vNegInf;
295 vEndJHi = vNegInf;
296 vILimit16 = simde_mm_set1_epi16(s1Len);
297 vJLimit16 = simde_mm_set1_epi16(s2Len);
298
299 /* initialize result */
300 #ifdef PARASAIL_TABLE
301 result = parasail_result_new_table1(s1Len, s2Len);
302 #else
303 #ifdef PARASAIL_ROWCOL
304 result = parasail_result_new_rowcol1(s1Len, s2Len);
305 #else
306 result = parasail_result_new();
307 #endif
308 #endif
309 if (!result) return NULL;
310
311 /* set known flags */
312 result->flag |= PARASAIL_FLAG_SW | PARASAIL_FLAG_DIAG
313 | PARASAIL_FLAG_BITS_8 | PARASAIL_FLAG_LANES_16;
314 #ifdef PARASAIL_TABLE
315 result->flag |= PARASAIL_FLAG_TABLE;
316 #endif
317 #ifdef PARASAIL_ROWCOL
318 result->flag |= PARASAIL_FLAG_ROWCOL;
319 #endif
320
321 /* initialize heap variables */
322 s2B= parasail_memalign_int8_t(16, s2Len+PAD2);
323 _H_pr = parasail_memalign_int8_t(16, s2Len+PAD2);
324 _F_pr = parasail_memalign_int8_t(16, s2Len+PAD2);
325 s2 = s2B+PAD; /* will allow later for negative indices */
326 H_pr = _H_pr+PAD;
327 F_pr = _F_pr+PAD;
328
329 /* validate heap variables */
330 if (!s2B) return NULL;
331 if (!_H_pr) return NULL;
332 if (!_F_pr) return NULL;
333
334 /* convert _s1 from char to int in range 0-23 */
335 if (matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) {
336 s1 = parasail_memalign_int8_t(16, s1Len+PAD);
337 if (!s1) return NULL;
338 for (i=0; i<s1Len; ++i) {
339 s1[i] = matrix->mapper[(unsigned char)_s1[i]];
340 }
341 /* pad back of s1 with dummy values */
342 for (i=s1Len; i<s1Len_PAD; ++i) {
343 s1[i] = 0; /* point to first matrix row because we don't care */
344 }
345 }
346
347 /* convert _s2 from char to int in range 0-23 */
348 for (j=0; j<s2Len; ++j) {
349 s2[j] = matrix->mapper[(unsigned char)_s2[j]];
350 }
351 /* pad front of s2 with dummy values */
352 for (j=-PAD; j<0; ++j) {
353 s2[j] = 0; /* point to first matrix row because we don't care */
354 }
355 /* pad back of s2 with dummy values */
356 for (j=s2Len; j<s2Len_PAD; ++j) {
357 s2[j] = 0; /* point to first matrix row because we don't care */
358 }
359
360 /* set initial values for stored row */
361 for (j=0; j<s2Len; ++j) {
362 H_pr[j] = 0;
363 F_pr[j] = NEG_LIMIT;
364 }
365 /* pad front of stored row values */
366 for (j=-PAD; j<0; ++j) {
367 H_pr[j] = NEG_LIMIT;
368 F_pr[j] = NEG_LIMIT;
369 }
370 /* pad back of stored row values */
371 for (j=s2Len; j<s2Len+PAD; ++j) {
372 H_pr[j] = NEG_LIMIT;
373 F_pr[j] = NEG_LIMIT;
374 }
375
376 /* iterate over query sequence */
377 for (i=0; i<s1Len; i+=N) {
378 simde__m128i vNH = vNegInf0;
379 simde__m128i vWH = vNegInf0;
380 simde__m128i vE = vNegInf;
381 simde__m128i vF = vNegInf;
382 simde__m128i vJLo16 = vJresetLo16;
383 simde__m128i vJHi16 = vJresetHi16;
384 const int * const restrict matrow0 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+0] : ((i+0 >= s1Len) ? s1Len-1 : i+0))];
385 const int * const restrict matrow1 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+1] : ((i+1 >= s1Len) ? s1Len-1 : i+1))];
386 const int * const restrict matrow2 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+2] : ((i+2 >= s1Len) ? s1Len-1 : i+2))];
387 const int * const restrict matrow3 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+3] : ((i+3 >= s1Len) ? s1Len-1 : i+3))];
388 const int * const restrict matrow4 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+4] : ((i+4 >= s1Len) ? s1Len-1 : i+4))];
389 const int * const restrict matrow5 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+5] : ((i+5 >= s1Len) ? s1Len-1 : i+5))];
390 const int * const restrict matrow6 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+6] : ((i+6 >= s1Len) ? s1Len-1 : i+6))];
391 const int * const restrict matrow7 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+7] : ((i+7 >= s1Len) ? s1Len-1 : i+7))];
392 const int * const restrict matrow8 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+8] : ((i+8 >= s1Len) ? s1Len-1 : i+8))];
393 const int * const restrict matrow9 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+9] : ((i+9 >= s1Len) ? s1Len-1 : i+9))];
394 const int * const restrict matrow10 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+10] : ((i+10 >= s1Len) ? s1Len-1 : i+10))];
395 const int * const restrict matrow11 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+11] : ((i+11 >= s1Len) ? s1Len-1 : i+11))];
396 const int * const restrict matrow12 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+12] : ((i+12 >= s1Len) ? s1Len-1 : i+12))];
397 const int * const restrict matrow13 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+13] : ((i+13 >= s1Len) ? s1Len-1 : i+13))];
398 const int * const restrict matrow14 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+14] : ((i+14 >= s1Len) ? s1Len-1 : i+14))];
399 const int * const restrict matrow15 = &matrix->matrix[matrix->size * ((matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) ? s1[i+15] : ((i+15 >= s1Len) ? s1Len-1 : i+15))];
400 simde__m128i vIltLimit = simde_mm_packs_epi16(
401 simde_mm_cmplt_epi16(vILo16, vILimit16),
402 simde_mm_cmplt_epi16(vIHi16, vILimit16));
403 /* iterate over database sequence */
404 for (j=0; j<s2Len+PAD; ++j) {
405 simde__m128i vMat;
406 simde__m128i vNWH = vNH;
407 vNH = simde_mm_srli_si128(vWH, 1);
408 vNH = simde_mm_insert_epi8(vNH, H_pr[j], 15);
409 vF = simde_mm_srli_si128(vF, 1);
410 vF = simde_mm_insert_epi8(vF, F_pr[j], 15);
411 vF = simde_mm_max_epi8(
412 simde_mm_subs_epi8(vNH, vOpen),
413 simde_mm_subs_epi8(vF, vGap));
414 vE = simde_mm_max_epi8(
415 simde_mm_subs_epi8(vWH, vOpen),
416 simde_mm_subs_epi8(vE, vGap));
417 vMat = simde_mm_set_epi8(
418 matrow0[s2[j-0]],
419 matrow1[s2[j-1]],
420 matrow2[s2[j-2]],
421 matrow3[s2[j-3]],
422 matrow4[s2[j-4]],
423 matrow5[s2[j-5]],
424 matrow6[s2[j-6]],
425 matrow7[s2[j-7]],
426 matrow8[s2[j-8]],
427 matrow9[s2[j-9]],
428 matrow10[s2[j-10]],
429 matrow11[s2[j-11]],
430 matrow12[s2[j-12]],
431 matrow13[s2[j-13]],
432 matrow14[s2[j-14]],
433 matrow15[s2[j-15]]
434 );
435 vNWH = simde_mm_adds_epi8(vNWH, vMat);
436 vWH = simde_mm_max_epi8(vNWH, vE);
437 vWH = simde_mm_max_epi8(vWH, vF);
438 vWH = simde_mm_max_epi8(vWH, vZero);
439 /* as minor diagonal vector passes across the j=-1 boundary,
440 * assign the appropriate boundary conditions */
441 {
442 simde__m128i cond = simde_mm_packs_epi16(
443 simde_mm_cmpeq_epi16(vJLo16,vNegOne16),
444 simde_mm_cmpeq_epi16(vJHi16,vNegOne16));
445 vWH = simde_mm_andnot_si128(cond, vWH);
446 vF = simde_mm_blendv_epi8(vF, vNegInf, cond);
447 vE = simde_mm_blendv_epi8(vE, vNegInf, cond);
448 }
449 /* cannot start checking sat until after J clears boundary */
450 if (j > PAD) {
451 vSaturationCheckMin = simde_mm_min_epi8(vSaturationCheckMin, vWH);
452 vSaturationCheckMax = simde_mm_max_epi8(vSaturationCheckMax, vWH);
453 }
454 #ifdef PARASAIL_TABLE
455 arr_store_si128(result->tables->score_table, vWH, i, s1Len, j, s2Len);
456 #endif
457 #ifdef PARASAIL_ROWCOL
458 arr_store_rowcol(result->rowcols->score_row, result->rowcols->score_col, vWH, i, s1Len, j, s2Len);
459 #endif
460 H_pr[j-15] = (int8_t)simde_mm_extract_epi8(vWH,0);
461 F_pr[j-15] = (int8_t)simde_mm_extract_epi8(vF,0);
462 /* as minor diagonal vector passes across table, extract
463 * max values within the i,j bounds */
464 {
465 simde__m128i cond_valid_J = simde_mm_and_si128(
466 simde_mm_packs_epi16(
467 simde_mm_cmpgt_epi16(vJLo16, vNegOne16),
468 simde_mm_cmpgt_epi16(vJHi16, vNegOne16)),
469 simde_mm_packs_epi16(
470 simde_mm_cmplt_epi16(vJLo16, vJLimit16),
471 simde_mm_cmplt_epi16(vJHi16, vJLimit16)));
472 simde__m128i cond_valid_IJ = simde_mm_and_si128(cond_valid_J, vIltLimit);
473 simde__m128i cond_eq = simde_mm_cmpeq_epi8(vWH, vMaxH);
474 simde__m128i cond_max = simde_mm_cmpgt_epi8(vWH, vMaxH);
475 simde__m128i cond_all = simde_mm_and_si128(cond_max, cond_valid_IJ);
476 simde__m128i cond_Jlt = simde_mm_packs_epi16(
477 simde_mm_cmplt_epi16(vJLo16, vEndJLo),
478 simde_mm_cmplt_epi16(vJHi16, vEndJHi));
479 simde__m128i cond_lo = simde_mm_unpacklo_epi8(cond_all, cond_all);
480 simde__m128i cond_hi = simde_mm_unpackhi_epi8(cond_all, cond_all);
481 vMaxH = simde_mm_blendv_epi8(vMaxH, vWH, cond_all);
482 vEndILo = simde_mm_blendv_epi8(vEndILo, vILo16, cond_lo);
483 vEndIHi = simde_mm_blendv_epi8(vEndIHi, vIHi16, cond_hi);
484 vEndJLo = simde_mm_blendv_epi8(vEndJLo, vJLo16, cond_lo);
485 vEndJHi = simde_mm_blendv_epi8(vEndJHi, vJHi16, cond_hi);
486 cond_all = simde_mm_and_si128(cond_Jlt, cond_eq);
487 cond_all = simde_mm_and_si128(cond_all, cond_valid_IJ);
488 cond_lo = simde_mm_unpacklo_epi8(cond_all, cond_all);
489 cond_hi = simde_mm_unpackhi_epi8(cond_all, cond_all);
490 vEndILo = simde_mm_blendv_epi8(vEndILo, vILo16, cond_lo);
491 vEndIHi = simde_mm_blendv_epi8(vEndIHi, vIHi16, cond_hi);
492 vEndJLo = simde_mm_blendv_epi8(vEndJLo, vJLo16, cond_lo);
493 vEndJHi = simde_mm_blendv_epi8(vEndJHi, vJHi16, cond_hi);
494 }
495 vJLo16 = simde_mm_add_epi16(vJLo16, vOne16);
496 vJHi16 = simde_mm_add_epi16(vJHi16, vOne16);
497 }
498 vILo16 = simde_mm_add_epi16(vILo16, vN16);
499 vIHi16 = simde_mm_add_epi16(vIHi16, vN16);
500 }
501
502 /* alignment ending position */
503 {
504 int8_t *t = (int8_t*)&vMaxH;
505 int16_t *ilo = (int16_t*)&vEndILo;
506 int16_t *jlo = (int16_t*)&vEndJLo;
507 int16_t *ihi = (int16_t*)&vEndIHi;
508 int16_t *jhi = (int16_t*)&vEndJHi;
509 int32_t k;
510 for (k=0; k<N/2; ++k, ++t, ++ilo, ++jlo) {
511 if (*t > score) {
512 score = *t;
513 end_query = *ilo;
514 end_ref = *jlo;
515 }
516 else if (*t == score) {
517 if (*jlo < end_ref) {
518 end_query = *ilo;
519 end_ref = *jlo;
520 }
521 else if (*jlo == end_ref && *ilo < end_query) {
522 end_query = *ilo;
523 end_ref = *jlo;
524 }
525 }
526 }
527 for (k=N/2; k<N; ++k, ++t, ++ihi, ++jhi) {
528 if (*t > score) {
529 score = *t;
530 end_query = *ihi;
531 end_ref = *jhi;
532 }
533 else if (*t == score) {
534 if (*jhi < end_ref) {
535 end_query = *ihi;
536 end_ref = *jhi;
537 }
538 else if (*jhi == end_ref && *ihi < end_query) {
539 end_query = *ihi;
540 end_ref = *jhi;
541 }
542 }
543 }
544 }
545
546 if (simde_mm_movemask_epi8(simde_mm_or_si128(
547 simde_mm_cmplt_epi8(vSaturationCheckMin, vNegLimit),
548 simde_mm_cmpgt_epi8(vSaturationCheckMax, vPosLimit)))) {
549 result->flag |= PARASAIL_FLAG_SATURATED;
550 score = 0;
551 end_query = 0;
552 end_ref = 0;
553 }
554
555 result->score = score;
556 result->end_query = end_query;
557 result->end_ref = end_ref;
558
559 parasail_free(_F_pr);
560 parasail_free(_H_pr);
561 parasail_free(s2B);
562 if (matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) {
563 parasail_free(s1);
564 }
565
566 return result;
567 }
568
569