c++ - Insert an `__asm__` block to do a addition in very large numbers -


i doing program, , @ point need make efficient. using haswell microarchitecture (64bits) , 'g++'. objective made use of adc instruction, until loop ends.

//i removed every carry handlers preview, yo more simple size_t anum = ap[i], bnum = bp[i]; unsigned carry;  // carry flag set here common addtion   anum += bnum; cnum[0]= anum; carry = check_carry(anum, bnum);  (int i=1; i<n; i++){      anum  = ap[i];     bnum = bp[i];      //i want remove line , insert __asm__ block     anum += (bnum + carry);     carry = check_carry(anum, bnum);      //this block not working     __asm__(             "movq   -64(%rbp), %rcx;"             "adcq   %rdx, %rcx;"             "movq   %rsi, -88(%rbp);"     );      cnum[i] = anum; } 

is cf set only in first addition? or every time adc instruction?

i think problem on loss of cf, every time loop done. if problem how can solve it?

you use asm in gcc family of compilers:

 int src = 1;  int dst;   asm ("mov %1, %0\n\t"      "add $1, %0"      : "=r" (dst)      : "r" (src));   printf("%d\n", dst); 

that is, can refer variables, rather guessing might in memory/registers.

[edit] on subject of carries: it's not clear wanting, but: adc takes cf input , produces output. however, many other instructions muck flags, (such used compiler construct for-loop), need use instructions save/restore cf (perhaps lahf/sahf).


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 -