Add inlined sparseLastTop

This allows the code to be inlined into other sparse optimal repeat
functions.
This commit is contained in:
Justin Viiret 2015-11-03 15:17:17 +11:00 committed by Matthew Barr
parent 2603be3924
commit 46ad39f253

View File

@ -1199,12 +1199,10 @@ u32 getSparseOptimalTargetValue(const struct RepeatInfo *info,
return loc; return loc;
} }
u64a repeatLastTopSparseOptimalP(const struct RepeatInfo *info, static
const union RepeatControl *ctrl, u64a sparseLastTop(const struct RepeatInfo *info,
const void *state) { const struct RepeatRingControl *xs, const u8 *state) {
DEBUG_PRINTF("looking for last top\n"); DEBUG_PRINTF("looking for last top\n");
const struct RepeatRingControl *xs = &ctrl->ring;
u32 patch_size = info->patchSize; u32 patch_size = info->patchSize;
u32 patch_count = info->patchCount; u32 patch_count = info->patchCount;
u32 encoding_size = info->encodingSize; u32 encoding_size = info->encodingSize;
@ -1216,7 +1214,7 @@ u64a repeatLastTopSparseOptimalP(const struct RepeatInfo *info,
} }
DEBUG_PRINTF("patch%u encoding_size%u occ%u\n", patch, encoding_size, occ); DEBUG_PRINTF("patch%u encoding_size%u occ%u\n", patch, encoding_size, occ);
const u8 *ring = (const u8 *)state + info->patchesOffset; const u8 *ring = state + info->patchesOffset;
u64a val = partial_load_u64a(ring + encoding_size * patch, encoding_size); u64a val = partial_load_u64a(ring + encoding_size * patch, encoding_size);
DEBUG_PRINTF("val:%llu\n", val); DEBUG_PRINTF("val:%llu\n", val);
@ -1233,6 +1231,12 @@ u64a repeatLastTopSparseOptimalP(const struct RepeatInfo *info,
return 0; return 0;
} }
u64a repeatLastTopSparseOptimalP(const struct RepeatInfo *info,
const union RepeatControl *ctrl,
const void *state) {
return sparseLastTop(info, &ctrl->ring, state);
}
u64a repeatNextMatchSparseOptimalP(const struct RepeatInfo *info, u64a repeatNextMatchSparseOptimalP(const struct RepeatInfo *info,
const union RepeatControl *ctrl, const union RepeatControl *ctrl,
const void *state, u64a offset) { const void *state, u64a offset) {
@ -1251,9 +1255,7 @@ u64a repeatNextMatchSparseOptimalP(const struct RepeatInfo *info,
if (nextOffset <= xs->offset + info->repeatMin) { if (nextOffset <= xs->offset + info->repeatMin) {
patch = xs->first; patch = xs->first;
tval = 0; tval = 0;
} else if (nextOffset > } else if (nextOffset > sparseLastTop(info, xs, state) + info->repeatMax) {
repeatLastTopSparseOptimalP(info, ctrl, state) +
info->repeatMax) {
DEBUG_PRINTF("ring is stale\n"); DEBUG_PRINTF("ring is stale\n");
return 0; return 0;
} else { } else {
@ -1348,14 +1350,13 @@ void repeatStoreSparseOptimalP(const struct RepeatInfo *info,
// If (a) this is the first top, or (b) the ring is stale, initialize the // If (a) this is the first top, or (b) the ring is stale, initialize the
// ring and write this offset in as the first top. // ring and write this offset in as the first top.
if (!is_alive || if (!is_alive ||
offset > offset > sparseLastTop(info, xs, state) + info->repeatMax) {
repeatLastTopSparseOptimalP(info, ctrl, state) + info->repeatMax) {
storeInitialRingTopPatch(info, xs, active, offset); storeInitialRingTopPatch(info, xs, active, offset);
return; return;
} }
// Tops should arrive in order, with no duplicates. // Tops should arrive in order, with no duplicates.
assert(offset > repeatLastTopSparseOptimalP(info, ctrl, state)); assert(offset > sparseLastTop(info, xs, state));
// As the ring is not stale, our delta should fit within a u32. // As the ring is not stale, our delta should fit within a u32.
assert(offset - xs->offset <= UINT32_MAX); assert(offset - xs->offset <= UINT32_MAX);
@ -1504,8 +1505,7 @@ enum RepeatMatch repeatHasMatchSparseOptimalP(const struct RepeatInfo *info,
if (offset < xs->offset + info->repeatMin) { if (offset < xs->offset + info->repeatMin) {
DEBUG_PRINTF("too soon\n"); DEBUG_PRINTF("too soon\n");
return REPEAT_NOMATCH; return REPEAT_NOMATCH;
} else if (offset > repeatLastTopSparseOptimalP(info, ctrl, state) + } else if (offset > sparseLastTop(info, xs, state) + info->repeatMax) {
info->repeatMax) {
DEBUG_PRINTF("stale\n"); DEBUG_PRINTF("stale\n");
return REPEAT_STALE; return REPEAT_STALE;
} }