title: How to implement atoi using SIMD?
body: <p>I'd like to try writing an atoi implementation using SIMD instructions, to be included in <a href="http://rapidjson.org/" rel="noreferrer">RapidJSON</a> (a C++ JSON reader/writer library).  It currently has some SSE2 and SSE4.2 optimizations in other places.</p>
  
  <p>If it's a speed gain, multiple <code>atoi</code> results can be done in parallel.  The strings are originally coming from a buffer of JSON data, so a multi-atoi function will have to do any required swizzling.</p>
  
  <p>The algorithm I came up with is the following:</p>
  
  <ol>
  <li>I can initialize a vector of length N in the following fashion:
  [10^N..10^1]</li>
  <li>I convert each character in the buffer to an integer and place them in another vector.</li>
  <li>I take each number in the significant digits vector and multiply it by the matching number in the numbers vector and sum the results.  </li>
  </ol>
  
  <p>I'm targeting x86 and x86-64 architectures.</p>
  
  <p>I know that AVX2 supports three operand Fused Multiply-Add so I'll be able to perform Sum = Number * Significant Digit + Sum.<br>
  That's where I got so far.<br>
  Is my algorithm correct? Is there a better way?<br>
  Is there a reference implementation for atoi using any SIMD instructions set?</p>