Fastest way to produce a mask with n ones starting at position i
<p>What is the fastest way (in terms of cpu cycles on common modern architecture), to produce a mask with <code>len</code> bits set to 1 starting at position <code>pos</code>:</p>

<pre><code>template &lt;class UIntType&gt;
constexpr T make_mask(std::size_t pos, std::size_t len)
{
    // Body of the function
}

// Call of the function
auto mask = make_mask&lt;uint32_t&gt;(4, 10);
// mask = 00000000 00000000 00111111 11110000 
// (in binary with MSB on the left and LSB on the right)
</code></pre>

<p>Plus, is there any compiler intrinsics or <a href="https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets">BMI</a> function that can help?</p>