title: Standard C++11 code equivalent to the PEXT Haswell instruction (and likely to be optimized by compiler)
body: <p>The Haswell architectures comes up with several new instructions. One of them is <code>PEXT</code> (<a href="http://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets" rel="noreferrer">parallel bits extract</a>) whose functionality is explained by this image (source <a href="http://palms.ee.princeton.edu/PALMSopen/hilewitz06FastBitCompression.pdf" rel="noreferrer">here</a>):</p>
  
  <p><img src="https://i.stack.imgur.com/75CQL.png" alt="pext"></p>
  
  <p>It takes a value <code>r2</code> and a mask <code>r3</code> and puts the extracted bits of <code>r2</code> into <code>r1</code>.</p>
  
  <p>My question is the following: what would be the equivalent code of an optimized templated function in <strong>pure standard</strong> C++11, that would be likely to be optimized to this instruction by compilers in the future.</p>