P3440R2 — Add mask_from_count function to std::simd
(6 items)
LEWG
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.
-
Section 3.5 (Pattern B) — The loop passes the block index i directly to data.subspan(i), indexing by block number rather than element offset and producing overlapping loads. Should be data.subspan(i * simd::vec
::size()) to match the stride used in the paper's own first motivating example. [2] [1] - Section 5.2 [simd.mask.from_count] — Heading contains a Unicode replacement character (U+FFFD) where a section number or formatting symbol should appear. [1] [2]
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)..."
"Add new section [simd.mask.from_count] «+ � Creating masks from element count [simd.mask.from_count] ``` template
[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..."
"general] Add to the list of simd operations: «+ ``` template
[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;..."
"Pattern B - Explicit remainder (potentially optimized): ``` auto fullBlocks = count / simd::vec
[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;..."
"Pattern B - Explicit remainder (potentially optimized): ``` auto fullBlocks = count / simd::vec
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.
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.