I've been writing some vectorized C++ code to compute the magnitude of a vector of 8-byte complex samples using AVX instructions on an Intel Xeon SandyBridge CPU. I recently noticed some minor differences between my output and that of the MKL vcAbs function. I've been able to mimic the speed of the MKL function by using the _mm256_rcp_ps() and _mm256_rsqrt_ps() functions to approximate the square root of the magnitude squared (vs. using _mm256_sqrt_ps()) but for some reason, my answers are coming out slightly different than those produced by vcAbs. For example, the hand-coded AVX might produce a magnitude value of 0.511695 and vcAbs will produce .511643 for that same sample. When running my test, I have the VML mode set to VML_EP. If I modify the code to use _mm256_sqrt_ps() instead and set the VML mode to VML_HA, I get answers that match. I'm just curious if there is more to the algorithm or something else going on inside the VML function that is affecting the answer when precision mode is VML_EP beyond just using the reciprocal approximations. I've tried re-ordering my function calls to use rcp followed by rsqrt as well as rsqrt followed by rcp but it doesn't seem to make a difference.
For reference, I am working on a CentOS 6 platform, using MKL v11.0, and compiling with Intel CompserXE 2013. I've been using the compile flags -O3, -xHost, -no-prec-div, -fp-model fast among others. Unfortunately this was all done at my office and I don't have access to my source code to post or the specific input/output values I was providing to the algorithm. Just wondering if someone can help me understand what other factors might cause a difference in the answers and what optimizations might be going on under the hood with VML_EP? I *think* the core algorithms (my rsqrt/rcp vs. VML) must be similar as the execution speed is similar on a vector of 16384 elements, looping 1e6 times.
Thanks in advance,