/** * @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_altivec.h" #ifdef PARASAIL_TABLE static inline void arr_store_si128( int *array, vec128i vH, int32_t t, int32_t seglen, int32_t d, int32_t dlen) { array[1LL*(0*seglen+t)*dlen + d] = (int16_t)_mm_extract_epi16(vH, 0); array[1LL*(1*seglen+t)*dlen + d] = (int16_t)_mm_extract_epi16(vH, 1); array[1LL*(2*seglen+t)*dlen + d] = (int16_t)_mm_extract_epi16(vH, 2); array[1LL*(3*seglen+t)*dlen + d] = (int16_t)_mm_extract_epi16(vH, 3); array[1LL*(4*seglen+t)*dlen + d] = (int16_t)_mm_extract_epi16(vH, 4); array[1LL*(5*seglen+t)*dlen + d] = (int16_t)_mm_extract_epi16(vH, 5); array[1LL*(6*seglen+t)*dlen + d] = (int16_t)_mm_extract_epi16(vH, 6); array[1LL*(7*seglen+t)*dlen + d] = (int16_t)_mm_extract_epi16(vH, 7); } #endif #ifdef PARASAIL_ROWCOL static inline void arr_store_col( int *col, vec128i vH, int32_t t, int32_t seglen) { col[0*seglen+t] = (int16_t)_mm_extract_epi16(vH, 0); col[1*seglen+t] = (int16_t)_mm_extract_epi16(vH, 1); col[2*seglen+t] = (int16_t)_mm_extract_epi16(vH, 2); col[3*seglen+t] = (int16_t)_mm_extract_epi16(vH, 3); col[4*seglen+t] = (int16_t)_mm_extract_epi16(vH, 4); col[5*seglen+t] = (int16_t)_mm_extract_epi16(vH, 5); col[6*seglen+t] = (int16_t)_mm_extract_epi16(vH, 6); col[7*seglen+t] = (int16_t)_mm_extract_epi16(vH, 7); } #endif #ifdef PARASAIL_TABLE #define FNAME parasail_nw_table_striped_altivec_128_16 #define PNAME parasail_nw_table_striped_profile_altivec_128_16 #else #ifdef PARASAIL_ROWCOL #define FNAME parasail_nw_rowcol_striped_altivec_128_16 #define PNAME parasail_nw_rowcol_striped_profile_altivec_128_16 #else #define FNAME parasail_nw_striped_altivec_128_16 #define PNAME parasail_nw_striped_profile_altivec_128_16 #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) { /* 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_altivec_128_16(s1, s1Len, matrix); if (!profile) return NULL; result = PNAME(profile, s2, s2Len, open, gap); 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) { /* declare local variables */ int32_t i = 0; int32_t j = 0; int32_t k = 0; int 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; vec128i* restrict vProfile = NULL; vec128i* restrict pvHStore = NULL; vec128i* restrict pvHLoad = NULL; vec128i* restrict pvE = NULL; int16_t* restrict boundary = NULL; vec128i vGapO; vec128i vGapE; int16_t NEG_LIMIT = 0; int16_t POS_LIMIT = 0; int16_t score = 0; vec128i vNegLimit; vec128i vPosLimit; vec128i vSaturationCheckMin; vec128i vSaturationCheckMax; parasail_result_t *result = NULL; /* validate inputs */ PARASAIL_CHECK_NULL(profile); PARASAIL_CHECK_NULL(profile->profile16.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 = 8; /* number of values in vector unit */ segLen = (s1Len + segWidth - 1) / segWidth; offset = (s1Len - 1) % segLen; position = (segWidth - 1) - (s1Len - 1) / segLen; vProfile = (vec128i*)profile->profile16.score; vGapO = _mm_set1_epi16(open); vGapE = _mm_set1_epi16(gap); NEG_LIMIT = (-open < matrix->min ? INT16_MIN + open : INT16_MIN - matrix->min) + 1; POS_LIMIT = INT16_MAX - matrix->max - 1; score = NEG_LIMIT; vNegLimit = _mm_set1_epi16(NEG_LIMIT); vPosLimit = _mm_set1_epi16(POS_LIMIT); vSaturationCheckMin = vPosLimit; vSaturationCheckMax = vNegLimit; /* 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_NW | PARASAIL_FLAG_STRIPED | PARASAIL_FLAG_BITS_16 | PARASAIL_FLAG_LANES_8; #ifdef PARASAIL_TABLE result->flag |= PARASAIL_FLAG_TABLE; #endif #ifdef PARASAIL_ROWCOL result->flag |= PARASAIL_FLAG_ROWCOL; #endif /* initialize heap variables */ pvHStore = parasail_memalign_vec128i(16, segLen); pvHLoad = parasail_memalign_vec128i(16, segLen); pvE = parasail_memalign_vec128i(16, segLen); boundary = parasail_memalign_int16_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. */ vec128i* pv = pvHLoad; pvHLoad = pvHStore; pvHStore = pv; /* insert upper boundary condition */ vH = _mm_insert_epi16(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 = _mm_subs_epi16(vH, vGapO); vE = _mm_subs_epi16(vE, vGapE); vE = _mm_max_epi16(vE, vH); _mm_store_si128(pvE + i, vE); /* Update vF value. */ vF = _mm_subs_epi16(vF, vGapE); vF = _mm_max_epi16(vF, vH); /* Load the next vH. */ vH = _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 = _mm_subs_epi16(vH, vGapO); vF = _mm_subs_epi16(vF, vGapE); if (! _mm_movemask_epi8(_mm_cmpgt_epi16(vF, vH))) goto end; /*vF = _mm_max_epi16(vF, vH);*/ } } end: { } #ifdef PARASAIL_ROWCOL /* extract last value from the column */ { vH = _mm_load_si128(pvHStore + offset); for (k=0; krowcols->score_row[j] = (int16_t) _mm_extract_epi16 (vH, 7); } #endif } #ifdef PARASAIL_ROWCOL for (i=0; irowcols->score_col, vH, i, segLen); } #endif /* extract last value from the last column */ { vec128i vH = _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; }