2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS sse2_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_sse2_single
51 * Electrostatics interaction: GeneralizedBorn
52 * VdW interaction: LennardJones
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_sse2_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
85 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,dvdatmp;
91 __m128 minushalf = _mm_set1_ps(-0.5);
92 real *invsqrta,*dvda,*gbtab;
94 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
98 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
100 __m128i ifour = _mm_set1_epi32(4);
101 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
103 __m128 dummy_mask,cutoff_mask;
104 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
105 __m128 one = _mm_set1_ps(1.0);
106 __m128 two = _mm_set1_ps(2.0);
112 jindex = nlist->jindex;
114 shiftidx = nlist->shift;
116 shiftvec = fr->shift_vec[0];
117 fshift = fr->fshift[0];
118 facel = _mm_set1_ps(fr->ic->epsfac);
119 charge = mdatoms->chargeA;
120 nvdwtype = fr->ntype;
122 vdwtype = mdatoms->typeA;
124 invsqrta = fr->invsqrta;
126 gbtabscale = _mm_set1_ps(fr->gbtab->scale);
127 gbtab = fr->gbtab->data;
128 gbinvepsdiff = _mm_set1_ps((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
130 /* Avoid stupid compiler warnings */
131 jnrA = jnrB = jnrC = jnrD = 0;
140 for(iidx=0;iidx<4*DIM;iidx++)
145 /* Start outer loop over neighborlists */
146 for(iidx=0; iidx<nri; iidx++)
148 /* Load shift vector for this list */
149 i_shift_offset = DIM*shiftidx[iidx];
151 /* Load limits for loop over neighbors */
152 j_index_start = jindex[iidx];
153 j_index_end = jindex[iidx+1];
155 /* Get outer coordinate index */
157 i_coord_offset = DIM*inr;
159 /* Load i particle coords and add shift vector */
160 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
162 fix0 = _mm_setzero_ps();
163 fiy0 = _mm_setzero_ps();
164 fiz0 = _mm_setzero_ps();
166 /* Load parameters for i particles */
167 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
168 isai0 = _mm_load1_ps(invsqrta+inr+0);
169 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
171 /* Reset potential sums */
172 velecsum = _mm_setzero_ps();
173 vgbsum = _mm_setzero_ps();
174 vvdwsum = _mm_setzero_ps();
175 dvdasum = _mm_setzero_ps();
177 /* Start inner kernel loop */
178 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
181 /* Get j neighbor index, and coordinate index */
186 j_coord_offsetA = DIM*jnrA;
187 j_coord_offsetB = DIM*jnrB;
188 j_coord_offsetC = DIM*jnrC;
189 j_coord_offsetD = DIM*jnrD;
191 /* load j atom coordinates */
192 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
193 x+j_coord_offsetC,x+j_coord_offsetD,
196 /* Calculate displacement vector */
197 dx00 = _mm_sub_ps(ix0,jx0);
198 dy00 = _mm_sub_ps(iy0,jy0);
199 dz00 = _mm_sub_ps(iz0,jz0);
201 /* Calculate squared distance and things based on it */
202 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
204 rinv00 = sse2_invsqrt_f(rsq00);
206 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
208 /* Load parameters for j particles */
209 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
210 charge+jnrC+0,charge+jnrD+0);
211 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
212 invsqrta+jnrC+0,invsqrta+jnrD+0);
213 vdwjidx0A = 2*vdwtype[jnrA+0];
214 vdwjidx0B = 2*vdwtype[jnrB+0];
215 vdwjidx0C = 2*vdwtype[jnrC+0];
216 vdwjidx0D = 2*vdwtype[jnrD+0];
218 /**************************
219 * CALCULATE INTERACTIONS *
220 **************************/
222 r00 = _mm_mul_ps(rsq00,rinv00);
224 /* Compute parameters for interactions between i and j atoms */
225 qq00 = _mm_mul_ps(iq0,jq0);
226 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
227 vdwparam+vdwioffset0+vdwjidx0B,
228 vdwparam+vdwioffset0+vdwjidx0C,
229 vdwparam+vdwioffset0+vdwjidx0D,
232 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
233 isaprod = _mm_mul_ps(isai0,isaj0);
234 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
235 gbscale = _mm_mul_ps(isaprod,gbtabscale);
237 /* Calculate generalized born table index - this is a separate table from the normal one,
238 * but we use the same procedure by multiplying r with scale and truncating to integer.
240 rt = _mm_mul_ps(r00,gbscale);
241 gbitab = _mm_cvttps_epi32(rt);
242 gbeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
243 gbitab = _mm_slli_epi32(gbitab,2);
245 Y = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
246 F = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
247 G = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
248 H = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
249 _MM_TRANSPOSE4_PS(Y,F,G,H);
250 Heps = _mm_mul_ps(gbeps,H);
251 Fp = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
252 VV = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
253 vgb = _mm_mul_ps(gbqqfactor,VV);
255 FF = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
256 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
257 dvdatmp = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
258 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
263 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
264 velec = _mm_mul_ps(qq00,rinv00);
265 felec = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
267 /* LENNARD-JONES DISPERSION/REPULSION */
269 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
270 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
271 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
272 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
273 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
275 /* Update potential sum for this i atom from the interaction with this j atom. */
276 velecsum = _mm_add_ps(velecsum,velec);
277 vgbsum = _mm_add_ps(vgbsum,vgb);
278 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
280 fscal = _mm_add_ps(felec,fvdw);
282 /* Calculate temporary vectorial force */
283 tx = _mm_mul_ps(fscal,dx00);
284 ty = _mm_mul_ps(fscal,dy00);
285 tz = _mm_mul_ps(fscal,dz00);
287 /* Update vectorial force */
288 fix0 = _mm_add_ps(fix0,tx);
289 fiy0 = _mm_add_ps(fiy0,ty);
290 fiz0 = _mm_add_ps(fiz0,tz);
292 fjptrA = f+j_coord_offsetA;
293 fjptrB = f+j_coord_offsetB;
294 fjptrC = f+j_coord_offsetC;
295 fjptrD = f+j_coord_offsetD;
296 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
298 /* Inner loop uses 71 flops */
304 /* Get j neighbor index, and coordinate index */
305 jnrlistA = jjnr[jidx];
306 jnrlistB = jjnr[jidx+1];
307 jnrlistC = jjnr[jidx+2];
308 jnrlistD = jjnr[jidx+3];
309 /* Sign of each element will be negative for non-real atoms.
310 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
311 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
313 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
314 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
315 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
316 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
317 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
318 j_coord_offsetA = DIM*jnrA;
319 j_coord_offsetB = DIM*jnrB;
320 j_coord_offsetC = DIM*jnrC;
321 j_coord_offsetD = DIM*jnrD;
323 /* load j atom coordinates */
324 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
325 x+j_coord_offsetC,x+j_coord_offsetD,
328 /* Calculate displacement vector */
329 dx00 = _mm_sub_ps(ix0,jx0);
330 dy00 = _mm_sub_ps(iy0,jy0);
331 dz00 = _mm_sub_ps(iz0,jz0);
333 /* Calculate squared distance and things based on it */
334 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
336 rinv00 = sse2_invsqrt_f(rsq00);
338 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
340 /* Load parameters for j particles */
341 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
342 charge+jnrC+0,charge+jnrD+0);
343 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
344 invsqrta+jnrC+0,invsqrta+jnrD+0);
345 vdwjidx0A = 2*vdwtype[jnrA+0];
346 vdwjidx0B = 2*vdwtype[jnrB+0];
347 vdwjidx0C = 2*vdwtype[jnrC+0];
348 vdwjidx0D = 2*vdwtype[jnrD+0];
350 /**************************
351 * CALCULATE INTERACTIONS *
352 **************************/
354 r00 = _mm_mul_ps(rsq00,rinv00);
355 r00 = _mm_andnot_ps(dummy_mask,r00);
357 /* Compute parameters for interactions between i and j atoms */
358 qq00 = _mm_mul_ps(iq0,jq0);
359 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
360 vdwparam+vdwioffset0+vdwjidx0B,
361 vdwparam+vdwioffset0+vdwjidx0C,
362 vdwparam+vdwioffset0+vdwjidx0D,
365 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
366 isaprod = _mm_mul_ps(isai0,isaj0);
367 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
368 gbscale = _mm_mul_ps(isaprod,gbtabscale);
370 /* Calculate generalized born table index - this is a separate table from the normal one,
371 * but we use the same procedure by multiplying r with scale and truncating to integer.
373 rt = _mm_mul_ps(r00,gbscale);
374 gbitab = _mm_cvttps_epi32(rt);
375 gbeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
376 gbitab = _mm_slli_epi32(gbitab,2);
378 Y = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
379 F = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
380 G = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
381 H = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
382 _MM_TRANSPOSE4_PS(Y,F,G,H);
383 Heps = _mm_mul_ps(gbeps,H);
384 Fp = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
385 VV = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
386 vgb = _mm_mul_ps(gbqqfactor,VV);
388 FF = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
389 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
390 dvdatmp = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
391 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
392 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
393 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
394 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
395 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
396 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
397 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
398 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
399 velec = _mm_mul_ps(qq00,rinv00);
400 felec = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
402 /* LENNARD-JONES DISPERSION/REPULSION */
404 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
405 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
406 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
407 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
408 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
410 /* Update potential sum for this i atom from the interaction with this j atom. */
411 velec = _mm_andnot_ps(dummy_mask,velec);
412 velecsum = _mm_add_ps(velecsum,velec);
413 vgb = _mm_andnot_ps(dummy_mask,vgb);
414 vgbsum = _mm_add_ps(vgbsum,vgb);
415 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
416 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
418 fscal = _mm_add_ps(felec,fvdw);
420 fscal = _mm_andnot_ps(dummy_mask,fscal);
422 /* Calculate temporary vectorial force */
423 tx = _mm_mul_ps(fscal,dx00);
424 ty = _mm_mul_ps(fscal,dy00);
425 tz = _mm_mul_ps(fscal,dz00);
427 /* Update vectorial force */
428 fix0 = _mm_add_ps(fix0,tx);
429 fiy0 = _mm_add_ps(fiy0,ty);
430 fiz0 = _mm_add_ps(fiz0,tz);
432 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
433 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
434 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
435 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
436 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
438 /* Inner loop uses 72 flops */
441 /* End of innermost loop */
443 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
444 f+i_coord_offset,fshift+i_shift_offset);
447 /* Update potential energies */
448 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
449 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
450 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
451 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
452 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
454 /* Increment number of inner iterations */
455 inneriter += j_index_end - j_index_start;
457 /* Outer loop uses 10 flops */
460 /* Increment number of outer iterations */
463 /* Update outer/inner flops */
465 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*72);
468 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_sse2_single
469 * Electrostatics interaction: GeneralizedBorn
470 * VdW interaction: LennardJones
471 * Geometry: Particle-Particle
472 * Calculate force/pot: Force
475 nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_sse2_single
476 (t_nblist * gmx_restrict nlist,
477 rvec * gmx_restrict xx,
478 rvec * gmx_restrict ff,
479 struct t_forcerec * gmx_restrict fr,
480 t_mdatoms * gmx_restrict mdatoms,
481 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
482 t_nrnb * gmx_restrict nrnb)
484 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
485 * just 0 for non-waters.
486 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
487 * jnr indices corresponding to data put in the four positions in the SIMD register.
489 int i_shift_offset,i_coord_offset,outeriter,inneriter;
490 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
491 int jnrA,jnrB,jnrC,jnrD;
492 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
493 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
494 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
496 real *shiftvec,*fshift,*x,*f;
497 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
499 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
501 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
502 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
503 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
504 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
505 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
508 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,dvdatmp;
509 __m128 minushalf = _mm_set1_ps(-0.5);
510 real *invsqrta,*dvda,*gbtab;
512 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
515 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
516 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
518 __m128i ifour = _mm_set1_epi32(4);
519 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
521 __m128 dummy_mask,cutoff_mask;
522 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
523 __m128 one = _mm_set1_ps(1.0);
524 __m128 two = _mm_set1_ps(2.0);
530 jindex = nlist->jindex;
532 shiftidx = nlist->shift;
534 shiftvec = fr->shift_vec[0];
535 fshift = fr->fshift[0];
536 facel = _mm_set1_ps(fr->ic->epsfac);
537 charge = mdatoms->chargeA;
538 nvdwtype = fr->ntype;
540 vdwtype = mdatoms->typeA;
542 invsqrta = fr->invsqrta;
544 gbtabscale = _mm_set1_ps(fr->gbtab->scale);
545 gbtab = fr->gbtab->data;
546 gbinvepsdiff = _mm_set1_ps((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
548 /* Avoid stupid compiler warnings */
549 jnrA = jnrB = jnrC = jnrD = 0;
558 for(iidx=0;iidx<4*DIM;iidx++)
563 /* Start outer loop over neighborlists */
564 for(iidx=0; iidx<nri; iidx++)
566 /* Load shift vector for this list */
567 i_shift_offset = DIM*shiftidx[iidx];
569 /* Load limits for loop over neighbors */
570 j_index_start = jindex[iidx];
571 j_index_end = jindex[iidx+1];
573 /* Get outer coordinate index */
575 i_coord_offset = DIM*inr;
577 /* Load i particle coords and add shift vector */
578 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
580 fix0 = _mm_setzero_ps();
581 fiy0 = _mm_setzero_ps();
582 fiz0 = _mm_setzero_ps();
584 /* Load parameters for i particles */
585 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
586 isai0 = _mm_load1_ps(invsqrta+inr+0);
587 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
589 dvdasum = _mm_setzero_ps();
591 /* Start inner kernel loop */
592 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
595 /* Get j neighbor index, and coordinate index */
600 j_coord_offsetA = DIM*jnrA;
601 j_coord_offsetB = DIM*jnrB;
602 j_coord_offsetC = DIM*jnrC;
603 j_coord_offsetD = DIM*jnrD;
605 /* load j atom coordinates */
606 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
607 x+j_coord_offsetC,x+j_coord_offsetD,
610 /* Calculate displacement vector */
611 dx00 = _mm_sub_ps(ix0,jx0);
612 dy00 = _mm_sub_ps(iy0,jy0);
613 dz00 = _mm_sub_ps(iz0,jz0);
615 /* Calculate squared distance and things based on it */
616 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
618 rinv00 = sse2_invsqrt_f(rsq00);
620 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
622 /* Load parameters for j particles */
623 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
624 charge+jnrC+0,charge+jnrD+0);
625 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
626 invsqrta+jnrC+0,invsqrta+jnrD+0);
627 vdwjidx0A = 2*vdwtype[jnrA+0];
628 vdwjidx0B = 2*vdwtype[jnrB+0];
629 vdwjidx0C = 2*vdwtype[jnrC+0];
630 vdwjidx0D = 2*vdwtype[jnrD+0];
632 /**************************
633 * CALCULATE INTERACTIONS *
634 **************************/
636 r00 = _mm_mul_ps(rsq00,rinv00);
638 /* Compute parameters for interactions between i and j atoms */
639 qq00 = _mm_mul_ps(iq0,jq0);
640 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
641 vdwparam+vdwioffset0+vdwjidx0B,
642 vdwparam+vdwioffset0+vdwjidx0C,
643 vdwparam+vdwioffset0+vdwjidx0D,
646 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
647 isaprod = _mm_mul_ps(isai0,isaj0);
648 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
649 gbscale = _mm_mul_ps(isaprod,gbtabscale);
651 /* Calculate generalized born table index - this is a separate table from the normal one,
652 * but we use the same procedure by multiplying r with scale and truncating to integer.
654 rt = _mm_mul_ps(r00,gbscale);
655 gbitab = _mm_cvttps_epi32(rt);
656 gbeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
657 gbitab = _mm_slli_epi32(gbitab,2);
659 Y = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
660 F = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
661 G = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
662 H = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
663 _MM_TRANSPOSE4_PS(Y,F,G,H);
664 Heps = _mm_mul_ps(gbeps,H);
665 Fp = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
666 VV = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
667 vgb = _mm_mul_ps(gbqqfactor,VV);
669 FF = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
670 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
671 dvdatmp = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
672 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
677 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
678 velec = _mm_mul_ps(qq00,rinv00);
679 felec = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
681 /* LENNARD-JONES DISPERSION/REPULSION */
683 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
684 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
686 fscal = _mm_add_ps(felec,fvdw);
688 /* Calculate temporary vectorial force */
689 tx = _mm_mul_ps(fscal,dx00);
690 ty = _mm_mul_ps(fscal,dy00);
691 tz = _mm_mul_ps(fscal,dz00);
693 /* Update vectorial force */
694 fix0 = _mm_add_ps(fix0,tx);
695 fiy0 = _mm_add_ps(fiy0,ty);
696 fiz0 = _mm_add_ps(fiz0,tz);
698 fjptrA = f+j_coord_offsetA;
699 fjptrB = f+j_coord_offsetB;
700 fjptrC = f+j_coord_offsetC;
701 fjptrD = f+j_coord_offsetD;
702 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
704 /* Inner loop uses 64 flops */
710 /* Get j neighbor index, and coordinate index */
711 jnrlistA = jjnr[jidx];
712 jnrlistB = jjnr[jidx+1];
713 jnrlistC = jjnr[jidx+2];
714 jnrlistD = jjnr[jidx+3];
715 /* Sign of each element will be negative for non-real atoms.
716 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
717 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
719 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
720 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
721 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
722 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
723 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
724 j_coord_offsetA = DIM*jnrA;
725 j_coord_offsetB = DIM*jnrB;
726 j_coord_offsetC = DIM*jnrC;
727 j_coord_offsetD = DIM*jnrD;
729 /* load j atom coordinates */
730 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
731 x+j_coord_offsetC,x+j_coord_offsetD,
734 /* Calculate displacement vector */
735 dx00 = _mm_sub_ps(ix0,jx0);
736 dy00 = _mm_sub_ps(iy0,jy0);
737 dz00 = _mm_sub_ps(iz0,jz0);
739 /* Calculate squared distance and things based on it */
740 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
742 rinv00 = sse2_invsqrt_f(rsq00);
744 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
746 /* Load parameters for j particles */
747 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
748 charge+jnrC+0,charge+jnrD+0);
749 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
750 invsqrta+jnrC+0,invsqrta+jnrD+0);
751 vdwjidx0A = 2*vdwtype[jnrA+0];
752 vdwjidx0B = 2*vdwtype[jnrB+0];
753 vdwjidx0C = 2*vdwtype[jnrC+0];
754 vdwjidx0D = 2*vdwtype[jnrD+0];
756 /**************************
757 * CALCULATE INTERACTIONS *
758 **************************/
760 r00 = _mm_mul_ps(rsq00,rinv00);
761 r00 = _mm_andnot_ps(dummy_mask,r00);
763 /* Compute parameters for interactions between i and j atoms */
764 qq00 = _mm_mul_ps(iq0,jq0);
765 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
766 vdwparam+vdwioffset0+vdwjidx0B,
767 vdwparam+vdwioffset0+vdwjidx0C,
768 vdwparam+vdwioffset0+vdwjidx0D,
771 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
772 isaprod = _mm_mul_ps(isai0,isaj0);
773 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
774 gbscale = _mm_mul_ps(isaprod,gbtabscale);
776 /* Calculate generalized born table index - this is a separate table from the normal one,
777 * but we use the same procedure by multiplying r with scale and truncating to integer.
779 rt = _mm_mul_ps(r00,gbscale);
780 gbitab = _mm_cvttps_epi32(rt);
781 gbeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
782 gbitab = _mm_slli_epi32(gbitab,2);
784 Y = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
785 F = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
786 G = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
787 H = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
788 _MM_TRANSPOSE4_PS(Y,F,G,H);
789 Heps = _mm_mul_ps(gbeps,H);
790 Fp = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
791 VV = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
792 vgb = _mm_mul_ps(gbqqfactor,VV);
794 FF = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
795 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
796 dvdatmp = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
797 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
798 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
799 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
800 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
801 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
802 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
803 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
804 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
805 velec = _mm_mul_ps(qq00,rinv00);
806 felec = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
808 /* LENNARD-JONES DISPERSION/REPULSION */
810 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
811 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
813 fscal = _mm_add_ps(felec,fvdw);
815 fscal = _mm_andnot_ps(dummy_mask,fscal);
817 /* Calculate temporary vectorial force */
818 tx = _mm_mul_ps(fscal,dx00);
819 ty = _mm_mul_ps(fscal,dy00);
820 tz = _mm_mul_ps(fscal,dz00);
822 /* Update vectorial force */
823 fix0 = _mm_add_ps(fix0,tx);
824 fiy0 = _mm_add_ps(fiy0,ty);
825 fiz0 = _mm_add_ps(fiz0,tz);
827 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
828 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
829 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
830 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
831 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
833 /* Inner loop uses 65 flops */
836 /* End of innermost loop */
838 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
839 f+i_coord_offset,fshift+i_shift_offset);
841 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
842 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
844 /* Increment number of inner iterations */
845 inneriter += j_index_end - j_index_start;
847 /* Outer loop uses 7 flops */
850 /* Increment number of outer iterations */
853 /* Update outer/inner flops */
855 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*65);