title: Using an union (encapsulated in a struct) to bypass conversions for neon data types
body: <p>I made my first approach with vectorization intrinsics with SSE, where there is basically only one data type <code>__m128i</code>. Switching to Neon I found the data types and function prototypes to be much more specific, e.g. <code>uint8x16_t</code> (a vector of 16 <code>unsigned char</code>), <code>uint8x8x2_t</code> (2 vectors with 8 <code>unsigned char</code> each), <code>uint32x4_t</code> (a vector with 4 <code>uint32_t</code>) etc. </p>
  
  <p>First I was enthusiastic (much easier to find the exact function operating on the desired data type), then I saw what a mess it was when wanting to treat the data in different ways. Using <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491h/BABHDBBB.html" rel="nofollow noreferrer">specific casting operators</a> would take me forever. The problem is also addressed <a href="https://stackoverflow.com/q/13711407/2436175">here</a>. I then came up with the idea of an union encapsulated into a struct, and some casting and assignment operators.</p>
  
  <pre><code>struct uint_128bit_t { union {
          uint8x16_t uint8x16;
          uint16x8_t uint16x8;
          uint32x4_t uint32x4;
          uint8x8x2_t uint8x8x2;
          uint8_t uint8_array[16] __attribute__ ((aligned (16) ));
          uint16_t uint16_array[8] __attribute__ ((aligned (16) ));
          uint32_t uint32_array[4] __attribute__ ((aligned (16) ));
      };
  
      operator uint8x16_t&amp; () {return uint8x16;}
      operator uint16x8_t&amp; () {return uint16x8;}
      operator uint32x4_t&amp; () {return uint32x4;}
      operator uint8x8x2_t&amp; () {return uint8x8x2;}
      uint8x16_t&amp; operator =(const uint8x16_t&amp; in) {uint8x16 = in; return uint8x16;}
      uint8x8x2_t&amp; operator =(const uint8x8x2_t&amp; in) {uint8x8x2 = in; return uint8x8x2;}
  
  };
  </code></pre>
  
  <p>This approach works for me: I can use a variable of type <code>uint_128bit_t</code> as an argument and output with different Neon intrinsics, e.g. <code>vshlq_n_u32</code>,  <code>vuzp_u8</code>, <code>vget_low_u8</code> (in this case just as input). And I can extend it with more data types if I need.
  Note: The arrays are to easily print the content of a variable.</p>
  
  <p>Is this a correct way of proceeding?<br/>
  Is there any hidden flaw?<br/>
  Have I reinvented the wheel?<br/>
  (Is the aligned attribute necessary?)</p>