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.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_VF_avx_128_fma_single
52 * Electrostatics interaction: Ewald
53 * VdW interaction: LJEwald
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_VF_avx_128_fma_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
94 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
95 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
96 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
97 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
100 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
104 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
110 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
111 __m128 one_half = _mm_set1_ps(0.5);
112 __m128 minus_one = _mm_set1_ps(-1.0);
114 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
115 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
117 __m128 dummy_mask,cutoff_mask;
118 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
119 __m128 one = _mm_set1_ps(1.0);
120 __m128 two = _mm_set1_ps(2.0);
126 jindex = nlist->jindex;
128 shiftidx = nlist->shift;
130 shiftvec = fr->shift_vec[0];
131 fshift = fr->fshift[0];
132 facel = _mm_set1_ps(fr->epsfac);
133 charge = mdatoms->chargeA;
134 nvdwtype = fr->ntype;
136 vdwtype = mdatoms->typeA;
137 vdwgridparam = fr->ljpme_c6grid;
138 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
139 ewclj = _mm_set1_ps(fr->ewaldcoeff_lj);
140 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
142 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
143 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
144 beta2 = _mm_mul_ps(beta,beta);
145 beta3 = _mm_mul_ps(beta,beta2);
146 ewtab = fr->ic->tabq_coul_FDV0;
147 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
148 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
150 /* Setup water-specific parameters */
151 inr = nlist->iinr[0];
152 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
153 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
154 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
155 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
157 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
158 rcutoff_scalar = fr->rcoulomb;
159 rcutoff = _mm_set1_ps(rcutoff_scalar);
160 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
162 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
163 rvdw = _mm_set1_ps(fr->rvdw);
165 /* Avoid stupid compiler warnings */
166 jnrA = jnrB = jnrC = jnrD = 0;
175 for(iidx=0;iidx<4*DIM;iidx++)
180 /* Start outer loop over neighborlists */
181 for(iidx=0; iidx<nri; iidx++)
183 /* Load shift vector for this list */
184 i_shift_offset = DIM*shiftidx[iidx];
186 /* Load limits for loop over neighbors */
187 j_index_start = jindex[iidx];
188 j_index_end = jindex[iidx+1];
190 /* Get outer coordinate index */
192 i_coord_offset = DIM*inr;
194 /* Load i particle coords and add shift vector */
195 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
196 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
198 fix0 = _mm_setzero_ps();
199 fiy0 = _mm_setzero_ps();
200 fiz0 = _mm_setzero_ps();
201 fix1 = _mm_setzero_ps();
202 fiy1 = _mm_setzero_ps();
203 fiz1 = _mm_setzero_ps();
204 fix2 = _mm_setzero_ps();
205 fiy2 = _mm_setzero_ps();
206 fiz2 = _mm_setzero_ps();
207 fix3 = _mm_setzero_ps();
208 fiy3 = _mm_setzero_ps();
209 fiz3 = _mm_setzero_ps();
211 /* Reset potential sums */
212 velecsum = _mm_setzero_ps();
213 vvdwsum = _mm_setzero_ps();
215 /* Start inner kernel loop */
216 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
219 /* Get j neighbor index, and coordinate index */
224 j_coord_offsetA = DIM*jnrA;
225 j_coord_offsetB = DIM*jnrB;
226 j_coord_offsetC = DIM*jnrC;
227 j_coord_offsetD = DIM*jnrD;
229 /* load j atom coordinates */
230 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
231 x+j_coord_offsetC,x+j_coord_offsetD,
234 /* Calculate displacement vector */
235 dx00 = _mm_sub_ps(ix0,jx0);
236 dy00 = _mm_sub_ps(iy0,jy0);
237 dz00 = _mm_sub_ps(iz0,jz0);
238 dx10 = _mm_sub_ps(ix1,jx0);
239 dy10 = _mm_sub_ps(iy1,jy0);
240 dz10 = _mm_sub_ps(iz1,jz0);
241 dx20 = _mm_sub_ps(ix2,jx0);
242 dy20 = _mm_sub_ps(iy2,jy0);
243 dz20 = _mm_sub_ps(iz2,jz0);
244 dx30 = _mm_sub_ps(ix3,jx0);
245 dy30 = _mm_sub_ps(iy3,jy0);
246 dz30 = _mm_sub_ps(iz3,jz0);
248 /* Calculate squared distance and things based on it */
249 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
250 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
251 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
252 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
254 rinv00 = gmx_mm_invsqrt_ps(rsq00);
255 rinv10 = gmx_mm_invsqrt_ps(rsq10);
256 rinv20 = gmx_mm_invsqrt_ps(rsq20);
257 rinv30 = gmx_mm_invsqrt_ps(rsq30);
259 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
260 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
261 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
262 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
264 /* Load parameters for j particles */
265 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
266 charge+jnrC+0,charge+jnrD+0);
267 vdwjidx0A = 2*vdwtype[jnrA+0];
268 vdwjidx0B = 2*vdwtype[jnrB+0];
269 vdwjidx0C = 2*vdwtype[jnrC+0];
270 vdwjidx0D = 2*vdwtype[jnrD+0];
272 fjx0 = _mm_setzero_ps();
273 fjy0 = _mm_setzero_ps();
274 fjz0 = _mm_setzero_ps();
276 /**************************
277 * CALCULATE INTERACTIONS *
278 **************************/
280 if (gmx_mm_any_lt(rsq00,rcutoff2))
283 r00 = _mm_mul_ps(rsq00,rinv00);
285 /* Compute parameters for interactions between i and j atoms */
286 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
287 vdwparam+vdwioffset0+vdwjidx0B,
288 vdwparam+vdwioffset0+vdwjidx0C,
289 vdwparam+vdwioffset0+vdwjidx0D,
292 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
293 vdwgridparam+vdwioffset0+vdwjidx0B,
294 vdwgridparam+vdwioffset0+vdwjidx0C,
295 vdwgridparam+vdwioffset0+vdwjidx0D);
297 /* Analytical LJ-PME */
298 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
299 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
300 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
301 exponent = gmx_simd_exp_r(ewcljrsq);
302 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
303 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
304 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
305 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
306 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
307 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
308 _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));
309 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
310 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);
312 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
314 /* Update potential sum for this i atom from the interaction with this j atom. */
315 vvdw = _mm_and_ps(vvdw,cutoff_mask);
316 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
320 fscal = _mm_and_ps(fscal,cutoff_mask);
322 /* Update vectorial force */
323 fix0 = _mm_macc_ps(dx00,fscal,fix0);
324 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
325 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
327 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
328 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
329 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
333 /**************************
334 * CALCULATE INTERACTIONS *
335 **************************/
337 if (gmx_mm_any_lt(rsq10,rcutoff2))
340 r10 = _mm_mul_ps(rsq10,rinv10);
342 /* Compute parameters for interactions between i and j atoms */
343 qq10 = _mm_mul_ps(iq1,jq0);
345 /* EWALD ELECTROSTATICS */
347 /* Analytical PME correction */
348 zeta2 = _mm_mul_ps(beta2,rsq10);
349 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
350 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
351 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
352 felec = _mm_mul_ps(qq10,felec);
353 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
354 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
355 velec = _mm_mul_ps(qq10,velec);
357 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
359 /* Update potential sum for this i atom from the interaction with this j atom. */
360 velec = _mm_and_ps(velec,cutoff_mask);
361 velecsum = _mm_add_ps(velecsum,velec);
365 fscal = _mm_and_ps(fscal,cutoff_mask);
367 /* Update vectorial force */
368 fix1 = _mm_macc_ps(dx10,fscal,fix1);
369 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
370 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
372 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
373 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
374 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
378 /**************************
379 * CALCULATE INTERACTIONS *
380 **************************/
382 if (gmx_mm_any_lt(rsq20,rcutoff2))
385 r20 = _mm_mul_ps(rsq20,rinv20);
387 /* Compute parameters for interactions between i and j atoms */
388 qq20 = _mm_mul_ps(iq2,jq0);
390 /* EWALD ELECTROSTATICS */
392 /* Analytical PME correction */
393 zeta2 = _mm_mul_ps(beta2,rsq20);
394 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
395 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
396 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
397 felec = _mm_mul_ps(qq20,felec);
398 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
399 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
400 velec = _mm_mul_ps(qq20,velec);
402 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
404 /* Update potential sum for this i atom from the interaction with this j atom. */
405 velec = _mm_and_ps(velec,cutoff_mask);
406 velecsum = _mm_add_ps(velecsum,velec);
410 fscal = _mm_and_ps(fscal,cutoff_mask);
412 /* Update vectorial force */
413 fix2 = _mm_macc_ps(dx20,fscal,fix2);
414 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
415 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
417 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
418 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
419 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
423 /**************************
424 * CALCULATE INTERACTIONS *
425 **************************/
427 if (gmx_mm_any_lt(rsq30,rcutoff2))
430 r30 = _mm_mul_ps(rsq30,rinv30);
432 /* Compute parameters for interactions between i and j atoms */
433 qq30 = _mm_mul_ps(iq3,jq0);
435 /* EWALD ELECTROSTATICS */
437 /* Analytical PME correction */
438 zeta2 = _mm_mul_ps(beta2,rsq30);
439 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
440 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
441 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
442 felec = _mm_mul_ps(qq30,felec);
443 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
444 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
445 velec = _mm_mul_ps(qq30,velec);
447 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
449 /* Update potential sum for this i atom from the interaction with this j atom. */
450 velec = _mm_and_ps(velec,cutoff_mask);
451 velecsum = _mm_add_ps(velecsum,velec);
455 fscal = _mm_and_ps(fscal,cutoff_mask);
457 /* Update vectorial force */
458 fix3 = _mm_macc_ps(dx30,fscal,fix3);
459 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
460 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
462 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
463 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
464 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
468 fjptrA = f+j_coord_offsetA;
469 fjptrB = f+j_coord_offsetB;
470 fjptrC = f+j_coord_offsetC;
471 fjptrD = f+j_coord_offsetD;
473 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
475 /* Inner loop uses 158 flops */
481 /* Get j neighbor index, and coordinate index */
482 jnrlistA = jjnr[jidx];
483 jnrlistB = jjnr[jidx+1];
484 jnrlistC = jjnr[jidx+2];
485 jnrlistD = jjnr[jidx+3];
486 /* Sign of each element will be negative for non-real atoms.
487 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
488 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
490 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
491 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
492 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
493 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
494 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
495 j_coord_offsetA = DIM*jnrA;
496 j_coord_offsetB = DIM*jnrB;
497 j_coord_offsetC = DIM*jnrC;
498 j_coord_offsetD = DIM*jnrD;
500 /* load j atom coordinates */
501 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
502 x+j_coord_offsetC,x+j_coord_offsetD,
505 /* Calculate displacement vector */
506 dx00 = _mm_sub_ps(ix0,jx0);
507 dy00 = _mm_sub_ps(iy0,jy0);
508 dz00 = _mm_sub_ps(iz0,jz0);
509 dx10 = _mm_sub_ps(ix1,jx0);
510 dy10 = _mm_sub_ps(iy1,jy0);
511 dz10 = _mm_sub_ps(iz1,jz0);
512 dx20 = _mm_sub_ps(ix2,jx0);
513 dy20 = _mm_sub_ps(iy2,jy0);
514 dz20 = _mm_sub_ps(iz2,jz0);
515 dx30 = _mm_sub_ps(ix3,jx0);
516 dy30 = _mm_sub_ps(iy3,jy0);
517 dz30 = _mm_sub_ps(iz3,jz0);
519 /* Calculate squared distance and things based on it */
520 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
521 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
522 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
523 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
525 rinv00 = gmx_mm_invsqrt_ps(rsq00);
526 rinv10 = gmx_mm_invsqrt_ps(rsq10);
527 rinv20 = gmx_mm_invsqrt_ps(rsq20);
528 rinv30 = gmx_mm_invsqrt_ps(rsq30);
530 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
531 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
532 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
533 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
535 /* Load parameters for j particles */
536 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
537 charge+jnrC+0,charge+jnrD+0);
538 vdwjidx0A = 2*vdwtype[jnrA+0];
539 vdwjidx0B = 2*vdwtype[jnrB+0];
540 vdwjidx0C = 2*vdwtype[jnrC+0];
541 vdwjidx0D = 2*vdwtype[jnrD+0];
543 fjx0 = _mm_setzero_ps();
544 fjy0 = _mm_setzero_ps();
545 fjz0 = _mm_setzero_ps();
547 /**************************
548 * CALCULATE INTERACTIONS *
549 **************************/
551 if (gmx_mm_any_lt(rsq00,rcutoff2))
554 r00 = _mm_mul_ps(rsq00,rinv00);
555 r00 = _mm_andnot_ps(dummy_mask,r00);
557 /* Compute parameters for interactions between i and j atoms */
558 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
559 vdwparam+vdwioffset0+vdwjidx0B,
560 vdwparam+vdwioffset0+vdwjidx0C,
561 vdwparam+vdwioffset0+vdwjidx0D,
564 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
565 vdwgridparam+vdwioffset0+vdwjidx0B,
566 vdwgridparam+vdwioffset0+vdwjidx0C,
567 vdwgridparam+vdwioffset0+vdwjidx0D);
569 /* Analytical LJ-PME */
570 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
571 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
572 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
573 exponent = gmx_simd_exp_r(ewcljrsq);
574 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
575 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
576 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
577 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
578 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
579 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
580 _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));
581 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
582 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);
584 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
586 /* Update potential sum for this i atom from the interaction with this j atom. */
587 vvdw = _mm_and_ps(vvdw,cutoff_mask);
588 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
589 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
593 fscal = _mm_and_ps(fscal,cutoff_mask);
595 fscal = _mm_andnot_ps(dummy_mask,fscal);
597 /* Update vectorial force */
598 fix0 = _mm_macc_ps(dx00,fscal,fix0);
599 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
600 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
602 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
603 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
604 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
608 /**************************
609 * CALCULATE INTERACTIONS *
610 **************************/
612 if (gmx_mm_any_lt(rsq10,rcutoff2))
615 r10 = _mm_mul_ps(rsq10,rinv10);
616 r10 = _mm_andnot_ps(dummy_mask,r10);
618 /* Compute parameters for interactions between i and j atoms */
619 qq10 = _mm_mul_ps(iq1,jq0);
621 /* EWALD ELECTROSTATICS */
623 /* Analytical PME correction */
624 zeta2 = _mm_mul_ps(beta2,rsq10);
625 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
626 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
627 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
628 felec = _mm_mul_ps(qq10,felec);
629 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
630 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
631 velec = _mm_mul_ps(qq10,velec);
633 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
635 /* Update potential sum for this i atom from the interaction with this j atom. */
636 velec = _mm_and_ps(velec,cutoff_mask);
637 velec = _mm_andnot_ps(dummy_mask,velec);
638 velecsum = _mm_add_ps(velecsum,velec);
642 fscal = _mm_and_ps(fscal,cutoff_mask);
644 fscal = _mm_andnot_ps(dummy_mask,fscal);
646 /* Update vectorial force */
647 fix1 = _mm_macc_ps(dx10,fscal,fix1);
648 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
649 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
651 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
652 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
653 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
657 /**************************
658 * CALCULATE INTERACTIONS *
659 **************************/
661 if (gmx_mm_any_lt(rsq20,rcutoff2))
664 r20 = _mm_mul_ps(rsq20,rinv20);
665 r20 = _mm_andnot_ps(dummy_mask,r20);
667 /* Compute parameters for interactions between i and j atoms */
668 qq20 = _mm_mul_ps(iq2,jq0);
670 /* EWALD ELECTROSTATICS */
672 /* Analytical PME correction */
673 zeta2 = _mm_mul_ps(beta2,rsq20);
674 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
675 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
676 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
677 felec = _mm_mul_ps(qq20,felec);
678 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
679 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
680 velec = _mm_mul_ps(qq20,velec);
682 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
684 /* Update potential sum for this i atom from the interaction with this j atom. */
685 velec = _mm_and_ps(velec,cutoff_mask);
686 velec = _mm_andnot_ps(dummy_mask,velec);
687 velecsum = _mm_add_ps(velecsum,velec);
691 fscal = _mm_and_ps(fscal,cutoff_mask);
693 fscal = _mm_andnot_ps(dummy_mask,fscal);
695 /* Update vectorial force */
696 fix2 = _mm_macc_ps(dx20,fscal,fix2);
697 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
698 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
700 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
701 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
702 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
706 /**************************
707 * CALCULATE INTERACTIONS *
708 **************************/
710 if (gmx_mm_any_lt(rsq30,rcutoff2))
713 r30 = _mm_mul_ps(rsq30,rinv30);
714 r30 = _mm_andnot_ps(dummy_mask,r30);
716 /* Compute parameters for interactions between i and j atoms */
717 qq30 = _mm_mul_ps(iq3,jq0);
719 /* EWALD ELECTROSTATICS */
721 /* Analytical PME correction */
722 zeta2 = _mm_mul_ps(beta2,rsq30);
723 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
724 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
725 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
726 felec = _mm_mul_ps(qq30,felec);
727 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
728 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
729 velec = _mm_mul_ps(qq30,velec);
731 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
733 /* Update potential sum for this i atom from the interaction with this j atom. */
734 velec = _mm_and_ps(velec,cutoff_mask);
735 velec = _mm_andnot_ps(dummy_mask,velec);
736 velecsum = _mm_add_ps(velecsum,velec);
740 fscal = _mm_and_ps(fscal,cutoff_mask);
742 fscal = _mm_andnot_ps(dummy_mask,fscal);
744 /* Update vectorial force */
745 fix3 = _mm_macc_ps(dx30,fscal,fix3);
746 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
747 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
749 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
750 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
751 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
755 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
756 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
757 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
758 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
760 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
762 /* Inner loop uses 162 flops */
765 /* End of innermost loop */
767 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
768 f+i_coord_offset,fshift+i_shift_offset);
771 /* Update potential energies */
772 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
773 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
775 /* Increment number of inner iterations */
776 inneriter += j_index_end - j_index_start;
778 /* Outer loop uses 26 flops */
781 /* Increment number of outer iterations */
784 /* Update outer/inner flops */
786 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*162);
789 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_F_avx_128_fma_single
790 * Electrostatics interaction: Ewald
791 * VdW interaction: LJEwald
792 * Geometry: Water4-Particle
793 * Calculate force/pot: Force
796 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_F_avx_128_fma_single
797 (t_nblist * gmx_restrict nlist,
798 rvec * gmx_restrict xx,
799 rvec * gmx_restrict ff,
800 t_forcerec * gmx_restrict fr,
801 t_mdatoms * gmx_restrict mdatoms,
802 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
803 t_nrnb * gmx_restrict nrnb)
805 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
806 * just 0 for non-waters.
807 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
808 * jnr indices corresponding to data put in the four positions in the SIMD register.
810 int i_shift_offset,i_coord_offset,outeriter,inneriter;
811 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
812 int jnrA,jnrB,jnrC,jnrD;
813 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
814 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
815 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
817 real *shiftvec,*fshift,*x,*f;
818 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
820 __m128 fscal,rcutoff,rcutoff2,jidxall;
822 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
824 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
826 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
828 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
829 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
830 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
831 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
832 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
833 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
834 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
835 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
838 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
841 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
842 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
848 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
849 __m128 one_half = _mm_set1_ps(0.5);
850 __m128 minus_one = _mm_set1_ps(-1.0);
852 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
853 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
855 __m128 dummy_mask,cutoff_mask;
856 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
857 __m128 one = _mm_set1_ps(1.0);
858 __m128 two = _mm_set1_ps(2.0);
864 jindex = nlist->jindex;
866 shiftidx = nlist->shift;
868 shiftvec = fr->shift_vec[0];
869 fshift = fr->fshift[0];
870 facel = _mm_set1_ps(fr->epsfac);
871 charge = mdatoms->chargeA;
872 nvdwtype = fr->ntype;
874 vdwtype = mdatoms->typeA;
875 vdwgridparam = fr->ljpme_c6grid;
876 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
877 ewclj = _mm_set1_ps(fr->ewaldcoeff_lj);
878 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
880 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
881 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
882 beta2 = _mm_mul_ps(beta,beta);
883 beta3 = _mm_mul_ps(beta,beta2);
884 ewtab = fr->ic->tabq_coul_F;
885 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
886 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
888 /* Setup water-specific parameters */
889 inr = nlist->iinr[0];
890 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
891 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
892 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
893 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
895 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
896 rcutoff_scalar = fr->rcoulomb;
897 rcutoff = _mm_set1_ps(rcutoff_scalar);
898 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
900 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
901 rvdw = _mm_set1_ps(fr->rvdw);
903 /* Avoid stupid compiler warnings */
904 jnrA = jnrB = jnrC = jnrD = 0;
913 for(iidx=0;iidx<4*DIM;iidx++)
918 /* Start outer loop over neighborlists */
919 for(iidx=0; iidx<nri; iidx++)
921 /* Load shift vector for this list */
922 i_shift_offset = DIM*shiftidx[iidx];
924 /* Load limits for loop over neighbors */
925 j_index_start = jindex[iidx];
926 j_index_end = jindex[iidx+1];
928 /* Get outer coordinate index */
930 i_coord_offset = DIM*inr;
932 /* Load i particle coords and add shift vector */
933 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
934 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
936 fix0 = _mm_setzero_ps();
937 fiy0 = _mm_setzero_ps();
938 fiz0 = _mm_setzero_ps();
939 fix1 = _mm_setzero_ps();
940 fiy1 = _mm_setzero_ps();
941 fiz1 = _mm_setzero_ps();
942 fix2 = _mm_setzero_ps();
943 fiy2 = _mm_setzero_ps();
944 fiz2 = _mm_setzero_ps();
945 fix3 = _mm_setzero_ps();
946 fiy3 = _mm_setzero_ps();
947 fiz3 = _mm_setzero_ps();
949 /* Start inner kernel loop */
950 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
953 /* Get j neighbor index, and coordinate index */
958 j_coord_offsetA = DIM*jnrA;
959 j_coord_offsetB = DIM*jnrB;
960 j_coord_offsetC = DIM*jnrC;
961 j_coord_offsetD = DIM*jnrD;
963 /* load j atom coordinates */
964 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
965 x+j_coord_offsetC,x+j_coord_offsetD,
968 /* Calculate displacement vector */
969 dx00 = _mm_sub_ps(ix0,jx0);
970 dy00 = _mm_sub_ps(iy0,jy0);
971 dz00 = _mm_sub_ps(iz0,jz0);
972 dx10 = _mm_sub_ps(ix1,jx0);
973 dy10 = _mm_sub_ps(iy1,jy0);
974 dz10 = _mm_sub_ps(iz1,jz0);
975 dx20 = _mm_sub_ps(ix2,jx0);
976 dy20 = _mm_sub_ps(iy2,jy0);
977 dz20 = _mm_sub_ps(iz2,jz0);
978 dx30 = _mm_sub_ps(ix3,jx0);
979 dy30 = _mm_sub_ps(iy3,jy0);
980 dz30 = _mm_sub_ps(iz3,jz0);
982 /* Calculate squared distance and things based on it */
983 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
984 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
985 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
986 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
988 rinv00 = gmx_mm_invsqrt_ps(rsq00);
989 rinv10 = gmx_mm_invsqrt_ps(rsq10);
990 rinv20 = gmx_mm_invsqrt_ps(rsq20);
991 rinv30 = gmx_mm_invsqrt_ps(rsq30);
993 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
994 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
995 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
996 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
998 /* Load parameters for j particles */
999 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1000 charge+jnrC+0,charge+jnrD+0);
1001 vdwjidx0A = 2*vdwtype[jnrA+0];
1002 vdwjidx0B = 2*vdwtype[jnrB+0];
1003 vdwjidx0C = 2*vdwtype[jnrC+0];
1004 vdwjidx0D = 2*vdwtype[jnrD+0];
1006 fjx0 = _mm_setzero_ps();
1007 fjy0 = _mm_setzero_ps();
1008 fjz0 = _mm_setzero_ps();
1010 /**************************
1011 * CALCULATE INTERACTIONS *
1012 **************************/
1014 if (gmx_mm_any_lt(rsq00,rcutoff2))
1017 r00 = _mm_mul_ps(rsq00,rinv00);
1019 /* Compute parameters for interactions between i and j atoms */
1020 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1021 vdwparam+vdwioffset0+vdwjidx0B,
1022 vdwparam+vdwioffset0+vdwjidx0C,
1023 vdwparam+vdwioffset0+vdwjidx0D,
1026 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
1027 vdwgridparam+vdwioffset0+vdwjidx0B,
1028 vdwgridparam+vdwioffset0+vdwjidx0C,
1029 vdwgridparam+vdwioffset0+vdwjidx0D);
1031 /* Analytical LJ-PME */
1032 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1033 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
1034 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
1035 exponent = gmx_simd_exp_r(ewcljrsq);
1036 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
1037 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
1038 /* f6A = 6 * C6grid * (1 - poly) */
1039 f6A = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
1040 /* f6B = C6grid * exponent * beta^6 */
1041 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
1042 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
1043 fvdw = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
1045 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1049 fscal = _mm_and_ps(fscal,cutoff_mask);
1051 /* Update vectorial force */
1052 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1053 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1054 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1056 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1057 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1058 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1062 /**************************
1063 * CALCULATE INTERACTIONS *
1064 **************************/
1066 if (gmx_mm_any_lt(rsq10,rcutoff2))
1069 r10 = _mm_mul_ps(rsq10,rinv10);
1071 /* Compute parameters for interactions between i and j atoms */
1072 qq10 = _mm_mul_ps(iq1,jq0);
1074 /* EWALD ELECTROSTATICS */
1076 /* Analytical PME correction */
1077 zeta2 = _mm_mul_ps(beta2,rsq10);
1078 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1079 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1080 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1081 felec = _mm_mul_ps(qq10,felec);
1083 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1087 fscal = _mm_and_ps(fscal,cutoff_mask);
1089 /* Update vectorial force */
1090 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1091 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1092 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1094 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1095 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1096 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1100 /**************************
1101 * CALCULATE INTERACTIONS *
1102 **************************/
1104 if (gmx_mm_any_lt(rsq20,rcutoff2))
1107 r20 = _mm_mul_ps(rsq20,rinv20);
1109 /* Compute parameters for interactions between i and j atoms */
1110 qq20 = _mm_mul_ps(iq2,jq0);
1112 /* EWALD ELECTROSTATICS */
1114 /* Analytical PME correction */
1115 zeta2 = _mm_mul_ps(beta2,rsq20);
1116 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1117 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1118 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1119 felec = _mm_mul_ps(qq20,felec);
1121 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1125 fscal = _mm_and_ps(fscal,cutoff_mask);
1127 /* Update vectorial force */
1128 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1129 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1130 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1132 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1133 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1134 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1138 /**************************
1139 * CALCULATE INTERACTIONS *
1140 **************************/
1142 if (gmx_mm_any_lt(rsq30,rcutoff2))
1145 r30 = _mm_mul_ps(rsq30,rinv30);
1147 /* Compute parameters for interactions between i and j atoms */
1148 qq30 = _mm_mul_ps(iq3,jq0);
1150 /* EWALD ELECTROSTATICS */
1152 /* Analytical PME correction */
1153 zeta2 = _mm_mul_ps(beta2,rsq30);
1154 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1155 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1156 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1157 felec = _mm_mul_ps(qq30,felec);
1159 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1163 fscal = _mm_and_ps(fscal,cutoff_mask);
1165 /* Update vectorial force */
1166 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1167 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1168 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1170 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1171 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1172 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1176 fjptrA = f+j_coord_offsetA;
1177 fjptrB = f+j_coord_offsetB;
1178 fjptrC = f+j_coord_offsetC;
1179 fjptrD = f+j_coord_offsetD;
1181 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1183 /* Inner loop uses 143 flops */
1186 if(jidx<j_index_end)
1189 /* Get j neighbor index, and coordinate index */
1190 jnrlistA = jjnr[jidx];
1191 jnrlistB = jjnr[jidx+1];
1192 jnrlistC = jjnr[jidx+2];
1193 jnrlistD = jjnr[jidx+3];
1194 /* Sign of each element will be negative for non-real atoms.
1195 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1196 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1198 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1199 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1200 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1201 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1202 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1203 j_coord_offsetA = DIM*jnrA;
1204 j_coord_offsetB = DIM*jnrB;
1205 j_coord_offsetC = DIM*jnrC;
1206 j_coord_offsetD = DIM*jnrD;
1208 /* load j atom coordinates */
1209 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1210 x+j_coord_offsetC,x+j_coord_offsetD,
1213 /* Calculate displacement vector */
1214 dx00 = _mm_sub_ps(ix0,jx0);
1215 dy00 = _mm_sub_ps(iy0,jy0);
1216 dz00 = _mm_sub_ps(iz0,jz0);
1217 dx10 = _mm_sub_ps(ix1,jx0);
1218 dy10 = _mm_sub_ps(iy1,jy0);
1219 dz10 = _mm_sub_ps(iz1,jz0);
1220 dx20 = _mm_sub_ps(ix2,jx0);
1221 dy20 = _mm_sub_ps(iy2,jy0);
1222 dz20 = _mm_sub_ps(iz2,jz0);
1223 dx30 = _mm_sub_ps(ix3,jx0);
1224 dy30 = _mm_sub_ps(iy3,jy0);
1225 dz30 = _mm_sub_ps(iz3,jz0);
1227 /* Calculate squared distance and things based on it */
1228 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1229 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1230 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1231 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1233 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1234 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1235 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1236 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1238 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1239 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1240 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1241 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1243 /* Load parameters for j particles */
1244 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1245 charge+jnrC+0,charge+jnrD+0);
1246 vdwjidx0A = 2*vdwtype[jnrA+0];
1247 vdwjidx0B = 2*vdwtype[jnrB+0];
1248 vdwjidx0C = 2*vdwtype[jnrC+0];
1249 vdwjidx0D = 2*vdwtype[jnrD+0];
1251 fjx0 = _mm_setzero_ps();
1252 fjy0 = _mm_setzero_ps();
1253 fjz0 = _mm_setzero_ps();
1255 /**************************
1256 * CALCULATE INTERACTIONS *
1257 **************************/
1259 if (gmx_mm_any_lt(rsq00,rcutoff2))
1262 r00 = _mm_mul_ps(rsq00,rinv00);
1263 r00 = _mm_andnot_ps(dummy_mask,r00);
1265 /* Compute parameters for interactions between i and j atoms */
1266 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1267 vdwparam+vdwioffset0+vdwjidx0B,
1268 vdwparam+vdwioffset0+vdwjidx0C,
1269 vdwparam+vdwioffset0+vdwjidx0D,
1272 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
1273 vdwgridparam+vdwioffset0+vdwjidx0B,
1274 vdwgridparam+vdwioffset0+vdwjidx0C,
1275 vdwgridparam+vdwioffset0+vdwjidx0D);
1277 /* Analytical LJ-PME */
1278 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1279 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
1280 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
1281 exponent = gmx_simd_exp_r(ewcljrsq);
1282 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
1283 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
1284 /* f6A = 6 * C6grid * (1 - poly) */
1285 f6A = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
1286 /* f6B = C6grid * exponent * beta^6 */
1287 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
1288 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
1289 fvdw = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
1291 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1295 fscal = _mm_and_ps(fscal,cutoff_mask);
1297 fscal = _mm_andnot_ps(dummy_mask,fscal);
1299 /* Update vectorial force */
1300 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1301 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1302 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1304 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1305 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1306 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1310 /**************************
1311 * CALCULATE INTERACTIONS *
1312 **************************/
1314 if (gmx_mm_any_lt(rsq10,rcutoff2))
1317 r10 = _mm_mul_ps(rsq10,rinv10);
1318 r10 = _mm_andnot_ps(dummy_mask,r10);
1320 /* Compute parameters for interactions between i and j atoms */
1321 qq10 = _mm_mul_ps(iq1,jq0);
1323 /* EWALD ELECTROSTATICS */
1325 /* Analytical PME correction */
1326 zeta2 = _mm_mul_ps(beta2,rsq10);
1327 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1328 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1329 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1330 felec = _mm_mul_ps(qq10,felec);
1332 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1336 fscal = _mm_and_ps(fscal,cutoff_mask);
1338 fscal = _mm_andnot_ps(dummy_mask,fscal);
1340 /* Update vectorial force */
1341 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1342 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1343 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1345 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1346 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1347 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1351 /**************************
1352 * CALCULATE INTERACTIONS *
1353 **************************/
1355 if (gmx_mm_any_lt(rsq20,rcutoff2))
1358 r20 = _mm_mul_ps(rsq20,rinv20);
1359 r20 = _mm_andnot_ps(dummy_mask,r20);
1361 /* Compute parameters for interactions between i and j atoms */
1362 qq20 = _mm_mul_ps(iq2,jq0);
1364 /* EWALD ELECTROSTATICS */
1366 /* Analytical PME correction */
1367 zeta2 = _mm_mul_ps(beta2,rsq20);
1368 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1369 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1370 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1371 felec = _mm_mul_ps(qq20,felec);
1373 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1377 fscal = _mm_and_ps(fscal,cutoff_mask);
1379 fscal = _mm_andnot_ps(dummy_mask,fscal);
1381 /* Update vectorial force */
1382 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1383 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1384 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1386 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1387 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1388 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1392 /**************************
1393 * CALCULATE INTERACTIONS *
1394 **************************/
1396 if (gmx_mm_any_lt(rsq30,rcutoff2))
1399 r30 = _mm_mul_ps(rsq30,rinv30);
1400 r30 = _mm_andnot_ps(dummy_mask,r30);
1402 /* Compute parameters for interactions between i and j atoms */
1403 qq30 = _mm_mul_ps(iq3,jq0);
1405 /* EWALD ELECTROSTATICS */
1407 /* Analytical PME correction */
1408 zeta2 = _mm_mul_ps(beta2,rsq30);
1409 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1410 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1411 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1412 felec = _mm_mul_ps(qq30,felec);
1414 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1418 fscal = _mm_and_ps(fscal,cutoff_mask);
1420 fscal = _mm_andnot_ps(dummy_mask,fscal);
1422 /* Update vectorial force */
1423 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1424 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1425 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1427 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1428 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1429 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1433 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1434 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1435 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1436 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1438 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1440 /* Inner loop uses 147 flops */
1443 /* End of innermost loop */
1445 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1446 f+i_coord_offset,fshift+i_shift_offset);
1448 /* Increment number of inner iterations */
1449 inneriter += j_index_end - j_index_start;
1451 /* Outer loop uses 24 flops */
1454 /* Increment number of outer iterations */
1457 /* Update outer/inner flops */
1459 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*147);