This forum has been archived. All content is frozen. Please use KDE Discuss instead.

approximate math

Tags: None
(comma "," separated)
lplagne
Registered Member
Posts
11
Karma
0

approximate math

Wed Jun 01, 2016 9:55 am
Hi,

Is it possible to use approximate division or sqrt for EIgen vector elements ?

Thanx

Laurent
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: approximate math

Thu Jun 02, 2016 2:42 pm
for division, yes if you compile with -ffast-math, but that's the compiler which is doing the job (tested with gccc and clang):

For a1 = a1/a2, Eigen calls _mm_div_ps(a1,a2) and the compiler generates:
Code: Select all
   movaps   (%rsi), %xmm1
   rcpps   %xmm1, %xmm0
   mulps   %xmm0, %xmm1
   mulps   %xmm0, %xmm1
   addps   %xmm0, %xmm0
   subps   %xmm1, %xmm0
   mulps   (%rdi), %xmm0
   movaps   %xmm0, (%rdi)


For a1 = a2.sqrt(), by default Eigen already generates fast code (unless you define EIGEN_FAST_MATH=0)

Code: Select all
   movaps   (%rsi), %xmm1
   movaps   LC1(%rip), %xmm3
   rsqrtps   %xmm1, %xmm2
   movaps   LC0(%rip), %xmm0
   mulps   %xmm1, %xmm3
   cmpleps   %xmm1, %xmm0
   andps   %xmm2, %xmm0
   mulps   %xmm0, %xmm3
   movaps   LC2(%rip), %xmm2
   mulps   %xmm0, %xmm3
   mulps   %xmm1, %xmm0
   subps   %xmm3, %xmm2
   mulps   %xmm2, %xmm0
   movaps   %xmm0, (%rdi)
lplagne
Registered Member
Posts
11
Karma
0

Re: approximate math

Sat Jun 04, 2016 1:33 pm
Thank you very much for this detailed answer.
I wonder about the interest of having a separate .fast_div() method in order to control precisely where you want approximate math and where you want to maintain IEEE compliant operations...
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: approximate math

Mon Jun 06, 2016 11:17 am
yes, adding fast* methods (fastRSqrt, fastSqrt, fastCos, fastSin, etc.) is an easy way to go, but it does not scale well and clutter the API. This question should be addressed on a more general level. Perhaps, we could take inspiration from boost::math's policies: http://www.boost.org/doc/libs/1_60_0/li ... orial.html

This is also related to bug http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1159.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]