title: Endianness confusion with ARM Neon vtbx
body: <p>I have a 16 byte permutation mask <code>uint8_t[16]</code> and a 16 byte data array <code>uint32_t[4]</code>. I want to "shuffle" this data array using <code>vtbl</code> like that:</p>
  
  <pre><code>          0   1   2   3   4   5   6   7    8   9    A    B    C    D    E    F
    Data ||0x0,0x0,0x1,0x2|0x0,0x3,0x0,0x4||0x5,0x6, 0x7, 0x8| 0x0, 0x0, 0x0, 0x9||
  
   SMask ||0x2,0x3,0x5,0x6|0x7,0x8,0x9,0xA||0xB,0xF,0x10,0x10|0x10,0x10,0x10,0x10||
  
  Result ||0x1,0x2,0x3,0x0|0x4,0x5,0x6,0x7||0x8,0x9, 0x0, 0x0| 0x0, 0x0, 0x0, 0x0||
  </code></pre>
  
  <p>This is my code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;arm_neon.h&gt;
  
  inline uint8x16_t Shuffle(const uint8x16_t &amp; src, const uint8x16_t &amp; shuffle) {
    return vcombine_u8(
            vtbl2_u8(
              (const uint8x8x2_t &amp;)src, 
              vget_low_u8(shuffle)
            ),
            vtbl2_u8(
              (const uint8x8x2_t &amp;)src, 
            vget_high_u8(shuffle)
            )
          );
  }
  
  int main() {
     uint32_t* data32 = new uint32_t[4];
     data32[0] = 258;             // [0x00 0x00 0x01 0x02]
     data32[1] = 196612;          // [0x00 0x03 0x00 0x04]
     data32[2] = 84281096;        // [0x05 0x06 0x07 0x08]
     data32[3] = 9;               // [0x00 0x00 0x00 0x09]    
     /*load structure*/
     uint32x4_t data32Vec = vld1q_u32(data32);
  
     uint8_t* sMask = new uint8_t[16];
     sMask[0] = 2;
     sMask[1] = 3;
     sMask[2] = 5;
     sMask[3] = 6;
     sMask[4] = 7;
     sMask[5] = 8;
     sMask[6] = 9;
     sMask[7] = 10;
     sMask[8] = 11;
     sMask[9] = 15;
     sMask[10] = 16;
     sMask[11] = 16;
     sMask[12] = 16;
     sMask[13] = 16;
     sMask[14] = 16;
     sMask[15] = 16;
     /*load permutationmask into vector register*/
     uint8x16_t shuffleMask = vld1q_u8(sMask);
  
     uint8_t* comprData = new uint8_t[16];
     /*shuffle the data with the mask and store it into an uint8_t[16]*/
     vst1q_u8(comprData, Shuffle(vreinterpretq_u8_u32(data32Vec),shuffleMask));
     for(int i = 0; i &lt; 16; ++i) {
        std::cout &lt;&lt; (unsigned)comprData[i] &lt;&lt; "   " ;
     }
     std::cout &lt;&lt; std::endl;
     delete[] comprData;
     delete[] sMask;
     delete[] data32;
     return 0;
  }
  </code></pre>
  
  <p>The output looks like the following:</p>
  
  <pre><code>0   0   0   3   0   8   7   6   5   0   0   0   0   0   0   0
  </code></pre>
  
  <p>It should be like that:</p>
  
  <pre><code>1   2   3   0   4   5   6   7   8   9   0   0   0   0   0   0
  </code></pre>
  
  <p>I think it has something to do with endianness, but just don't see the problem. Does anyone has a hint?</p>
  
  <p>I updated the code regarding to the answer from ErmIg. The main problem was, that I mixed up vtbx and vtbl.</p>
  
  <p>Sincerely</p>