I have profiled my program and it spends 20% of the CPU time basically evaluating the following expression:
abs(x) > abs(y)
where x,y are double-precision floating point variables.
Is there a way to refactor the expression to a faster variant?
The following line (called in two different places) takes close to 10% CPU time at each line:
(This is a snippet from the function Image_3::TestGradientAtPoint)
if (abs(maxx[ch]) < abs(a)) maxx[ch] = a;
01187AC9 mov eax,dword ptr [ch]
01187ACC sub esp,8
01187ACF fld qword ptr [ebp+eax*8-68h]
01187AD3 fstp qword ptr [esp]
01187AD6 call abs (11305F9h)
01187ADB fld qword ptr [ebp-70h]
01187ADE fstp qword ptr [esp]
01187AE1 fstp qword ptr [ebp-0F8h]
01187AE7 call abs (11305F9h)
01187AEC add esp,8
01187AEF fcomp qword ptr [ebp-0F8h]
01187AF5 fnstsw ax
01187AF7 test ah,41h
01187AFA jne Image_3::TestGradientAtPoint+176h (1187B06h)
01187AFC mov eax,dword ptr [ch]
01187AFF fld qword ptr [ebp-70h]
01187B02 fstp qword ptr [ebp+eax*8-68h]
The profiler has stated that the call to abs() has taken 20% CPU time. I am calling the method on the order of 10^8 iterations - I am working with large images.
Edit
I forgot to say that but the code is runs in Debug mode, and I need to optimize it here a bit, because I want to still be able to use the MSVC debugger in reasonable time.