title: Fastest way to copy memory with stride in C?
body: <p>I'm trying to copy 1 or 2 colour channels from RGBA image data as quickly as possible (this is the slowest part of my code, and it's slowing the whole app down). Is there a fast way of copying with stride?</p>
  
  <p>The data is simply laid out as RGBARGBARGBA etc., and I need to copy just the R values, or in another case just the RG values. </p>
  
  <p>What I have so far is roughly this to copy the R values:</p>
  
  <pre><code>for(int i=0; i&lt;dataSize; i++){
      dest[i] = source[i*4];
  }
  </code></pre>
  
  <p>For the RG values, I'm doing:</p>
  
  <pre><code>for(int i=0; i&lt;dataSize; i+=2){
      dest[i] = source[i*2];
      dest[i+1] = source[(i*2)+1];
  }
  </code></pre>
  
  <p>All the data is unsigned 1-byte values. Is there a faster way? I've already partially unrolled the loop (doing 64 values per iteration - insignificant speedup beyond that). Platform is Armv7 (iOS), so using NEON (SIMD) might be useful, I've zero experience with that unfortunately!</p>
  
  <p>Changing the data is unfortunately out of the question, it's provided by opengl's readPixels() function, and iOS doesn't support reading as L, LA, RG etc. so far as I've been able to tell.</p>