rbyd-rr: Tweaked diverging machine for a bit better code reuse

Mainly deduplicating the pruning of pre-diverged-lower alts and the
diverging alt itself.

This saves some code:

           code          stack
  before: 34308           2864
  after:  34236 (-0.2%)   2864 (+0.0%)
This commit is contained in:
Christopher Haster
2024-03-29 15:22:41 -05:00
parent 120f0a2e17
commit 115fad0c80
+53 -58
View File
@@ -2910,76 +2910,71 @@ again:;
jump = branch - jump; jump = branch - jump;
lfs_size_t branch_ = branch + d; lfs_size_t branch_ = branch + d;
// do bounds want to take different paths? begin diverging // progress diverging state machine?
if (!lfsr_d_isdiverged(d_state) if (!lfsr_d_isdiverged(d_state)) {
&& lfsr_tag_follow2(alt, weight, // do bounds want to take different paths? begin diverging
bool diverge
= lfsr_tag_follow2(alt, weight,
p_alts[0], p_weights[0], p_alts[0], p_weights[0],
lower_rid, upper_rid, lower_rid, upper_rid,
a_rid, a_tag) a_rid, a_tag)
^ lfsr_tag_follow2(alt, weight, ^ lfsr_tag_follow2(alt, weight,
p_alts[0], p_weights[0], p_alts[0], p_weights[0],
lower_rid, upper_rid, lower_rid, upper_rid,
b_rid, b_tag)) { b_rid, b_tag);
LFS_ASSERT(d_state != LFSR_D_NOTDIVERGING);
// note that if red alt diverged if would have been caught // skip common alts on lower pass and the diverging alt
// on the previous pass // itself on both paths
d_state = lfsr_d_diverge(d_state); if (d_state == LFSR_D_DIVERGINGLOWER || diverge) {
LFS_ASSERT(d_state != LFSR_D_NOTDIVERGING);
if (lfsr_tag_follow2( if (lfsr_tag_follow2(
alt, weight, 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], p_alts[0], p_weights[0],
lower_rid, upper_rid); lower_rid, upper_rid,
lfs_swap32(&jump, &branch_); a_rid, a_tag)) {
} lfsr_tag_flip2(
lfsr_tag_trim2( &alt, &weight,
alt, weight, p_alts[0], p_weights[0],
p_alts[0], p_weights[0], lower_rid, upper_rid);
&lower_rid, &upper_rid, lfs_swap32(&jump, &branch_);
&lower_tag, &upper_tag);
// stitch together diverged branches
if (d_state == LFSR_D_DIVERGEDUPPER) {
err = lfsr_rbyd_p_push(lfs, rbyd,
p_alts, p_weights, p_jumps,
LFSR_TAG_ALT(LFSR_TAG_LE, LFSR_TAG_B, d_tag),
d_rid - lower_rid + weight,
d_branch);
if (err) {
return err;
} }
lfsr_tag_trim2(
alt, weight,
p_alts[0], p_weights[0],
&lower_rid, &upper_rid,
&lower_tag, &upper_tag);
// transition to the diverged state
//
// note that if red alt diverged if would have been
// caught on the previous pass
if (diverge) {
d_state = lfsr_d_diverge(d_state);
// stitch together diverged branches
if (d_state == LFSR_D_DIVERGEDUPPER) {
err = lfsr_rbyd_p_push(lfs, rbyd,
p_alts, p_weights, p_jumps,
LFSR_TAG_ALT(
LFSR_TAG_LE,
LFSR_TAG_B,
d_tag),
d_rid - lower_rid + weight,
d_branch);
if (err) {
return err;
}
}
}
branch = branch_;
continue;
} }
}
branch = branch_; // trim unreachable diverged alts so they end up pruned
continue; if (lfsr_d_isdiverged(d_state)
// don't write diverging lower alts
} else if (d_state == LFSR_D_DIVERGINGLOWER) {
if (lfsr_tag_follow(
alt, weight,
lower_rid, upper_rid,
a_rid, a_tag)) {
lfsr_tag_flip(
&alt, &weight,
lower_rid, upper_rid);
lfs_swap32(&jump, &branch_);
}
lfsr_tag_trim(
alt, weight,
&lower_rid, &upper_rid,
&lower_tag, &upper_tag);
branch = branch_;
continue;
// trim unreachable alts created by diverged paths so they
// will be pruned
} else if (lfsr_d_isdiverged(d_state)
&& (d_state == LFSR_D_DIVERGEDUPPER) && (d_state == LFSR_D_DIVERGEDUPPER)
^ lfsr_tag_isgt(alt) ^ lfsr_tag_isgt(alt)
^ lfsr_tag_follow2( ^ lfsr_tag_follow2(