simplified bwt_occ4() a little

This commit is contained in:
Heng Li 2013-02-26 11:49:39 -05:00
parent c848b44481
commit 264d5e42e5
1 changed files with 12 additions and 14 deletions

26
bwt.c
View File

@ -160,8 +160,8 @@ void bwt_2occ(const bwt_t *bwt, bwtint_t k, bwtint_t l, ubyte_t c, bwtint_t *ok,
void bwt_occ4(const bwt_t *bwt, bwtint_t k, bwtint_t cnt[4]) void bwt_occ4(const bwt_t *bwt, bwtint_t k, bwtint_t cnt[4])
{ {
bwtint_t l, j, x; bwtint_t x;
uint32_t *p, tmp; uint32_t *p, tmp, *end;
if (k == (bwtint_t)(-1)) { if (k == (bwtint_t)(-1)) {
memset(cnt, 0, 4 * sizeof(bwtint_t)); memset(cnt, 0, 4 * sizeof(bwtint_t));
return; return;
@ -169,10 +169,9 @@ void bwt_occ4(const bwt_t *bwt, bwtint_t k, bwtint_t cnt[4])
k -= (k >= bwt->primary); // because $ is not in bwt k -= (k >= bwt->primary); // because $ is not in bwt
p = bwt_occ_intv(bwt, k); p = bwt_occ_intv(bwt, k);
memcpy(cnt, p, 4 * sizeof(bwtint_t)); memcpy(cnt, p, 4 * sizeof(bwtint_t));
p += sizeof(bwtint_t); p += sizeof(bwtint_t); // sizeof(bwtint_t) = 4*(sizeof(bwtint_t)/sizeof(uint32_t))
j = k >> 4 << 4; end = p + ((k>>4) - ((k&~OCC_INTV_MASK)>>4)); // this is the end point of the following loop
for (l = k & ~OCC_INTV_MASK, x = 0; l < j; l += 16, ++p) for (x = 0; p < end; ++p) x += __occ_aux4(bwt, *p);
x += __occ_aux4(bwt, *p);
tmp = *p & ~((1U<<((~k&15)<<1)) - 1); tmp = *p & ~((1U<<((~k&15)<<1)) - 1);
x += __occ_aux4(bwt, tmp) - (~k&15); x += __occ_aux4(bwt, tmp) - (~k&15);
cnt[0] += x&0xff; cnt[1] += x>>8&0xff; cnt[2] += x>>16&0xff; cnt[3] += x>>24; cnt[0] += x&0xff; cnt[1] += x>>8&0xff; cnt[2] += x>>16&0xff; cnt[3] += x>>24;
@ -188,23 +187,22 @@ void bwt_2occ4(const bwt_t *bwt, bwtint_t k, bwtint_t l, bwtint_t cntk[4], bwtin
bwt_occ4(bwt, k, cntk); bwt_occ4(bwt, k, cntk);
bwt_occ4(bwt, l, cntl); bwt_occ4(bwt, l, cntl);
} else { } else {
bwtint_t i, j, x, y; bwtint_t x, y;
uint32_t *p, tmp; uint32_t *p, tmp, *endk, *endl;
k -= (k >= bwt->primary); // because $ is not in bwt k -= (k >= bwt->primary); // because $ is not in bwt
l -= (l >= bwt->primary); l -= (l >= bwt->primary);
p = bwt_occ_intv(bwt, k); p = bwt_occ_intv(bwt, k);
memcpy(cntk, p, 4 * sizeof(bwtint_t)); memcpy(cntk, p, 4 * sizeof(bwtint_t));
p += sizeof(bwtint_t); p += sizeof(bwtint_t); // sizeof(bwtint_t) = 4*(sizeof(bwtint_t)/sizeof(uint32_t))
// prepare cntk[] // prepare cntk[]
j = k >> 4 << 4; endk = p + ((k>>4) - ((k&~OCC_INTV_MASK)>>4));
for (i = k & ~OCC_INTV_MASK, x = 0; i < j; i += 16, ++p) endl = p + ((l>>4) - ((l&~OCC_INTV_MASK)>>4));
x += __occ_aux4(bwt, *p); for (x = 0; p < endk; ++p) x += __occ_aux4(bwt, *p);
y = x; y = x;
tmp = *p & ~((1U<<((~k&15)<<1)) - 1); tmp = *p & ~((1U<<((~k&15)<<1)) - 1);
x += __occ_aux4(bwt, tmp) - (~k&15); x += __occ_aux4(bwt, tmp) - (~k&15);
// calculate cntl[] and finalize cntk[] // calculate cntl[] and finalize cntk[]
j = l >> 4 << 4; for (; p < endl; ++p) y += __occ_aux4(bwt, *p);
for (; i < j; i += 16, ++p) y += __occ_aux4(bwt, *p);
tmp = *p & ~((1U<<((~l&15)<<1)) - 1); tmp = *p & ~((1U<<((~l&15)<<1)) - 1);
y += __occ_aux4(bwt, tmp) - (~l&15); y += __occ_aux4(bwt, tmp) - (~l&15);
memcpy(cntl, cntk, 4 * sizeof(bwtint_t)); memcpy(cntl, cntk, 4 * sizeof(bwtint_t));