nb_kernel210_x86_64_sse.s
来自「最著名最快的分子模拟软件」· S 代码 · 共 1,526 行 · 第 1/3 页
S
1,526 行
movlps (%rdi,%rax,4),%xmm1 ## x1 y1 - - movlps (%rdi,%rbx,4),%xmm2 ## x2 y2 - - movss 8(%rdi,%rax,4),%xmm5 ## z1 - - - movss 8(%rdi,%rbx,4),%xmm6 ## z2 - - - unpcklps %xmm2,%xmm1 ## x1 x2 y1 y2 movhlps %xmm1,%xmm2 ## y1 y2 - - unpcklps %xmm6,%xmm5 ## z1 z2 - - ## calc dr subps nb210_ix(%rsp),%xmm1 subps nb210_iy(%rsp),%xmm2 subps nb210_iz(%rsp),%xmm5 ## store dr in xmm9-xmm11 movaps %xmm1,%xmm9 movaps %xmm2,%xmm10 movaps %xmm5,%xmm11 ## square it mulps %xmm1,%xmm1 mulps %xmm2,%xmm2 mulps %xmm5,%xmm5 addps %xmm2,%xmm1 addps %xmm5,%xmm1 ## rsq in xmm1 movaps nb210_krf(%rsp),%xmm7 mulps %xmm1,%xmm7 ## krsq ## calculate rinv=1/sqrt(rsq) rsqrtps %xmm1,%xmm5 movaps %xmm5,%xmm6 mulps %xmm5,%xmm5 movaps nb210_three(%rsp),%xmm4 mulps %xmm1,%xmm5 ## rsq*lu*lu subps %xmm5,%xmm4 ## 30-rsq*lu*lu mulps %xmm6,%xmm4 mulps nb210_half(%rsp),%xmm4 movaps %xmm4,%xmm1 mulps %xmm4,%xmm4 ## xmm1=rinv ## xmm4=rinvsq movaps %xmm1,%xmm3 subps %xmm7,%xmm1 subps %xmm7,%xmm1 ## rinv-2*krsq addps %xmm7,%xmm3 ## rinv+krsq subps nb210_crf(%rsp),%xmm3 ## rinv+krsq-crf mulps %xmm12,%xmm3 ## vcoul=qq*(rinv+krsq-crf) mulps %xmm12,%xmm1 ## fijC movaps %xmm4,%xmm5 mulps %xmm4,%xmm5 ## rinv4 mulps %xmm4,%xmm5 ## rinv6 movaps %xmm5,%xmm6 mulps %xmm5,%xmm5 ## xmm5=rinv12 ## add to vctot addps nb210_vctot(%rsp),%xmm3 movlps %xmm3,nb210_vctot(%rsp) mulps nb210_c6(%rsp),%xmm6 ## vvdw6=c6*rinv6 mulps nb210_c12(%rsp),%xmm5 ## vvdw12=c12*rinv12 movaps %xmm5,%xmm7 subps %xmm6,%xmm5 ## Vvdw=Vvdw12-Vvdw6 mulps nb210_six(%rsp),%xmm6 mulps nb210_twelve(%rsp),%xmm7 subps %xmm6,%xmm7 addps %xmm7,%xmm1 mulps %xmm1,%xmm4 ## xmm4=total fscal xorps %xmm7,%xmm7 movlhps %xmm7,%xmm5 ## add potential to Vvdwtot addps nb210_Vvdwtot(%rsp),%xmm5 movaps %xmm5,nb210_Vvdwtot(%rsp) ## calculate scalar force by multiplying dx/dy/dz with fscal mulps %xmm4,%xmm9 mulps %xmm4,%xmm10 mulps %xmm4,%xmm11 movlhps %xmm7,%xmm9 movlhps %xmm7,%xmm10 movlhps %xmm7,%xmm11 ## accumulate i forces addps %xmm9,%xmm13 addps %xmm10,%xmm14 addps %xmm11,%xmm15 movq nb210_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_kernel210_x86_64_sse.nb210_checksingle: movl nb210_innerk(%rsp),%edx andl $1,%edx jnz _nb_kernel210_x86_64_sse.nb210_dosingle jmp _nb_kernel210_x86_64_sse.nb210_updateouterdata_nb_kernel210_x86_64_sse.nb210_dosingle: movq nb210_innerjjnr(%rsp),%rcx movl (%rcx),%eax movq nb210_charge(%rbp),%rsi movss (%rsi,%rax,4),%xmm12 mulss nb210_iq(%rsp),%xmm12 ## qq movq nb210_type(%rbp),%rsi movl (%rsi,%rax,4),%r12d shll %r12d movl nb210_ntia(%rsp),%edi addl %edi,%r12d movq nb210_vdwparam(%rbp),%rsi movss (%rsi,%r12,4),%xmm0 movss 4(%rsi,%r12,4),%xmm3 movaps %xmm0,nb210_c6(%rsp) movaps %xmm3,nb210_c12(%rsp) lea (%rax,%rax,2),%rax ## replace jnr with j3 movq nb210_pos(%rbp),%rdi ## load coordinates movss (%rdi,%rax,4),%xmm1 ## x1 - - - movss 4(%rdi,%rax,4),%xmm2 ## y2 - - - movss 8(%rdi,%rax,4),%xmm5 ## 13 - - - ## calc dr subss nb210_ix(%rsp),%xmm1 subss nb210_iy(%rsp),%xmm2 subss nb210_iz(%rsp),%xmm5 ## store dr in xmm9-xmm11 movaps %xmm1,%xmm9 movaps %xmm2,%xmm10 movaps %xmm5,%xmm11 ## square it mulss %xmm1,%xmm1 mulss %xmm2,%xmm2 mulss %xmm5,%xmm5 addss %xmm2,%xmm1 addss %xmm5,%xmm1 ## rsq in xmm1 movaps nb210_krf(%rsp),%xmm7 mulss %xmm1,%xmm7 ## krsq ## calculate rinv=1/sqrt(rsq) rsqrtss %xmm1,%xmm5 movaps %xmm5,%xmm6 mulss %xmm5,%xmm5 movaps nb210_three(%rsp),%xmm4 mulss %xmm1,%xmm5 ## rsq*lu*lu subss %xmm5,%xmm4 ## 30-rsq*lu*lu mulss %xmm6,%xmm4 mulss nb210_half(%rsp),%xmm4 movaps %xmm4,%xmm1 mulss %xmm4,%xmm4 ## xmm1=rinv ## xmm4=rinvsq movaps %xmm1,%xmm3 subss %xmm7,%xmm1 subss %xmm7,%xmm1 ## rinv-2*krsq addss %xmm7,%xmm3 ## rinv+krsq subss nb210_crf(%rsp),%xmm3 ## rinv+krsq-crf mulss %xmm12,%xmm3 ## vcoul=qq*(rinv+krsq-crf) mulss %xmm12,%xmm1 ## fijC movaps %xmm4,%xmm5 mulss %xmm4,%xmm5 ## rinv4 mulss %xmm4,%xmm5 ## rinv6 movaps %xmm5,%xmm6 mulss %xmm5,%xmm5 ## xmm5=rinv12 ## add to vctot addss nb210_vctot(%rsp),%xmm3 movss %xmm3,nb210_vctot(%rsp) mulss nb210_c6(%rsp),%xmm6 ## vvdw6=c6*rinv6 mulss nb210_c12(%rsp),%xmm5 ## vvdw12=c12*rinv12 movaps %xmm5,%xmm7 subss %xmm6,%xmm5 ## Vvdw=Vvdw12-Vvdw6 mulss nb210_six(%rsp),%xmm6 mulss nb210_twelve(%rsp),%xmm7 subss %xmm6,%xmm7 addss %xmm7,%xmm1 mulss %xmm1,%xmm4 ## xmm4=total fscal ## add potential to Vvdwtot addss nb210_Vvdwtot(%rsp),%xmm5 movss %xmm5,nb210_Vvdwtot(%rsp) ## calculate scalar force by multiplying dx/dy/dz with fscal mulss %xmm4,%xmm9 mulss %xmm4,%xmm10 mulss %xmm4,%xmm11 ## xmm0-xmm2 contains tx-tz (partial force) ## accumulate i forces addss %xmm9,%xmm13 addss %xmm10,%xmm14 addss %xmm11,%xmm15 movq nb210_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_kernel210_x86_64_sse.nb210_updateouterdata: movl nb210_ii3(%rsp),%ecx movq nb210_faction(%rbp),%rdi movq nb210_fshift(%rbp),%rsi movl nb210_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 nb210_n(%rsp),%esi ## get group index for i particle movq nb210_gid(%rbp),%rdx ## base of gid[] movl (%rdx,%rsi,4),%edx ## ggid=gid[n] ## accumulate total potential energy and update it movaps nb210_vctot(%rsp),%xmm7 ## accumulate movhlps %xmm7,%xmm6 addps %xmm6,%xmm7 ## pos 0-1 in xmm7 have the sum now movaps %xmm7,%xmm6 shufps $1,%xmm6,%xmm6 addss %xmm6,%xmm7 ## add earlier value from mem movq nb210_Vc(%rbp),%rax addss (%rax,%rdx,4),%xmm7 ## move back to mem movss %xmm7,(%rax,%rdx,4) ## accumulate total potential energy and update it movaps nb210_Vvdwtot(%rsp),%xmm12 ## 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 nb210_Vvdw(%rbp),%rax addss (%rax,%rdx,4),%xmm12 ## move back to mem movss %xmm12,(%rax,%rdx,4) ## finish if last movl nb210_nn1(%rsp),%ecx ## esi already loaded with n incl %esi subl %esi,%ecx jz _nb_kernel210_x86_64_sse.nb210_outerend ## not last, iterate outer loop once more! movl %esi,nb210_n(%rsp) jmp _nb_kernel210_x86_64_sse.nb210_outer_nb_kernel210_x86_64_sse.nb210_outerend: ## check if more outer neighborlists remain movl nb210_nri(%rsp),%ecx ## esi already loaded with n above subl %esi,%ecx jz _nb_kernel210_x86_64_sse.nb210_end ## non-zero, do one more workunit jmp _nb_kernel210_x86_64_sse.nb210_threadloop_nb_kernel210_x86_64_sse.nb210_end: movl nb210_nouter(%rsp),%eax movl nb210_ninner(%rsp),%ebx movq nb210_outeriter(%rbp),%rcx movq nb210_inneriter(%rbp),%rdx movl %eax,(%rcx) movl %ebx,(%rdx) addq $440,%rsp emms pop %r15 pop %r14 pop %r13 pop %r12 pop %rbx pop %rbp ret.globl nb_kernel210nf_x86_64_sse.globl _nb_kernel210nf_x86_64_ssenb_kernel210nf_x86_64_sse: _nb_kernel210nf_x86_64_sse: ## Room for return address and rbp (16 bytes).set nb210nf_fshift, 16.set nb210nf_gid, 24.set nb210nf_pos, 32.set nb210nf_faction, 40.set nb210nf_charge, 48.set nb210nf_p_facel, 56.set nb210nf_argkrf, 64.set nb210nf_argcrf, 72.set nb210nf_Vc, 80.set nb210nf_type, 88.set nb210nf_p_ntype, 96.set nb210nf_vdwparam, 104.set nb210nf_Vvdw, 112.set nb210nf_p_tabscale, 120.set nb210nf_VFtab, 128.set nb210nf_invsqrta, 136.set nb210nf_dvda, 144.set nb210nf_p_gbtabscale, 152.set nb210nf_GBtab, 160.set nb210nf_p_nthreads, 168.set nb210nf_count, 176.set nb210nf_mtx, 184.set nb210nf_outeriter, 192.set nb210nf_inneriter, 200.set nb210nf_work, 208 ## stack offsets for local variables ## bottom of stack is cache-aligned for sse use .set nb210nf_ix, 0.set nb210nf_iy, 16.set nb210nf_iz, 32.set nb210nf_iq, 48.set nb210nf_c6, 64.set nb210nf_c12, 80.set nb210nf_vctot, 96.set nb210nf_Vvdwtot, 112.set nb210nf_half, 128.set nb210nf_three, 144.set nb210nf_krf, 160.set nb210nf_crf, 176.set nb210nf_nri, 192.set nb210nf_iinr, 200.set nb210nf_jindex, 208.set nb210nf_jjnr, 216.set nb210nf_shift, 224.set nb210nf_shiftvec, 232.set nb210nf_facel, 240.set nb210nf_innerjjnr, 248.set nb210nf_is3, 256.set nb210nf_ii3, 260.set nb210nf_ntia, 264.set nb210nf_innerk, 268.set nb210nf_n, 272.set nb210nf_nn1, 276.set nb210nf_ntype, 280.set nb210nf_nouter, 284.set nb210nf_ninner, 288 push %rbp movq %rsp,%rbp push %rbx emms push %r12 push %r13 push %r14 push %r15 subq $312,%rsp ## local variable stack space (n*16+8) ## zero 32-bit iteration counters movl $0,%eax movl %eax,nb210nf_nouter(%rsp) movl %eax,nb210nf_ninner(%rsp) movl (%rdi),%edi movl %edi,nb210nf_nri(%rsp) movq %rsi,nb210nf_iinr(%rsp) movq %rdx,nb210nf_jindex(%rsp) movq %rcx,nb210nf_jjnr(%rsp) movq %r8,nb210nf_shift(%rsp) movq %r9,nb210nf_shiftvec(%rsp) movq nb210nf_p_ntype(%rbp),%rdi movl (%rdi),%edi movl %edi,nb210nf_ntype(%rsp) movq nb210nf_p_facel(%rbp),%rsi movss (%rsi),%xmm0 movss %xmm0,nb210nf_facel(%rsp) movq nb210nf_argkrf(%rbp),%rsi movq nb210nf_argcrf(%rbp),%rdi movss (%rsi),%xmm1 movss (%rdi),%xmm2 shufps $0,%xmm1,%xmm1 shufps $0,%xmm2,%xmm2 movaps %xmm1,nb210nf_krf(%rsp) movaps %xmm2,nb210nf_crf(%rsp) ## create constant floating-point factors on stack movl $0x3f000000,%eax ## half in IEEE (hex) movl %eax,nb210nf_half(%rsp) movss nb210nf_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,nb210nf_half(%rsp) movaps %xmm3,nb210nf_three(%rsp)_nb_kernel210nf_x86_64_sse.nb210nf_threadloop: movq nb210nf_count(%rbp),%rsi ## pointer to sync counter movl (%rsi),%eax_nb_kernel210nf_x86_64_sse.nb210nf_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_kernel210nf_x86_64_sse.nb210nf_spinlock ## if(nn1>nri) nn1=nri movl nb210nf_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,nb210nf_n(%rsp) movl %ebx,nb210nf_nn1(%rsp) subl %eax,%ebx ## calc number of outer lists
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?