2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, 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 avx_128_fma_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_VF_avx_128_fma_single
54 * Electrostatics interaction: Ewald
55 * VdW interaction: LJEwald
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_VF_avx_128_fma_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
92 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
97 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
98 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
99 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
102 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
105 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
106 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
112 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
113 __m128 one_half = _mm_set1_ps(0.5);
114 __m128 minus_one = _mm_set1_ps(-1.0);
116 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
117 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
119 __m128 dummy_mask,cutoff_mask;
120 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
121 __m128 one = _mm_set1_ps(1.0);
122 __m128 two = _mm_set1_ps(2.0);
128 jindex = nlist->jindex;
130 shiftidx = nlist->shift;
132 shiftvec = fr->shift_vec[0];
133 fshift = fr->fshift[0];
134 facel = _mm_set1_ps(fr->epsfac);
135 charge = mdatoms->chargeA;
136 nvdwtype = fr->ntype;
138 vdwtype = mdatoms->typeA;
139 vdwgridparam = fr->ljpme_c6grid;
140 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
141 ewclj = _mm_set1_ps(fr->ewaldcoeff_lj);
142 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
144 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
145 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
146 beta2 = _mm_mul_ps(beta,beta);
147 beta3 = _mm_mul_ps(beta,beta2);
148 ewtab = fr->ic->tabq_coul_FDV0;
149 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
150 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
152 /* Setup water-specific parameters */
153 inr = nlist->iinr[0];
154 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
155 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
156 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
157 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
159 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
160 rcutoff_scalar = fr->rcoulomb;
161 rcutoff = _mm_set1_ps(rcutoff_scalar);
162 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
164 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
165 rvdw = _mm_set1_ps(fr->rvdw);
167 /* Avoid stupid compiler warnings */
168 jnrA = jnrB = jnrC = jnrD = 0;
177 for(iidx=0;iidx<4*DIM;iidx++)
182 /* Start outer loop over neighborlists */
183 for(iidx=0; iidx<nri; iidx++)
185 /* Load shift vector for this list */
186 i_shift_offset = DIM*shiftidx[iidx];
188 /* Load limits for loop over neighbors */
189 j_index_start = jindex[iidx];
190 j_index_end = jindex[iidx+1];
192 /* Get outer coordinate index */
194 i_coord_offset = DIM*inr;
196 /* Load i particle coords and add shift vector */
197 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
198 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
200 fix0 = _mm_setzero_ps();
201 fiy0 = _mm_setzero_ps();
202 fiz0 = _mm_setzero_ps();
203 fix1 = _mm_setzero_ps();
204 fiy1 = _mm_setzero_ps();
205 fiz1 = _mm_setzero_ps();
206 fix2 = _mm_setzero_ps();
207 fiy2 = _mm_setzero_ps();
208 fiz2 = _mm_setzero_ps();
209 fix3 = _mm_setzero_ps();
210 fiy3 = _mm_setzero_ps();
211 fiz3 = _mm_setzero_ps();
213 /* Reset potential sums */
214 velecsum = _mm_setzero_ps();
215 vvdwsum = _mm_setzero_ps();
217 /* Start inner kernel loop */
218 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
221 /* Get j neighbor index, and coordinate index */
226 j_coord_offsetA = DIM*jnrA;
227 j_coord_offsetB = DIM*jnrB;
228 j_coord_offsetC = DIM*jnrC;
229 j_coord_offsetD = DIM*jnrD;
231 /* load j atom coordinates */
232 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
233 x+j_coord_offsetC,x+j_coord_offsetD,
236 /* Calculate displacement vector */
237 dx00 = _mm_sub_ps(ix0,jx0);
238 dy00 = _mm_sub_ps(iy0,jy0);
239 dz00 = _mm_sub_ps(iz0,jz0);
240 dx10 = _mm_sub_ps(ix1,jx0);
241 dy10 = _mm_sub_ps(iy1,jy0);
242 dz10 = _mm_sub_ps(iz1,jz0);
243 dx20 = _mm_sub_ps(ix2,jx0);
244 dy20 = _mm_sub_ps(iy2,jy0);
245 dz20 = _mm_sub_ps(iz2,jz0);
246 dx30 = _mm_sub_ps(ix3,jx0);
247 dy30 = _mm_sub_ps(iy3,jy0);
248 dz30 = _mm_sub_ps(iz3,jz0);
250 /* Calculate squared distance and things based on it */
251 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
252 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
253 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
254 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
256 rinv00 = gmx_mm_invsqrt_ps(rsq00);
257 rinv10 = gmx_mm_invsqrt_ps(rsq10);
258 rinv20 = gmx_mm_invsqrt_ps(rsq20);
259 rinv30 = gmx_mm_invsqrt_ps(rsq30);
261 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
262 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
263 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
264 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
266 /* Load parameters for j particles */
267 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
268 charge+jnrC+0,charge+jnrD+0);
269 vdwjidx0A = 2*vdwtype[jnrA+0];
270 vdwjidx0B = 2*vdwtype[jnrB+0];
271 vdwjidx0C = 2*vdwtype[jnrC+0];
272 vdwjidx0D = 2*vdwtype[jnrD+0];
274 fjx0 = _mm_setzero_ps();
275 fjy0 = _mm_setzero_ps();
276 fjz0 = _mm_setzero_ps();
278 /**************************
279 * CALCULATE INTERACTIONS *
280 **************************/
282 if (gmx_mm_any_lt(rsq00,rcutoff2))
285 r00 = _mm_mul_ps(rsq00,rinv00);
287 /* Compute parameters for interactions between i and j atoms */
288 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
289 vdwparam+vdwioffset0+vdwjidx0B,
290 vdwparam+vdwioffset0+vdwjidx0C,
291 vdwparam+vdwioffset0+vdwjidx0D,
294 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
295 vdwgridparam+vdwioffset0+vdwjidx0B,
296 vdwgridparam+vdwioffset0+vdwjidx0C,
297 vdwgridparam+vdwioffset0+vdwjidx0D);
299 /* Analytical LJ-PME */
300 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
301 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
302 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
303 exponent = gmx_simd_exp_r(ewcljrsq);
304 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
305 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
306 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
307 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
308 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
309 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
310 _mm_mul_ps(_mm_sub_ps(vvdw6,_mm_macc_ps(c6grid_00,sh_lj_ewald,_mm_mul_ps(c6_00,sh_vdw_invrcut6))),one_sixth));
311 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
312 fvdw = _mm_mul_ps(_mm_add_ps(vvdw12,_mm_msub_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6),vvdw6)),rinvsq00);
314 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
316 /* Update potential sum for this i atom from the interaction with this j atom. */
317 vvdw = _mm_and_ps(vvdw,cutoff_mask);
318 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
322 fscal = _mm_and_ps(fscal,cutoff_mask);
324 /* Update vectorial force */
325 fix0 = _mm_macc_ps(dx00,fscal,fix0);
326 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
327 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
329 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
330 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
331 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
335 /**************************
336 * CALCULATE INTERACTIONS *
337 **************************/
339 if (gmx_mm_any_lt(rsq10,rcutoff2))
342 r10 = _mm_mul_ps(rsq10,rinv10);
344 /* Compute parameters for interactions between i and j atoms */
345 qq10 = _mm_mul_ps(iq1,jq0);
347 /* EWALD ELECTROSTATICS */
349 /* Analytical PME correction */
350 zeta2 = _mm_mul_ps(beta2,rsq10);
351 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
352 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
353 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
354 felec = _mm_mul_ps(qq10,felec);
355 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
356 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
357 velec = _mm_mul_ps(qq10,velec);
359 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
361 /* Update potential sum for this i atom from the interaction with this j atom. */
362 velec = _mm_and_ps(velec,cutoff_mask);
363 velecsum = _mm_add_ps(velecsum,velec);
367 fscal = _mm_and_ps(fscal,cutoff_mask);
369 /* Update vectorial force */
370 fix1 = _mm_macc_ps(dx10,fscal,fix1);
371 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
372 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
374 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
375 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
376 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
380 /**************************
381 * CALCULATE INTERACTIONS *
382 **************************/
384 if (gmx_mm_any_lt(rsq20,rcutoff2))
387 r20 = _mm_mul_ps(rsq20,rinv20);
389 /* Compute parameters for interactions between i and j atoms */
390 qq20 = _mm_mul_ps(iq2,jq0);
392 /* EWALD ELECTROSTATICS */
394 /* Analytical PME correction */
395 zeta2 = _mm_mul_ps(beta2,rsq20);
396 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
397 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
398 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
399 felec = _mm_mul_ps(qq20,felec);
400 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
401 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
402 velec = _mm_mul_ps(qq20,velec);
404 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
406 /* Update potential sum for this i atom from the interaction with this j atom. */
407 velec = _mm_and_ps(velec,cutoff_mask);
408 velecsum = _mm_add_ps(velecsum,velec);
412 fscal = _mm_and_ps(fscal,cutoff_mask);
414 /* Update vectorial force */
415 fix2 = _mm_macc_ps(dx20,fscal,fix2);
416 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
417 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
419 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
420 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
421 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
425 /**************************
426 * CALCULATE INTERACTIONS *
427 **************************/
429 if (gmx_mm_any_lt(rsq30,rcutoff2))
432 r30 = _mm_mul_ps(rsq30,rinv30);
434 /* Compute parameters for interactions between i and j atoms */
435 qq30 = _mm_mul_ps(iq3,jq0);
437 /* EWALD ELECTROSTATICS */
439 /* Analytical PME correction */
440 zeta2 = _mm_mul_ps(beta2,rsq30);
441 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
442 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
443 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
444 felec = _mm_mul_ps(qq30,felec);
445 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
446 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
447 velec = _mm_mul_ps(qq30,velec);
449 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
451 /* Update potential sum for this i atom from the interaction with this j atom. */
452 velec = _mm_and_ps(velec,cutoff_mask);
453 velecsum = _mm_add_ps(velecsum,velec);
457 fscal = _mm_and_ps(fscal,cutoff_mask);
459 /* Update vectorial force */
460 fix3 = _mm_macc_ps(dx30,fscal,fix3);
461 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
462 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
464 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
465 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
466 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
470 fjptrA = f+j_coord_offsetA;
471 fjptrB = f+j_coord_offsetB;
472 fjptrC = f+j_coord_offsetC;
473 fjptrD = f+j_coord_offsetD;
475 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
477 /* Inner loop uses 158 flops */
483 /* Get j neighbor index, and coordinate index */
484 jnrlistA = jjnr[jidx];
485 jnrlistB = jjnr[jidx+1];
486 jnrlistC = jjnr[jidx+2];
487 jnrlistD = jjnr[jidx+3];
488 /* Sign of each element will be negative for non-real atoms.
489 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
490 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
492 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
493 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
494 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
495 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
496 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
497 j_coord_offsetA = DIM*jnrA;
498 j_coord_offsetB = DIM*jnrB;
499 j_coord_offsetC = DIM*jnrC;
500 j_coord_offsetD = DIM*jnrD;
502 /* load j atom coordinates */
503 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
504 x+j_coord_offsetC,x+j_coord_offsetD,
507 /* Calculate displacement vector */
508 dx00 = _mm_sub_ps(ix0,jx0);
509 dy00 = _mm_sub_ps(iy0,jy0);
510 dz00 = _mm_sub_ps(iz0,jz0);
511 dx10 = _mm_sub_ps(ix1,jx0);
512 dy10 = _mm_sub_ps(iy1,jy0);
513 dz10 = _mm_sub_ps(iz1,jz0);
514 dx20 = _mm_sub_ps(ix2,jx0);
515 dy20 = _mm_sub_ps(iy2,jy0);
516 dz20 = _mm_sub_ps(iz2,jz0);
517 dx30 = _mm_sub_ps(ix3,jx0);
518 dy30 = _mm_sub_ps(iy3,jy0);
519 dz30 = _mm_sub_ps(iz3,jz0);
521 /* Calculate squared distance and things based on it */
522 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
523 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
524 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
525 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
527 rinv00 = gmx_mm_invsqrt_ps(rsq00);
528 rinv10 = gmx_mm_invsqrt_ps(rsq10);
529 rinv20 = gmx_mm_invsqrt_ps(rsq20);
530 rinv30 = gmx_mm_invsqrt_ps(rsq30);
532 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
533 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
534 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
535 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
537 /* Load parameters for j particles */
538 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
539 charge+jnrC+0,charge+jnrD+0);
540 vdwjidx0A = 2*vdwtype[jnrA+0];
541 vdwjidx0B = 2*vdwtype[jnrB+0];
542 vdwjidx0C = 2*vdwtype[jnrC+0];
543 vdwjidx0D = 2*vdwtype[jnrD+0];
545 fjx0 = _mm_setzero_ps();
546 fjy0 = _mm_setzero_ps();
547 fjz0 = _mm_setzero_ps();
549 /**************************
550 * CALCULATE INTERACTIONS *
551 **************************/
553 if (gmx_mm_any_lt(rsq00,rcutoff2))
556 r00 = _mm_mul_ps(rsq00,rinv00);
557 r00 = _mm_andnot_ps(dummy_mask,r00);
559 /* Compute parameters for interactions between i and j atoms */
560 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
561 vdwparam+vdwioffset0+vdwjidx0B,
562 vdwparam+vdwioffset0+vdwjidx0C,
563 vdwparam+vdwioffset0+vdwjidx0D,
566 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
567 vdwgridparam+vdwioffset0+vdwjidx0B,
568 vdwgridparam+vdwioffset0+vdwjidx0C,
569 vdwgridparam+vdwioffset0+vdwjidx0D);
571 /* Analytical LJ-PME */
572 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
573 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
574 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
575 exponent = gmx_simd_exp_r(ewcljrsq);
576 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
577 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
578 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
579 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
580 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
581 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
582 _mm_mul_ps(_mm_sub_ps(vvdw6,_mm_macc_ps(c6grid_00,sh_lj_ewald,_mm_mul_ps(c6_00,sh_vdw_invrcut6))),one_sixth));
583 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
584 fvdw = _mm_mul_ps(_mm_add_ps(vvdw12,_mm_msub_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6),vvdw6)),rinvsq00);
586 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
588 /* Update potential sum for this i atom from the interaction with this j atom. */
589 vvdw = _mm_and_ps(vvdw,cutoff_mask);
590 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
591 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
595 fscal = _mm_and_ps(fscal,cutoff_mask);
597 fscal = _mm_andnot_ps(dummy_mask,fscal);
599 /* Update vectorial force */
600 fix0 = _mm_macc_ps(dx00,fscal,fix0);
601 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
602 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
604 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
605 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
606 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
610 /**************************
611 * CALCULATE INTERACTIONS *
612 **************************/
614 if (gmx_mm_any_lt(rsq10,rcutoff2))
617 r10 = _mm_mul_ps(rsq10,rinv10);
618 r10 = _mm_andnot_ps(dummy_mask,r10);
620 /* Compute parameters for interactions between i and j atoms */
621 qq10 = _mm_mul_ps(iq1,jq0);
623 /* EWALD ELECTROSTATICS */
625 /* Analytical PME correction */
626 zeta2 = _mm_mul_ps(beta2,rsq10);
627 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
628 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
629 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
630 felec = _mm_mul_ps(qq10,felec);
631 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
632 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
633 velec = _mm_mul_ps(qq10,velec);
635 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
637 /* Update potential sum for this i atom from the interaction with this j atom. */
638 velec = _mm_and_ps(velec,cutoff_mask);
639 velec = _mm_andnot_ps(dummy_mask,velec);
640 velecsum = _mm_add_ps(velecsum,velec);
644 fscal = _mm_and_ps(fscal,cutoff_mask);
646 fscal = _mm_andnot_ps(dummy_mask,fscal);
648 /* Update vectorial force */
649 fix1 = _mm_macc_ps(dx10,fscal,fix1);
650 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
651 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
653 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
654 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
655 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
659 /**************************
660 * CALCULATE INTERACTIONS *
661 **************************/
663 if (gmx_mm_any_lt(rsq20,rcutoff2))
666 r20 = _mm_mul_ps(rsq20,rinv20);
667 r20 = _mm_andnot_ps(dummy_mask,r20);
669 /* Compute parameters for interactions between i and j atoms */
670 qq20 = _mm_mul_ps(iq2,jq0);
672 /* EWALD ELECTROSTATICS */
674 /* Analytical PME correction */
675 zeta2 = _mm_mul_ps(beta2,rsq20);
676 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
677 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
678 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
679 felec = _mm_mul_ps(qq20,felec);
680 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
681 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
682 velec = _mm_mul_ps(qq20,velec);
684 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
686 /* Update potential sum for this i atom from the interaction with this j atom. */
687 velec = _mm_and_ps(velec,cutoff_mask);
688 velec = _mm_andnot_ps(dummy_mask,velec);
689 velecsum = _mm_add_ps(velecsum,velec);
693 fscal = _mm_and_ps(fscal,cutoff_mask);
695 fscal = _mm_andnot_ps(dummy_mask,fscal);
697 /* Update vectorial force */
698 fix2 = _mm_macc_ps(dx20,fscal,fix2);
699 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
700 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
702 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
703 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
704 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
708 /**************************
709 * CALCULATE INTERACTIONS *
710 **************************/
712 if (gmx_mm_any_lt(rsq30,rcutoff2))
715 r30 = _mm_mul_ps(rsq30,rinv30);
716 r30 = _mm_andnot_ps(dummy_mask,r30);
718 /* Compute parameters for interactions between i and j atoms */
719 qq30 = _mm_mul_ps(iq3,jq0);
721 /* EWALD ELECTROSTATICS */
723 /* Analytical PME correction */
724 zeta2 = _mm_mul_ps(beta2,rsq30);
725 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
726 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
727 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
728 felec = _mm_mul_ps(qq30,felec);
729 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
730 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
731 velec = _mm_mul_ps(qq30,velec);
733 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
735 /* Update potential sum for this i atom from the interaction with this j atom. */
736 velec = _mm_and_ps(velec,cutoff_mask);
737 velec = _mm_andnot_ps(dummy_mask,velec);
738 velecsum = _mm_add_ps(velecsum,velec);
742 fscal = _mm_and_ps(fscal,cutoff_mask);
744 fscal = _mm_andnot_ps(dummy_mask,fscal);
746 /* Update vectorial force */
747 fix3 = _mm_macc_ps(dx30,fscal,fix3);
748 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
749 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
751 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
752 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
753 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
757 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
758 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
759 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
760 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
762 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
764 /* Inner loop uses 162 flops */
767 /* End of innermost loop */
769 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
770 f+i_coord_offset,fshift+i_shift_offset);
773 /* Update potential energies */
774 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
775 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
777 /* Increment number of inner iterations */
778 inneriter += j_index_end - j_index_start;
780 /* Outer loop uses 26 flops */
783 /* Increment number of outer iterations */
786 /* Update outer/inner flops */
788 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*162);
791 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_F_avx_128_fma_single
792 * Electrostatics interaction: Ewald
793 * VdW interaction: LJEwald
794 * Geometry: Water4-Particle
795 * Calculate force/pot: Force
798 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_F_avx_128_fma_single
799 (t_nblist * gmx_restrict nlist,
800 rvec * gmx_restrict xx,
801 rvec * gmx_restrict ff,
802 t_forcerec * gmx_restrict fr,
803 t_mdatoms * gmx_restrict mdatoms,
804 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
805 t_nrnb * gmx_restrict nrnb)
807 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
808 * just 0 for non-waters.
809 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
810 * jnr indices corresponding to data put in the four positions in the SIMD register.
812 int i_shift_offset,i_coord_offset,outeriter,inneriter;
813 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
814 int jnrA,jnrB,jnrC,jnrD;
815 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
816 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
817 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
819 real *shiftvec,*fshift,*x,*f;
820 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
822 __m128 fscal,rcutoff,rcutoff2,jidxall;
824 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
826 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
828 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
830 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
831 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
832 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
833 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
834 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
835 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
836 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
837 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
840 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
843 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
844 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
850 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
851 __m128 one_half = _mm_set1_ps(0.5);
852 __m128 minus_one = _mm_set1_ps(-1.0);
854 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
855 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
857 __m128 dummy_mask,cutoff_mask;
858 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
859 __m128 one = _mm_set1_ps(1.0);
860 __m128 two = _mm_set1_ps(2.0);
866 jindex = nlist->jindex;
868 shiftidx = nlist->shift;
870 shiftvec = fr->shift_vec[0];
871 fshift = fr->fshift[0];
872 facel = _mm_set1_ps(fr->epsfac);
873 charge = mdatoms->chargeA;
874 nvdwtype = fr->ntype;
876 vdwtype = mdatoms->typeA;
877 vdwgridparam = fr->ljpme_c6grid;
878 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
879 ewclj = _mm_set1_ps(fr->ewaldcoeff_lj);
880 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
882 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
883 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
884 beta2 = _mm_mul_ps(beta,beta);
885 beta3 = _mm_mul_ps(beta,beta2);
886 ewtab = fr->ic->tabq_coul_F;
887 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
888 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
890 /* Setup water-specific parameters */
891 inr = nlist->iinr[0];
892 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
893 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
894 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
895 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
897 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
898 rcutoff_scalar = fr->rcoulomb;
899 rcutoff = _mm_set1_ps(rcutoff_scalar);
900 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
902 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
903 rvdw = _mm_set1_ps(fr->rvdw);
905 /* Avoid stupid compiler warnings */
906 jnrA = jnrB = jnrC = jnrD = 0;
915 for(iidx=0;iidx<4*DIM;iidx++)
920 /* Start outer loop over neighborlists */
921 for(iidx=0; iidx<nri; iidx++)
923 /* Load shift vector for this list */
924 i_shift_offset = DIM*shiftidx[iidx];
926 /* Load limits for loop over neighbors */
927 j_index_start = jindex[iidx];
928 j_index_end = jindex[iidx+1];
930 /* Get outer coordinate index */
932 i_coord_offset = DIM*inr;
934 /* Load i particle coords and add shift vector */
935 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
936 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
938 fix0 = _mm_setzero_ps();
939 fiy0 = _mm_setzero_ps();
940 fiz0 = _mm_setzero_ps();
941 fix1 = _mm_setzero_ps();
942 fiy1 = _mm_setzero_ps();
943 fiz1 = _mm_setzero_ps();
944 fix2 = _mm_setzero_ps();
945 fiy2 = _mm_setzero_ps();
946 fiz2 = _mm_setzero_ps();
947 fix3 = _mm_setzero_ps();
948 fiy3 = _mm_setzero_ps();
949 fiz3 = _mm_setzero_ps();
951 /* Start inner kernel loop */
952 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
955 /* Get j neighbor index, and coordinate index */
960 j_coord_offsetA = DIM*jnrA;
961 j_coord_offsetB = DIM*jnrB;
962 j_coord_offsetC = DIM*jnrC;
963 j_coord_offsetD = DIM*jnrD;
965 /* load j atom coordinates */
966 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
967 x+j_coord_offsetC,x+j_coord_offsetD,
970 /* Calculate displacement vector */
971 dx00 = _mm_sub_ps(ix0,jx0);
972 dy00 = _mm_sub_ps(iy0,jy0);
973 dz00 = _mm_sub_ps(iz0,jz0);
974 dx10 = _mm_sub_ps(ix1,jx0);
975 dy10 = _mm_sub_ps(iy1,jy0);
976 dz10 = _mm_sub_ps(iz1,jz0);
977 dx20 = _mm_sub_ps(ix2,jx0);
978 dy20 = _mm_sub_ps(iy2,jy0);
979 dz20 = _mm_sub_ps(iz2,jz0);
980 dx30 = _mm_sub_ps(ix3,jx0);
981 dy30 = _mm_sub_ps(iy3,jy0);
982 dz30 = _mm_sub_ps(iz3,jz0);
984 /* Calculate squared distance and things based on it */
985 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
986 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
987 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
988 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
990 rinv00 = gmx_mm_invsqrt_ps(rsq00);
991 rinv10 = gmx_mm_invsqrt_ps(rsq10);
992 rinv20 = gmx_mm_invsqrt_ps(rsq20);
993 rinv30 = gmx_mm_invsqrt_ps(rsq30);
995 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
996 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
997 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
998 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1000 /* Load parameters for j particles */
1001 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1002 charge+jnrC+0,charge+jnrD+0);
1003 vdwjidx0A = 2*vdwtype[jnrA+0];
1004 vdwjidx0B = 2*vdwtype[jnrB+0];
1005 vdwjidx0C = 2*vdwtype[jnrC+0];
1006 vdwjidx0D = 2*vdwtype[jnrD+0];
1008 fjx0 = _mm_setzero_ps();
1009 fjy0 = _mm_setzero_ps();
1010 fjz0 = _mm_setzero_ps();
1012 /**************************
1013 * CALCULATE INTERACTIONS *
1014 **************************/
1016 if (gmx_mm_any_lt(rsq00,rcutoff2))
1019 r00 = _mm_mul_ps(rsq00,rinv00);
1021 /* Compute parameters for interactions between i and j atoms */
1022 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1023 vdwparam+vdwioffset0+vdwjidx0B,
1024 vdwparam+vdwioffset0+vdwjidx0C,
1025 vdwparam+vdwioffset0+vdwjidx0D,
1028 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
1029 vdwgridparam+vdwioffset0+vdwjidx0B,
1030 vdwgridparam+vdwioffset0+vdwjidx0C,
1031 vdwgridparam+vdwioffset0+vdwjidx0D);
1033 /* Analytical LJ-PME */
1034 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1035 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
1036 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
1037 exponent = gmx_simd_exp_r(ewcljrsq);
1038 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
1039 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
1040 /* f6A = 6 * C6grid * (1 - poly) */
1041 f6A = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
1042 /* f6B = C6grid * exponent * beta^6 */
1043 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
1044 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
1045 fvdw = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
1047 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1051 fscal = _mm_and_ps(fscal,cutoff_mask);
1053 /* Update vectorial force */
1054 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1055 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1056 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1058 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1059 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1060 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1064 /**************************
1065 * CALCULATE INTERACTIONS *
1066 **************************/
1068 if (gmx_mm_any_lt(rsq10,rcutoff2))
1071 r10 = _mm_mul_ps(rsq10,rinv10);
1073 /* Compute parameters for interactions between i and j atoms */
1074 qq10 = _mm_mul_ps(iq1,jq0);
1076 /* EWALD ELECTROSTATICS */
1078 /* Analytical PME correction */
1079 zeta2 = _mm_mul_ps(beta2,rsq10);
1080 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1081 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1082 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1083 felec = _mm_mul_ps(qq10,felec);
1085 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1089 fscal = _mm_and_ps(fscal,cutoff_mask);
1091 /* Update vectorial force */
1092 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1093 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1094 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1096 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1097 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1098 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1102 /**************************
1103 * CALCULATE INTERACTIONS *
1104 **************************/
1106 if (gmx_mm_any_lt(rsq20,rcutoff2))
1109 r20 = _mm_mul_ps(rsq20,rinv20);
1111 /* Compute parameters for interactions between i and j atoms */
1112 qq20 = _mm_mul_ps(iq2,jq0);
1114 /* EWALD ELECTROSTATICS */
1116 /* Analytical PME correction */
1117 zeta2 = _mm_mul_ps(beta2,rsq20);
1118 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1119 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1120 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1121 felec = _mm_mul_ps(qq20,felec);
1123 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1127 fscal = _mm_and_ps(fscal,cutoff_mask);
1129 /* Update vectorial force */
1130 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1131 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1132 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1134 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1135 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1136 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1140 /**************************
1141 * CALCULATE INTERACTIONS *
1142 **************************/
1144 if (gmx_mm_any_lt(rsq30,rcutoff2))
1147 r30 = _mm_mul_ps(rsq30,rinv30);
1149 /* Compute parameters for interactions between i and j atoms */
1150 qq30 = _mm_mul_ps(iq3,jq0);
1152 /* EWALD ELECTROSTATICS */
1154 /* Analytical PME correction */
1155 zeta2 = _mm_mul_ps(beta2,rsq30);
1156 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1157 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1158 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1159 felec = _mm_mul_ps(qq30,felec);
1161 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1165 fscal = _mm_and_ps(fscal,cutoff_mask);
1167 /* Update vectorial force */
1168 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1169 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1170 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1172 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1173 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1174 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1178 fjptrA = f+j_coord_offsetA;
1179 fjptrB = f+j_coord_offsetB;
1180 fjptrC = f+j_coord_offsetC;
1181 fjptrD = f+j_coord_offsetD;
1183 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1185 /* Inner loop uses 143 flops */
1188 if(jidx<j_index_end)
1191 /* Get j neighbor index, and coordinate index */
1192 jnrlistA = jjnr[jidx];
1193 jnrlistB = jjnr[jidx+1];
1194 jnrlistC = jjnr[jidx+2];
1195 jnrlistD = jjnr[jidx+3];
1196 /* Sign of each element will be negative for non-real atoms.
1197 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1198 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1200 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1201 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1202 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1203 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1204 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1205 j_coord_offsetA = DIM*jnrA;
1206 j_coord_offsetB = DIM*jnrB;
1207 j_coord_offsetC = DIM*jnrC;
1208 j_coord_offsetD = DIM*jnrD;
1210 /* load j atom coordinates */
1211 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1212 x+j_coord_offsetC,x+j_coord_offsetD,
1215 /* Calculate displacement vector */
1216 dx00 = _mm_sub_ps(ix0,jx0);
1217 dy00 = _mm_sub_ps(iy0,jy0);
1218 dz00 = _mm_sub_ps(iz0,jz0);
1219 dx10 = _mm_sub_ps(ix1,jx0);
1220 dy10 = _mm_sub_ps(iy1,jy0);
1221 dz10 = _mm_sub_ps(iz1,jz0);
1222 dx20 = _mm_sub_ps(ix2,jx0);
1223 dy20 = _mm_sub_ps(iy2,jy0);
1224 dz20 = _mm_sub_ps(iz2,jz0);
1225 dx30 = _mm_sub_ps(ix3,jx0);
1226 dy30 = _mm_sub_ps(iy3,jy0);
1227 dz30 = _mm_sub_ps(iz3,jz0);
1229 /* Calculate squared distance and things based on it */
1230 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1231 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1232 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1233 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1235 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1236 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1237 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1238 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1240 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1241 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1242 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1243 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1245 /* Load parameters for j particles */
1246 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1247 charge+jnrC+0,charge+jnrD+0);
1248 vdwjidx0A = 2*vdwtype[jnrA+0];
1249 vdwjidx0B = 2*vdwtype[jnrB+0];
1250 vdwjidx0C = 2*vdwtype[jnrC+0];
1251 vdwjidx0D = 2*vdwtype[jnrD+0];
1253 fjx0 = _mm_setzero_ps();
1254 fjy0 = _mm_setzero_ps();
1255 fjz0 = _mm_setzero_ps();
1257 /**************************
1258 * CALCULATE INTERACTIONS *
1259 **************************/
1261 if (gmx_mm_any_lt(rsq00,rcutoff2))
1264 r00 = _mm_mul_ps(rsq00,rinv00);
1265 r00 = _mm_andnot_ps(dummy_mask,r00);
1267 /* Compute parameters for interactions between i and j atoms */
1268 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1269 vdwparam+vdwioffset0+vdwjidx0B,
1270 vdwparam+vdwioffset0+vdwjidx0C,
1271 vdwparam+vdwioffset0+vdwjidx0D,
1274 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
1275 vdwgridparam+vdwioffset0+vdwjidx0B,
1276 vdwgridparam+vdwioffset0+vdwjidx0C,
1277 vdwgridparam+vdwioffset0+vdwjidx0D);
1279 /* Analytical LJ-PME */
1280 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1281 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
1282 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
1283 exponent = gmx_simd_exp_r(ewcljrsq);
1284 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
1285 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
1286 /* f6A = 6 * C6grid * (1 - poly) */
1287 f6A = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
1288 /* f6B = C6grid * exponent * beta^6 */
1289 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
1290 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
1291 fvdw = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
1293 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1297 fscal = _mm_and_ps(fscal,cutoff_mask);
1299 fscal = _mm_andnot_ps(dummy_mask,fscal);
1301 /* Update vectorial force */
1302 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1303 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1304 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1306 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1307 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1308 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1312 /**************************
1313 * CALCULATE INTERACTIONS *
1314 **************************/
1316 if (gmx_mm_any_lt(rsq10,rcutoff2))
1319 r10 = _mm_mul_ps(rsq10,rinv10);
1320 r10 = _mm_andnot_ps(dummy_mask,r10);
1322 /* Compute parameters for interactions between i and j atoms */
1323 qq10 = _mm_mul_ps(iq1,jq0);
1325 /* EWALD ELECTROSTATICS */
1327 /* Analytical PME correction */
1328 zeta2 = _mm_mul_ps(beta2,rsq10);
1329 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1330 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1331 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1332 felec = _mm_mul_ps(qq10,felec);
1334 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1338 fscal = _mm_and_ps(fscal,cutoff_mask);
1340 fscal = _mm_andnot_ps(dummy_mask,fscal);
1342 /* Update vectorial force */
1343 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1344 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1345 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1347 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1348 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1349 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1353 /**************************
1354 * CALCULATE INTERACTIONS *
1355 **************************/
1357 if (gmx_mm_any_lt(rsq20,rcutoff2))
1360 r20 = _mm_mul_ps(rsq20,rinv20);
1361 r20 = _mm_andnot_ps(dummy_mask,r20);
1363 /* Compute parameters for interactions between i and j atoms */
1364 qq20 = _mm_mul_ps(iq2,jq0);
1366 /* EWALD ELECTROSTATICS */
1368 /* Analytical PME correction */
1369 zeta2 = _mm_mul_ps(beta2,rsq20);
1370 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1371 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1372 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1373 felec = _mm_mul_ps(qq20,felec);
1375 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1379 fscal = _mm_and_ps(fscal,cutoff_mask);
1381 fscal = _mm_andnot_ps(dummy_mask,fscal);
1383 /* Update vectorial force */
1384 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1385 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1386 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1388 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1389 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1390 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1394 /**************************
1395 * CALCULATE INTERACTIONS *
1396 **************************/
1398 if (gmx_mm_any_lt(rsq30,rcutoff2))
1401 r30 = _mm_mul_ps(rsq30,rinv30);
1402 r30 = _mm_andnot_ps(dummy_mask,r30);
1404 /* Compute parameters for interactions between i and j atoms */
1405 qq30 = _mm_mul_ps(iq3,jq0);
1407 /* EWALD ELECTROSTATICS */
1409 /* Analytical PME correction */
1410 zeta2 = _mm_mul_ps(beta2,rsq30);
1411 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1412 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1413 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1414 felec = _mm_mul_ps(qq30,felec);
1416 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1420 fscal = _mm_and_ps(fscal,cutoff_mask);
1422 fscal = _mm_andnot_ps(dummy_mask,fscal);
1424 /* Update vectorial force */
1425 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1426 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1427 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1429 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1430 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1431 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1435 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1436 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1437 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1438 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1440 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1442 /* Inner loop uses 147 flops */
1445 /* End of innermost loop */
1447 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1448 f+i_coord_offset,fshift+i_shift_offset);
1450 /* Increment number of inner iterations */
1451 inneriter += j_index_end - j_index_start;
1453 /* Outer loop uses 24 flops */
1456 /* Increment number of outer iterations */
1459 /* Update outer/inner flops */
1461 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*147);