Skip to content

Commit 4c9a6c4

Browse files
luisleo526claude
andcommitted
Cohort exposure fold: pin the completion threshold to the retained roster size
The choice between the roster walk and the selector copy compares the retained member count with the selector charge. Every row of the overflow path built a roster whose retired prefix is empty, where that count equals the total number of accepted entries, so using the total in its place went unnoticed. In a run, retiring a prefix makes the two differ: the results stay bit-identical but the work does not, and the wrong count picks the selector when the walk is cheaper. The new row puts two unmapped entries in front of the mapped block, pads the roster to one more than the selector charge, retires the two entries and so leaves the retained count one below the charge while the total stays above it. It asserts the retained and total counts, the sole large row's absolute position, the order-sensitive total, and that the walk ran (the gather's steps plus the retained count); a threshold on the total would report the selector's steps instead. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 3da8fbb commit 4c9a6c4

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎tests/test_cohort_exposure_fold.cpp‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,43 @@ void overflow_selector_interleavings() {
224224
assert(std::memcmp(&denormal.total, &expected_tiny, sizeof expected_tiny) == 0);
225225
assert(denormal.path == 3 && denormal.steps == actual.steps);
226226
}
227+
{
228+
OriginRoster origins;
229+
const Units units{{7, 1e16}, {19, 1.0}, {43, 1.0}, {71, 1.0}};
230+
// Only these unmapped entries occupy the prefix at positions 0 and 1.
231+
push(origins, 900);
232+
push(origins, 901);
233+
for (std::size_t i = 0; i < mapped_positions - 1; ++i) {
234+
if (i == 4) push(origins, 7);
235+
push(origins, small_ids[i % small_ids.size()]);
236+
}
237+
for (std::size_t i = origins.size(); i < selector_charge + 1; ++i)
238+
push(origins, 1000 + i);
239+
origins.retire_before(2);
240+
assert(origins.base() == 2); // retire_before sets the global base.
241+
// C + 1 accepted entries minus the two retired entries leaves C - 1.
242+
assert(origins.members().size() == selector_charge - 1);
243+
// Retirement preserves size() = base() + members().size() = C + 1.
244+
assert(origins.size() >= selector_charge);
245+
// The removed ids have no retained positions. The sole large term
246+
// stays at absolute position 2 + 4, after the same four small terms.
247+
assert(origins.positions_of(900) == nullptr &&
248+
origins.positions_of(901) == nullptr);
249+
const auto* large_positions = origins.positions_of(7);
250+
assert(large_positions && large_positions->size() == 1 &&
251+
large_positions->front() == 2 + 4);
252+
const auto actual = check(origins, units);
253+
// M = C - 1 exceeds 4R + 16, and P exceeds the stack capacity.
254+
assert(actual.path == 3);
255+
// Four ones precede 1e16; its resulting even significand and ULP 2
256+
// make every later one round away, despite the global position offset.
257+
const double expected = 10000000000000004.0;
258+
assert(std::memcmp(&actual.total, &expected, sizeof expected) == 0);
259+
// Gather visits R + P, then the walk visits the retained M = C - 1.
260+
// Comparing size() instead would select selector_steps: shifting all
261+
// mapped positions by two preserves every selector comparison.
262+
assert(actual.steps == gather_steps + origins.members().size());
263+
}
227264
}
228265

229266
detail::CohortExposureFold check_stack_sort(const OriginRoster& origins,

0 commit comments

Comments
 (0)