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

how to enable vectorization for dot product?

Tags: None
(comma "," separated)
jpritikin
Registered Member
Posts
4
Karma
0
I read the FAQ, but it's still not working. Here's my trivial program:

Code: Select all
#include<Eigen/Core>
using namespace Eigen;
void foo(VectorXd foo, VectorXd bar)
{
   double ll=0;
  EIGEN_ASM_COMMENT("begin");
  ll += foo.transpose() * bar;
  EIGEN_ASM_COMMENT("end");
}


Here's how I compile it:

Code: Select all
g++  -I"/opt/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/opt/R/x86_64-pc-linux-gnu-library/3.3/RcppEigen/include" foo.cpp -O2 -c -S -o myprogram.s


Here's part of the asm output:

Code: Select all
   .cfi_startproc
#APP
# 8 "foo.cpp" 1
   #begin
# 0 "" 2
#NO_APP
   movq   8(%rsi), %rax
   cmpq   %rax, 8(%rdi)
   jne   .L5
#APP
# 10 "foo.cpp" 1
   #end
# 0 "" 2
#NO_APP
   ret
.L5:
   pushq   %rax
   .cfi_def_cfa_offset 16
   movl   $_ZZN5Eigen13CwiseBinaryOpINS_8internal17scalar_product_opIddEEKNS_9TransposeIKNS4_INS_6MatrixIdLin1ELi1ELi0ELin1ELi1EEEEEEEKS6_EC4ERSA_RSB_RKS3_E19__PRETTY_FUNCTION__, %ecx
   movl   $132, %edx
   movl   $.LC0, %esi
   movl   $.LC1, %edi
   call   __assert_fail
   .cfi_endproc


If I use the trivial code from the FAQ then it seems to work:

Code: Select all
#include<Eigen/Core>
using namespace Eigen;
void foo(Vector4f& u, Vector4f& v, Vector4f& w)
{
  EIGEN_ASM_COMMENT("begin");
  u = v + 3*w;
  EIGEN_ASM_COMMENT("end");
}


Compiles to:

Code: Select all
   movaps   .LC0(%rip), %xmm0
   mulps   (%rdx), %xmm0
   addps   (%rsi), %xmm0
   movaps   %xmm0, (%rdi)


This looks good, right? What am I doing wrong with my dot product?

Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
it has been optimized away by the compiler because "ll" is not used. To get something meaningful, add "return ll;"


Bookmarks



Who is online

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