/** * @file * * @author jeff.daily@pnnl.gov * * Copyright (c) 2015 Battelle Memorial Institute. */ #include "config.h" #include #include %(HEADER)s #include "parasail.h" #include "parasail/memory.h" #include "parasail/internal_%(ISA)s.h" #define NEG_INF %(NEG_INF)s %(FIXES)s #ifdef PARASAIL_TABLE static inline void arr_store_si%(BITS)s( int *array, %(VTYPE)s vH, %(INDEX)s t, %(INDEX)s seglen, %(INDEX)s d, %(INDEX)s dlen) { %(PRINTER)s } #endif #ifdef PARASAIL_ROWCOL static inline void arr_store_col( int *col, %(VTYPE)s vH, %(INDEX)s t, %(INDEX)s seglen) { %(PRINTER_ROWCOL)s } #endif #ifdef PARASAIL_TABLE #define FNAME %(NAME_TABLE)s #define PNAME %(PNAME_TABLE)s #else #ifdef PARASAIL_ROWCOL #define FNAME %(NAME_ROWCOL)s #define PNAME %(PNAME_ROWCOL)s #else #define FNAME %(NAME)s #define PNAME %(PNAME)s #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) { parasail_profile_t *profile = parasail_profile_create_%(ISA)s_%(BITS)s_%(WIDTH)s(s1, s1Len, matrix); parasail_result_t *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) { %(INDEX)s i = 0; %(INDEX)s j = 0; %(INDEX)s k = 0; %(INDEX)s end_query = 0; %(INDEX)s end_ref = 0; const int s1Len = profile->s1Len; const parasail_matrix_t *matrix = profile->matrix; const %(INDEX)s segWidth = %(LANES)s; /* number of values in vector unit */ const %(INDEX)s segLen = (s1Len + segWidth - 1) / segWidth; const %(INDEX)s offset = (s1Len - 1) %% segLen; const %(INDEX)s position = (segWidth - 1) - (s1Len - 1) / segLen; %(VTYPE)s* const restrict vProfile = (%(VTYPE)s*)profile->profile%(WIDTH)s.score; %(VTYPE)s* restrict pvHStore = parasail_memalign_%(VTYPE)s(%(ALIGNMENT)s, segLen); %(VTYPE)s* restrict pvHLoad = parasail_memalign_%(VTYPE)s(%(ALIGNMENT)s, segLen); %(VTYPE)s* const restrict pvE = parasail_memalign_%(VTYPE)s(%(ALIGNMENT)s, segLen); %(VTYPE)s vGapO = %(VSET1)s(open); %(VTYPE)s vGapE = %(VSET1)s(gap); %(VTYPE)s vNegInf = %(VSET1)s(NEG_INF); %(INT)s score = NEG_INF; %(VTYPE)s vMaxH = vNegInf; %(VTYPE)s vPosMask = %(VCMPEQ)s(%(VSET1)s(position), %(VSET)s(%(POSITION_MASK)s)); %(SATURATION_CHECK_INIT)s #ifdef PARASAIL_TABLE parasail_result_t *result = parasail_result_new_table1(segLen*segWidth, s2Len); #else #ifdef PARASAIL_ROWCOL parasail_result_t *result = parasail_result_new_rowcol1(segLen*segWidth, s2Len); #else parasail_result_t *result = parasail_result_new(); #endif #endif /* initialize H and E */ parasail_memset_%(VTYPE)s(pvHStore, %(VSET1)s(0), segLen); parasail_memset_%(VTYPE)s(pvE, %(VSET1)s(-open), segLen); /* outer loop over database sequence */ for (j=0; jmapper[(unsigned char)s2[j]] * segLen; /* Swap the 2 H buffers. */ %(VTYPE)s* pv = pvHLoad; pvHLoad = pvHStore; pvHStore = pv; /* inner loop to process the query sequence */ for (i=0; iscore_table, vH, i, segLen, j, s2Len); #endif /* Update vE value. */ vH = %(VSUB)s(vH, vGapO); vE = %(VSUB)s(vE, vGapE); vE = %(VMAX)s(vE, vH); %(VSTORE)s(pvE + i, vE); /* Update vF value. */ vF = %(VSUB)s(vF, vGapE); vF = %(VMAX)s(vF, vH); /* Load the next vH. */ vH = %(VLOAD)s(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; kscore_table, vH, i, segLen, j, s2Len); #endif vH = %(VSUB)s(vH, vGapO); vF = %(VSUB)s(vF, vGapE); if (! %(VMOVEMASK)s(%(VCMPGT)s(vF, vH))) goto end; /*vF = %(VMAX)s(vF, vH);*/ } } end: { /* extract vector containing last value from the column */ %(VTYPE)s vCompare; vH = %(VLOAD)s(pvHStore + offset); vCompare = %(VAND)s(vPosMask, %(VCMPGT)s(vH, vMaxH)); vMaxH = %(VMAX)s(vH, vMaxH); if (%(VMOVEMASK)s(vCompare)) { end_ref = j; end_query = s1Len - 1; } #ifdef PARASAIL_ROWCOL for (k=0; kscore_row[j] = (%(INT)s) %(VEXTRACT)s (vH, %(LAST_POS)s); #endif } } /* max last value from all columns */ { for (k=0; kscore_col, vH, i, segLen); #endif } /* max in vec */ score_last = %(VHMAX)s(vMaxH); if (score_last > score) { score = score_last; end_ref = s2Len - 1; end_query = s1Len; /* Trace the alignment ending position on read. */ { %(INT)s *t = (%(INT)s*)pvHStore; %(INDEX)s column_len = segLen * segWidth; for (i = 0; iscore = score; result->end_query = end_query; result->end_ref = end_ref; parasail_free(pvE); parasail_free(pvHLoad); parasail_free(pvHStore); return result; }