Hoist the crossed offset test in fast.cpp
Test end.offset <= 1 before revTruncLeOneLow in the reversed crossed dispatch, and specialize revTruncLeOneLow under that path fact. The helper drops the now-tautological end.offset conjuncts and the key comparison implied by a failed optLe. The crossed truncated reverse benchmark drops from about 67 ns to about 61 ns. Sweep, corpus, SMT cases, and 100% line and branch coverage still pass.
This commit is contained in:
1 parent
e1395f20ef
commit
e351a0cf8d
2 files changed
+19
-20
No files matched your search
+3
-2
@@ -132,7 +132,7 @@ coverage. `sweep_test` alone covers every region, function, line, and
|
|||||||
branch side of the summarised implementation:
|
branch side of the summarised implementation:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
src/fast.cpp 560 regions (0 missed) 121 functions (0 missed) 675 lines (0 missed) 374 branches (0 missed)
|
src/fast.cpp 553 regions (0 missed) 119 functions (0 missed) 668 lines (0 missed) 362 branches (0 missed)
|
||||||
```
|
```
|
||||||
|
|
||||||
That is 100.00% line, function, region, and branch coverage. Offset 5 is part of
|
That is 100.00% line, function, region, and branch coverage. Offset 5 is part of
|
||||||
@@ -142,7 +142,8 @@ which the previous `[-3, 4]` window missed.
|
|||||||
Because equivalence is only promised on readable inputs, `src/fast.cpp` deletes
|
Because equivalence is only promised on readable inputs, `src/fast.cpp` deletes
|
||||||
both unreachable control-flow branches and predicate operands that an enclosing
|
both unreachable control-flow branches and predicate operands that an enclosing
|
||||||
dispatch invariant fixes. Examples include the complete-closed family, the
|
dispatch invariant fixes. Examples include the complete-closed family, the
|
||||||
offset-one total/any wrappers, the `end.offset <= 1` shortcuts, the
|
offset-one total/any wrappers, the hoisted and specialised
|
||||||
|
`end.offset <= 1` / `revTruncLeOneLow` path split, the
|
||||||
`crossedCompleteEndLeOne` guard, and the repeated
|
`crossedCompleteEndLeOne` guard, and the repeated
|
||||||
`!c.r->reverse`/`!o.more`/offset tests inside subtrees that are only entered
|
`!c.r->reverse`/`!o.more`/offset tests inside subtrees that are only entered
|
||||||
after those tests succeeded. `literal.cpp` keeps the full Lean conditions so the
|
after those tests succeeded. `literal.cpp` keeps the full Lean conditions so the
|
||||||
|
|||||||
+16
-18
@@ -749,22 +749,17 @@ struct Impl {
|
|||||||
return c.r->begin.offset == 0;
|
return c.r->begin.offset == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevUnder(const Ctx& c, const Obs& o) const {
|
// `revTruncLeOneLow` is reached only under `end.offset <= 1` (the dispatch
|
||||||
return optLe(c.r->begin.key, c.r->end_.key) && c.r->end_.offset <= 1;
|
// tests that comparison first), so the `end.offset <= 1` conjunct in each
|
||||||
}
|
// original disjunct is discharged by the caller and has been dropped here.
|
||||||
|
|
||||||
bool negCrossTruncRevCrossedLow(const Ctx& c, const Obs& o) const {
|
|
||||||
return optLt(c.r->end_.key, c.r->begin.key) &&
|
|
||||||
c.r->end_.offset <= 1 &&
|
|
||||||
niLe(niAdd(niAdd(cardEB(c),
|
|
||||||
NatInf::of(static_cast<std::uint64_t>(c.n))),
|
|
||||||
NatInf::of(toNat(1 - c.r->end_.offset))),
|
|
||||||
NatInf::of(bSlack(c) + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool revTruncLeOneLow(const Ctx& c, const Obs& o) const {
|
bool revTruncLeOneLow(const Ctx& c, const Obs& o) const {
|
||||||
return negCrossTruncRevUnder(c, o) ||
|
if (optLe(c.r->begin.key, c.r->end_.key)) return true;
|
||||||
negCrossTruncRevCrossedLow(c, o);
|
// The failed `optLe` test already gives `end.key < begin.key`, so the
|
||||||
|
// original `optLt` conjunct is implied here.
|
||||||
|
return niLe(niAdd(niAdd(cardEB(c),
|
||||||
|
NatInf::of(static_cast<std::uint64_t>(c.n))),
|
||||||
|
NatInf::of(toNat(1 - c.r->end_.offset))),
|
||||||
|
NatInf::of(bSlack(c) + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevBelowEnd(const Ctx& c, const Obs& o) const {
|
bool negCrossTruncRevBelowEnd(const Ctx& c, const Obs& o) const {
|
||||||
@@ -896,10 +891,13 @@ struct Impl {
|
|||||||
if (c.r->reverse) {
|
if (c.r->reverse) {
|
||||||
if (zeroCrossTruncRevCrossed(c, o))
|
if (zeroCrossTruncRevCrossed(c, o))
|
||||||
return closedFormZeroCrossTruncRevCrossed(c, o);
|
return closedFormZeroCrossTruncRevCrossed(c, o);
|
||||||
if (revTruncLeOneLow(c, o))
|
// `revTruncLeOneLow` implies `end.offset <= 1`, so test the cheap
|
||||||
return mk(OptKey{o.lastK()}, c.r->end_.key);
|
// comparison first and keep the disjunction on that branch only.
|
||||||
if (c.r->end_.offset <= 1)
|
if (c.r->end_.offset <= 1) {
|
||||||
|
if (revTruncLeOneLow(c, o))
|
||||||
|
return mk(OptKey{o.lastK()}, c.r->end_.key);
|
||||||
return mk(OptKey{o.lastK()}, c.r->begin.key);
|
return mk(OptKey{o.lastK()}, c.r->begin.key);
|
||||||
|
}
|
||||||
if (revTruncGeTwoTop(c, o))
|
if (revTruncGeTwoTop(c, o))
|
||||||
return mk(OptKey{o.lastK()}, topKey());
|
return mk(OptKey{o.lastK()}, topKey());
|
||||||
if (revTruncGeTwoLarge(c, o))
|
if (revTruncGeTwoLarge(c, o))
|
||||||
|
|||||||
Reference in new issue
Block a user