rbyd-rr: Cleaned up appendattr diverged handling a bit

- Made diverging-lower pruning its own case to simplify the pruning
  logic, though this does lead to a bit more code duplication...

- Duplicated the diverging-alt pruning logic to simplify/give more
  control to the diverging-alt case. No more diverged_this_alt hack.

  Note that d_tag can no longer be null now that we have it deriving
  from lower_rid correctly.

Maybe this can be deduplicated better (diverged-pruning be implicitly
controlled by lower/upper bounds?), but I sort of want to get things
just working first.
This commit is contained in:
Christopher Haster
2024-03-26 02:57:32 -05:00
parent 8a646d5b8e
commit 6b3730723e
+85 -20
View File
@@ -2866,7 +2866,6 @@ again:;
// make jump absolute
jump = branch - jump;
lfs_size_t branch_ = branch + d;
bool diverged_this_alt = false;
// do bounds want to take different paths? begin diverging
if (!lfsr_d_isdiverged(d_state)
@@ -2898,7 +2897,7 @@ again:;
weight);
// stitch together diverged branches
if (d_state == LFSR_D_DIVERGEDUPPER && d_tag) {
if (d_state == LFSR_D_DIVERGEDUPPER) {
printf("%04x->%04x: stitching: 0x%x w%d, 0x%x\n",
branch,
rbyd->eoff,
@@ -2915,8 +2914,72 @@ again:;
}
}
diverged_this_alt = true;
if (lfsr_tag_follow2(
alt, weight,
p_alts[0], p_weights[0],
lower_rid, upper_rid,
a_rid, a_tag)) {
lfsr_tag_flip2(
&alt, &weight,
p_alts[0], p_weights[0],
lower_rid, upper_rid);
lfs_swap32(&jump, &branch_);
}
lfsr_tag_trim(
alt, weight,
&lower_rid, &upper_rid,
&lower_tag, &upper_tag);
printf("%04x->%04x: dprune 0x%x w%d\n",
branch,
rbyd->eoff,
alt,
weight);
// TODO need this?
// propagate pruning to yellow splits to avoid issues
// with tail-recursive recoloring
// if (lfsr_d_isdiverged(d_state)) {
// d_pruned = true;
// }
// TODO can we move y_branch updates to beginning of loop?
y_branch = branch;
branch = branch_;
continue;
}
// don't write diverging lower alts
} else if (d_state == LFSR_D_DIVERGINGLOWER) {
if (lfsr_tag_follow2(
alt, weight,
p_alts[0], p_weights[0],
lower_rid, upper_rid,
a_rid, a_tag)) {
lfsr_tag_flip2(
&alt, &weight,
p_alts[0], p_weights[0],
lower_rid, upper_rid);
lfs_swap32(&jump, &branch_);
}
lfsr_tag_trim(
alt, weight,
&lower_rid, &upper_rid,
&lower_tag, &upper_tag);
printf("%04x->%04x: dprune 0x%x w%d\n",
branch,
rbyd->eoff,
alt,
weight);
// TODO need this?
// propagate pruning to yellow splits to avoid issues
// with tail-recursive recoloring
// if (lfsr_d_isdiverged(d_state)) {
// d_pruned = true;
// }
// TODO can we move y_branch updates to beginning of loop?
y_branch = branch;
branch = branch_;
continue;
}
// if (lfsr_d_isdiverged(d_state)) {
@@ -2939,7 +3002,9 @@ again:;
lower_rid, upper_rid,
lower_tag, upper_tag)
// prune because of diverged paths?
|| d_state == LFSR_D_DIVERGINGLOWER
// || d_state == LFSR_D_DIVERGINGLOWER
// TODO can we adjust lower/upper rid/tag to make this
// happen implicitly?
|| (lfsr_d_isdiverged(d_state)
&& (d_state == LFSR_D_DIVERGEDUPPER)
^ lfsr_tag_isgt(alt)
@@ -2981,21 +3046,21 @@ again:;
// black alts just become unreachable, if we pruned these
// it would break the coloring of our tree
} else {
if (d_state == LFSR_D_DIVERGINGLOWER || diverged_this_alt) {
printf("%04x->%04x: dprune 0x%x w%d\n",
branch,
rbyd->eoff,
alt,
weight);
// propagate pruning to yellow splits to avoid issues
// with tail-recursive recoloring
if (lfsr_d_isdiverged(d_state)) {
d_pruned = true;
}
y_branch = branch;
branch = branch_;
continue;
} else {
// if (d_state == LFSR_D_DIVERGINGLOWER) {
// printf("%04x->%04x: dprune 0x%x w%d\n",
// branch,
// rbyd->eoff,
// alt,
// weight);
// // propagate pruning to yellow splits to avoid issues
// // with tail-recursive recoloring
// if (lfsr_d_isdiverged(d_state)) {
// d_pruned = true;
// }
// y_branch = branch;
// branch = branch_;
// continue;
// } else {
printf("%04x->%04x: bprune 0x%x w%d\n",
branch,
rbyd->eoff,
@@ -3004,7 +3069,7 @@ again:;
alt = LFSR_TAG_ALT(LFSR_TAG_LE, LFSR_TAG_B, 0);
weight = 0;
// jump = 0;
}
// }
}
}