c - How to update all the elements in a double array in X86? -


i newbie of x86 , stuck on updating double array using values of double array. following code function , want use inline assembly replace piece of code inside loop. have attached error message below. can helps me point out errors? confused error messages , don't know how revise it.

static inline void update(double * x,double * y,double * z,double * vx,         double * vy,double * vz,uint32_t size){         (uint32_t i=0;i<size;++i){             x[i] = x[i] + vx[i];             y[i] = y[i] + vy[i];             z[i] = z[i] + vz[i];         } } uint32_t counter = 0; __asm__ __volatile__ (       "loop: \n\t"      "faddq (%4), (%1)\n\t"     "faddq (%5), (%2)\n\t"     "faddq (%6), (%3)\n\t"     "addq $8, %1\n\t"     "addq $8, %2\n\t"     "addq $8, %3\n\t"     "addq $8, %4\n\t"     "addq $8, %5\n\t"     "addq $8, %6\n\t"     "incq %0\n\t"     "cmp %0, %7\n\t"     "jne loopb"     : "+r"(counter)     : "r" (x),"r" (y),"r"(z),"r"(vx),"r"(vy),"r"(vz),"r"(size)      : "memory", "cc"); 

error messages:

update_locations_ass.c:150:15: error: invalid instruction mnemonic 'faddq'         "loop: \n\t"                   ^ <inline asm>:2:2: note: instantiated assembly here         faddq (%rdi), (%rcx)         ^~~~~ update_locations_ass.c:151:25: error: invalid instruction mnemonic 'faddq'         "faddq (%4), (%1)\n\t"                            ^ <inline asm>:3:2: note: instantiated assembly here         faddq (%r8), (%rdx)         ^~~~~ update_locations_ass.c:152:28: error: invalid instruction mnemonic 'faddq'         "faddq (%5), (%2)\n\t"                            ^ <inline asm>:4:2: note: instantiated assembly here         faddq (%r9), (%rsi)         ^~~~~ update_locations_ass.c:159:23: error: invalid operand instruction         "addq $8, %6\n\t"                       ^ <inline asm>:11:7: note: instantiated assembly here         incq %eax 

compiler version: configured with: --prefix=/applications/xcode.app/contents/developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 apple llvm version 6.1.0 (clang-602.0.53) (based on llvm 3.6.0svn) target: x86_64-apple-darwin14.0.0 thread model: posix

i'm equally confused here. faddq, , did from? supposed fadd? can't use 2 memory operands fadd anyway, code looks incorrect. if you're curious correct way it, try compiling -s , -o2 can @ optimized compiler output.

if want faster version of function, easiest in c anyway. assuming arrays don't overlap, here faster version:

// assuming x , vx not overlap void update1(double *restrict x, const double *restrict vx, unsigned count) {     (unsigned = 0; < count; i++) {         x[i] += vx[i];     } }  void update(/* ... */) {     update1(x, vx, count);     update1(y, vy, count);     update1(z, vz, count); } 

if compile -o3, compiler generate code uses addpd, depending on compilation target. going miles better write using x87 fpu instructions.

these simple functions--just adding arrays other arrays--are easy compiler optimize, unless teaching assembly language, let compiler you.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -