title: SIMD Vectorization of Sobel function on ARM Cortex
body: <p>Currently struggling to vectorize a function as shown below.
  It's a function used in image processing and I cannot for the life of me figure out how to vectorize it.
  I assume I have to optimize the for loop where the Gx and Gy variables are being updated on the //Calculate the sum of the Sobel mask times the nine surrounding pixels in the x and y 
  section.</p>
  
  <p>I was recommended to use __SMLAD() from the arm intrinsics as linked here: <a href="https://developer.arm.com/docs/dui0472/j/armv6-simd-instruction-intrinsics/__smlad-intrinsic" rel="nofollow noreferrer">https://developer.arm.com/docs/dui0472/j/armv6-simd-instruction-intrinsics/__smlad-intrinsic</a>
  However,  I just can't figure out how to use it..any help on how to use __SMLAD() would be much appreciated, as it seems there just aren't any examples of it being used on the internet anywhere.</p>
  
  <p>Here's the function:</p>
  
  <pre><code>void Sobel(){
  
  int row, col, rowOffset, colOffset,Gx,Gy;   
  
  float thisAngle;                
  uint8_t newAngle;
  
      /*---------------------- Sobel ---------------------------------*/
      for (row = 1; row &lt; N-1; row++) {
      for (col = 1; col &lt; M-1; col++) {
  
          Gx = 0;
          Gy = 0;
  
          //Calculate the sum of the Sobel mask times the nine surrounding pixels in the x and y direction 
          for (rowOffset=-1; rowOffset&lt;=1; rowOffset++) {
              for (colOffset=-1; colOffset&lt;=1; colOffset++) {
  
                  Gx += out_img[row+rowOffset][col+colOffset] * GxMask[rowOffset + 1][colOffset + 1];
                  Gy += out_img[row+rowOffset][col+colOffset] * GyMask[rowOffset + 1][colOffset + 1];
              }
          }
  
          gradient[row][col] = abs(Gx) + abs(Gy); // Calculate gradient strength      
          thisAngle = (atan2((float) Gx, (float) Gy)/3.14159f) * 180.0f;      // Calculate actual direction of edge [-180, +180]
  
          // Convert actual edge direction to approximate value 
          if ( ( (thisAngle &gt;= -22.5f) &amp;&amp; (thisAngle &lt;= 22.5f) ) || (thisAngle &gt;= 157.5f) || (thisAngle &lt;= -157.5f) )
              newAngle = 0;
          if ( ( (thisAngle &gt; 22.5f) &amp;&amp; (thisAngle &lt; 67.5f) ) || ( (thisAngle &gt; -157.5f) &amp;&amp; (thisAngle &lt; -112.5f) ) )
              newAngle = 45;
          if ( ( (thisAngle &gt;= 67.5f) &amp;&amp; (thisAngle &lt;= 112.5f) ) || ( (thisAngle &gt;= -112.5f) &amp;&amp; (thisAngle &lt;= -67.5f) ) )
              newAngle = 90;
          if ( ( (thisAngle &gt; 112.5f) &amp;&amp; (thisAngle &lt; 157.5f) ) || ( (thisAngle &gt; -67.5f) &amp;&amp; (thisAngle &lt; -22.5f) ) )
              newAngle = 135;
  
          edge_Dir[row][col] = newAngle;      
  
  
      }
  }
  
  }
  </code></pre>