Removed include simple.h from nb_kernel_avx_128_fma_XX
[gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_avx_128_fma_single.c
blob845c02e2e7325328d29ca6bbe3a6bcc63e34da42
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015, 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.
38 #include "gmxpre.h"
40 #include "config.h"
42 #include <math.h>
44 #include "../nb_kernel.h"
45 #include "gromacs/math/vec.h"
46 #include "gromacs/legacyheaders/nrnb.h"
48 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
49 #include "kernelutil_x86_avx_128_fma_single.h"
52 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_VF_avx_128_fma_single
53 * Electrostatics interaction: Ewald
54 * VdW interaction: LJEwald
55 * Geometry: Water4-Particle
56 * Calculate force/pot: PotentialAndForce
58 void
59 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_VF_avx_128_fma_single
60 (t_nblist * gmx_restrict nlist,
61 rvec * gmx_restrict xx,
62 rvec * gmx_restrict ff,
63 t_forcerec * gmx_restrict fr,
64 t_mdatoms * gmx_restrict mdatoms,
65 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
66 t_nrnb * gmx_restrict nrnb)
68 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
69 * just 0 for non-waters.
70 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
71 * jnr indices corresponding to data put in the four positions in the SIMD register.
73 int i_shift_offset,i_coord_offset,outeriter,inneriter;
74 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
75 int jnrA,jnrB,jnrC,jnrD;
76 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
77 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
78 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real rcutoff_scalar;
80 real *shiftvec,*fshift,*x,*f;
81 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 real scratch[4*DIM];
83 __m128 fscal,rcutoff,rcutoff2,jidxall;
84 int vdwioffset0;
85 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 int vdwioffset1;
87 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 int vdwioffset2;
89 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 int vdwioffset3;
91 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
92 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
93 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
94 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
95 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
96 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
97 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
98 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
99 real *charge;
100 int nvdwtype;
101 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
102 int *vdwtype;
103 real *vdwparam;
104 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
105 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
106 __m128 c6grid_00;
107 __m128 c6grid_10;
108 __m128 c6grid_20;
109 __m128 c6grid_30;
110 real *vdwgridparam;
111 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
112 __m128 one_half = _mm_set1_ps(0.5);
113 __m128 minus_one = _mm_set1_ps(-1.0);
114 __m128i ewitab;
115 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
116 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
117 real *ewtab;
118 __m128 dummy_mask,cutoff_mask;
119 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
120 __m128 one = _mm_set1_ps(1.0);
121 __m128 two = _mm_set1_ps(2.0);
122 x = xx[0];
123 f = ff[0];
125 nri = nlist->nri;
126 iinr = nlist->iinr;
127 jindex = nlist->jindex;
128 jjnr = nlist->jjnr;
129 shiftidx = nlist->shift;
130 gid = nlist->gid;
131 shiftvec = fr->shift_vec[0];
132 fshift = fr->fshift[0];
133 facel = _mm_set1_ps(fr->epsfac);
134 charge = mdatoms->chargeA;
135 nvdwtype = fr->ntype;
136 vdwparam = fr->nbfp;
137 vdwtype = mdatoms->typeA;
138 vdwgridparam = fr->ljpme_c6grid;
139 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
140 ewclj = _mm_set1_ps(fr->ewaldcoeff_lj);
141 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
143 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
144 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
145 beta2 = _mm_mul_ps(beta,beta);
146 beta3 = _mm_mul_ps(beta,beta2);
147 ewtab = fr->ic->tabq_coul_FDV0;
148 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
149 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
151 /* Setup water-specific parameters */
152 inr = nlist->iinr[0];
153 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
154 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
155 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
156 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
158 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
159 rcutoff_scalar = fr->rcoulomb;
160 rcutoff = _mm_set1_ps(rcutoff_scalar);
161 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
163 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
164 rvdw = _mm_set1_ps(fr->rvdw);
166 /* Avoid stupid compiler warnings */
167 jnrA = jnrB = jnrC = jnrD = 0;
168 j_coord_offsetA = 0;
169 j_coord_offsetB = 0;
170 j_coord_offsetC = 0;
171 j_coord_offsetD = 0;
173 outeriter = 0;
174 inneriter = 0;
176 for(iidx=0;iidx<4*DIM;iidx++)
178 scratch[iidx] = 0.0;
181 /* Start outer loop over neighborlists */
182 for(iidx=0; iidx<nri; iidx++)
184 /* Load shift vector for this list */
185 i_shift_offset = DIM*shiftidx[iidx];
187 /* Load limits for loop over neighbors */
188 j_index_start = jindex[iidx];
189 j_index_end = jindex[iidx+1];
191 /* Get outer coordinate index */
192 inr = iinr[iidx];
193 i_coord_offset = DIM*inr;
195 /* Load i particle coords and add shift vector */
196 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
197 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
199 fix0 = _mm_setzero_ps();
200 fiy0 = _mm_setzero_ps();
201 fiz0 = _mm_setzero_ps();
202 fix1 = _mm_setzero_ps();
203 fiy1 = _mm_setzero_ps();
204 fiz1 = _mm_setzero_ps();
205 fix2 = _mm_setzero_ps();
206 fiy2 = _mm_setzero_ps();
207 fiz2 = _mm_setzero_ps();
208 fix3 = _mm_setzero_ps();
209 fiy3 = _mm_setzero_ps();
210 fiz3 = _mm_setzero_ps();
212 /* Reset potential sums */
213 velecsum = _mm_setzero_ps();
214 vvdwsum = _mm_setzero_ps();
216 /* Start inner kernel loop */
217 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
220 /* Get j neighbor index, and coordinate index */
221 jnrA = jjnr[jidx];
222 jnrB = jjnr[jidx+1];
223 jnrC = jjnr[jidx+2];
224 jnrD = jjnr[jidx+3];
225 j_coord_offsetA = DIM*jnrA;
226 j_coord_offsetB = DIM*jnrB;
227 j_coord_offsetC = DIM*jnrC;
228 j_coord_offsetD = DIM*jnrD;
230 /* load j atom coordinates */
231 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
232 x+j_coord_offsetC,x+j_coord_offsetD,
233 &jx0,&jy0,&jz0);
235 /* Calculate displacement vector */
236 dx00 = _mm_sub_ps(ix0,jx0);
237 dy00 = _mm_sub_ps(iy0,jy0);
238 dz00 = _mm_sub_ps(iz0,jz0);
239 dx10 = _mm_sub_ps(ix1,jx0);
240 dy10 = _mm_sub_ps(iy1,jy0);
241 dz10 = _mm_sub_ps(iz1,jz0);
242 dx20 = _mm_sub_ps(ix2,jx0);
243 dy20 = _mm_sub_ps(iy2,jy0);
244 dz20 = _mm_sub_ps(iz2,jz0);
245 dx30 = _mm_sub_ps(ix3,jx0);
246 dy30 = _mm_sub_ps(iy3,jy0);
247 dz30 = _mm_sub_ps(iz3,jz0);
249 /* Calculate squared distance and things based on it */
250 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
251 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
252 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
253 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
255 rinv00 = gmx_mm_invsqrt_ps(rsq00);
256 rinv10 = gmx_mm_invsqrt_ps(rsq10);
257 rinv20 = gmx_mm_invsqrt_ps(rsq20);
258 rinv30 = gmx_mm_invsqrt_ps(rsq30);
260 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
261 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
262 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
263 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
265 /* Load parameters for j particles */
266 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
267 charge+jnrC+0,charge+jnrD+0);
268 vdwjidx0A = 2*vdwtype[jnrA+0];
269 vdwjidx0B = 2*vdwtype[jnrB+0];
270 vdwjidx0C = 2*vdwtype[jnrC+0];
271 vdwjidx0D = 2*vdwtype[jnrD+0];
273 fjx0 = _mm_setzero_ps();
274 fjy0 = _mm_setzero_ps();
275 fjz0 = _mm_setzero_ps();
277 /**************************
278 * CALCULATE INTERACTIONS *
279 **************************/
281 if (gmx_mm_any_lt(rsq00,rcutoff2))
284 r00 = _mm_mul_ps(rsq00,rinv00);
286 /* Compute parameters for interactions between i and j atoms */
287 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
288 vdwparam+vdwioffset0+vdwjidx0B,
289 vdwparam+vdwioffset0+vdwjidx0C,
290 vdwparam+vdwioffset0+vdwjidx0D,
291 &c6_00,&c12_00);
293 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
294 vdwgridparam+vdwioffset0+vdwjidx0B,
295 vdwgridparam+vdwioffset0+vdwjidx0C,
296 vdwgridparam+vdwioffset0+vdwjidx0D);
298 /* Analytical LJ-PME */
299 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
300 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
301 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
302 exponent = gmx_simd_exp_r(ewcljrsq);
303 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
304 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
305 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
306 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
307 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
308 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
309 _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));
310 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
311 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);
313 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
315 /* Update potential sum for this i atom from the interaction with this j atom. */
316 vvdw = _mm_and_ps(vvdw,cutoff_mask);
317 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
319 fscal = fvdw;
321 fscal = _mm_and_ps(fscal,cutoff_mask);
323 /* Update vectorial force */
324 fix0 = _mm_macc_ps(dx00,fscal,fix0);
325 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
326 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
328 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
329 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
330 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
334 /**************************
335 * CALCULATE INTERACTIONS *
336 **************************/
338 if (gmx_mm_any_lt(rsq10,rcutoff2))
341 r10 = _mm_mul_ps(rsq10,rinv10);
343 /* Compute parameters for interactions between i and j atoms */
344 qq10 = _mm_mul_ps(iq1,jq0);
346 /* EWALD ELECTROSTATICS */
348 /* Analytical PME correction */
349 zeta2 = _mm_mul_ps(beta2,rsq10);
350 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
351 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
352 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
353 felec = _mm_mul_ps(qq10,felec);
354 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
355 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
356 velec = _mm_mul_ps(qq10,velec);
358 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
360 /* Update potential sum for this i atom from the interaction with this j atom. */
361 velec = _mm_and_ps(velec,cutoff_mask);
362 velecsum = _mm_add_ps(velecsum,velec);
364 fscal = felec;
366 fscal = _mm_and_ps(fscal,cutoff_mask);
368 /* Update vectorial force */
369 fix1 = _mm_macc_ps(dx10,fscal,fix1);
370 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
371 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
373 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
374 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
375 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
379 /**************************
380 * CALCULATE INTERACTIONS *
381 **************************/
383 if (gmx_mm_any_lt(rsq20,rcutoff2))
386 r20 = _mm_mul_ps(rsq20,rinv20);
388 /* Compute parameters for interactions between i and j atoms */
389 qq20 = _mm_mul_ps(iq2,jq0);
391 /* EWALD ELECTROSTATICS */
393 /* Analytical PME correction */
394 zeta2 = _mm_mul_ps(beta2,rsq20);
395 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
396 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
397 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
398 felec = _mm_mul_ps(qq20,felec);
399 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
400 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
401 velec = _mm_mul_ps(qq20,velec);
403 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
405 /* Update potential sum for this i atom from the interaction with this j atom. */
406 velec = _mm_and_ps(velec,cutoff_mask);
407 velecsum = _mm_add_ps(velecsum,velec);
409 fscal = felec;
411 fscal = _mm_and_ps(fscal,cutoff_mask);
413 /* Update vectorial force */
414 fix2 = _mm_macc_ps(dx20,fscal,fix2);
415 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
416 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
418 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
419 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
420 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
424 /**************************
425 * CALCULATE INTERACTIONS *
426 **************************/
428 if (gmx_mm_any_lt(rsq30,rcutoff2))
431 r30 = _mm_mul_ps(rsq30,rinv30);
433 /* Compute parameters for interactions between i and j atoms */
434 qq30 = _mm_mul_ps(iq3,jq0);
436 /* EWALD ELECTROSTATICS */
438 /* Analytical PME correction */
439 zeta2 = _mm_mul_ps(beta2,rsq30);
440 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
441 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
442 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
443 felec = _mm_mul_ps(qq30,felec);
444 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
445 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
446 velec = _mm_mul_ps(qq30,velec);
448 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
450 /* Update potential sum for this i atom from the interaction with this j atom. */
451 velec = _mm_and_ps(velec,cutoff_mask);
452 velecsum = _mm_add_ps(velecsum,velec);
454 fscal = felec;
456 fscal = _mm_and_ps(fscal,cutoff_mask);
458 /* Update vectorial force */
459 fix3 = _mm_macc_ps(dx30,fscal,fix3);
460 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
461 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
463 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
464 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
465 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
469 fjptrA = f+j_coord_offsetA;
470 fjptrB = f+j_coord_offsetB;
471 fjptrC = f+j_coord_offsetC;
472 fjptrD = f+j_coord_offsetD;
474 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
476 /* Inner loop uses 158 flops */
479 if(jidx<j_index_end)
482 /* Get j neighbor index, and coordinate index */
483 jnrlistA = jjnr[jidx];
484 jnrlistB = jjnr[jidx+1];
485 jnrlistC = jjnr[jidx+2];
486 jnrlistD = jjnr[jidx+3];
487 /* Sign of each element will be negative for non-real atoms.
488 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
489 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
491 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
492 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
493 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
494 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
495 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
496 j_coord_offsetA = DIM*jnrA;
497 j_coord_offsetB = DIM*jnrB;
498 j_coord_offsetC = DIM*jnrC;
499 j_coord_offsetD = DIM*jnrD;
501 /* load j atom coordinates */
502 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
503 x+j_coord_offsetC,x+j_coord_offsetD,
504 &jx0,&jy0,&jz0);
506 /* Calculate displacement vector */
507 dx00 = _mm_sub_ps(ix0,jx0);
508 dy00 = _mm_sub_ps(iy0,jy0);
509 dz00 = _mm_sub_ps(iz0,jz0);
510 dx10 = _mm_sub_ps(ix1,jx0);
511 dy10 = _mm_sub_ps(iy1,jy0);
512 dz10 = _mm_sub_ps(iz1,jz0);
513 dx20 = _mm_sub_ps(ix2,jx0);
514 dy20 = _mm_sub_ps(iy2,jy0);
515 dz20 = _mm_sub_ps(iz2,jz0);
516 dx30 = _mm_sub_ps(ix3,jx0);
517 dy30 = _mm_sub_ps(iy3,jy0);
518 dz30 = _mm_sub_ps(iz3,jz0);
520 /* Calculate squared distance and things based on it */
521 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
522 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
523 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
524 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
526 rinv00 = gmx_mm_invsqrt_ps(rsq00);
527 rinv10 = gmx_mm_invsqrt_ps(rsq10);
528 rinv20 = gmx_mm_invsqrt_ps(rsq20);
529 rinv30 = gmx_mm_invsqrt_ps(rsq30);
531 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
532 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
533 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
534 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
536 /* Load parameters for j particles */
537 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
538 charge+jnrC+0,charge+jnrD+0);
539 vdwjidx0A = 2*vdwtype[jnrA+0];
540 vdwjidx0B = 2*vdwtype[jnrB+0];
541 vdwjidx0C = 2*vdwtype[jnrC+0];
542 vdwjidx0D = 2*vdwtype[jnrD+0];
544 fjx0 = _mm_setzero_ps();
545 fjy0 = _mm_setzero_ps();
546 fjz0 = _mm_setzero_ps();
548 /**************************
549 * CALCULATE INTERACTIONS *
550 **************************/
552 if (gmx_mm_any_lt(rsq00,rcutoff2))
555 r00 = _mm_mul_ps(rsq00,rinv00);
556 r00 = _mm_andnot_ps(dummy_mask,r00);
558 /* Compute parameters for interactions between i and j atoms */
559 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
560 vdwparam+vdwioffset0+vdwjidx0B,
561 vdwparam+vdwioffset0+vdwjidx0C,
562 vdwparam+vdwioffset0+vdwjidx0D,
563 &c6_00,&c12_00);
565 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
566 vdwgridparam+vdwioffset0+vdwjidx0B,
567 vdwgridparam+vdwioffset0+vdwjidx0C,
568 vdwgridparam+vdwioffset0+vdwjidx0D);
570 /* Analytical LJ-PME */
571 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
572 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
573 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
574 exponent = gmx_simd_exp_r(ewcljrsq);
575 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
576 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
577 /* vvdw6 = [C6 - C6grid * (1-poly)]/r6 */
578 vvdw6 = _mm_mul_ps(_mm_macc_ps(-c6grid_00,_mm_sub_ps(one,poly),c6_00),rinvsix);
579 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
580 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
581 _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));
582 /* fvdw = vvdw12/r - (vvdw6/r + (C6grid * exponent * beta^6)/r) */
583 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);
585 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
587 /* Update potential sum for this i atom from the interaction with this j atom. */
588 vvdw = _mm_and_ps(vvdw,cutoff_mask);
589 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
590 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
592 fscal = fvdw;
594 fscal = _mm_and_ps(fscal,cutoff_mask);
596 fscal = _mm_andnot_ps(dummy_mask,fscal);
598 /* Update vectorial force */
599 fix0 = _mm_macc_ps(dx00,fscal,fix0);
600 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
601 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
603 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
604 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
605 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
609 /**************************
610 * CALCULATE INTERACTIONS *
611 **************************/
613 if (gmx_mm_any_lt(rsq10,rcutoff2))
616 r10 = _mm_mul_ps(rsq10,rinv10);
617 r10 = _mm_andnot_ps(dummy_mask,r10);
619 /* Compute parameters for interactions between i and j atoms */
620 qq10 = _mm_mul_ps(iq1,jq0);
622 /* EWALD ELECTROSTATICS */
624 /* Analytical PME correction */
625 zeta2 = _mm_mul_ps(beta2,rsq10);
626 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
627 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
628 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
629 felec = _mm_mul_ps(qq10,felec);
630 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
631 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
632 velec = _mm_mul_ps(qq10,velec);
634 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
636 /* Update potential sum for this i atom from the interaction with this j atom. */
637 velec = _mm_and_ps(velec,cutoff_mask);
638 velec = _mm_andnot_ps(dummy_mask,velec);
639 velecsum = _mm_add_ps(velecsum,velec);
641 fscal = felec;
643 fscal = _mm_and_ps(fscal,cutoff_mask);
645 fscal = _mm_andnot_ps(dummy_mask,fscal);
647 /* Update vectorial force */
648 fix1 = _mm_macc_ps(dx10,fscal,fix1);
649 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
650 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
652 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
653 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
654 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
658 /**************************
659 * CALCULATE INTERACTIONS *
660 **************************/
662 if (gmx_mm_any_lt(rsq20,rcutoff2))
665 r20 = _mm_mul_ps(rsq20,rinv20);
666 r20 = _mm_andnot_ps(dummy_mask,r20);
668 /* Compute parameters for interactions between i and j atoms */
669 qq20 = _mm_mul_ps(iq2,jq0);
671 /* EWALD ELECTROSTATICS */
673 /* Analytical PME correction */
674 zeta2 = _mm_mul_ps(beta2,rsq20);
675 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
676 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
677 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
678 felec = _mm_mul_ps(qq20,felec);
679 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
680 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
681 velec = _mm_mul_ps(qq20,velec);
683 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
685 /* Update potential sum for this i atom from the interaction with this j atom. */
686 velec = _mm_and_ps(velec,cutoff_mask);
687 velec = _mm_andnot_ps(dummy_mask,velec);
688 velecsum = _mm_add_ps(velecsum,velec);
690 fscal = felec;
692 fscal = _mm_and_ps(fscal,cutoff_mask);
694 fscal = _mm_andnot_ps(dummy_mask,fscal);
696 /* Update vectorial force */
697 fix2 = _mm_macc_ps(dx20,fscal,fix2);
698 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
699 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
701 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
702 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
703 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
707 /**************************
708 * CALCULATE INTERACTIONS *
709 **************************/
711 if (gmx_mm_any_lt(rsq30,rcutoff2))
714 r30 = _mm_mul_ps(rsq30,rinv30);
715 r30 = _mm_andnot_ps(dummy_mask,r30);
717 /* Compute parameters for interactions between i and j atoms */
718 qq30 = _mm_mul_ps(iq3,jq0);
720 /* EWALD ELECTROSTATICS */
722 /* Analytical PME correction */
723 zeta2 = _mm_mul_ps(beta2,rsq30);
724 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
725 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
726 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
727 felec = _mm_mul_ps(qq30,felec);
728 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
729 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
730 velec = _mm_mul_ps(qq30,velec);
732 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
734 /* Update potential sum for this i atom from the interaction with this j atom. */
735 velec = _mm_and_ps(velec,cutoff_mask);
736 velec = _mm_andnot_ps(dummy_mask,velec);
737 velecsum = _mm_add_ps(velecsum,velec);
739 fscal = felec;
741 fscal = _mm_and_ps(fscal,cutoff_mask);
743 fscal = _mm_andnot_ps(dummy_mask,fscal);
745 /* Update vectorial force */
746 fix3 = _mm_macc_ps(dx30,fscal,fix3);
747 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
748 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
750 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
751 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
752 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
756 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
757 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
758 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
759 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
761 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
763 /* Inner loop uses 162 flops */
766 /* End of innermost loop */
768 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
769 f+i_coord_offset,fshift+i_shift_offset);
771 ggid = gid[iidx];
772 /* Update potential energies */
773 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
774 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
776 /* Increment number of inner iterations */
777 inneriter += j_index_end - j_index_start;
779 /* Outer loop uses 26 flops */
782 /* Increment number of outer iterations */
783 outeriter += nri;
785 /* Update outer/inner flops */
787 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*162);
790 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_F_avx_128_fma_single
791 * Electrostatics interaction: Ewald
792 * VdW interaction: LJEwald
793 * Geometry: Water4-Particle
794 * Calculate force/pot: Force
796 void
797 nb_kernel_ElecEwSh_VdwLJEwSh_GeomW4P1_F_avx_128_fma_single
798 (t_nblist * gmx_restrict nlist,
799 rvec * gmx_restrict xx,
800 rvec * gmx_restrict ff,
801 t_forcerec * gmx_restrict fr,
802 t_mdatoms * gmx_restrict mdatoms,
803 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
804 t_nrnb * gmx_restrict nrnb)
806 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
807 * just 0 for non-waters.
808 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
809 * jnr indices corresponding to data put in the four positions in the SIMD register.
811 int i_shift_offset,i_coord_offset,outeriter,inneriter;
812 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
813 int jnrA,jnrB,jnrC,jnrD;
814 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
815 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
816 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
817 real rcutoff_scalar;
818 real *shiftvec,*fshift,*x,*f;
819 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
820 real scratch[4*DIM];
821 __m128 fscal,rcutoff,rcutoff2,jidxall;
822 int vdwioffset0;
823 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
824 int vdwioffset1;
825 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
826 int vdwioffset2;
827 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
828 int vdwioffset3;
829 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
830 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
831 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
832 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
833 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
834 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
835 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
836 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
837 real *charge;
838 int nvdwtype;
839 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
840 int *vdwtype;
841 real *vdwparam;
842 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
843 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
844 __m128 c6grid_00;
845 __m128 c6grid_10;
846 __m128 c6grid_20;
847 __m128 c6grid_30;
848 real *vdwgridparam;
849 __m128 ewclj,ewclj2,ewclj6,ewcljrsq,poly,exponent,f6A,f6B,sh_lj_ewald;
850 __m128 one_half = _mm_set1_ps(0.5);
851 __m128 minus_one = _mm_set1_ps(-1.0);
852 __m128i ewitab;
853 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
854 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
855 real *ewtab;
856 __m128 dummy_mask,cutoff_mask;
857 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
858 __m128 one = _mm_set1_ps(1.0);
859 __m128 two = _mm_set1_ps(2.0);
860 x = xx[0];
861 f = ff[0];
863 nri = nlist->nri;
864 iinr = nlist->iinr;
865 jindex = nlist->jindex;
866 jjnr = nlist->jjnr;
867 shiftidx = nlist->shift;
868 gid = nlist->gid;
869 shiftvec = fr->shift_vec[0];
870 fshift = fr->fshift[0];
871 facel = _mm_set1_ps(fr->epsfac);
872 charge = mdatoms->chargeA;
873 nvdwtype = fr->ntype;
874 vdwparam = fr->nbfp;
875 vdwtype = mdatoms->typeA;
876 vdwgridparam = fr->ljpme_c6grid;
877 sh_lj_ewald = _mm_set1_ps(fr->ic->sh_lj_ewald);
878 ewclj = _mm_set1_ps(fr->ewaldcoeff_lj);
879 ewclj2 = _mm_mul_ps(minus_one,_mm_mul_ps(ewclj,ewclj));
881 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
882 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
883 beta2 = _mm_mul_ps(beta,beta);
884 beta3 = _mm_mul_ps(beta,beta2);
885 ewtab = fr->ic->tabq_coul_F;
886 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
887 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
889 /* Setup water-specific parameters */
890 inr = nlist->iinr[0];
891 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
892 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
893 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
894 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
896 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
897 rcutoff_scalar = fr->rcoulomb;
898 rcutoff = _mm_set1_ps(rcutoff_scalar);
899 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
901 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
902 rvdw = _mm_set1_ps(fr->rvdw);
904 /* Avoid stupid compiler warnings */
905 jnrA = jnrB = jnrC = jnrD = 0;
906 j_coord_offsetA = 0;
907 j_coord_offsetB = 0;
908 j_coord_offsetC = 0;
909 j_coord_offsetD = 0;
911 outeriter = 0;
912 inneriter = 0;
914 for(iidx=0;iidx<4*DIM;iidx++)
916 scratch[iidx] = 0.0;
919 /* Start outer loop over neighborlists */
920 for(iidx=0; iidx<nri; iidx++)
922 /* Load shift vector for this list */
923 i_shift_offset = DIM*shiftidx[iidx];
925 /* Load limits for loop over neighbors */
926 j_index_start = jindex[iidx];
927 j_index_end = jindex[iidx+1];
929 /* Get outer coordinate index */
930 inr = iinr[iidx];
931 i_coord_offset = DIM*inr;
933 /* Load i particle coords and add shift vector */
934 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
935 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
937 fix0 = _mm_setzero_ps();
938 fiy0 = _mm_setzero_ps();
939 fiz0 = _mm_setzero_ps();
940 fix1 = _mm_setzero_ps();
941 fiy1 = _mm_setzero_ps();
942 fiz1 = _mm_setzero_ps();
943 fix2 = _mm_setzero_ps();
944 fiy2 = _mm_setzero_ps();
945 fiz2 = _mm_setzero_ps();
946 fix3 = _mm_setzero_ps();
947 fiy3 = _mm_setzero_ps();
948 fiz3 = _mm_setzero_ps();
950 /* Start inner kernel loop */
951 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
954 /* Get j neighbor index, and coordinate index */
955 jnrA = jjnr[jidx];
956 jnrB = jjnr[jidx+1];
957 jnrC = jjnr[jidx+2];
958 jnrD = jjnr[jidx+3];
959 j_coord_offsetA = DIM*jnrA;
960 j_coord_offsetB = DIM*jnrB;
961 j_coord_offsetC = DIM*jnrC;
962 j_coord_offsetD = DIM*jnrD;
964 /* load j atom coordinates */
965 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
966 x+j_coord_offsetC,x+j_coord_offsetD,
967 &jx0,&jy0,&jz0);
969 /* Calculate displacement vector */
970 dx00 = _mm_sub_ps(ix0,jx0);
971 dy00 = _mm_sub_ps(iy0,jy0);
972 dz00 = _mm_sub_ps(iz0,jz0);
973 dx10 = _mm_sub_ps(ix1,jx0);
974 dy10 = _mm_sub_ps(iy1,jy0);
975 dz10 = _mm_sub_ps(iz1,jz0);
976 dx20 = _mm_sub_ps(ix2,jx0);
977 dy20 = _mm_sub_ps(iy2,jy0);
978 dz20 = _mm_sub_ps(iz2,jz0);
979 dx30 = _mm_sub_ps(ix3,jx0);
980 dy30 = _mm_sub_ps(iy3,jy0);
981 dz30 = _mm_sub_ps(iz3,jz0);
983 /* Calculate squared distance and things based on it */
984 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
985 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
986 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
987 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
989 rinv00 = gmx_mm_invsqrt_ps(rsq00);
990 rinv10 = gmx_mm_invsqrt_ps(rsq10);
991 rinv20 = gmx_mm_invsqrt_ps(rsq20);
992 rinv30 = gmx_mm_invsqrt_ps(rsq30);
994 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
995 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
996 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
997 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
999 /* Load parameters for j particles */
1000 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1001 charge+jnrC+0,charge+jnrD+0);
1002 vdwjidx0A = 2*vdwtype[jnrA+0];
1003 vdwjidx0B = 2*vdwtype[jnrB+0];
1004 vdwjidx0C = 2*vdwtype[jnrC+0];
1005 vdwjidx0D = 2*vdwtype[jnrD+0];
1007 fjx0 = _mm_setzero_ps();
1008 fjy0 = _mm_setzero_ps();
1009 fjz0 = _mm_setzero_ps();
1011 /**************************
1012 * CALCULATE INTERACTIONS *
1013 **************************/
1015 if (gmx_mm_any_lt(rsq00,rcutoff2))
1018 r00 = _mm_mul_ps(rsq00,rinv00);
1020 /* Compute parameters for interactions between i and j atoms */
1021 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1022 vdwparam+vdwioffset0+vdwjidx0B,
1023 vdwparam+vdwioffset0+vdwjidx0C,
1024 vdwparam+vdwioffset0+vdwjidx0D,
1025 &c6_00,&c12_00);
1027 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
1028 vdwgridparam+vdwioffset0+vdwjidx0B,
1029 vdwgridparam+vdwioffset0+vdwjidx0C,
1030 vdwgridparam+vdwioffset0+vdwjidx0D);
1032 /* Analytical LJ-PME */
1033 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1034 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
1035 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
1036 exponent = gmx_simd_exp_r(ewcljrsq);
1037 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
1038 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
1039 /* f6A = 6 * C6grid * (1 - poly) */
1040 f6A = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
1041 /* f6B = C6grid * exponent * beta^6 */
1042 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
1043 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
1044 fvdw = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
1046 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1048 fscal = fvdw;
1050 fscal = _mm_and_ps(fscal,cutoff_mask);
1052 /* Update vectorial force */
1053 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1054 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1055 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1057 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1058 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1059 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1063 /**************************
1064 * CALCULATE INTERACTIONS *
1065 **************************/
1067 if (gmx_mm_any_lt(rsq10,rcutoff2))
1070 r10 = _mm_mul_ps(rsq10,rinv10);
1072 /* Compute parameters for interactions between i and j atoms */
1073 qq10 = _mm_mul_ps(iq1,jq0);
1075 /* EWALD ELECTROSTATICS */
1077 /* Analytical PME correction */
1078 zeta2 = _mm_mul_ps(beta2,rsq10);
1079 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1080 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1081 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1082 felec = _mm_mul_ps(qq10,felec);
1084 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1086 fscal = felec;
1088 fscal = _mm_and_ps(fscal,cutoff_mask);
1090 /* Update vectorial force */
1091 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1092 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1093 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1095 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1096 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1097 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1101 /**************************
1102 * CALCULATE INTERACTIONS *
1103 **************************/
1105 if (gmx_mm_any_lt(rsq20,rcutoff2))
1108 r20 = _mm_mul_ps(rsq20,rinv20);
1110 /* Compute parameters for interactions between i and j atoms */
1111 qq20 = _mm_mul_ps(iq2,jq0);
1113 /* EWALD ELECTROSTATICS */
1115 /* Analytical PME correction */
1116 zeta2 = _mm_mul_ps(beta2,rsq20);
1117 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1118 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1119 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1120 felec = _mm_mul_ps(qq20,felec);
1122 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1124 fscal = felec;
1126 fscal = _mm_and_ps(fscal,cutoff_mask);
1128 /* Update vectorial force */
1129 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1130 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1131 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1133 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1134 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1135 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1139 /**************************
1140 * CALCULATE INTERACTIONS *
1141 **************************/
1143 if (gmx_mm_any_lt(rsq30,rcutoff2))
1146 r30 = _mm_mul_ps(rsq30,rinv30);
1148 /* Compute parameters for interactions between i and j atoms */
1149 qq30 = _mm_mul_ps(iq3,jq0);
1151 /* EWALD ELECTROSTATICS */
1153 /* Analytical PME correction */
1154 zeta2 = _mm_mul_ps(beta2,rsq30);
1155 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1156 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1157 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1158 felec = _mm_mul_ps(qq30,felec);
1160 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1162 fscal = felec;
1164 fscal = _mm_and_ps(fscal,cutoff_mask);
1166 /* Update vectorial force */
1167 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1168 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1169 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1171 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1172 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1173 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1177 fjptrA = f+j_coord_offsetA;
1178 fjptrB = f+j_coord_offsetB;
1179 fjptrC = f+j_coord_offsetC;
1180 fjptrD = f+j_coord_offsetD;
1182 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1184 /* Inner loop uses 143 flops */
1187 if(jidx<j_index_end)
1190 /* Get j neighbor index, and coordinate index */
1191 jnrlistA = jjnr[jidx];
1192 jnrlistB = jjnr[jidx+1];
1193 jnrlistC = jjnr[jidx+2];
1194 jnrlistD = jjnr[jidx+3];
1195 /* Sign of each element will be negative for non-real atoms.
1196 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1197 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1199 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1200 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1201 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1202 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1203 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1204 j_coord_offsetA = DIM*jnrA;
1205 j_coord_offsetB = DIM*jnrB;
1206 j_coord_offsetC = DIM*jnrC;
1207 j_coord_offsetD = DIM*jnrD;
1209 /* load j atom coordinates */
1210 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1211 x+j_coord_offsetC,x+j_coord_offsetD,
1212 &jx0,&jy0,&jz0);
1214 /* Calculate displacement vector */
1215 dx00 = _mm_sub_ps(ix0,jx0);
1216 dy00 = _mm_sub_ps(iy0,jy0);
1217 dz00 = _mm_sub_ps(iz0,jz0);
1218 dx10 = _mm_sub_ps(ix1,jx0);
1219 dy10 = _mm_sub_ps(iy1,jy0);
1220 dz10 = _mm_sub_ps(iz1,jz0);
1221 dx20 = _mm_sub_ps(ix2,jx0);
1222 dy20 = _mm_sub_ps(iy2,jy0);
1223 dz20 = _mm_sub_ps(iz2,jz0);
1224 dx30 = _mm_sub_ps(ix3,jx0);
1225 dy30 = _mm_sub_ps(iy3,jy0);
1226 dz30 = _mm_sub_ps(iz3,jz0);
1228 /* Calculate squared distance and things based on it */
1229 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1230 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1231 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1232 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1234 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1235 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1236 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1237 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1239 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1240 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1241 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1242 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1244 /* Load parameters for j particles */
1245 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1246 charge+jnrC+0,charge+jnrD+0);
1247 vdwjidx0A = 2*vdwtype[jnrA+0];
1248 vdwjidx0B = 2*vdwtype[jnrB+0];
1249 vdwjidx0C = 2*vdwtype[jnrC+0];
1250 vdwjidx0D = 2*vdwtype[jnrD+0];
1252 fjx0 = _mm_setzero_ps();
1253 fjy0 = _mm_setzero_ps();
1254 fjz0 = _mm_setzero_ps();
1256 /**************************
1257 * CALCULATE INTERACTIONS *
1258 **************************/
1260 if (gmx_mm_any_lt(rsq00,rcutoff2))
1263 r00 = _mm_mul_ps(rsq00,rinv00);
1264 r00 = _mm_andnot_ps(dummy_mask,r00);
1266 /* Compute parameters for interactions between i and j atoms */
1267 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1268 vdwparam+vdwioffset0+vdwjidx0B,
1269 vdwparam+vdwioffset0+vdwjidx0C,
1270 vdwparam+vdwioffset0+vdwjidx0D,
1271 &c6_00,&c12_00);
1273 c6grid_00 = gmx_mm_load_4real_swizzle_ps(vdwgridparam+vdwioffset0+vdwjidx0A,
1274 vdwgridparam+vdwioffset0+vdwjidx0B,
1275 vdwgridparam+vdwioffset0+vdwjidx0C,
1276 vdwgridparam+vdwioffset0+vdwjidx0D);
1278 /* Analytical LJ-PME */
1279 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1280 ewcljrsq = _mm_mul_ps(ewclj2,rsq00);
1281 ewclj6 = _mm_mul_ps(ewclj2,_mm_mul_ps(ewclj2,ewclj2));
1282 exponent = gmx_simd_exp_r(ewcljrsq);
1283 /* poly = exp(-(beta*r)^2) * (1 + (beta*r)^2 + (beta*r)^4 /2) */
1284 poly = _mm_mul_ps(exponent,_mm_macc_ps(_mm_mul_ps(ewcljrsq,ewcljrsq),one_half,_mm_sub_ps(one,ewcljrsq)));
1285 /* f6A = 6 * C6grid * (1 - poly) */
1286 f6A = _mm_mul_ps(c6grid_00,_mm_sub_ps(one,poly));
1287 /* f6B = C6grid * exponent * beta^6 */
1288 f6B = _mm_mul_ps(_mm_mul_ps(c6grid_00,one_sixth),_mm_mul_ps(exponent,ewclj6));
1289 /* fvdw = 12*C12/r13 - ((6*C6 - f6A)/r6 + f6B)/r */
1290 fvdw = _mm_mul_ps(_mm_macc_ps(_mm_msub_ps(c12_00,rinvsix,_mm_sub_ps(c6_00,f6A)),rinvsix,f6B),rinvsq00);
1292 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1294 fscal = fvdw;
1296 fscal = _mm_and_ps(fscal,cutoff_mask);
1298 fscal = _mm_andnot_ps(dummy_mask,fscal);
1300 /* Update vectorial force */
1301 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1302 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1303 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1305 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1306 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1307 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1311 /**************************
1312 * CALCULATE INTERACTIONS *
1313 **************************/
1315 if (gmx_mm_any_lt(rsq10,rcutoff2))
1318 r10 = _mm_mul_ps(rsq10,rinv10);
1319 r10 = _mm_andnot_ps(dummy_mask,r10);
1321 /* Compute parameters for interactions between i and j atoms */
1322 qq10 = _mm_mul_ps(iq1,jq0);
1324 /* EWALD ELECTROSTATICS */
1326 /* Analytical PME correction */
1327 zeta2 = _mm_mul_ps(beta2,rsq10);
1328 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1329 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1330 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1331 felec = _mm_mul_ps(qq10,felec);
1333 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1335 fscal = felec;
1337 fscal = _mm_and_ps(fscal,cutoff_mask);
1339 fscal = _mm_andnot_ps(dummy_mask,fscal);
1341 /* Update vectorial force */
1342 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1343 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1344 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1346 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1347 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1348 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1352 /**************************
1353 * CALCULATE INTERACTIONS *
1354 **************************/
1356 if (gmx_mm_any_lt(rsq20,rcutoff2))
1359 r20 = _mm_mul_ps(rsq20,rinv20);
1360 r20 = _mm_andnot_ps(dummy_mask,r20);
1362 /* Compute parameters for interactions between i and j atoms */
1363 qq20 = _mm_mul_ps(iq2,jq0);
1365 /* EWALD ELECTROSTATICS */
1367 /* Analytical PME correction */
1368 zeta2 = _mm_mul_ps(beta2,rsq20);
1369 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1370 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1371 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1372 felec = _mm_mul_ps(qq20,felec);
1374 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1376 fscal = felec;
1378 fscal = _mm_and_ps(fscal,cutoff_mask);
1380 fscal = _mm_andnot_ps(dummy_mask,fscal);
1382 /* Update vectorial force */
1383 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1384 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1385 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1387 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1388 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1389 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1393 /**************************
1394 * CALCULATE INTERACTIONS *
1395 **************************/
1397 if (gmx_mm_any_lt(rsq30,rcutoff2))
1400 r30 = _mm_mul_ps(rsq30,rinv30);
1401 r30 = _mm_andnot_ps(dummy_mask,r30);
1403 /* Compute parameters for interactions between i and j atoms */
1404 qq30 = _mm_mul_ps(iq3,jq0);
1406 /* EWALD ELECTROSTATICS */
1408 /* Analytical PME correction */
1409 zeta2 = _mm_mul_ps(beta2,rsq30);
1410 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1411 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1412 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1413 felec = _mm_mul_ps(qq30,felec);
1415 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1417 fscal = felec;
1419 fscal = _mm_and_ps(fscal,cutoff_mask);
1421 fscal = _mm_andnot_ps(dummy_mask,fscal);
1423 /* Update vectorial force */
1424 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1425 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1426 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1428 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1429 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1430 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1434 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1435 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1436 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1437 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1439 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1441 /* Inner loop uses 147 flops */
1444 /* End of innermost loop */
1446 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1447 f+i_coord_offset,fshift+i_shift_offset);
1449 /* Increment number of inner iterations */
1450 inneriter += j_index_end - j_index_start;
1452 /* Outer loop uses 24 flops */
1455 /* Increment number of outer iterations */
1456 outeriter += nri;
1458 /* Update outer/inner flops */
1460 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*147);