title: LSB to MSB bit reversal on ARM
body: <p>I need to reverse an YUV image with each byte in LSB instead of MSB. I have read <a href="https://stackoverflow.com/questions/746171/best-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c">Best Algorithm for Bit Reversal ( from MSB-&gt;LSB to LSB-&gt;MSB) in C</a> but I would like to do something that is ARM-optimized.</p>
  
  <pre><code>int8 *image;
  for(i = 0; i &lt; size; i++) {
      image[i] = reversebit8(image[i]); //Use the lookup mechanism
  }
  </code></pre>
  
  <p>As I control the image format (two-byte YUYV or any permutation), I would be OK to reverse 16 bits:</p>
  
  <pre><code>int16 *image;
  for(i = 0; i &lt; size / 2; i++) {
      image[i] = reversebit16(image[i]);
  }
  </code></pre>
  
  <p>Image goes from YUYV LSB to UYVY MSB. Or even in 32 bits:</p>
  
  <pre><code>int32 *image;
  for(i = 0; i &lt; size / 4; i++) {
      image[i] = reversebit32(image[i]);
  }
  </code></pre>
  
  <p>Image goes from YUYV LSB to VYUY MSB.</p>
  
  <p>Question: How can I do that in an optimized way for ARM? Neon is good too.</p>
  
  <p>I think that those instructions <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.kui0100a/armasm_cihjgdid.htm" rel="nofollow noreferrer">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.kui0100a/armasm_cihjgdid.htm</a> could be useful.</p>