2 * Note: this file was generated by the Gromacs avx_128_fma_single kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_avx_128_fma_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_avx_128_fma_single
38 * Electrostatics interaction: Ewald
39 * VdW interaction: LennardJones
40 * Geometry: Water4-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_avx_128_fma_single
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60 int jnrA,jnrB,jnrC,jnrD;
61 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
65 real *shiftvec,*fshift,*x,*f;
66 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
68 __m128 fscal,rcutoff,rcutoff2,jidxall;
70 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
76 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
77 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
78 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
79 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
80 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
81 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
82 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
83 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
86 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
89 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
90 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
92 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
93 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
95 __m128 dummy_mask,cutoff_mask;
96 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
97 __m128 one = _mm_set1_ps(1.0);
98 __m128 two = _mm_set1_ps(2.0);
104 jindex = nlist->jindex;
106 shiftidx = nlist->shift;
108 shiftvec = fr->shift_vec[0];
109 fshift = fr->fshift[0];
110 facel = _mm_set1_ps(fr->epsfac);
111 charge = mdatoms->chargeA;
112 nvdwtype = fr->ntype;
114 vdwtype = mdatoms->typeA;
116 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
117 beta = _mm_set1_ps(fr->ic->ewaldcoeff);
118 beta2 = _mm_mul_ps(beta,beta);
119 beta3 = _mm_mul_ps(beta,beta2);
120 ewtab = fr->ic->tabq_coul_FDV0;
121 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
122 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
124 /* Setup water-specific parameters */
125 inr = nlist->iinr[0];
126 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
127 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
128 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
129 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
131 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
132 rcutoff_scalar = fr->rcoulomb;
133 rcutoff = _mm_set1_ps(rcutoff_scalar);
134 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
136 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
137 rvdw = _mm_set1_ps(fr->rvdw);
139 /* Avoid stupid compiler warnings */
140 jnrA = jnrB = jnrC = jnrD = 0;
149 for(iidx=0;iidx<4*DIM;iidx++)
154 /* Start outer loop over neighborlists */
155 for(iidx=0; iidx<nri; iidx++)
157 /* Load shift vector for this list */
158 i_shift_offset = DIM*shiftidx[iidx];
160 /* Load limits for loop over neighbors */
161 j_index_start = jindex[iidx];
162 j_index_end = jindex[iidx+1];
164 /* Get outer coordinate index */
166 i_coord_offset = DIM*inr;
168 /* Load i particle coords and add shift vector */
169 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
170 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
172 fix0 = _mm_setzero_ps();
173 fiy0 = _mm_setzero_ps();
174 fiz0 = _mm_setzero_ps();
175 fix1 = _mm_setzero_ps();
176 fiy1 = _mm_setzero_ps();
177 fiz1 = _mm_setzero_ps();
178 fix2 = _mm_setzero_ps();
179 fiy2 = _mm_setzero_ps();
180 fiz2 = _mm_setzero_ps();
181 fix3 = _mm_setzero_ps();
182 fiy3 = _mm_setzero_ps();
183 fiz3 = _mm_setzero_ps();
185 /* Reset potential sums */
186 velecsum = _mm_setzero_ps();
187 vvdwsum = _mm_setzero_ps();
189 /* Start inner kernel loop */
190 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
193 /* Get j neighbor index, and coordinate index */
198 j_coord_offsetA = DIM*jnrA;
199 j_coord_offsetB = DIM*jnrB;
200 j_coord_offsetC = DIM*jnrC;
201 j_coord_offsetD = DIM*jnrD;
203 /* load j atom coordinates */
204 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
205 x+j_coord_offsetC,x+j_coord_offsetD,
208 /* Calculate displacement vector */
209 dx00 = _mm_sub_ps(ix0,jx0);
210 dy00 = _mm_sub_ps(iy0,jy0);
211 dz00 = _mm_sub_ps(iz0,jz0);
212 dx10 = _mm_sub_ps(ix1,jx0);
213 dy10 = _mm_sub_ps(iy1,jy0);
214 dz10 = _mm_sub_ps(iz1,jz0);
215 dx20 = _mm_sub_ps(ix2,jx0);
216 dy20 = _mm_sub_ps(iy2,jy0);
217 dz20 = _mm_sub_ps(iz2,jz0);
218 dx30 = _mm_sub_ps(ix3,jx0);
219 dy30 = _mm_sub_ps(iy3,jy0);
220 dz30 = _mm_sub_ps(iz3,jz0);
222 /* Calculate squared distance and things based on it */
223 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
224 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
225 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
226 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
228 rinv10 = gmx_mm_invsqrt_ps(rsq10);
229 rinv20 = gmx_mm_invsqrt_ps(rsq20);
230 rinv30 = gmx_mm_invsqrt_ps(rsq30);
232 rinvsq00 = gmx_mm_inv_ps(rsq00);
233 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
234 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
235 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
237 /* Load parameters for j particles */
238 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
239 charge+jnrC+0,charge+jnrD+0);
240 vdwjidx0A = 2*vdwtype[jnrA+0];
241 vdwjidx0B = 2*vdwtype[jnrB+0];
242 vdwjidx0C = 2*vdwtype[jnrC+0];
243 vdwjidx0D = 2*vdwtype[jnrD+0];
245 fjx0 = _mm_setzero_ps();
246 fjy0 = _mm_setzero_ps();
247 fjz0 = _mm_setzero_ps();
249 /**************************
250 * CALCULATE INTERACTIONS *
251 **************************/
253 if (gmx_mm_any_lt(rsq00,rcutoff2))
256 /* Compute parameters for interactions between i and j atoms */
257 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
258 vdwparam+vdwioffset0+vdwjidx0B,
259 vdwparam+vdwioffset0+vdwjidx0C,
260 vdwparam+vdwioffset0+vdwjidx0D,
263 /* LENNARD-JONES DISPERSION/REPULSION */
265 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
266 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
267 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
268 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
269 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
270 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
272 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
274 /* Update potential sum for this i atom from the interaction with this j atom. */
275 vvdw = _mm_and_ps(vvdw,cutoff_mask);
276 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
280 fscal = _mm_and_ps(fscal,cutoff_mask);
282 /* Update vectorial force */
283 fix0 = _mm_macc_ps(dx00,fscal,fix0);
284 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
285 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
287 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
288 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
289 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
293 /**************************
294 * CALCULATE INTERACTIONS *
295 **************************/
297 if (gmx_mm_any_lt(rsq10,rcutoff2))
300 r10 = _mm_mul_ps(rsq10,rinv10);
302 /* Compute parameters for interactions between i and j atoms */
303 qq10 = _mm_mul_ps(iq1,jq0);
305 /* EWALD ELECTROSTATICS */
307 /* Analytical PME correction */
308 zeta2 = _mm_mul_ps(beta2,rsq10);
309 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
310 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
311 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
312 felec = _mm_mul_ps(qq10,felec);
313 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
314 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
315 velec = _mm_mul_ps(qq10,velec);
317 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
319 /* Update potential sum for this i atom from the interaction with this j atom. */
320 velec = _mm_and_ps(velec,cutoff_mask);
321 velecsum = _mm_add_ps(velecsum,velec);
325 fscal = _mm_and_ps(fscal,cutoff_mask);
327 /* Update vectorial force */
328 fix1 = _mm_macc_ps(dx10,fscal,fix1);
329 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
330 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
332 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
333 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
334 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
338 /**************************
339 * CALCULATE INTERACTIONS *
340 **************************/
342 if (gmx_mm_any_lt(rsq20,rcutoff2))
345 r20 = _mm_mul_ps(rsq20,rinv20);
347 /* Compute parameters for interactions between i and j atoms */
348 qq20 = _mm_mul_ps(iq2,jq0);
350 /* EWALD ELECTROSTATICS */
352 /* Analytical PME correction */
353 zeta2 = _mm_mul_ps(beta2,rsq20);
354 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
355 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
356 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
357 felec = _mm_mul_ps(qq20,felec);
358 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
359 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
360 velec = _mm_mul_ps(qq20,velec);
362 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
364 /* Update potential sum for this i atom from the interaction with this j atom. */
365 velec = _mm_and_ps(velec,cutoff_mask);
366 velecsum = _mm_add_ps(velecsum,velec);
370 fscal = _mm_and_ps(fscal,cutoff_mask);
372 /* Update vectorial force */
373 fix2 = _mm_macc_ps(dx20,fscal,fix2);
374 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
375 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
377 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
378 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
379 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
383 /**************************
384 * CALCULATE INTERACTIONS *
385 **************************/
387 if (gmx_mm_any_lt(rsq30,rcutoff2))
390 r30 = _mm_mul_ps(rsq30,rinv30);
392 /* Compute parameters for interactions between i and j atoms */
393 qq30 = _mm_mul_ps(iq3,jq0);
395 /* EWALD ELECTROSTATICS */
397 /* Analytical PME correction */
398 zeta2 = _mm_mul_ps(beta2,rsq30);
399 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
400 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
401 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
402 felec = _mm_mul_ps(qq30,felec);
403 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
404 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
405 velec = _mm_mul_ps(qq30,velec);
407 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
409 /* Update potential sum for this i atom from the interaction with this j atom. */
410 velec = _mm_and_ps(velec,cutoff_mask);
411 velecsum = _mm_add_ps(velecsum,velec);
415 fscal = _mm_and_ps(fscal,cutoff_mask);
417 /* Update vectorial force */
418 fix3 = _mm_macc_ps(dx30,fscal,fix3);
419 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
420 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
422 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
423 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
424 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
428 fjptrA = f+j_coord_offsetA;
429 fjptrB = f+j_coord_offsetB;
430 fjptrC = f+j_coord_offsetC;
431 fjptrD = f+j_coord_offsetD;
433 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
435 /* Inner loop uses 143 flops */
441 /* Get j neighbor index, and coordinate index */
442 jnrlistA = jjnr[jidx];
443 jnrlistB = jjnr[jidx+1];
444 jnrlistC = jjnr[jidx+2];
445 jnrlistD = jjnr[jidx+3];
446 /* Sign of each element will be negative for non-real atoms.
447 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
448 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
450 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
451 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
452 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
453 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
454 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
455 j_coord_offsetA = DIM*jnrA;
456 j_coord_offsetB = DIM*jnrB;
457 j_coord_offsetC = DIM*jnrC;
458 j_coord_offsetD = DIM*jnrD;
460 /* load j atom coordinates */
461 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
462 x+j_coord_offsetC,x+j_coord_offsetD,
465 /* Calculate displacement vector */
466 dx00 = _mm_sub_ps(ix0,jx0);
467 dy00 = _mm_sub_ps(iy0,jy0);
468 dz00 = _mm_sub_ps(iz0,jz0);
469 dx10 = _mm_sub_ps(ix1,jx0);
470 dy10 = _mm_sub_ps(iy1,jy0);
471 dz10 = _mm_sub_ps(iz1,jz0);
472 dx20 = _mm_sub_ps(ix2,jx0);
473 dy20 = _mm_sub_ps(iy2,jy0);
474 dz20 = _mm_sub_ps(iz2,jz0);
475 dx30 = _mm_sub_ps(ix3,jx0);
476 dy30 = _mm_sub_ps(iy3,jy0);
477 dz30 = _mm_sub_ps(iz3,jz0);
479 /* Calculate squared distance and things based on it */
480 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
481 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
482 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
483 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
485 rinv10 = gmx_mm_invsqrt_ps(rsq10);
486 rinv20 = gmx_mm_invsqrt_ps(rsq20);
487 rinv30 = gmx_mm_invsqrt_ps(rsq30);
489 rinvsq00 = gmx_mm_inv_ps(rsq00);
490 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
491 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
492 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
494 /* Load parameters for j particles */
495 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
496 charge+jnrC+0,charge+jnrD+0);
497 vdwjidx0A = 2*vdwtype[jnrA+0];
498 vdwjidx0B = 2*vdwtype[jnrB+0];
499 vdwjidx0C = 2*vdwtype[jnrC+0];
500 vdwjidx0D = 2*vdwtype[jnrD+0];
502 fjx0 = _mm_setzero_ps();
503 fjy0 = _mm_setzero_ps();
504 fjz0 = _mm_setzero_ps();
506 /**************************
507 * CALCULATE INTERACTIONS *
508 **************************/
510 if (gmx_mm_any_lt(rsq00,rcutoff2))
513 /* Compute parameters for interactions between i and j atoms */
514 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
515 vdwparam+vdwioffset0+vdwjidx0B,
516 vdwparam+vdwioffset0+vdwjidx0C,
517 vdwparam+vdwioffset0+vdwjidx0D,
520 /* LENNARD-JONES DISPERSION/REPULSION */
522 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
523 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
524 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
525 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
526 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
527 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
529 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
531 /* Update potential sum for this i atom from the interaction with this j atom. */
532 vvdw = _mm_and_ps(vvdw,cutoff_mask);
533 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
534 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
538 fscal = _mm_and_ps(fscal,cutoff_mask);
540 fscal = _mm_andnot_ps(dummy_mask,fscal);
542 /* Update vectorial force */
543 fix0 = _mm_macc_ps(dx00,fscal,fix0);
544 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
545 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
547 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
548 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
549 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
553 /**************************
554 * CALCULATE INTERACTIONS *
555 **************************/
557 if (gmx_mm_any_lt(rsq10,rcutoff2))
560 r10 = _mm_mul_ps(rsq10,rinv10);
561 r10 = _mm_andnot_ps(dummy_mask,r10);
563 /* Compute parameters for interactions between i and j atoms */
564 qq10 = _mm_mul_ps(iq1,jq0);
566 /* EWALD ELECTROSTATICS */
568 /* Analytical PME correction */
569 zeta2 = _mm_mul_ps(beta2,rsq10);
570 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
571 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
572 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
573 felec = _mm_mul_ps(qq10,felec);
574 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
575 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
576 velec = _mm_mul_ps(qq10,velec);
578 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
580 /* Update potential sum for this i atom from the interaction with this j atom. */
581 velec = _mm_and_ps(velec,cutoff_mask);
582 velec = _mm_andnot_ps(dummy_mask,velec);
583 velecsum = _mm_add_ps(velecsum,velec);
587 fscal = _mm_and_ps(fscal,cutoff_mask);
589 fscal = _mm_andnot_ps(dummy_mask,fscal);
591 /* Update vectorial force */
592 fix1 = _mm_macc_ps(dx10,fscal,fix1);
593 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
594 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
596 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
597 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
598 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
602 /**************************
603 * CALCULATE INTERACTIONS *
604 **************************/
606 if (gmx_mm_any_lt(rsq20,rcutoff2))
609 r20 = _mm_mul_ps(rsq20,rinv20);
610 r20 = _mm_andnot_ps(dummy_mask,r20);
612 /* Compute parameters for interactions between i and j atoms */
613 qq20 = _mm_mul_ps(iq2,jq0);
615 /* EWALD ELECTROSTATICS */
617 /* Analytical PME correction */
618 zeta2 = _mm_mul_ps(beta2,rsq20);
619 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
620 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
621 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
622 felec = _mm_mul_ps(qq20,felec);
623 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
624 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
625 velec = _mm_mul_ps(qq20,velec);
627 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
629 /* Update potential sum for this i atom from the interaction with this j atom. */
630 velec = _mm_and_ps(velec,cutoff_mask);
631 velec = _mm_andnot_ps(dummy_mask,velec);
632 velecsum = _mm_add_ps(velecsum,velec);
636 fscal = _mm_and_ps(fscal,cutoff_mask);
638 fscal = _mm_andnot_ps(dummy_mask,fscal);
640 /* Update vectorial force */
641 fix2 = _mm_macc_ps(dx20,fscal,fix2);
642 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
643 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
645 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
646 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
647 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
651 /**************************
652 * CALCULATE INTERACTIONS *
653 **************************/
655 if (gmx_mm_any_lt(rsq30,rcutoff2))
658 r30 = _mm_mul_ps(rsq30,rinv30);
659 r30 = _mm_andnot_ps(dummy_mask,r30);
661 /* Compute parameters for interactions between i and j atoms */
662 qq30 = _mm_mul_ps(iq3,jq0);
664 /* EWALD ELECTROSTATICS */
666 /* Analytical PME correction */
667 zeta2 = _mm_mul_ps(beta2,rsq30);
668 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
669 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
670 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
671 felec = _mm_mul_ps(qq30,felec);
672 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
673 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
674 velec = _mm_mul_ps(qq30,velec);
676 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
678 /* Update potential sum for this i atom from the interaction with this j atom. */
679 velec = _mm_and_ps(velec,cutoff_mask);
680 velec = _mm_andnot_ps(dummy_mask,velec);
681 velecsum = _mm_add_ps(velecsum,velec);
685 fscal = _mm_and_ps(fscal,cutoff_mask);
687 fscal = _mm_andnot_ps(dummy_mask,fscal);
689 /* Update vectorial force */
690 fix3 = _mm_macc_ps(dx30,fscal,fix3);
691 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
692 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
694 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
695 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
696 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
700 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
701 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
702 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
703 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
705 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
707 /* Inner loop uses 146 flops */
710 /* End of innermost loop */
712 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
713 f+i_coord_offset,fshift+i_shift_offset);
716 /* Update potential energies */
717 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
718 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
720 /* Increment number of inner iterations */
721 inneriter += j_index_end - j_index_start;
723 /* Outer loop uses 26 flops */
726 /* Increment number of outer iterations */
729 /* Update outer/inner flops */
731 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*146);
734 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_avx_128_fma_single
735 * Electrostatics interaction: Ewald
736 * VdW interaction: LennardJones
737 * Geometry: Water4-Particle
738 * Calculate force/pot: Force
741 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_avx_128_fma_single
742 (t_nblist * gmx_restrict nlist,
743 rvec * gmx_restrict xx,
744 rvec * gmx_restrict ff,
745 t_forcerec * gmx_restrict fr,
746 t_mdatoms * gmx_restrict mdatoms,
747 nb_kernel_data_t * gmx_restrict kernel_data,
748 t_nrnb * gmx_restrict nrnb)
750 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
751 * just 0 for non-waters.
752 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
753 * jnr indices corresponding to data put in the four positions in the SIMD register.
755 int i_shift_offset,i_coord_offset,outeriter,inneriter;
756 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
757 int jnrA,jnrB,jnrC,jnrD;
758 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
759 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
760 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
762 real *shiftvec,*fshift,*x,*f;
763 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
765 __m128 fscal,rcutoff,rcutoff2,jidxall;
767 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
769 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
771 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
773 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
774 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
775 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
776 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
777 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
778 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
779 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
780 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
783 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
786 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
787 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
789 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
790 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
792 __m128 dummy_mask,cutoff_mask;
793 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
794 __m128 one = _mm_set1_ps(1.0);
795 __m128 two = _mm_set1_ps(2.0);
801 jindex = nlist->jindex;
803 shiftidx = nlist->shift;
805 shiftvec = fr->shift_vec[0];
806 fshift = fr->fshift[0];
807 facel = _mm_set1_ps(fr->epsfac);
808 charge = mdatoms->chargeA;
809 nvdwtype = fr->ntype;
811 vdwtype = mdatoms->typeA;
813 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
814 beta = _mm_set1_ps(fr->ic->ewaldcoeff);
815 beta2 = _mm_mul_ps(beta,beta);
816 beta3 = _mm_mul_ps(beta,beta2);
817 ewtab = fr->ic->tabq_coul_F;
818 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
819 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
821 /* Setup water-specific parameters */
822 inr = nlist->iinr[0];
823 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
824 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
825 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
826 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
828 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
829 rcutoff_scalar = fr->rcoulomb;
830 rcutoff = _mm_set1_ps(rcutoff_scalar);
831 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
833 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
834 rvdw = _mm_set1_ps(fr->rvdw);
836 /* Avoid stupid compiler warnings */
837 jnrA = jnrB = jnrC = jnrD = 0;
846 for(iidx=0;iidx<4*DIM;iidx++)
851 /* Start outer loop over neighborlists */
852 for(iidx=0; iidx<nri; iidx++)
854 /* Load shift vector for this list */
855 i_shift_offset = DIM*shiftidx[iidx];
857 /* Load limits for loop over neighbors */
858 j_index_start = jindex[iidx];
859 j_index_end = jindex[iidx+1];
861 /* Get outer coordinate index */
863 i_coord_offset = DIM*inr;
865 /* Load i particle coords and add shift vector */
866 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
867 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
869 fix0 = _mm_setzero_ps();
870 fiy0 = _mm_setzero_ps();
871 fiz0 = _mm_setzero_ps();
872 fix1 = _mm_setzero_ps();
873 fiy1 = _mm_setzero_ps();
874 fiz1 = _mm_setzero_ps();
875 fix2 = _mm_setzero_ps();
876 fiy2 = _mm_setzero_ps();
877 fiz2 = _mm_setzero_ps();
878 fix3 = _mm_setzero_ps();
879 fiy3 = _mm_setzero_ps();
880 fiz3 = _mm_setzero_ps();
882 /* Start inner kernel loop */
883 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
886 /* Get j neighbor index, and coordinate index */
891 j_coord_offsetA = DIM*jnrA;
892 j_coord_offsetB = DIM*jnrB;
893 j_coord_offsetC = DIM*jnrC;
894 j_coord_offsetD = DIM*jnrD;
896 /* load j atom coordinates */
897 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
898 x+j_coord_offsetC,x+j_coord_offsetD,
901 /* Calculate displacement vector */
902 dx00 = _mm_sub_ps(ix0,jx0);
903 dy00 = _mm_sub_ps(iy0,jy0);
904 dz00 = _mm_sub_ps(iz0,jz0);
905 dx10 = _mm_sub_ps(ix1,jx0);
906 dy10 = _mm_sub_ps(iy1,jy0);
907 dz10 = _mm_sub_ps(iz1,jz0);
908 dx20 = _mm_sub_ps(ix2,jx0);
909 dy20 = _mm_sub_ps(iy2,jy0);
910 dz20 = _mm_sub_ps(iz2,jz0);
911 dx30 = _mm_sub_ps(ix3,jx0);
912 dy30 = _mm_sub_ps(iy3,jy0);
913 dz30 = _mm_sub_ps(iz3,jz0);
915 /* Calculate squared distance and things based on it */
916 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
917 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
918 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
919 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
921 rinv10 = gmx_mm_invsqrt_ps(rsq10);
922 rinv20 = gmx_mm_invsqrt_ps(rsq20);
923 rinv30 = gmx_mm_invsqrt_ps(rsq30);
925 rinvsq00 = gmx_mm_inv_ps(rsq00);
926 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
927 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
928 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
930 /* Load parameters for j particles */
931 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
932 charge+jnrC+0,charge+jnrD+0);
933 vdwjidx0A = 2*vdwtype[jnrA+0];
934 vdwjidx0B = 2*vdwtype[jnrB+0];
935 vdwjidx0C = 2*vdwtype[jnrC+0];
936 vdwjidx0D = 2*vdwtype[jnrD+0];
938 fjx0 = _mm_setzero_ps();
939 fjy0 = _mm_setzero_ps();
940 fjz0 = _mm_setzero_ps();
942 /**************************
943 * CALCULATE INTERACTIONS *
944 **************************/
946 if (gmx_mm_any_lt(rsq00,rcutoff2))
949 /* Compute parameters for interactions between i and j atoms */
950 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
951 vdwparam+vdwioffset0+vdwjidx0B,
952 vdwparam+vdwioffset0+vdwjidx0C,
953 vdwparam+vdwioffset0+vdwjidx0D,
956 /* LENNARD-JONES DISPERSION/REPULSION */
958 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
959 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
961 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
965 fscal = _mm_and_ps(fscal,cutoff_mask);
967 /* Update vectorial force */
968 fix0 = _mm_macc_ps(dx00,fscal,fix0);
969 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
970 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
972 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
973 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
974 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
978 /**************************
979 * CALCULATE INTERACTIONS *
980 **************************/
982 if (gmx_mm_any_lt(rsq10,rcutoff2))
985 r10 = _mm_mul_ps(rsq10,rinv10);
987 /* Compute parameters for interactions between i and j atoms */
988 qq10 = _mm_mul_ps(iq1,jq0);
990 /* EWALD ELECTROSTATICS */
992 /* Analytical PME correction */
993 zeta2 = _mm_mul_ps(beta2,rsq10);
994 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
995 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
996 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
997 felec = _mm_mul_ps(qq10,felec);
999 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1003 fscal = _mm_and_ps(fscal,cutoff_mask);
1005 /* Update vectorial force */
1006 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1007 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1008 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1010 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1011 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1012 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1016 /**************************
1017 * CALCULATE INTERACTIONS *
1018 **************************/
1020 if (gmx_mm_any_lt(rsq20,rcutoff2))
1023 r20 = _mm_mul_ps(rsq20,rinv20);
1025 /* Compute parameters for interactions between i and j atoms */
1026 qq20 = _mm_mul_ps(iq2,jq0);
1028 /* EWALD ELECTROSTATICS */
1030 /* Analytical PME correction */
1031 zeta2 = _mm_mul_ps(beta2,rsq20);
1032 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1033 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1034 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1035 felec = _mm_mul_ps(qq20,felec);
1037 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1041 fscal = _mm_and_ps(fscal,cutoff_mask);
1043 /* Update vectorial force */
1044 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1045 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1046 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1048 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1049 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1050 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1054 /**************************
1055 * CALCULATE INTERACTIONS *
1056 **************************/
1058 if (gmx_mm_any_lt(rsq30,rcutoff2))
1061 r30 = _mm_mul_ps(rsq30,rinv30);
1063 /* Compute parameters for interactions between i and j atoms */
1064 qq30 = _mm_mul_ps(iq3,jq0);
1066 /* EWALD ELECTROSTATICS */
1068 /* Analytical PME correction */
1069 zeta2 = _mm_mul_ps(beta2,rsq30);
1070 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1071 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1072 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1073 felec = _mm_mul_ps(qq30,felec);
1075 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1079 fscal = _mm_and_ps(fscal,cutoff_mask);
1081 /* Update vectorial force */
1082 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1083 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1084 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1086 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1087 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1088 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1092 fjptrA = f+j_coord_offsetA;
1093 fjptrB = f+j_coord_offsetB;
1094 fjptrC = f+j_coord_offsetC;
1095 fjptrD = f+j_coord_offsetD;
1097 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1099 /* Inner loop uses 126 flops */
1102 if(jidx<j_index_end)
1105 /* Get j neighbor index, and coordinate index */
1106 jnrlistA = jjnr[jidx];
1107 jnrlistB = jjnr[jidx+1];
1108 jnrlistC = jjnr[jidx+2];
1109 jnrlistD = jjnr[jidx+3];
1110 /* Sign of each element will be negative for non-real atoms.
1111 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1112 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1114 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1115 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1116 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1117 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1118 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1119 j_coord_offsetA = DIM*jnrA;
1120 j_coord_offsetB = DIM*jnrB;
1121 j_coord_offsetC = DIM*jnrC;
1122 j_coord_offsetD = DIM*jnrD;
1124 /* load j atom coordinates */
1125 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1126 x+j_coord_offsetC,x+j_coord_offsetD,
1129 /* Calculate displacement vector */
1130 dx00 = _mm_sub_ps(ix0,jx0);
1131 dy00 = _mm_sub_ps(iy0,jy0);
1132 dz00 = _mm_sub_ps(iz0,jz0);
1133 dx10 = _mm_sub_ps(ix1,jx0);
1134 dy10 = _mm_sub_ps(iy1,jy0);
1135 dz10 = _mm_sub_ps(iz1,jz0);
1136 dx20 = _mm_sub_ps(ix2,jx0);
1137 dy20 = _mm_sub_ps(iy2,jy0);
1138 dz20 = _mm_sub_ps(iz2,jz0);
1139 dx30 = _mm_sub_ps(ix3,jx0);
1140 dy30 = _mm_sub_ps(iy3,jy0);
1141 dz30 = _mm_sub_ps(iz3,jz0);
1143 /* Calculate squared distance and things based on it */
1144 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1145 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1146 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1147 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1149 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1150 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1151 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1153 rinvsq00 = gmx_mm_inv_ps(rsq00);
1154 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1155 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1156 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1158 /* Load parameters for j particles */
1159 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1160 charge+jnrC+0,charge+jnrD+0);
1161 vdwjidx0A = 2*vdwtype[jnrA+0];
1162 vdwjidx0B = 2*vdwtype[jnrB+0];
1163 vdwjidx0C = 2*vdwtype[jnrC+0];
1164 vdwjidx0D = 2*vdwtype[jnrD+0];
1166 fjx0 = _mm_setzero_ps();
1167 fjy0 = _mm_setzero_ps();
1168 fjz0 = _mm_setzero_ps();
1170 /**************************
1171 * CALCULATE INTERACTIONS *
1172 **************************/
1174 if (gmx_mm_any_lt(rsq00,rcutoff2))
1177 /* Compute parameters for interactions between i and j atoms */
1178 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1179 vdwparam+vdwioffset0+vdwjidx0B,
1180 vdwparam+vdwioffset0+vdwjidx0C,
1181 vdwparam+vdwioffset0+vdwjidx0D,
1184 /* LENNARD-JONES DISPERSION/REPULSION */
1186 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1187 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1189 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1193 fscal = _mm_and_ps(fscal,cutoff_mask);
1195 fscal = _mm_andnot_ps(dummy_mask,fscal);
1197 /* Update vectorial force */
1198 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1199 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1200 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1202 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1203 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1204 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1208 /**************************
1209 * CALCULATE INTERACTIONS *
1210 **************************/
1212 if (gmx_mm_any_lt(rsq10,rcutoff2))
1215 r10 = _mm_mul_ps(rsq10,rinv10);
1216 r10 = _mm_andnot_ps(dummy_mask,r10);
1218 /* Compute parameters for interactions between i and j atoms */
1219 qq10 = _mm_mul_ps(iq1,jq0);
1221 /* EWALD ELECTROSTATICS */
1223 /* Analytical PME correction */
1224 zeta2 = _mm_mul_ps(beta2,rsq10);
1225 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1226 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1227 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1228 felec = _mm_mul_ps(qq10,felec);
1230 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1234 fscal = _mm_and_ps(fscal,cutoff_mask);
1236 fscal = _mm_andnot_ps(dummy_mask,fscal);
1238 /* Update vectorial force */
1239 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1240 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1241 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1243 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1244 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1245 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1249 /**************************
1250 * CALCULATE INTERACTIONS *
1251 **************************/
1253 if (gmx_mm_any_lt(rsq20,rcutoff2))
1256 r20 = _mm_mul_ps(rsq20,rinv20);
1257 r20 = _mm_andnot_ps(dummy_mask,r20);
1259 /* Compute parameters for interactions between i and j atoms */
1260 qq20 = _mm_mul_ps(iq2,jq0);
1262 /* EWALD ELECTROSTATICS */
1264 /* Analytical PME correction */
1265 zeta2 = _mm_mul_ps(beta2,rsq20);
1266 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1267 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1268 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1269 felec = _mm_mul_ps(qq20,felec);
1271 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1275 fscal = _mm_and_ps(fscal,cutoff_mask);
1277 fscal = _mm_andnot_ps(dummy_mask,fscal);
1279 /* Update vectorial force */
1280 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1281 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1282 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1284 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1285 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1286 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1290 /**************************
1291 * CALCULATE INTERACTIONS *
1292 **************************/
1294 if (gmx_mm_any_lt(rsq30,rcutoff2))
1297 r30 = _mm_mul_ps(rsq30,rinv30);
1298 r30 = _mm_andnot_ps(dummy_mask,r30);
1300 /* Compute parameters for interactions between i and j atoms */
1301 qq30 = _mm_mul_ps(iq3,jq0);
1303 /* EWALD ELECTROSTATICS */
1305 /* Analytical PME correction */
1306 zeta2 = _mm_mul_ps(beta2,rsq30);
1307 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1308 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1309 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1310 felec = _mm_mul_ps(qq30,felec);
1312 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1316 fscal = _mm_and_ps(fscal,cutoff_mask);
1318 fscal = _mm_andnot_ps(dummy_mask,fscal);
1320 /* Update vectorial force */
1321 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1322 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1323 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1325 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1326 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1327 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1331 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1332 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1333 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1334 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1336 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1338 /* Inner loop uses 129 flops */
1341 /* End of innermost loop */
1343 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1344 f+i_coord_offset,fshift+i_shift_offset);
1346 /* Increment number of inner iterations */
1347 inneriter += j_index_end - j_index_start;
1349 /* Outer loop uses 24 flops */
1352 /* Increment number of outer iterations */
1355 /* Update outer/inner flops */
1357 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*129);