title: Alternative to immintrin.h
body: <p>In c/c++, the explicit vectorization intrinsics provided by <code>immintrin.h</code>, I would argue, is a kludge.  That is, for each CPU instruction set (e.g. SSE, AVX2,AVX512,...) and for each number type (i.e. float, double, int, etc), there is a unique function for the same fundamental operations, such as <code>_mm_add_epi8</code>, <code>_mm_add_epi16</code>, <code>_mm256_add_epi8</code>, <code>_mm256_add_epi16</code>, all for the basic <code>+</code>.  So if you code with intrinsics for AVX, you have to recode when you upgrade to AVX2 and then for AVX512 and so on.</p>
  
  <p>On the other hand, some of the compilers basic, built-in operator (i.e. '+', '-', etc) seem to work nicely (provide data is aligned) on all types (vector and not) and some mixed type operations (as illustrated in snippet below), leading to better readability and scalability (with simd instruction set). </p>
  
  <pre><code>// no need for #include "immintrin.h"
  
  #ifndef __AVX2__
  #define SIMD_LEN 16
  #else
  #define SIMD_LEN 32
  #endif
  
  typedef int num_t;
  
  num_t a[N], b[N];
  
  // for any num_t and SIMD_LEN, explicitly vectorize b[n] = 2*a[n] + 4 
  
  typedef num_t    vec_t __attribute__ ((__vector_size__ (SIMD_LEN)));
  
  vec_t *vA = (vec_t*)a;
  vec_t *vB = (vec_t*)b;
  
  int nNums = SIMD_LEN/sizeof(num_t);
  
  for (int n=0; n &lt; (N/nNums); n++) 
      vB[n] = 2*vA[n] + 4;
  </code></pre>
  
  <p>Obviously such flexibity/scalability is not going to be available for ALL operations, but it seems that <code>immintrin.h</code> is not structured to allow natural expressions as much as it could.</p>
  
  <p>To that end, is there an alternative "intrinsic" header to the <code>immintrin.h</code> family that allows more natural expression, as illustrated above?  At least one that covers many of the universal, scalable op, like horizontal add, unaligned load, compare, etc?  </p>
  
  <p>And for the purpose of this question, I'm not interested in "just let the compiler vectorize".  That simply answers the question of whether to use intrinsics or not.</p>