P3440R2 — Add mask_from_count function to std::simd (6 items) LEWG
Daniel Towner
This paper proposes adding a free function std::simd::mask_from_count to the std::simd library that creates a mask with exactly N bits set at positions [0..N). The function is simd-generic, accepting both basic_vec types and scalar types as template parameters, and gracefully handles empty, partial, and saturated cases without additional preconditions. The primary motivation is to provide a portable, efficient, and correct way to generate remainder masks when processing dynamic data sets with std::simd, avoiding subtle correctness pitfalls inherent in manual mask generation approaches.

References — Anthropic Citations API

[1] chars 12972–13270
"Add new section [simd.mask.from_count] «+ � Creating masks from element count [simd.mask.from_count] ``` template constexpr /*see below*/ mask_from_count(simd-size-type count)..."
[1] chars 12803–13270
"general] Add to the list of simd operations: «+ ``` template constexpr /*see below*/ mask_from_count(simd-size-type count) noexcept; ``` +» ### 5.2. Add new section..."
[2] chars 10766–11441
"Pattern B - Explicit remainder (potentially optimized): ``` auto fullBlocks = count / simd::vec::size(); auto remainder = count % simd::vec::size(); for (int i = 0; i < fullBlocks;..."
[2] chars 10766–11441
"Pattern B - Explicit remainder (potentially optimized): ``` auto fullBlocks = count / simd::vec::size(); auto remainder = count % simd::vec::size(); for (int i = 0; i < fullBlocks;..."
Summary: P3440R2 proposes adding a mask_from_count free function to std::simd that constructs a mask with the first N elements set to true, motivated by common remainder-loop and partial-load patterns. Two defects were found: one corrupted character in the proposed wording and one incorrect subspan indexing in a motivating code example.
Pipeline: Discovery (Anthropic Opus + Citations API) → Verification Gate (OpenRouter Opus) → Report Writer (OpenRouter Opus)
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.