refactor: do some internal refactor.

This commit is contained in:
Haojun Liao 2023-01-06 15:45:15 +08:00
parent d8dd3d44af
commit 18738ecdd6
1 changed files with 26 additions and 11 deletions

View File

@ -284,21 +284,38 @@ int32_t tsDecompressINTImp(const char *const input, const int32_t nelements, cha
int64_t* p = (int64_t*) output; int64_t* p = (int64_t*) output;
if (selector == 0 || selector == 1) { if (selector == 0 || selector == 1) {
zigzag_value = 0; int32_t batch = elems >> 2;
int32_t remainder = elems & 0x3;
for (int32_t i = 0; i < elems && count < nelements; i++, count++) { int32_t gRemainder = nelements - count;
prev_value += ZIGZAG_DECODE(int64_t, zigzag_value); int32_t gBatch = gRemainder >> 2;
int32_t minBatch = TMIN(batch, gBatch);
int32_t minRemain = TMIN(remainder, gRemainder);
for(int32_t i = 0; i < minBatch; ++i) {
p[_pos++] = prev_value;
p[_pos++] = prev_value;
p[_pos++] = prev_value;
p[_pos++] = prev_value; p[_pos++] = prev_value;
} }
for (int32_t i = 0; i < minRemain; i++) {
p[_pos++] = prev_value;
}
count += ((minBatch << 2)+ minRemain);
} else { } else {
int32_t batch = elems >> 2; int32_t batch = elems >> 2;
int32_t globalBatch = (nelements - count) >> 2; int32_t remain = elems & 0x03;
int32_t globalRemain = (nelements - count);
int32_t globalBatch = globalRemain >> 2;
int32_t minBatch = TMIN(batch, globalBatch); int32_t minBatch = TMIN(batch, globalBatch);
int32_t minRemain = TMIN(remain, globalRemain);
#if 1 #if 1
// manual unrolling, to erase the hotspot // manual unrolling, to erase the hotspot
for (int32_t i = 0; i < minBatch; ++i, count += 4) { for (int32_t i = 0; i < minBatch; ++i) {
zigzag_value = ((w >> v) & mask); zigzag_value = ((w >> v) & mask);
prev_value += ZIGZAG_DECODE(int64_t, zigzag_value); prev_value += ZIGZAG_DECODE(int64_t, zigzag_value);
@ -325,17 +342,15 @@ int32_t tsDecompressINTImp(const char *const input, const int32_t nelements, cha
} }
// handle the remain // handle the remain
int32_t remain = elems & 0x03; for (int32_t i = 0; i < minRemain; i++) {
int32_t globalRemain = (nelements - count);
int32_t minRemain = TMIN(globalRemain, remain);
for (int32_t i = 0; i < minRemain; i++, count++) {
zigzag_value = ((w >> v) & mask); zigzag_value = ((w >> v) & mask);
prev_value += ZIGZAG_DECODE(int64_t, zigzag_value); prev_value += ZIGZAG_DECODE(int64_t, zigzag_value);
p[_pos++] = prev_value; p[_pos++] = prev_value;
v += bit; v += bit;
} }
count += ((minBatch << 2)+ minRemain);
#else #else
for (int32_t i = 0; i < elems && count < nelements; i++, count++) { for (int32_t i = 0; i < elems && count < nelements; i++, count++) {
zigzag_value = ((w >> (4 + v)) & mask); zigzag_value = ((w >> (4 + v)) & mask);