title: ARM-NEON: Conditional register swapping based on parameters
body: <p>I am writing a piece of subroutine in NEON for image processing which does color swapping, i.e., I sequentialy load the R,G,B channels from an array, and depending on some configuration, permute some of them.</p>
  
  <p>There are as maximum 6 permutes </p>
  
  <pre><code>  (RGB) -&gt; { (RGB),(RBG),(GRB),(GBR),(BRG),(BGR) }
  </code></pre>
  
  <p>The most efficient way would be to have a separate subroutine for each case and the corresponding VSWP instructions. As the Subroutine will do several other things, I would prefer to keep everything in just one sub, even if it is not so efficient, </p>
  
  <p>Also have read that conditional execution and branching is not advisable. So, if I want to have it in a block with branchless code, the only thing coming to my mind is</p>
  
  <pre><code>New_R = a(0)*R+a(1)*G+a(2)*B
  New_G = a(3)*R+a(4)*G+a(5)*B
  New_B = a(6)*R+a(7)*G+a(8)*B
  </code></pre>
  
  <p>where only one a(i) in each row and column will be =1 each time, and the rest will be =0</p>
  
  <p>Question: Any smarter way to do it, having in mind that it has to be coded to NEON?</p>