title: How to rotate packed quadwords in xmm register?
body: <p>Given an 128-bit <code>xmm</code> register that is packed with two quadwords (i.e. two 64-bit integers):</p>
  
  <pre><code>     ╭──────────────────┬──────────────────╮
  xmm0 │ ffeeddccbbaa9988 │ 7766554433221100 │
       ╰──────────────────┴──────────────────╯
  </code></pre>
  
  <p>How can i perform a <em>rotate</em> on the individual quadwords? For example:</p>
  
  <pre><code>prorqw xmm0, 32   // rotate right packed quadwords
  
       ╭──────────────────┬──────────────────╮
  xmm0 │ bbaa9988ffeeddcc │ 3322110077665544 │
       ╰──────────────────┴──────────────────╯
  </code></pre>
  
  <p>I know SSE2 provides:</p>
  
  <ul>
  <li><strong><code>PSHUFW</code></strong>: <em>shuffle packed <strong>words</em></strong> (16-bits)</li>
  <li><strong><code>PSHUFD</code></strong>: <em>shuffle packed <strong>doublewords</em></strong> (32-bits)</li>
  </ul>
  
  <p>Although i don't know what the instructions do, nor is there a <strong>quadword</strong> (64-bit) version.</p>
  
  <h1>Bonus Question</h1>
  
  <p>How would you perform a <code>ROR</code> of an <code>xmm</code> register - assuming packed data of <em>other</em> sizes?</p>
  
  <ul>
  <li><p>Rotate Right Packed <strong>doublewords</strong> by 16-bits:</p>
  
  <pre><code>     ╭──────────┬──────────┬──────────┬──────────╮
  xmm0 │ ffeeddcc │ bbaa9988 │ 77665544 │ 33221100 │
       ╰──────────┴──────────┴──────────┴──────────╯
                          ⇓
       ╭──────────┬──────────┬──────────┬──────────╮
  xmm0 │ ddccffee │ 9988bbaa │ 55447766 │ 11003322 │
       ╰──────────┴──────────┴──────────┴──────────╯
  </code></pre></li>
  <li><p>Rotate Right Packed <strong>Words</strong> by 8-bits:</p>
  
  <pre><code>     ╭──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────╮
  xmm0 │ ffee │ ddcc │ bbaa │ 9988 │ 7766 │ 5544 │ 3322 │ 1100 │
       ╰──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────╯
                          ⇓
       ╭──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────╮
  xmm0 │ eeff │ ccdd │ aabb │ 8899 │ 6677 │ 4455 │ 2233 │ 0011 │
       ╰──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────╯
  </code></pre></li>
  </ul>
  
  <h2>Extra bonus question</h2>
  
  <p>How would you perform the above if it was a 256-bit <code>ymm</code> register?</p>
  
  <pre><code>     ╭──────────────────────────────────┬──────────────────────────────────╮
  ymm0 │ 2f2e2d2c2b2a29282726252423222120 │ ffeeddccbbaa99887766554433221100 │ packed doublequadwords
       ╰──────────────────────────────────┴──────────────────────────────────╯
       ╭──────────────────┬──────────────────┬──────────────────┬──────────────────╮
  ymm0 │ 2f2e2d2c2b2a2928 │ 2726252423222120 │ ffeeddccbbaa9988 │ 7766554433221100 │ packed quadwords
       ╰──────────────────┴──────────────────┴──────────────────┴──────────────────╯
       ╭──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────╮
  ymm0 │ 2f2e2d2c │ 2b2a2928 │ 27262524 │ 23222120 │ ffeeddcc │ bbaa9988 │ 77665544 │ 33221100 │ packed doublewords
       ╰──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────╯
       ╭──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────╮
  ymm0 │ 2f2e │ 2d2c │ 2b2a │ 2928 │ 2726 │ 2524 │ 2322 │ 2120 │ ffee │ ddcc │ bbaa │ 9988 │ 7766 │ 5544 │ 3322 │ 1100 │ packed words
       ╰──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────╯
  </code></pre>
  
  <h1>Bonus Reading</h1>
  
  <ul>
  <li><a href="https://software.intel.com/sites/landingpage/IntrinsicsGuide/#expand=88,79,5619,5163&amp;text=pshuf" rel="noreferrer">Intel Intrinsics Guide</a></li>
  <li><a href="http://ref.x86asm.net/coder64.html" rel="noreferrer">X86 Opcode and Instruction Reference Home</a></li>
  <li><a href="https://stackoverflow.com/questions/34117537/rotation-or-shifting-with-x86-x64-assembly">Rotation or Shifting with x86/x64 Assembly</a></li>
  <li><a href="https://www.gamedev.net/forums/topic/430880-mmx-asm-pshufw-explanation/" rel="noreferrer">PSHUFW explanation?</a></li>
  </ul>