title: Why does ARM use two instructions to mask a value?
body: <p>For the following function...</p>
  
  <pre><code>uint16_t swap(const uint16_t value)
  {
      return value &lt;&lt; 8 | value &gt;&gt; 8;
  }
  </code></pre>
  
  <p>...why does ARM gcc 6.3.0 with -O2 yield the following assembly?</p>
  
  <pre><code>swap(unsigned short):
    lsr r3, r0, #8
    orr r0, r3, r0, lsl #8
    lsl r0, r0, #16         # shift left
    lsr r0, r0, #16         # shift right
    bx lr
  </code></pre>
  
  <p>It appears the compiler is using two shifts to mask off the unwanted bytes, instead of using a logical AND. Could the compiler instead use <code>and r0, r0, #4294901760</code>?</p>