#ifdef PRECISION #include #include #include void CONCAT(CONCAT(precompute_masks_,SIMD_ENGINE), PRECISION)(const testcase& tc, int COLS, int numMaskVecs, MASK_TYPE (*maskArr)[NUM_DISTINCT_CHARS]) { const int maskBitCnt = MAIN_TYPE_SIZE ; for (int vi=0; vi < numMaskVecs; ++vi) { for (int rs=0; rs < NUM_DISTINCT_CHARS; ++rs) { maskArr[vi][rs] = 0 ; } maskArr[vi][AMBIG_CHAR] = MASK_ALL_ONES ; } for (int col=1; col < COLS; ++col) { int mIndex = (col-1) / maskBitCnt ; int mOffset = (col-1) % maskBitCnt ; MASK_TYPE bitMask = ((MASK_TYPE)0x1) << (maskBitCnt-1-mOffset) ; char hapChar = ConvertChar::get(tc.hap[col-1]); if (hapChar == AMBIG_CHAR) { for (int ci=0; ci < NUM_DISTINCT_CHARS; ++ci) maskArr[mIndex][ci] |= bitMask ; } maskArr[mIndex][hapChar] |= bitMask ; // bit corresponding to col 1 will be the MSB of the mask 0 // bit corresponding to col 2 will be the MSB-1 of the mask 0 // ... // bit corresponding to col 32 will be the LSB of the mask 0 // bit corresponding to col 33 will be the MSB of the mask 1 // ... } } void CONCAT(CONCAT(init_masks_for_row_,SIMD_ENGINE), PRECISION)(const testcase& tc, char* rsArr, MASK_TYPE* lastMaskShiftOut, int beginRowIndex, int numRowsToProcess) { for (int ri=0; ri < numRowsToProcess; ++ri) { rsArr[ri] = ConvertChar::get(tc.rs[ri+beginRowIndex-1]) ; } for (int ei=0; ei < AVX_LENGTH; ++ei) { lastMaskShiftOut[ei] = 0 ; } } #define SET_MASK_WORD(__dstMask, __srcMask, __lastShiftOut, __shiftBy, __maskBitCnt){ \ MASK_TYPE __bitMask = (((MASK_TYPE)0x1) << __shiftBy) - 1 ; \ MASK_TYPE __nextShiftOut = (__srcMask & __bitMask) << (__maskBitCnt - __shiftBy) ; \ __dstMask = (__srcMask >> __shiftBy) | __lastShiftOut ; \ __lastShiftOut = __nextShiftOut ; \ } void CONCAT(CONCAT(update_masks_for_cols_,SIMD_ENGINE), PRECISION)(int maskIndex, BITMASK_VEC& bitMaskVec, MASK_TYPE (*maskArr) [NUM_DISTINCT_CHARS], char* rsArr, MASK_TYPE* lastMaskShiftOut, int maskBitCnt) { for (int ei=0; ei < AVX_LENGTH/2; ++ei) { SET_MASK_WORD(bitMaskVec.getLowEntry(ei), maskArr[maskIndex][rsArr[ei]], lastMaskShiftOut[ei], ei, maskBitCnt) ; int ei2 = ei + AVX_LENGTH/2 ; // the second entry index SET_MASK_WORD(bitMaskVec.getHighEntry(ei), maskArr[maskIndex][rsArr[ei2]], lastMaskShiftOut[ei2], ei2, maskBitCnt) ; } } inline void CONCAT(CONCAT(computeDistVec,SIMD_ENGINE), PRECISION) (BITMASK_VEC& bitMaskVec, SIMD_TYPE& distm, SIMD_TYPE& _1_distm, SIMD_TYPE& distmChosen) { distmChosen = VEC_BLENDV(distm, _1_distm, bitMaskVec.getCombinedMask()) ; bitMaskVec.shift_left_1bit() ; } template void CONCAT(CONCAT(initializeVectors,SIMD_ENGINE), PRECISION)(int ROWS, int COLS, NUMBER* shiftOutM, NUMBER *shiftOutX, NUMBER *shiftOutY, Context ctx, testcase *tc, SIMD_TYPE *p_MM, SIMD_TYPE *p_GAPM, SIMD_TYPE *p_MX, SIMD_TYPE *p_XX, SIMD_TYPE *p_MY, SIMD_TYPE *p_YY, SIMD_TYPE *distm1D) { NUMBER zero = ctx._(0.0); NUMBER init_Y = ctx.INITIAL_CONSTANT / (tc->haplen); for (int s=0;si[r-1] & 127; int _d = tc->d[r-1] & 127; int _c = tc->c[r-1] & 127; *(ptr_p_MM+r-1) = ctx._(1.0) - ctx.ph2pr[(_i + _d) & 127]; *(ptr_p_GAPM+r-1) = ctx._(1.0) - ctx.ph2pr[_c]; *(ptr_p_MX+r-1) = ctx.ph2pr[_i]; *(ptr_p_XX+r-1) = ctx.ph2pr[_c]; *(ptr_p_MY+r-1) = ctx.ph2pr[_d]; *(ptr_p_YY+r-1) = ctx.ph2pr[_c]; } NUMBER *ptr_distm1D = (NUMBER *)distm1D; for (int r = 1; r < ROWS; r++) { int _q = tc->q[r-1] & 127; ptr_distm1D[r-1] = ctx.ph2pr[_q]; } } template inline void CONCAT(CONCAT(stripeINITIALIZATION,SIMD_ENGINE), PRECISION)( int stripeIdx, Context ctx, testcase *tc, SIMD_TYPE &pGAPM, SIMD_TYPE &pMM, SIMD_TYPE &pMX, SIMD_TYPE &pXX, SIMD_TYPE &pMY, SIMD_TYPE &pYY, SIMD_TYPE &rs, UNION_TYPE &rsN, SIMD_TYPE &distm, SIMD_TYPE &_1_distm, SIMD_TYPE *distm1D, SIMD_TYPE N_packed256, SIMD_TYPE *p_MM , SIMD_TYPE *p_GAPM , SIMD_TYPE *p_MX, SIMD_TYPE *p_XX , SIMD_TYPE *p_MY, SIMD_TYPE *p_YY, UNION_TYPE &M_t_2, UNION_TYPE &X_t_2, UNION_TYPE &M_t_1, UNION_TYPE &X_t_1, UNION_TYPE &Y_t_2, UNION_TYPE &Y_t_1, UNION_TYPE &M_t_1_y, NUMBER* shiftOutX, NUMBER* shiftOutM) { int i = stripeIdx; pGAPM = p_GAPM[i]; pMM = p_MM[i]; pMX = p_MX[i]; pXX = p_XX[i]; pMY = p_MY[i]; pYY = p_YY[i]; NUMBER zero = ctx._(0.0); NUMBER init_Y = ctx.INITIAL_CONSTANT / (tc->haplen); UNION_TYPE packed1; packed1.d = VEC_SET1_VAL(1.0); UNION_TYPE packed3; packed3.d = VEC_SET1_VAL(3.0); distm = distm1D[i]; _1_distm = VEC_SUB(packed1.d, distm); distm = VEC_DIV(distm, packed3.d); /* initialize M_t_2, M_t_1, X_t_2, X_t_1, Y_t_2, Y_t_1 */ M_t_2.d = VEC_SET1_VAL(zero); X_t_2.d = VEC_SET1_VAL(zero); if (i==0) { M_t_1.d = VEC_SET1_VAL(zero); X_t_1.d = VEC_SET1_VAL(zero); Y_t_2.d = VEC_SET_LSE(init_Y); Y_t_1.d = VEC_SET1_VAL(zero); } else { X_t_1.d = VEC_SET_LSE(shiftOutX[AVX_LENGTH]); M_t_1.d = VEC_SET_LSE(shiftOutM[AVX_LENGTH]); Y_t_2.d = VEC_SET1_VAL(zero); Y_t_1.d = VEC_SET1_VAL(zero); } M_t_1_y = M_t_1; } inline SIMD_TYPE CONCAT(CONCAT(computeDISTM,SIMD_ENGINE), PRECISION)(int d, int COLS, testcase * tc, HAP_TYPE &hap, SIMD_TYPE rs, UNION_TYPE rsN, SIMD_TYPE N_packed256, SIMD_TYPE distm, SIMD_TYPE _1_distm) { UNION_TYPE hapN, rshap; SIMD_TYPE cond; IF_32 shiftInHap; int *hap_ptr = tc->ihap; shiftInHap.i = (d NUMBER CONCAT(CONCAT(compute_full_prob_,SIMD_ENGINE), PRECISION) (testcase *tc, NUMBER *before_last_log = NULL) { int ROWS = tc->rslen + 1; int COLS = tc->haplen + 1; int MAVX_COUNT = (ROWS+AVX_LENGTH-1)/AVX_LENGTH; SIMD_TYPE p_MM [MAVX_COUNT], p_GAPM [MAVX_COUNT], p_MX [MAVX_COUNT]; SIMD_TYPE p_XX [MAVX_COUNT], p_MY [MAVX_COUNT], p_YY [MAVX_COUNT]; SIMD_TYPE distm1D[MAVX_COUNT]; NUMBER shiftOutM[ROWS+COLS+AVX_LENGTH], shiftOutX[ROWS+COLS+AVX_LENGTH], shiftOutY[ROWS+COLS+AVX_LENGTH]; UNION_TYPE M_t, M_t_1, M_t_2, X_t, X_t_1, X_t_2, Y_t, Y_t_1, Y_t_2, M_t_y, M_t_1_y; SIMD_TYPE pGAPM, pMM, pMX, pXX, pMY, pYY; struct timeval start, end; NUMBER result_avx2; Context ctx; UNION_TYPE rs , rsN; HAP_TYPE hap; SIMD_TYPE distmSel, distmChosen ; SIMD_TYPE distm, _1_distm; int r, c; NUMBER zero = ctx._(0.0); UNION_TYPE packed1; packed1.d = VEC_SET1_VAL(1.0); SIMD_TYPE N_packed256 = VEC_POPCVT_CHAR('N'); NUMBER init_Y = ctx.INITIAL_CONSTANT / (tc->haplen); int remainingRows = (ROWS-1) % AVX_LENGTH; int stripe_cnt = ((ROWS-1) / AVX_LENGTH) + (remainingRows!=0); const int maskBitCnt = MAIN_TYPE_SIZE ; const int numMaskVecs = (COLS+ROWS+maskBitCnt-1)/maskBitCnt ; // ceil function MASK_TYPE maskArr[numMaskVecs][NUM_DISTINCT_CHARS] ; CONCAT(CONCAT(precompute_masks_,SIMD_ENGINE), PRECISION)(*tc, COLS, numMaskVecs, maskArr) ; char rsArr[AVX_LENGTH] ; MASK_TYPE lastMaskShiftOut[AVX_LENGTH] ; CONCAT(CONCAT(initializeVectors,SIMD_ENGINE), PRECISION)(ROWS, COLS, shiftOutM, shiftOutX, shiftOutY, ctx, tc, p_MM, p_GAPM, p_MX, p_XX, p_MY, p_YY, distm1D); for (int i=0;i