title: Optimal NEON vector structure for processing vectors of uint8_t type with Arm Cortex-A8 (32-bit)
body: <p>I am doing some image processing on an embedded system (BeagleBone Black) using OpenCV and need to write some code to take advantage of NEON optimization. Specifically, I would like to write a NEON optimized thresholding function and then a NEON optimized erosion/dilation function.</p>
  
  <p>This is my first time writing NEON code and I don't have experience writing assmbly code, so I have been looking at examples and resources for the C-style <a href="http://gcc.gnu.org/onlinedocs/gcc/ARM-NEON-Intrinsics.html" rel="nofollow noreferrer">NEON intrinsics</a>. I believe that I can put some working code together, but am <strong>not sure how I should structure the vectors</strong>. According to page 2 of the "<a href="https://pixhawk.ethz.ch/_media/software/optimization/neon_support_in_the_arm_compiler.pdf" rel="nofollow noreferrer">ARM NEON support in the ARM compiler</a>" white paper:</p>
  
  <blockquote>
    <p>"These registers can hold "vectors" of items which are 8, 16, 32 or 64
    bits. The traditional advice when optimizing or porting algorithms
    written in C/C++ is to <strong>use the natural type of the machine for data
    handling (in the case of ARM 32 bits)</strong>. The unwanted bits can then be
    discarded by casting and/or shifting before storing to memory."</p>
  </blockquote>
  
  <p>What exactly does this mean? Do I need to to restrict my NEON code to using <code>uint32x4_t</code> vectors rather than <code>uint8x16_t</code>? How would I go about loading the registers? Or does this mean than I need to take some special steps when using <code>vst1q_u8</code> to store the data to memory?</p>
  
  <p>I did find <a href="https://stackoverflow.com/questions/11724207/test-neon-optimized-cvthreshold-on-mobile-device">this example</a>, which is untested but uses the <code>uint8x16_t</code> type. Does it adhere to the "32-bit" advice given above?</p>
  
  <p>I would really appreciate it if someone could please elaborate on the above quotation and maybe provide a very simple working example.</p>