P4010R0 — Funnel Shift Operations
(8 items)
SG6, LEWG
This paper proposes adding funnel shift operations (funnel_shift_left and funnel_shift_right) to the C++ standard library's header. Funnel shifts concatenate two integer values, shift the result, and extract bits from it, generalizing bit rotation and mapping directly to hardware instructions such as x86 SHLD/SHRD and ARM EXTR. The proposal covers both scalar and SIMD interfaces, constrained to unsigned integer types, with preconditions requiring the shift count to be in [0, N) without implicit modular reduction.
- §7.2 Funnel shifts [bit.funnel] — Returns formula for funnel_shift_right yields (low | high) when r=0, contradicting the Remarks which state the result is low. Needs a conditional: if r is 0, return low; otherwise apply the shift expression without the modulo on (N - r). [1] [1]
- §7.2 Funnel shifts [bit.funnel] — Returns formula for funnel_shift_left yields (high | low) when r=0, contradicting the Remarks which state the result is high. Same fix needed: conditional on r=0 returning high, else the shift expression without modulo on (N - r). [2] [2]
- §4.7 Scalar Interface — Design section formula for funnel_shift_right has the same r=0 defect: (low >> 0) | (high << ((N - 0) % N)) evaluates to low | high, not low. [1] [3]
- §4.7 Scalar Interface — Design section formula for funnel_shift_left has the same r=0 defect: (high << 0) | (low >> ((N - 0) % N)) evaluates to high | low, not high. [2] [4]
- §4.1.1 Unsigned Integers Only — Claims right shifts on signed integers have implementation-defined behavior in C++. Since C++20 (P0907R4, P1236R1), signed integers are two's complement and right shift is defined as arithmetic shift per [expr.shift]. The claim is outdated. [3] [5]
- §7.2 Funnel shifts [bit.funnel] — Cross-reference [concepts] for the integral concept is imprecise; it refers to the broad Concepts library header. The correct stable name is [concept.integral]. [4] [6]
References — Anthropic Citations API
[1]
"Returns: (low >> r) | (high << ((N - r) % N)). and Remarks: funnel_shift_right(high, low, 0) returns low."
"Returns: (low >> r) | (high << ((N - r) % N)). and Remarks: funnel_shift_right(high, low, 0) returns low."
[2]
"Returns: (high << r) | (low >> ((N - r) % N)). and Remarks: funnel_shift_left(high, low, 0) returns high."
"Returns: (high << r) | (low >> ((N - r) % N)). and Remarks: funnel_shift_left(high, low, 0) returns high."
[3]
chars 12051–12141
"funnel_shift_right(high, low, s) is equivalent to (low >> r) | (high << ((N - r) % N)). "
"funnel_shift_right(high, low, s) is equivalent to (low >> r) | (high << ((N - r) % N)). "
[4]
chars 12141–12231
"funnel_shift_left(high, low, s) is equivalent to (high << r) | (low >> ((N - r) % N)). "
"funnel_shift_left(high, low, s) is equivalent to (high << r) | (low >> ((N - r) % N)). "
[5]
chars 7589–7727
"Well-defined shift semantics: Right shifts on signed integers have implementation-defined behavior in C++ (arithmetic vs. logical shift). "
"Well-defined shift semantics: Right shifts on signed integers have implementation-defined behavior in C++ (arithmetic vs. logical shift). "
[6]
chars 20263–20567
"``` template constexpr V funnel_shift_left(const V& high, const V& low, S s) noexcept; template constexpr V funnel_shift_right(const V& high, const V& low, S s) noexcept; ``` Constraints: The..."
"``` template constexpr V funnel_shift_left(const V& high, const V& low, S s) noexcept; template constexpr V funnel_shift_right(const V& high, const V& low, S s) noexcept; ``` Constraints: The..."
[6]
chars 18186–18220
"S models integral ([concepts]). "
"S models integral ([concepts]). "
[6]
chars 18597–18631
"S models integral ([concepts]). "
"S models integral ([concepts]). "
Summary: P4010R0 proposes std::funnel_shift_left and std::funnel_shift_right operations for unsigned integer types, extracting N bits from a 2N-bit concatenation of two values shifted by a given amount. The proposal includes both scalar and SIMD interfaces and provides proposed wording for inclusion in .
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.