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