title: Cortex A9 NEON vs VFP usage confusion
body: <p>I'm trying to build a library for a Cortex A9 ARM processor(an OMAP4 to be more specific) and I'm in a little bit of confusion regarding which\when to use NEON vs VFP in the context of floating point operations and SIMD. To be noted that I know the difference between the 2 hardware coprocessor units(as also outlined <a href="https://stackoverflow.com/questions/4097034/arm-cortex-a8-whats-the-difference-between-vfp-and-neon">here on SO</a>), I just have some misunderstanding regarding their proper usage.</p>
  
  <p>Related to this I'm using the following compilation flags:</p>
  
  <pre><code>GCC
  -O3 -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp
  -O3 -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=softfp
  ARMCC
  --cpu=Cortex-A9 --apcs=/softfp
  --cpu=Cortex-A9 --fpu=VFPv3 --apcs=/softfp
  </code></pre>
  
  <p>I've read through the ARM documentation, a lot of wiki(<a href="http://pandorawiki.org/Floating_Point_Optimization" rel="noreferrer">like this one</a>), forum and blog posts and everybody seems to agree that using NEON is better than using VFP
  or at least mixing NEON(e.g. using the instrinsics to implement some algos in SIMD) and VFP is not such a good idea; I'm not 100% sure yet if this applies in the context of the entire application\library or just to specific places(functions) in code.</p>
  
  <p>So I'm using neon as the FPU for my application as I also want to use the intrinsics. As a result I'm in a little bit of trouble and my confusion on how to best use these features(NEON vs VFP) on the Cortex A9 just deepens further instead of clearing up. I have some code that does benchmarking for my app and uses some custom made timer classes
  in which calculations are based on double precision floating point. Using NEON as the FPU gives completely inappropriate results(trying to print those values results in printing mostly inf and NaN; the same code works without a hitch when built for x86). So I changed my calculations to use single precision floating point as <strong>is documented that NEON does not handle double precision floating point</strong>. My benchmarks still don't give the proper results(and what's worst is that now it does not work anymore on x86; I think it's because of the lost in precision but I'm not sure). So I'm almost completely lost: on one hand I want to use NEON for the SIMD capabilities and using it as the FPU does not provide the proper results, on the other hand mixing it with the VFP does not seem a very good idea.
  Any advice in this area will be greatly appreciated !!</p>
  
  <p>I found in the article in the above mentioned wiki a summary of what should be done for floating point optimization in the context of NEON:</p>
  
  <p>"</p>
  
  <ul>
  <li>Only use single precision floating point</li>
  <li>Use NEON intrinsics / ASM when ever you find a bottlenecking FP function. You can do better than the compiler.</li>
  <li>Minimize Conditional Branches</li>
  <li>Enable RunFast mode</li>
  </ul>
  
  <p>For softfp:</p>
  
  <ul>
  <li>Inline floating point code (unless its very large)</li>
  <li>Pass FP arguments via pointers instead of by value and do integer work in between function calls.</li>
  </ul>
  
  <p>"</p>
  
  <p>I cannot use hard for the float ABI as I cannot link with the libraries I have available.
  Most of the reccomendations make sense to me(except the "runfast mode" which I don't understand exactly what's supposed to do and the fact that at this moment in time I could do better than the compiler) but I keep getting inconsistent results and I'm not sure of anything right now.</p>
  
  <p>Could anyone shed some light on how to properly use the floating point and the NEON for the Cortex A9/A8 and which compilation flags should I use?</p>