/** * @file * * @author jeffrey.daily@gmail.com * * Copyright (c) 2015 Battelle Memorial Institute. */ #include "config.h" #include #include #include "parasail.h" #include "parasail/memory.h" #include "parasail/internal_neon.h" #define SG_SUFFIX _striped_neon_128_64 #define SG_SUFFIX_PROF _striped_profile_neon_128_64 #include "sg_helper.h" #ifdef PARASAIL_TABLE static inline void arr_store_si128( int *array, simde__m128i vH, int32_t t, int32_t seglen, int32_t d, int32_t dlen) { array[1LL*(0*seglen+t)*dlen + d] = (int64_t)simde_mm_extract_epi64(vH, 0); array[1LL*(1*seglen+t)*dlen + d] = (int64_t)simde_mm_extract_epi64(vH, 1); } #endif #ifdef PARASAIL_ROWCOL static inline void arr_store_col( int *col, simde__m128i vH, int32_t t, int32_t seglen) { col[0*seglen+t] = (int64_t)simde_mm_extract_epi64(vH, 0); col[1*seglen+t] = (int64_t)simde_mm_extract_epi64(vH, 1); } #endif #ifdef PARASAIL_TABLE #define FNAME parasail_sg_flags_table_striped_neon_128_64 #define PNAME parasail_sg_flags_table_striped_profile_neon_128_64 #else #ifdef PARASAIL_ROWCOL #define FNAME parasail_sg_flags_rowcol_striped_neon_128_64 #define PNAME parasail_sg_flags_rowcol_striped_profile_neon_128_64 #else #define FNAME parasail_sg_flags_striped_neon_128_64 #define PNAME parasail_sg_flags_striped_profile_neon_128_64 #endif #endif parasail_result_t* FNAME( const char * const restrict s1, const int s1Len, const char * const restrict s2, const int s2Len, const int open, const int gap, const parasail_matrix_t *matrix, int s1_beg, int s1_end, int s2_beg, int s2_end) { /* declare local variables */ parasail_profile_t *profile = NULL; parasail_result_t *result = NULL; /* validate inputs */ PARASAIL_CHECK_NULL(s2); PARASAIL_CHECK_GT0(s2Len); PARASAIL_CHECK_GE0(open); PARASAIL_CHECK_GE0(gap); PARASAIL_CHECK_NULL(matrix); if (matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) { PARASAIL_CHECK_NULL(s1); PARASAIL_CHECK_GT0(s1Len); } /* initialize local variables */ profile = parasail_profile_create_neon_128_64(s1, s1Len, matrix); if (!profile) return NULL; result = PNAME(profile, s2, s2Len, open, gap, s1_beg, s1_end, s2_beg, s2_end); parasail_profile_free(profile); return result; } parasail_result_t* PNAME( const parasail_profile_t * const restrict profile, const char * const restrict s2, const int s2Len, const int open, const int gap, int s1_beg, int s1_end, int s2_beg, int s2_end) { /* declare local variables */ int32_t i = 0; int32_t j = 0; int32_t k = 0; int32_t s1Len = 0; int32_t end_query = 0; int32_t end_ref = 0; const parasail_matrix_t *matrix = NULL; int32_t segWidth = 0; int32_t segLen = 0; int32_t offset = 0; int32_t position = 0; simde__m128i* restrict vProfile = NULL; simde__m128i* restrict pvHStore = NULL; simde__m128i* restrict pvHLoad = NULL; simde__m128i* restrict pvE = NULL; int64_t* restrict boundary = NULL; simde__m128i vGapO; simde__m128i vGapE; int64_t NEG_LIMIT = 0; int64_t POS_LIMIT = 0; int64_t score = 0; simde__m128i vNegLimit; simde__m128i vPosLimit; simde__m128i vSaturationCheckMin; simde__m128i vSaturationCheckMax; simde__m128i vMaxH; simde__m128i vPosMask; parasail_result_t *result = NULL; /* validate inputs */ PARASAIL_CHECK_NULL(profile); PARASAIL_CHECK_NULL(profile->profile64.score); PARASAIL_CHECK_NULL(profile->matrix); PARASAIL_CHECK_GT0(profile->s1Len); PARASAIL_CHECK_NULL(s2); PARASAIL_CHECK_GT0(s2Len); PARASAIL_CHECK_GE0(open); PARASAIL_CHECK_GE0(gap); /* initialize stack variables */ i = 0; j = 0; k = 0; s1Len = profile->s1Len; end_query = s1Len-1; end_ref = s2Len-1; matrix = profile->matrix; segWidth = 2; /* number of values in vector unit */ segLen = (s1Len + segWidth - 1) / segWidth; offset = (s1Len - 1) % segLen; position = (segWidth - 1) - (s1Len - 1) / segLen; vProfile = (simde__m128i*)profile->profile64.score; vGapO = simde_mm_set1_epi64x(open); vGapE = simde_mm_set1_epi64x(gap); NEG_LIMIT = (-open < matrix->min ? INT64_MIN + open : INT64_MIN - matrix->min) + 1; POS_LIMIT = INT64_MAX - matrix->max - 1; score = NEG_LIMIT; vNegLimit = simde_mm_set1_epi64x(NEG_LIMIT); vPosLimit = simde_mm_set1_epi64x(POS_LIMIT); vSaturationCheckMin = vPosLimit; vSaturationCheckMax = vNegLimit; vMaxH = vNegLimit; vPosMask = simde_mm_cmpeq_epi64(simde_mm_set1_epi64x(position), simde_mm_set_epi64x(0,1)); /* initialize result */ #ifdef PARASAIL_TABLE result = parasail_result_new_table1(segLen*segWidth, s2Len); #else #ifdef PARASAIL_ROWCOL result = parasail_result_new_rowcol1(segLen*segWidth, s2Len); #else result = parasail_result_new(); #endif #endif if (!result) return NULL; /* set known flags */ result->flag |= PARASAIL_FLAG_SG | PARASAIL_FLAG_STRIPED | PARASAIL_FLAG_BITS_64 | PARASAIL_FLAG_LANES_2; result->flag |= s1_beg ? PARASAIL_FLAG_SG_S1_BEG : 0; result->flag |= s1_end ? PARASAIL_FLAG_SG_S1_END : 0; result->flag |= s2_beg ? PARASAIL_FLAG_SG_S2_BEG : 0; result->flag |= s2_end ? PARASAIL_FLAG_SG_S2_END : 0; #ifdef PARASAIL_TABLE result->flag |= PARASAIL_FLAG_TABLE; #endif #ifdef PARASAIL_ROWCOL result->flag |= PARASAIL_FLAG_ROWCOL; #endif /* initialize heap variables */ pvHStore = parasail_memalign_simde__m128i(16, segLen); pvHLoad = parasail_memalign_simde__m128i(16, segLen); pvE = parasail_memalign_simde__m128i(16, segLen); boundary = parasail_memalign_int64_t(16, s2Len+1); /* validate heap variables */ if (!pvHStore) return NULL; if (!pvHLoad) return NULL; if (!pvE) return NULL; if (!boundary) return NULL; /* initialize H and E */ { int32_t index = 0; for (i=0; imapper[(unsigned char)s2[j]] * segLen; /* Swap the 2 H buffers. */ simde__m128i* pv = pvHLoad; pvHLoad = pvHStore; pvHStore = pv; /* insert upper boundary condition */ vH = simde_mm_insert_epi64(vH, boundary[j], 0); /* inner loop to process the query sequence */ for (i=0; itables->score_table, vH, i, segLen, j, s2Len); #endif /* Update vE value. */ vH = simde_mm_sub_epi64(vH, vGapO); vE = simde_mm_sub_epi64(vE, vGapE); vE = simde_mm_max_epi64(vE, vH); simde_mm_store_si128(pvE + i, vE); /* Update vF value. */ vF = simde_mm_sub_epi64(vF, vGapE); vF = simde_mm_max_epi64(vF, vH); /* Load the next vH. */ vH = simde_mm_load_si128(pvHLoad + i); } /* Lazy_F loop: has been revised to disallow adjecent insertion and * then deletion, so don't update E(i, i), learn from SWPS3 */ for (k=0; ktables->score_table, vH, i, segLen, j, s2Len); #endif vH = simde_mm_sub_epi64(vH, vGapO); vF = simde_mm_sub_epi64(vF, vGapE); if (! simde_mm_movemask_epi8(simde_mm_cmpgt_epi64(vF, vH))) goto end; /*vF = simde_mm_max_epi64(vF, vH);*/ } } end: { /* extract vector containing last value from the column */ simde__m128i vCompare; vH = simde_mm_load_si128(pvHStore + offset); vCompare = simde_mm_and_si128(vPosMask, simde_mm_cmpgt_epi64(vH, vMaxH)); vMaxH = simde_mm_max_epi64(vH, vMaxH); if (simde_mm_movemask_epi8(vCompare)) { end_ref = j; } #ifdef PARASAIL_ROWCOL for (k=0; krowcols->score_row[j] = (int64_t) simde_mm_extract_epi64 (vH, 1); #endif } } #ifdef PARASAIL_ROWCOL for (i=0; irowcols->score_col, vH, i, segLen); } #endif /* max last value from all columns */ if (s2_end) { for (k=0; k= s1Len) continue; if (*t > score) { score = *t; end_query = temp; end_ref = s2Len-1; } else if (*t == score && end_ref == s2Len-1 && temp < end_query) { end_query = temp; } } } if (!s1_end && !s2_end) { /* extract last value from the last column */ { simde__m128i vH = simde_mm_load_si128(pvHStore + offset); for (k=0; kflag |= PARASAIL_FLAG_SATURATED; score = 0; end_query = 0; end_ref = 0; } result->score = score; result->end_query = end_query; result->end_ref = end_ref; parasail_free(boundary); parasail_free(pvE); parasail_free(pvHLoad); parasail_free(pvHStore); return result; } SG_IMPL_ALL SG_IMPL_PROF_ALL