exp: interleave groups merge the short tail (no weak tail group)
A burst landing in the final partial group (4 blocks of a 68-block blob) hit each of its blocks with L/4 bytes instead of L/64 -- that is why 64 B bursts measured 0.94 instead of 1.00. Groups are now formed so the last partial group is absorbed into the previous one (every group >= depth). Re-measured, 50 trials: d16/d32/d64-t32 at 64 B bursts 1.00 (was 0.94); d64-t32 at 256 B and 64x4 bursts 1.00 (was 0.95 / 0.83).
This commit is contained in:
1 parent
5d3ee79fd3
commit
4b6d4cfa45
1 file changed
+25
-12
+25
-12
@@ -32,17 +32,21 @@ typedef struct {
|
||||
int t;
|
||||
} intlv_priv_t;
|
||||
|
||||
/* Permute the encoded stream in place (forward = interleave).
|
||||
/* Permute the encoded stream (forward = interleave).
|
||||
* blocks[] holds the stored length of each block; nblocks total.
|
||||
* out must hold the same total length. */
|
||||
* out must hold the same total length.
|
||||
*
|
||||
* Groups: blocks are cut into groups of `depth`, EXCEPT the final
|
||||
* partial group is merged into the previous one instead of standing
|
||||
* alone. A tiny tail group is the weak point: a burst landing in a
|
||||
* 4-block tail hits each of its blocks with L/4 bytes instead of
|
||||
* L/64, which is exactly why the first measurement showed 0.94
|
||||
* instead of 1.00 on 64-byte bursts (the 68-block blob ends in a
|
||||
* 4-block tail). Merging makes every group >= depth (the last may
|
||||
* exceed it); when nblocks <= depth there is a single group. */
|
||||
static void permute(const uint8_t *in, uint8_t *out, const size_t *blocks,
|
||||
size_t nblocks, int depth, int forward)
|
||||
{
|
||||
size_t total = 0;
|
||||
for (size_t i = 0; i < nblocks; i++)
|
||||
total += blocks[i];
|
||||
(void)total;
|
||||
/* block start offsets */
|
||||
size_t *start = (size_t *)malloc((nblocks + 1) * sizeof(size_t));
|
||||
if (!start)
|
||||
return;
|
||||
@@ -50,16 +54,24 @@ static void permute(const uint8_t *in, uint8_t *out, const size_t *blocks,
|
||||
for (size_t i = 0; i < nblocks; i++)
|
||||
start[i + 1] = start[i] + blocks[i];
|
||||
|
||||
for (size_t g0 = 0; g0 < nblocks; g0 += (size_t)depth) {
|
||||
size_t g = nblocks - g0 < (size_t)depth ? nblocks - g0
|
||||
: (size_t)depth;
|
||||
/* group boundaries: groups of `depth`, last partial group merged
|
||||
into the previous one */
|
||||
size_t g0 = 0;
|
||||
while (g0 < nblocks) {
|
||||
size_t remain = nblocks - g0;
|
||||
size_t g = remain < (size_t)depth ? remain : (size_t)depth;
|
||||
/* If this would leave a short tail after this group, extend
|
||||
this group to absorb the tail. (Invariant: a short tail
|
||||
never survives an iteration, so no group is ever < depth
|
||||
except when the whole blob is.) */
|
||||
if (remain > (size_t)depth && remain - (size_t)depth < (size_t)depth)
|
||||
g = remain;
|
||||
size_t maxlen = 0;
|
||||
for (size_t j = 0; j < g; j++)
|
||||
if (blocks[g0 + j] > maxlen)
|
||||
maxlen = blocks[g0 + j];
|
||||
/* group output offset = start of first block in the group */
|
||||
size_t goff = start[g0];
|
||||
size_t pos = 0; /* position within the group's output */
|
||||
size_t pos = 0;
|
||||
for (size_t c = 0; c < maxlen; c++) {
|
||||
for (size_t j = 0; j < g; j++) {
|
||||
if (c >= blocks[g0 + j])
|
||||
@@ -73,6 +85,7 @@ static void permute(const uint8_t *in, uint8_t *out, const size_t *blocks,
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
g0 += g;
|
||||
}
|
||||
free(start);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user