nb_kernel300_x86_64_sse.s
来自「最著名最快的分子模拟软件」· S 代码 · 共 1,442 行 · 第 1/3 页
S
1,442 行
movaps %xmm4,%xmm9 movaps %xmm5,%xmm10 movaps %xmm6,%xmm11 ## square it mulps %xmm4,%xmm4 mulps %xmm5,%xmm5 mulps %xmm6,%xmm6 addps %xmm5,%xmm4 addps %xmm6,%xmm4 ## rsq in xmm4 ## calculate rinv=1/sqrt(rsq) rsqrtps %xmm4,%xmm5 movaps %xmm5,%xmm2 mulps %xmm5,%xmm5 movaps nb300_three(%rsp),%xmm1 mulps %xmm4,%xmm5 ## rsq*lu*lu subps %xmm5,%xmm1 ## 30-rsq*lu*lu mulps %xmm2,%xmm1 mulps nb300_half(%rsp),%xmm1 ## xmm1=rinv movaps %xmm4,%xmm3 ## xmm3=rsq mulps %xmm1,%xmm3 ## r mulps nb300_tsc(%rsp),%xmm3 ## rtab ## truncate and convert to integers cvttps2dq %xmm3,%xmm2 ## convert back to float cvtdq2ps %xmm2,%xmm0 ## multiply by 4 pslld $2,%xmm2 ## move to integer registers movd %xmm2,%r12d pshufd $1,%xmm2,%xmm2 movd %xmm2,%r13d ## calculate eps subps %xmm0,%xmm3 movq nb300_VFtab(%rbp),%rsi ## load table data movlps (%rsi,%r12,4),%xmm4 movlps (%rsi,%r13,4),%xmm5 unpcklps %xmm5,%xmm4 movhlps %xmm4,%xmm5 movlps 8(%rsi,%r12,4),%xmm6 movlps 8(%rsi,%r13,4),%xmm7 unpcklps %xmm7,%xmm6 movhlps %xmm6,%xmm7 ## table data ready in xmm4-xmm7 mulps %xmm3,%xmm7 ## Heps mulps %xmm3,%xmm6 ## Geps mulps %xmm3,%xmm7 ## Heps2 addps %xmm6,%xmm5 ## F+Geps addps %xmm7,%xmm5 ## F+Geps+Heps2 = Fp addps %xmm7,%xmm7 ## 2*Heps2 addps %xmm6,%xmm7 ## 2*Heps2+Geps addps %xmm5,%xmm7 ## FF = Fp + 2*Heps2 + Geps mulps %xmm3,%xmm5 ## eps*Fp addps %xmm4,%xmm5 ## VV mulps %xmm8,%xmm5 ## VV*qq=vcoul mulps %xmm8,%xmm7 ## FF*qq=fijC xorps %xmm6,%xmm6 movlhps %xmm6,%xmm5 ## add potential to vctot (sum in xmm12) addps %xmm5,%xmm12 mulps nb300_tsc(%rsp),%xmm7 mulps %xmm1,%xmm7 xorps %xmm4,%xmm4 subps %xmm7,%xmm4 ## fscal ## calculate scalar force by multiplying dx/dy/dz with fscal mulps %xmm4,%xmm9 mulps %xmm4,%xmm10 mulps %xmm4,%xmm11 movlhps %xmm6,%xmm9 movlhps %xmm6,%xmm10 movlhps %xmm6,%xmm11 ## accumulate i forces addps %xmm9,%xmm13 addps %xmm10,%xmm14 addps %xmm11,%xmm15 movq nb300_faction(%rbp),%rsi ## the fj's - start by accumulating x & y forces from memory movlps (%rsi,%rax,4),%xmm0 ## x1 y1 - - movhps (%rsi,%rbx,4),%xmm0 ## x1 y1 x2 y2 unpcklps %xmm10,%xmm9 ## x1 y1 x2 y2 addps %xmm9,%xmm0 movlps %xmm0,(%rsi,%rax,4) movhps %xmm0,(%rsi,%rbx,4) ## z forces pshufd $1,%xmm11,%xmm8 addss 8(%rsi,%rax,4),%xmm11 addss 8(%rsi,%rbx,4),%xmm8 movss %xmm11,8(%rsi,%rax,4) movss %xmm8,8(%rsi,%rbx,4)_nb_kernel300_x86_64_sse.nb300_checksingle: movl nb300_innerk(%rsp),%edx andl $1,%edx jnz _nb_kernel300_x86_64_sse.nb300_dosingle jmp _nb_kernel300_x86_64_sse.nb300_updateouterdata_nb_kernel300_x86_64_sse.nb300_dosingle: movq nb300_innerjjnr(%rsp),%rcx movl (%rcx),%eax movq nb300_charge(%rbp),%rsi movss (%rsi,%rax,4),%xmm8 ## jq mulss nb300_iq(%rsp),%xmm8 ## qq lea (%rax,%rax,2),%rax ## replace jnr with j3 movq nb300_pos(%rbp),%rdi movss (%rdi,%rax,4),%xmm4 ## x1 - - - movss 4(%rdi,%rax,4),%xmm5 ## y2 - - - movss 8(%rdi,%rax,4),%xmm6 ## 13 - - - ## calc dr subss nb300_ix(%rsp),%xmm4 subss nb300_iy(%rsp),%xmm5 subss nb300_iz(%rsp),%xmm6 ## store dr in xmm9-xmm11 movaps %xmm4,%xmm9 movaps %xmm5,%xmm10 movaps %xmm6,%xmm11 ## square it mulss %xmm4,%xmm4 mulss %xmm5,%xmm5 mulss %xmm6,%xmm6 addss %xmm5,%xmm4 addss %xmm6,%xmm4 ## rsq in xmm4 ## calculate rinv=1/sqrt(rsq) rsqrtss %xmm4,%xmm5 movaps %xmm5,%xmm2 mulss %xmm5,%xmm5 movaps nb300_three(%rsp),%xmm1 mulss %xmm4,%xmm5 ## rsq*lu*lu subss %xmm5,%xmm1 ## 30-rsq*lu*lu mulss %xmm2,%xmm1 mulss nb300_half(%rsp),%xmm1 ## xmm1=rinv movaps %xmm4,%xmm3 ## xmm3=rsq mulss %xmm1,%xmm3 ## r mulss nb300_tsc(%rsp),%xmm3 ## rtab ## truncate and convert to integers cvttss2si %xmm3,%r12d ## convert back to float cvtsi2ss %r12d,%xmm0 ## multiply by 4 shll $2,%r12d ## calculate eps subss %xmm0,%xmm3 movq nb300_VFtab(%rbp),%rsi ## load table data movss (%rsi,%r12,4),%xmm4 movss 4(%rsi,%r12,4),%xmm5 movss 8(%rsi,%r12,4),%xmm6 movss 12(%rsi,%r12,4),%xmm7 ## table data ready in xmm4-xmm7 mulss %xmm3,%xmm7 ## Heps mulss %xmm3,%xmm6 ## Geps mulss %xmm3,%xmm7 ## Heps2 addss %xmm6,%xmm5 ## F+Geps addss %xmm7,%xmm5 ## F+Geps+Heps2 = Fp addss %xmm7,%xmm7 ## 2*Heps2 addss %xmm6,%xmm7 ## 2*Heps2+Geps addss %xmm5,%xmm7 ## FF = Fp + 2*Heps2 + Geps mulss %xmm3,%xmm5 ## eps*Fp addss %xmm4,%xmm5 ## VV mulss %xmm8,%xmm5 ## VV*qq=vcoul mulss %xmm8,%xmm7 ## FF*qq=fijC ## add potential to vctot (sum in xmm12) addss %xmm5,%xmm12 mulss nb300_tsc(%rsp),%xmm7 mulss %xmm1,%xmm7 xorps %xmm4,%xmm4 subss %xmm7,%xmm4 ## fscal ## calculate scalar force by multiplying dx/dy/dz with fscal mulss %xmm4,%xmm9 mulss %xmm4,%xmm10 mulss %xmm4,%xmm11 ## accumulate i forces addss %xmm9,%xmm13 addss %xmm10,%xmm14 addss %xmm11,%xmm15 movq nb300_faction(%rbp),%rsi ## add to j forces addss (%rsi,%rax,4),%xmm9 addss 4(%rsi,%rax,4),%xmm10 addss 8(%rsi,%rax,4),%xmm11 movss %xmm9,(%rsi,%rax,4) movss %xmm10,4(%rsi,%rax,4) movss %xmm11,8(%rsi,%rax,4)_nb_kernel300_x86_64_sse.nb300_updateouterdata: movl nb300_ii3(%rsp),%ecx movq nb300_faction(%rbp),%rdi movq nb300_fshift(%rbp),%rsi movl nb300_is3(%rsp),%edx ## accumulate i forces in xmm13, xmm14, xmm15 movhlps %xmm13,%xmm0 movhlps %xmm14,%xmm1 movhlps %xmm15,%xmm2 addps %xmm13,%xmm0 addps %xmm14,%xmm1 addps %xmm15,%xmm2 movaps %xmm0,%xmm3 movaps %xmm1,%xmm4 movaps %xmm2,%xmm5 shufps $1,%xmm3,%xmm3 shufps $1,%xmm4,%xmm4 shufps $1,%xmm5,%xmm5 addss %xmm3,%xmm0 addss %xmm4,%xmm1 addss %xmm5,%xmm2 ## xmm0-xmm2 has single force in pos0 ## increment i force movss (%rdi,%rcx,4),%xmm3 movss 4(%rdi,%rcx,4),%xmm4 movss 8(%rdi,%rcx,4),%xmm5 subss %xmm0,%xmm3 subss %xmm1,%xmm4 subss %xmm2,%xmm5 movss %xmm3,(%rdi,%rcx,4) movss %xmm4,4(%rdi,%rcx,4) movss %xmm5,8(%rdi,%rcx,4) ## increment fshift force movss (%rsi,%rdx,4),%xmm3 movss 4(%rsi,%rdx,4),%xmm4 movss 8(%rsi,%rdx,4),%xmm5 subss %xmm0,%xmm3 subss %xmm1,%xmm4 subss %xmm2,%xmm5 movss %xmm3,(%rsi,%rdx,4) movss %xmm4,4(%rsi,%rdx,4) movss %xmm5,8(%rsi,%rdx,4) ## get n from stack movl nb300_n(%rsp),%esi ## get group index for i particle movq nb300_gid(%rbp),%rdx ## base of gid[] movl (%rdx,%rsi,4),%edx ## ggid=gid[n] ## accumulate total potential energy and update it ## accumulate movhlps %xmm12,%xmm6 addps %xmm6,%xmm12 ## pos 0-1 in xmm12 have the sum now movaps %xmm12,%xmm6 shufps $1,%xmm6,%xmm6 addss %xmm6,%xmm12 ## add earlier value from mem movq nb300_Vc(%rbp),%rax addss (%rax,%rdx,4),%xmm12 ## move back to mem movss %xmm12,(%rax,%rdx,4) ## finish if last movl nb300_nn1(%rsp),%ecx ## esi already loaded with n incl %esi subl %esi,%ecx jz _nb_kernel300_x86_64_sse.nb300_outerend ## not last, iterate outer loop once more! movl %esi,nb300_n(%rsp) jmp _nb_kernel300_x86_64_sse.nb300_outer_nb_kernel300_x86_64_sse.nb300_outerend: ## check if more outer neighborlists remain movl nb300_nri(%rsp),%ecx ## esi already loaded with n above subl %esi,%ecx jz _nb_kernel300_x86_64_sse.nb300_end ## non-zero, do one more workunit jmp _nb_kernel300_x86_64_sse.nb300_threadloop_nb_kernel300_x86_64_sse.nb300_end: movl nb300_nouter(%rsp),%eax movl nb300_ninner(%rsp),%ebx movq nb300_outeriter(%rbp),%rcx movq nb300_inneriter(%rbp),%rdx movl %eax,(%rcx) movl %ebx,(%rdx) addq $376,%rsp emms pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret.globl nb_kernel300nf_x86_64_sse.globl _nb_kernel300nf_x86_64_ssenb_kernel300nf_x86_64_sse: _nb_kernel300nf_x86_64_sse: ## Room for return address and rbp (16 bytes).set nb300nf_fshift, 16.set nb300nf_gid, 24.set nb300nf_pos, 32.set nb300nf_faction, 40.set nb300nf_charge, 48.set nb300nf_p_facel, 56.set nb300nf_argkrf, 64.set nb300nf_argcrf, 72.set nb300nf_Vc, 80.set nb300nf_type, 88.set nb300nf_p_ntype, 96.set nb300nf_vdwparam, 104.set nb300nf_Vvdw, 112.set nb300nf_p_tabscale, 120.set nb300nf_VFtab, 128.set nb300nf_invsqrta, 136.set nb300nf_dvda, 144.set nb300nf_p_gbtabscale, 152.set nb300nf_GBtab, 160.set nb300nf_p_nthreads, 168.set nb300nf_count, 176.set nb300nf_mtx, 184.set nb300nf_outeriter, 192.set nb300nf_inneriter, 200.set nb300nf_work, 208 ## bottom of stack is cache-aligned for sse use .set nb300nf_ix, 0.set nb300nf_iy, 16.set nb300nf_iz, 32.set nb300nf_iq, 48.set nb300nf_tsc, 64.set nb300nf_qq, 80.set nb300nf_vctot, 96.set nb300nf_half, 112.set nb300nf_three, 128.set nb300nf_is3, 144.set nb300nf_ii3, 148.set nb300nf_innerjjnr, 152.set nb300nf_nri, 160.set nb300nf_iinr, 168.set nb300nf_jindex, 176.set nb300nf_jjnr, 184.set nb300nf_shift, 192.set nb300nf_shiftvec, 200.set nb300nf_facel, 208.set nb300nf_innerk, 216.set nb300nf_n, 220.set nb300nf_nn1, 224.set nb300nf_nouter, 228.set nb300nf_ninner, 232 push %rbp movq %rsp,%rbp push %rbx emms push %r12 push %r13 push %r14 push %r15 subq $248,%rsp ## local variable stack space (n*16+8) ## zero 32-bit iteration counters movl $0,%eax movl %eax,nb300nf_nouter(%rsp) movl %eax,nb300nf_ninner(%rsp) movl (%rdi),%edi movl %edi,nb300nf_nri(%rsp) movq %rsi,nb300nf_iinr(%rsp) movq %rdx,nb300nf_jindex(%rsp) movq %rcx,nb300nf_jjnr(%rsp) movq %r8,nb300nf_shift(%rsp) movq %r9,nb300nf_shiftvec(%rsp) movq nb300nf_p_facel(%rbp),%rsi movss (%rsi),%xmm0 movss %xmm0,nb300nf_facel(%rsp) movq nb300nf_p_tabscale(%rbp),%rax movss (%rax),%xmm3 shufps $0,%xmm3,%xmm3 movaps %xmm3,nb300nf_tsc(%rsp) ## create constant floating-point factors on stack movl $0x3f000000,%eax ## half in IEEE (hex) movl %eax,nb300nf_half(%rsp) movss nb300nf_half(%rsp),%xmm1 shufps $0,%xmm1,%xmm1 ## splat to all elements movaps %xmm1,%xmm2 addps %xmm2,%xmm2 ## one movaps %xmm2,%xmm3 addps %xmm2,%xmm2 ## two addps %xmm2,%xmm3 ## three movaps %xmm1,nb300nf_half(%rsp) movaps %xmm3,nb300nf_three(%rsp)_nb_kernel300nf_x86_64_sse.nb300nf_threadloop: movq nb300nf_count(%rbp),%rsi ## pointer to sync counter movl (%rsi),%eax_nb_kernel300nf_x86_64_sse.nb300nf_spinlock: movl %eax,%ebx ## ebx=*count=nn0 addl $1,%ebx ## ebx=nn1=nn0+10 lock cmpxchgl %ebx,(%rsi) ## write nn1 to *counter, ## if it hasnt changed. ## or reread *counter to eax. pause ## -> better p4 performance jnz _nb_kernel300nf_x86_64_sse.nb300nf_spinlock ## if(nn1>nri) nn1=nri movl nb300nf_nri(%rsp),%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(%rsp) movl %ebx,nb300nf_nn1(%rsp) subl %eax,%ebx ## calc number of outer lists movl %eax,%esi ## copy n to esi jg _nb_kernel300nf_x86_64_sse.nb300nf_outerstart jmp _nb_kernel300nf_x86_64_sse.nb300nf_end_nb_kernel300nf_x86_64_sse.nb300nf_outerstart: ## ebx contains number of outer iterations addl nb300nf_nouter(%rsp),%ebx movl %ebx,nb300nf_nouter(%rsp)_nb_kernel300nf_x86_64_sse.nb300nf_outer: movq nb300nf_shift(%rsp),%rax ## rax = pointer into shift[] movl (%rax,%rsi,4),%ebx ## ebx=shift[n] lea (%rbx,%rbx,2),%rbx ## rbx=3*is
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?