📄 nb_kernel300_ia32_3dnow.s
字号:
movl %eax,nb300nf_ninner(%esp)_nb_kernel300nf_ia32_3dnow.nb300nf_threadloop: movl nb300nf_count(%ebp),%esi ## pointer to sync counter movl (%esi),%eax_nb_kernel300nf_ia32_3dnow.nb300nf_spinlock: movl %eax,%ebx ## ebx=*count=nn0 addl $1,%ebx ## ebx=nn1=nn0+10 lock cmpxchgl %ebx,(%esi) ## write nn1 to *counter, ## if it hasnt changed. ## or reread *counter to eax. pause ## -> better p4 performance jnz _nb_kernel300nf_ia32_3dnow.nb300nf_spinlock ## if(nn1>nri) nn1=nri movl nb300nf_nri(%esp),%ecx movl %ecx,%edx subl %ebx,%ecx cmovlel %edx,%ebx ## if(nn1>nri) nn1=nri ## Cleared the spinlock if we got here. ## eax contains nn0, ebx contains nn1. movl %eax,nb300nf_n(%esp) movl %ebx,nb300nf_nn1(%esp) subl %eax,%ebx ## calc number of outer lists movl %eax,%esi ## copy n to esi jg _nb_kernel300nf_ia32_3dnow.nb300nf_outerstart jmp _nb_kernel300nf_ia32_3dnow.nb300nf_end_nb_kernel300nf_ia32_3dnow.nb300nf_outerstart: ## ebx contains number of outer iterations addl nb300nf_nouter(%esp),%ebx movl %ebx,nb300nf_nouter(%esp)_nb_kernel300nf_ia32_3dnow.nb300nf_outer: movl nb300nf_shift(%ebp),%eax ## eax = pointer into shift[] movl (%eax,%esi,4),%ebx ## ebx=shift[n] leal (%ebx,%ebx,2),%ebx ## ebx=3*is movl %ebx,nb300nf_is3(%esp) ## store is3 movl nb300nf_shiftvec(%ebp),%eax ## eax = base of shiftvec[] movq (%eax,%ebx,4),%mm0 ## move shX/shY to mm0 and shZ to mm1 movd 8(%eax,%ebx,4),%mm1 movl nb300nf_iinr(%ebp),%ecx ## ecx = pointer into iinr[] movl (%ecx,%esi,4),%ebx ## ebx=ii movl nb300nf_charge(%ebp),%edx movd (%edx,%ebx,4),%mm2 ## mm2=charge[ii] pfmul nb300nf_facel(%esp),%mm2 punpckldq %mm2,%mm2 ## spread to both halves movq %mm2,nb300nf_iq(%esp) ## iq =facel*charge[ii] leal (%ebx,%ebx,2),%ebx ## ebx = 3*ii=ii3 movl nb300nf_pos(%ebp),%eax ## eax = base of pos[] pfadd (%eax,%ebx,4),%mm0 ## ix = shX + posX (and iy too) movd 8(%eax,%ebx,4),%mm3 ## cant use direct memory add for 4 bytes (iz) movl %ebx,nb300nf_ii3(%esp) pfadd %mm3,%mm1 movq %mm0,nb300nf_ix(%esp) movd %mm1,nb300nf_iz(%esp) ## clear total potential and i forces pxor %mm7,%mm7 movq %mm7,nb300nf_vctot(%esp) movl nb300nf_jindex(%ebp),%eax movl (%eax,%esi,4),%ecx ## jindex[n] movl 4(%eax,%esi,4),%edx ## jindex[n+1] subl %ecx,%edx ## number of innerloop atoms movl nb300nf_pos(%ebp),%esi movl nb300nf_jjnr(%ebp),%eax shll $2,%ecx addl %ecx,%eax movl %eax,nb300nf_innerjjnr(%esp) ## pointer to jjnr[nj0] movl %edx,%ecx subl $2,%edx addl nb300nf_ninner(%esp),%ecx movl %ecx,nb300nf_ninner(%esp) movl %edx,nb300nf_innerk(%esp) ## number of innerloop atoms addl $0,%edx jge _nb_kernel300nf_ia32_3dnow.nb300nf_unroll_loop jmp _nb_kernel300nf_ia32_3dnow.nb300nf_finish_inner_nb_kernel300nf_ia32_3dnow.nb300nf_unroll_loop: ## paired innerloop starts here movl nb300nf_innerjjnr(%esp),%ecx ## pointer to jjnr[k] movl (%ecx),%eax movl 4(%ecx),%ebx ## eax/ebx=jnr addl $8,nb300nf_innerjjnr(%esp) ## advance pointer (unrolled 2) prefetch 16(%ecx) ## prefetch data - trial and error says 16 is best movl nb300nf_charge(%ebp),%ecx ## base of charge[] movq nb300nf_iq(%esp),%mm5 movd (%ecx,%eax,4),%mm3 ## charge[jnr1] punpckldq (%ecx,%ebx,4),%mm3 ## move charge 2 to high part of mm3 pfmul %mm5,%mm3 ## mm3 now has qq for both particles leal (%eax,%eax,2),%eax ## replace jnr with j3 leal (%ebx,%ebx,2),%ebx movl nb300nf_pos(%ebp),%esi movq nb300nf_ix(%esp),%mm0 movd nb300nf_iz(%esp),%mm1 movq (%esi,%eax,4),%mm4 ## fetch first j coordinates movd 8(%esi,%eax,4),%mm5 pfsubr %mm0,%mm4 ## dr = ir - jr pfsubr %mm1,%mm5 pfmul %mm4,%mm4 ## square dx,dy,dz pfmul %mm5,%mm5 pfacc %mm5,%mm4 ## accumulate to get dx*dx+ dy*dy+ dz*dz pfacc %mm5,%mm4 ## first rsq in lower mm4 movq (%esi,%ebx,4),%mm6 ## fetch second j coordinates movd 8(%esi,%ebx,4),%mm7 pfsubr %mm0,%mm6 ## dr = ir - jr pfsubr %mm1,%mm7 pfmul %mm6,%mm6 ## square dx,dy,dz pfmul %mm7,%mm7 pfacc %mm7,%mm6 ## accumulate to get dx*dx+ dy*dy+ dz*dz pfacc %mm7,%mm6 ## second rsq in lower mm6 pfrsqrt %mm4,%mm0 ## lookup inverse square root seed pfrsqrt %mm6,%mm1 punpckldq %mm1,%mm0 punpckldq %mm6,%mm4 ## now 4 has rsq and 0 the seed for both pairs. movq %mm0,%mm2 ## amd 3dnow N-R iteration to get full precision. pfmul %mm0,%mm0 pfrsqit1 %mm4,%mm0 pfrcpit2 %mm2,%mm0 pfmul %mm0,%mm4 movq %mm4,%mm1 ## mm0 is invsqrt, and mm1 r. ## do potential and fscal pfmul nb300nf_tsc(%esp),%mm1 ## mm1=rt pf2iw %mm1,%mm4 movq %mm4,nb300nf_n1(%esp) pi2fd %mm4,%mm4 pfsub %mm4,%mm1 ## now mm1 is eps and mm4 is n0 movq %mm1,%mm2 pfmul %mm2,%mm2 ## mm1 is eps, mm2 is eps2 movl nb300nf_VFtab(%ebp),%edx movl nb300nf_n1(%esp),%ecx shll $2,%ecx ## coulomb table ## load all the table values we need movd (%edx,%ecx,4),%mm4 movd 4(%edx,%ecx,4),%mm5 movd 8(%edx,%ecx,4),%mm6 movd 12(%edx,%ecx,4),%mm7 movl nb300nf_n1+4(%esp),%ecx shll $2,%ecx punpckldq (%edx,%ecx,4),%mm4 punpckldq 4(%edx,%ecx,4),%mm5 punpckldq 8(%edx,%ecx,4),%mm6 punpckldq 12(%edx,%ecx,4),%mm7 pfmul %mm1,%mm6 ## mm6 = Geps pfmul %mm2,%mm7 ## mm7 = Heps2 pfadd %mm6,%mm5 pfadd %mm7,%mm5 ## mm5 = Fp pfmul %mm1,%mm5 ## mm5=eps*Fp pfadd %mm4,%mm5 ## mm5= VV pfmul %mm3,%mm5 ## vcoul=qq*VV ## at this point mm5 contains vcoul ## increment vcoul - then we can get rid of mm5. ## update vctot pfadd nb300nf_vctot(%esp),%mm5 ## add the earlier value movq %mm5,nb300nf_vctot(%esp) ## store the sum ## should we do one more iteration? subl $2,nb300nf_innerk(%esp) jl _nb_kernel300nf_ia32_3dnow.nb300nf_finish_inner jmp _nb_kernel300nf_ia32_3dnow.nb300nf_unroll_loop_nb_kernel300nf_ia32_3dnow.nb300nf_finish_inner: andl $1,nb300nf_innerk(%esp) jnz _nb_kernel300nf_ia32_3dnow.nb300nf_single_inner jmp _nb_kernel300nf_ia32_3dnow.nb300nf_updateouterdata_nb_kernel300nf_ia32_3dnow.nb300nf_single_inner: ## a single j particle iteration here - compare with the unrolled code for comments. movl nb300nf_innerjjnr(%esp),%eax movl (%eax),%eax ## eax=jnr offset movl nb300nf_charge(%ebp),%ecx movd nb300nf_iq(%esp),%mm5 movd (%ecx,%eax,4),%mm3 pfmul %mm5,%mm3 ## mm3=qq movl nb300nf_pos(%ebp),%esi leal (%eax,%eax,2),%eax movq nb300nf_ix(%esp),%mm0 movd nb300nf_iz(%esp),%mm1 movq (%esi,%eax,4),%mm4 movd 8(%esi,%eax,4),%mm5 pfsubr %mm0,%mm4 pfsubr %mm1,%mm5 pfmul %mm4,%mm4 pfmul %mm5,%mm5 pfacc %mm5,%mm4 pfacc %mm5,%mm4 ## mm0=rsq pfrsqrt %mm4,%mm0 movq %mm0,%mm2 pfmul %mm0,%mm0 pfrsqit1 %mm4,%mm0 pfrcpit2 %mm2,%mm0 ## mm1=invsqrt pfmul %mm0,%mm4 movq %mm4,%mm1 ## mm0 is invsqrt, and mm1 r. ## calculate potentials and scalar force pfmul nb300nf_tsc(%esp),%mm1 ## mm1=rt pf2iw %mm1,%mm4 movd %mm4,nb300nf_n1(%esp) pi2fd %mm4,%mm4 pfsub %mm4,%mm1 ## now mm1 is eps and mm4 is n0 movq %mm1,%mm2 pfmul %mm2,%mm2 ## mm1 is eps, mm2 is eps2 ## coulomb table movl nb300nf_VFtab(%ebp),%edx movl nb300nf_n1(%esp),%ecx shll $2,%ecx ## load all the table values we need movd (%edx,%ecx,4),%mm4 movd 4(%edx,%ecx,4),%mm5 movd 8(%edx,%ecx,4),%mm6 movd 12(%edx,%ecx,4),%mm7 pfmul %mm1,%mm6 ## mm6 = Geps pfmul %mm2,%mm7 ## mm7 = Heps2 pfadd %mm6,%mm5 pfadd %mm7,%mm5 ## mm5 = Fp pfmul %mm1,%mm5 ## mm5=eps*Fp pfadd %mm4,%mm5 ## mm5= VV pfmul %mm3,%mm5 ## vcoul=qq*VV ## at this point mm5 contains vcoul ## increment vcoul - then we can get rid of mm5 ## update vctot pfadd nb300nf_vctot(%esp),%mm5 ## add the earlier value movq %mm5,nb300nf_vctot(%esp) ## store the sum _nb_kernel300nf_ia32_3dnow.nb300nf_updateouterdata: ## get n from stack movl nb300nf_n(%esp),%esi ## get group index for i particle movl nb300nf_gid(%ebp),%edx ## base of gid[] movl (%edx,%esi,4),%edx ## ggid=gid[n] movq nb300nf_vctot(%esp),%mm7 pfacc %mm7,%mm7 ## get and sum the two parts of total potential movl nb300nf_Vc(%ebp),%eax movd (%eax,%edx,4),%mm6 pfadd %mm7,%mm6 movd %mm6,(%eax,%edx,4) ## increment vc[gid] ## finish if last movl nb300nf_nn1(%esp),%ecx ## esi already loaded with n incl %esi subl %esi,%ecx jz _nb_kernel300nf_ia32_3dnow.nb300nf_outerend ## not last, iterate outer loop once more! movl %esi,nb300nf_n(%esp) jmp _nb_kernel300nf_ia32_3dnow.nb300nf_outer_nb_kernel300nf_ia32_3dnow.nb300nf_outerend: ## check if more outer neighborlists remain movl nb300nf_nri(%esp),%ecx ## esi already loaded with n above subl %esi,%ecx jz _nb_kernel300nf_ia32_3dnow.nb300nf_end ## non-zero, do one more workunit jmp _nb_kernel300nf_ia32_3dnow.nb300nf_threadloop_nb_kernel300nf_ia32_3dnow.nb300nf_end: femms movl nb300nf_nouter(%esp),%eax movl nb300nf_ninner(%esp),%ebx movl nb300nf_outeriter(%ebp),%ecx movl nb300nf_inneriter(%ebp),%edx movl %eax,(%ecx) movl %ebx,(%edx) addl $88,%esp popl %edi popl %esi popl %edx popl %ecx popl %ebx popl %eax leave ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -