2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW4W4_VF_avx_128_fma_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: LennardJones
53 * Geometry: Water4-Water4
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwLJSh_GeomW4W4_VF_avx_128_fma_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
90 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
91 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
93 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
94 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
95 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
96 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
97 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
98 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
99 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
100 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
101 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
102 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
103 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
104 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
105 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
106 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
107 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
108 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
111 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
114 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
115 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
116 __m128 dummy_mask,cutoff_mask;
117 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
118 __m128 one = _mm_set1_ps(1.0);
119 __m128 two = _mm_set1_ps(2.0);
125 jindex = nlist->jindex;
127 shiftidx = nlist->shift;
129 shiftvec = fr->shift_vec[0];
130 fshift = fr->fshift[0];
131 facel = _mm_set1_ps(fr->ic->epsfac);
132 charge = mdatoms->chargeA;
133 krf = _mm_set1_ps(fr->ic->k_rf);
134 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
135 crf = _mm_set1_ps(fr->ic->c_rf);
136 nvdwtype = fr->ntype;
138 vdwtype = mdatoms->typeA;
140 /* Setup water-specific parameters */
141 inr = nlist->iinr[0];
142 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
143 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
144 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
145 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
147 jq1 = _mm_set1_ps(charge[inr+1]);
148 jq2 = _mm_set1_ps(charge[inr+2]);
149 jq3 = _mm_set1_ps(charge[inr+3]);
150 vdwjidx0A = 2*vdwtype[inr+0];
151 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
152 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
153 qq11 = _mm_mul_ps(iq1,jq1);
154 qq12 = _mm_mul_ps(iq1,jq2);
155 qq13 = _mm_mul_ps(iq1,jq3);
156 qq21 = _mm_mul_ps(iq2,jq1);
157 qq22 = _mm_mul_ps(iq2,jq2);
158 qq23 = _mm_mul_ps(iq2,jq3);
159 qq31 = _mm_mul_ps(iq3,jq1);
160 qq32 = _mm_mul_ps(iq3,jq2);
161 qq33 = _mm_mul_ps(iq3,jq3);
163 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
164 rcutoff_scalar = fr->ic->rcoulomb;
165 rcutoff = _mm_set1_ps(rcutoff_scalar);
166 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
168 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
169 rvdw = _mm_set1_ps(fr->ic->rvdw);
171 /* Avoid stupid compiler warnings */
172 jnrA = jnrB = jnrC = jnrD = 0;
181 for(iidx=0;iidx<4*DIM;iidx++)
186 /* Start outer loop over neighborlists */
187 for(iidx=0; iidx<nri; iidx++)
189 /* Load shift vector for this list */
190 i_shift_offset = DIM*shiftidx[iidx];
192 /* Load limits for loop over neighbors */
193 j_index_start = jindex[iidx];
194 j_index_end = jindex[iidx+1];
196 /* Get outer coordinate index */
198 i_coord_offset = DIM*inr;
200 /* Load i particle coords and add shift vector */
201 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
202 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
204 fix0 = _mm_setzero_ps();
205 fiy0 = _mm_setzero_ps();
206 fiz0 = _mm_setzero_ps();
207 fix1 = _mm_setzero_ps();
208 fiy1 = _mm_setzero_ps();
209 fiz1 = _mm_setzero_ps();
210 fix2 = _mm_setzero_ps();
211 fiy2 = _mm_setzero_ps();
212 fiz2 = _mm_setzero_ps();
213 fix3 = _mm_setzero_ps();
214 fiy3 = _mm_setzero_ps();
215 fiz3 = _mm_setzero_ps();
217 /* Reset potential sums */
218 velecsum = _mm_setzero_ps();
219 vvdwsum = _mm_setzero_ps();
221 /* Start inner kernel loop */
222 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
225 /* Get j neighbor index, and coordinate index */
230 j_coord_offsetA = DIM*jnrA;
231 j_coord_offsetB = DIM*jnrB;
232 j_coord_offsetC = DIM*jnrC;
233 j_coord_offsetD = DIM*jnrD;
235 /* load j atom coordinates */
236 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
237 x+j_coord_offsetC,x+j_coord_offsetD,
238 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
239 &jy2,&jz2,&jx3,&jy3,&jz3);
241 /* Calculate displacement vector */
242 dx00 = _mm_sub_ps(ix0,jx0);
243 dy00 = _mm_sub_ps(iy0,jy0);
244 dz00 = _mm_sub_ps(iz0,jz0);
245 dx11 = _mm_sub_ps(ix1,jx1);
246 dy11 = _mm_sub_ps(iy1,jy1);
247 dz11 = _mm_sub_ps(iz1,jz1);
248 dx12 = _mm_sub_ps(ix1,jx2);
249 dy12 = _mm_sub_ps(iy1,jy2);
250 dz12 = _mm_sub_ps(iz1,jz2);
251 dx13 = _mm_sub_ps(ix1,jx3);
252 dy13 = _mm_sub_ps(iy1,jy3);
253 dz13 = _mm_sub_ps(iz1,jz3);
254 dx21 = _mm_sub_ps(ix2,jx1);
255 dy21 = _mm_sub_ps(iy2,jy1);
256 dz21 = _mm_sub_ps(iz2,jz1);
257 dx22 = _mm_sub_ps(ix2,jx2);
258 dy22 = _mm_sub_ps(iy2,jy2);
259 dz22 = _mm_sub_ps(iz2,jz2);
260 dx23 = _mm_sub_ps(ix2,jx3);
261 dy23 = _mm_sub_ps(iy2,jy3);
262 dz23 = _mm_sub_ps(iz2,jz3);
263 dx31 = _mm_sub_ps(ix3,jx1);
264 dy31 = _mm_sub_ps(iy3,jy1);
265 dz31 = _mm_sub_ps(iz3,jz1);
266 dx32 = _mm_sub_ps(ix3,jx2);
267 dy32 = _mm_sub_ps(iy3,jy2);
268 dz32 = _mm_sub_ps(iz3,jz2);
269 dx33 = _mm_sub_ps(ix3,jx3);
270 dy33 = _mm_sub_ps(iy3,jy3);
271 dz33 = _mm_sub_ps(iz3,jz3);
273 /* Calculate squared distance and things based on it */
274 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
275 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
276 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
277 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
278 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
279 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
280 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
281 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
282 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
283 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
285 rinv11 = avx128fma_invsqrt_f(rsq11);
286 rinv12 = avx128fma_invsqrt_f(rsq12);
287 rinv13 = avx128fma_invsqrt_f(rsq13);
288 rinv21 = avx128fma_invsqrt_f(rsq21);
289 rinv22 = avx128fma_invsqrt_f(rsq22);
290 rinv23 = avx128fma_invsqrt_f(rsq23);
291 rinv31 = avx128fma_invsqrt_f(rsq31);
292 rinv32 = avx128fma_invsqrt_f(rsq32);
293 rinv33 = avx128fma_invsqrt_f(rsq33);
295 rinvsq00 = avx128fma_inv_f(rsq00);
296 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
297 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
298 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
299 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
300 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
301 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
302 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
303 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
304 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
306 fjx0 = _mm_setzero_ps();
307 fjy0 = _mm_setzero_ps();
308 fjz0 = _mm_setzero_ps();
309 fjx1 = _mm_setzero_ps();
310 fjy1 = _mm_setzero_ps();
311 fjz1 = _mm_setzero_ps();
312 fjx2 = _mm_setzero_ps();
313 fjy2 = _mm_setzero_ps();
314 fjz2 = _mm_setzero_ps();
315 fjx3 = _mm_setzero_ps();
316 fjy3 = _mm_setzero_ps();
317 fjz3 = _mm_setzero_ps();
319 /**************************
320 * CALCULATE INTERACTIONS *
321 **************************/
323 if (gmx_mm_any_lt(rsq00,rcutoff2))
326 /* LENNARD-JONES DISPERSION/REPULSION */
328 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
329 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
330 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
331 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
332 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
333 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
335 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
337 /* Update potential sum for this i atom from the interaction with this j atom. */
338 vvdw = _mm_and_ps(vvdw,cutoff_mask);
339 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
343 fscal = _mm_and_ps(fscal,cutoff_mask);
345 /* Update vectorial force */
346 fix0 = _mm_macc_ps(dx00,fscal,fix0);
347 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
348 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
350 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
351 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
352 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
356 /**************************
357 * CALCULATE INTERACTIONS *
358 **************************/
360 if (gmx_mm_any_lt(rsq11,rcutoff2))
363 /* REACTION-FIELD ELECTROSTATICS */
364 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
365 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
367 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
369 /* Update potential sum for this i atom from the interaction with this j atom. */
370 velec = _mm_and_ps(velec,cutoff_mask);
371 velecsum = _mm_add_ps(velecsum,velec);
375 fscal = _mm_and_ps(fscal,cutoff_mask);
377 /* Update vectorial force */
378 fix1 = _mm_macc_ps(dx11,fscal,fix1);
379 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
380 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
382 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
383 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
384 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
388 /**************************
389 * CALCULATE INTERACTIONS *
390 **************************/
392 if (gmx_mm_any_lt(rsq12,rcutoff2))
395 /* REACTION-FIELD ELECTROSTATICS */
396 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
397 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
399 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
401 /* Update potential sum for this i atom from the interaction with this j atom. */
402 velec = _mm_and_ps(velec,cutoff_mask);
403 velecsum = _mm_add_ps(velecsum,velec);
407 fscal = _mm_and_ps(fscal,cutoff_mask);
409 /* Update vectorial force */
410 fix1 = _mm_macc_ps(dx12,fscal,fix1);
411 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
412 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
414 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
415 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
416 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
420 /**************************
421 * CALCULATE INTERACTIONS *
422 **************************/
424 if (gmx_mm_any_lt(rsq13,rcutoff2))
427 /* REACTION-FIELD ELECTROSTATICS */
428 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_macc_ps(krf,rsq13,rinv13),crf));
429 felec = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
431 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
433 /* Update potential sum for this i atom from the interaction with this j atom. */
434 velec = _mm_and_ps(velec,cutoff_mask);
435 velecsum = _mm_add_ps(velecsum,velec);
439 fscal = _mm_and_ps(fscal,cutoff_mask);
441 /* Update vectorial force */
442 fix1 = _mm_macc_ps(dx13,fscal,fix1);
443 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
444 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
446 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
447 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
448 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
452 /**************************
453 * CALCULATE INTERACTIONS *
454 **************************/
456 if (gmx_mm_any_lt(rsq21,rcutoff2))
459 /* REACTION-FIELD ELECTROSTATICS */
460 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
461 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
463 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
465 /* Update potential sum for this i atom from the interaction with this j atom. */
466 velec = _mm_and_ps(velec,cutoff_mask);
467 velecsum = _mm_add_ps(velecsum,velec);
471 fscal = _mm_and_ps(fscal,cutoff_mask);
473 /* Update vectorial force */
474 fix2 = _mm_macc_ps(dx21,fscal,fix2);
475 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
476 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
478 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
479 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
480 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
484 /**************************
485 * CALCULATE INTERACTIONS *
486 **************************/
488 if (gmx_mm_any_lt(rsq22,rcutoff2))
491 /* REACTION-FIELD ELECTROSTATICS */
492 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
493 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
495 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
497 /* Update potential sum for this i atom from the interaction with this j atom. */
498 velec = _mm_and_ps(velec,cutoff_mask);
499 velecsum = _mm_add_ps(velecsum,velec);
503 fscal = _mm_and_ps(fscal,cutoff_mask);
505 /* Update vectorial force */
506 fix2 = _mm_macc_ps(dx22,fscal,fix2);
507 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
508 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
510 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
511 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
512 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
516 /**************************
517 * CALCULATE INTERACTIONS *
518 **************************/
520 if (gmx_mm_any_lt(rsq23,rcutoff2))
523 /* REACTION-FIELD ELECTROSTATICS */
524 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_macc_ps(krf,rsq23,rinv23),crf));
525 felec = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
527 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
529 /* Update potential sum for this i atom from the interaction with this j atom. */
530 velec = _mm_and_ps(velec,cutoff_mask);
531 velecsum = _mm_add_ps(velecsum,velec);
535 fscal = _mm_and_ps(fscal,cutoff_mask);
537 /* Update vectorial force */
538 fix2 = _mm_macc_ps(dx23,fscal,fix2);
539 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
540 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
542 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
543 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
544 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
548 /**************************
549 * CALCULATE INTERACTIONS *
550 **************************/
552 if (gmx_mm_any_lt(rsq31,rcutoff2))
555 /* REACTION-FIELD ELECTROSTATICS */
556 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_macc_ps(krf,rsq31,rinv31),crf));
557 felec = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
559 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
561 /* Update potential sum for this i atom from the interaction with this j atom. */
562 velec = _mm_and_ps(velec,cutoff_mask);
563 velecsum = _mm_add_ps(velecsum,velec);
567 fscal = _mm_and_ps(fscal,cutoff_mask);
569 /* Update vectorial force */
570 fix3 = _mm_macc_ps(dx31,fscal,fix3);
571 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
572 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
574 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
575 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
576 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
580 /**************************
581 * CALCULATE INTERACTIONS *
582 **************************/
584 if (gmx_mm_any_lt(rsq32,rcutoff2))
587 /* REACTION-FIELD ELECTROSTATICS */
588 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_macc_ps(krf,rsq32,rinv32),crf));
589 felec = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
591 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
593 /* Update potential sum for this i atom from the interaction with this j atom. */
594 velec = _mm_and_ps(velec,cutoff_mask);
595 velecsum = _mm_add_ps(velecsum,velec);
599 fscal = _mm_and_ps(fscal,cutoff_mask);
601 /* Update vectorial force */
602 fix3 = _mm_macc_ps(dx32,fscal,fix3);
603 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
604 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
606 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
607 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
608 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
612 /**************************
613 * CALCULATE INTERACTIONS *
614 **************************/
616 if (gmx_mm_any_lt(rsq33,rcutoff2))
619 /* REACTION-FIELD ELECTROSTATICS */
620 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_macc_ps(krf,rsq33,rinv33),crf));
621 felec = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
623 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
625 /* Update potential sum for this i atom from the interaction with this j atom. */
626 velec = _mm_and_ps(velec,cutoff_mask);
627 velecsum = _mm_add_ps(velecsum,velec);
631 fscal = _mm_and_ps(fscal,cutoff_mask);
633 /* Update vectorial force */
634 fix3 = _mm_macc_ps(dx33,fscal,fix3);
635 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
636 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
638 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
639 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
640 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
644 fjptrA = f+j_coord_offsetA;
645 fjptrB = f+j_coord_offsetB;
646 fjptrC = f+j_coord_offsetC;
647 fjptrD = f+j_coord_offsetD;
649 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
650 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
651 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
653 /* Inner loop uses 398 flops */
659 /* Get j neighbor index, and coordinate index */
660 jnrlistA = jjnr[jidx];
661 jnrlistB = jjnr[jidx+1];
662 jnrlistC = jjnr[jidx+2];
663 jnrlistD = jjnr[jidx+3];
664 /* Sign of each element will be negative for non-real atoms.
665 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
666 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
668 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
669 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
670 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
671 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
672 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
673 j_coord_offsetA = DIM*jnrA;
674 j_coord_offsetB = DIM*jnrB;
675 j_coord_offsetC = DIM*jnrC;
676 j_coord_offsetD = DIM*jnrD;
678 /* load j atom coordinates */
679 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
680 x+j_coord_offsetC,x+j_coord_offsetD,
681 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
682 &jy2,&jz2,&jx3,&jy3,&jz3);
684 /* Calculate displacement vector */
685 dx00 = _mm_sub_ps(ix0,jx0);
686 dy00 = _mm_sub_ps(iy0,jy0);
687 dz00 = _mm_sub_ps(iz0,jz0);
688 dx11 = _mm_sub_ps(ix1,jx1);
689 dy11 = _mm_sub_ps(iy1,jy1);
690 dz11 = _mm_sub_ps(iz1,jz1);
691 dx12 = _mm_sub_ps(ix1,jx2);
692 dy12 = _mm_sub_ps(iy1,jy2);
693 dz12 = _mm_sub_ps(iz1,jz2);
694 dx13 = _mm_sub_ps(ix1,jx3);
695 dy13 = _mm_sub_ps(iy1,jy3);
696 dz13 = _mm_sub_ps(iz1,jz3);
697 dx21 = _mm_sub_ps(ix2,jx1);
698 dy21 = _mm_sub_ps(iy2,jy1);
699 dz21 = _mm_sub_ps(iz2,jz1);
700 dx22 = _mm_sub_ps(ix2,jx2);
701 dy22 = _mm_sub_ps(iy2,jy2);
702 dz22 = _mm_sub_ps(iz2,jz2);
703 dx23 = _mm_sub_ps(ix2,jx3);
704 dy23 = _mm_sub_ps(iy2,jy3);
705 dz23 = _mm_sub_ps(iz2,jz3);
706 dx31 = _mm_sub_ps(ix3,jx1);
707 dy31 = _mm_sub_ps(iy3,jy1);
708 dz31 = _mm_sub_ps(iz3,jz1);
709 dx32 = _mm_sub_ps(ix3,jx2);
710 dy32 = _mm_sub_ps(iy3,jy2);
711 dz32 = _mm_sub_ps(iz3,jz2);
712 dx33 = _mm_sub_ps(ix3,jx3);
713 dy33 = _mm_sub_ps(iy3,jy3);
714 dz33 = _mm_sub_ps(iz3,jz3);
716 /* Calculate squared distance and things based on it */
717 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
718 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
719 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
720 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
721 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
722 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
723 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
724 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
725 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
726 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
728 rinv11 = avx128fma_invsqrt_f(rsq11);
729 rinv12 = avx128fma_invsqrt_f(rsq12);
730 rinv13 = avx128fma_invsqrt_f(rsq13);
731 rinv21 = avx128fma_invsqrt_f(rsq21);
732 rinv22 = avx128fma_invsqrt_f(rsq22);
733 rinv23 = avx128fma_invsqrt_f(rsq23);
734 rinv31 = avx128fma_invsqrt_f(rsq31);
735 rinv32 = avx128fma_invsqrt_f(rsq32);
736 rinv33 = avx128fma_invsqrt_f(rsq33);
738 rinvsq00 = avx128fma_inv_f(rsq00);
739 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
740 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
741 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
742 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
743 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
744 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
745 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
746 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
747 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
749 fjx0 = _mm_setzero_ps();
750 fjy0 = _mm_setzero_ps();
751 fjz0 = _mm_setzero_ps();
752 fjx1 = _mm_setzero_ps();
753 fjy1 = _mm_setzero_ps();
754 fjz1 = _mm_setzero_ps();
755 fjx2 = _mm_setzero_ps();
756 fjy2 = _mm_setzero_ps();
757 fjz2 = _mm_setzero_ps();
758 fjx3 = _mm_setzero_ps();
759 fjy3 = _mm_setzero_ps();
760 fjz3 = _mm_setzero_ps();
762 /**************************
763 * CALCULATE INTERACTIONS *
764 **************************/
766 if (gmx_mm_any_lt(rsq00,rcutoff2))
769 /* LENNARD-JONES DISPERSION/REPULSION */
771 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
772 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
773 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
774 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
775 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
776 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
778 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
780 /* Update potential sum for this i atom from the interaction with this j atom. */
781 vvdw = _mm_and_ps(vvdw,cutoff_mask);
782 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
783 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
787 fscal = _mm_and_ps(fscal,cutoff_mask);
789 fscal = _mm_andnot_ps(dummy_mask,fscal);
791 /* Update vectorial force */
792 fix0 = _mm_macc_ps(dx00,fscal,fix0);
793 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
794 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
796 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
797 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
798 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
802 /**************************
803 * CALCULATE INTERACTIONS *
804 **************************/
806 if (gmx_mm_any_lt(rsq11,rcutoff2))
809 /* REACTION-FIELD ELECTROSTATICS */
810 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
811 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
813 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
815 /* Update potential sum for this i atom from the interaction with this j atom. */
816 velec = _mm_and_ps(velec,cutoff_mask);
817 velec = _mm_andnot_ps(dummy_mask,velec);
818 velecsum = _mm_add_ps(velecsum,velec);
822 fscal = _mm_and_ps(fscal,cutoff_mask);
824 fscal = _mm_andnot_ps(dummy_mask,fscal);
826 /* Update vectorial force */
827 fix1 = _mm_macc_ps(dx11,fscal,fix1);
828 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
829 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
831 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
832 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
833 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
837 /**************************
838 * CALCULATE INTERACTIONS *
839 **************************/
841 if (gmx_mm_any_lt(rsq12,rcutoff2))
844 /* REACTION-FIELD ELECTROSTATICS */
845 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
846 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
848 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
850 /* Update potential sum for this i atom from the interaction with this j atom. */
851 velec = _mm_and_ps(velec,cutoff_mask);
852 velec = _mm_andnot_ps(dummy_mask,velec);
853 velecsum = _mm_add_ps(velecsum,velec);
857 fscal = _mm_and_ps(fscal,cutoff_mask);
859 fscal = _mm_andnot_ps(dummy_mask,fscal);
861 /* Update vectorial force */
862 fix1 = _mm_macc_ps(dx12,fscal,fix1);
863 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
864 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
866 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
867 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
868 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
872 /**************************
873 * CALCULATE INTERACTIONS *
874 **************************/
876 if (gmx_mm_any_lt(rsq13,rcutoff2))
879 /* REACTION-FIELD ELECTROSTATICS */
880 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_macc_ps(krf,rsq13,rinv13),crf));
881 felec = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
883 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
885 /* Update potential sum for this i atom from the interaction with this j atom. */
886 velec = _mm_and_ps(velec,cutoff_mask);
887 velec = _mm_andnot_ps(dummy_mask,velec);
888 velecsum = _mm_add_ps(velecsum,velec);
892 fscal = _mm_and_ps(fscal,cutoff_mask);
894 fscal = _mm_andnot_ps(dummy_mask,fscal);
896 /* Update vectorial force */
897 fix1 = _mm_macc_ps(dx13,fscal,fix1);
898 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
899 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
901 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
902 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
903 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
907 /**************************
908 * CALCULATE INTERACTIONS *
909 **************************/
911 if (gmx_mm_any_lt(rsq21,rcutoff2))
914 /* REACTION-FIELD ELECTROSTATICS */
915 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
916 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
918 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
920 /* Update potential sum for this i atom from the interaction with this j atom. */
921 velec = _mm_and_ps(velec,cutoff_mask);
922 velec = _mm_andnot_ps(dummy_mask,velec);
923 velecsum = _mm_add_ps(velecsum,velec);
927 fscal = _mm_and_ps(fscal,cutoff_mask);
929 fscal = _mm_andnot_ps(dummy_mask,fscal);
931 /* Update vectorial force */
932 fix2 = _mm_macc_ps(dx21,fscal,fix2);
933 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
934 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
936 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
937 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
938 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
942 /**************************
943 * CALCULATE INTERACTIONS *
944 **************************/
946 if (gmx_mm_any_lt(rsq22,rcutoff2))
949 /* REACTION-FIELD ELECTROSTATICS */
950 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
951 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
953 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
955 /* Update potential sum for this i atom from the interaction with this j atom. */
956 velec = _mm_and_ps(velec,cutoff_mask);
957 velec = _mm_andnot_ps(dummy_mask,velec);
958 velecsum = _mm_add_ps(velecsum,velec);
962 fscal = _mm_and_ps(fscal,cutoff_mask);
964 fscal = _mm_andnot_ps(dummy_mask,fscal);
966 /* Update vectorial force */
967 fix2 = _mm_macc_ps(dx22,fscal,fix2);
968 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
969 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
971 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
972 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
973 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
977 /**************************
978 * CALCULATE INTERACTIONS *
979 **************************/
981 if (gmx_mm_any_lt(rsq23,rcutoff2))
984 /* REACTION-FIELD ELECTROSTATICS */
985 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_macc_ps(krf,rsq23,rinv23),crf));
986 felec = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
988 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
990 /* Update potential sum for this i atom from the interaction with this j atom. */
991 velec = _mm_and_ps(velec,cutoff_mask);
992 velec = _mm_andnot_ps(dummy_mask,velec);
993 velecsum = _mm_add_ps(velecsum,velec);
997 fscal = _mm_and_ps(fscal,cutoff_mask);
999 fscal = _mm_andnot_ps(dummy_mask,fscal);
1001 /* Update vectorial force */
1002 fix2 = _mm_macc_ps(dx23,fscal,fix2);
1003 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
1004 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
1006 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
1007 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
1008 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
1012 /**************************
1013 * CALCULATE INTERACTIONS *
1014 **************************/
1016 if (gmx_mm_any_lt(rsq31,rcutoff2))
1019 /* REACTION-FIELD ELECTROSTATICS */
1020 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_macc_ps(krf,rsq31,rinv31),crf));
1021 felec = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
1023 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
1025 /* Update potential sum for this i atom from the interaction with this j atom. */
1026 velec = _mm_and_ps(velec,cutoff_mask);
1027 velec = _mm_andnot_ps(dummy_mask,velec);
1028 velecsum = _mm_add_ps(velecsum,velec);
1032 fscal = _mm_and_ps(fscal,cutoff_mask);
1034 fscal = _mm_andnot_ps(dummy_mask,fscal);
1036 /* Update vectorial force */
1037 fix3 = _mm_macc_ps(dx31,fscal,fix3);
1038 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
1039 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
1041 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
1042 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
1043 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
1047 /**************************
1048 * CALCULATE INTERACTIONS *
1049 **************************/
1051 if (gmx_mm_any_lt(rsq32,rcutoff2))
1054 /* REACTION-FIELD ELECTROSTATICS */
1055 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_macc_ps(krf,rsq32,rinv32),crf));
1056 felec = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
1058 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
1060 /* Update potential sum for this i atom from the interaction with this j atom. */
1061 velec = _mm_and_ps(velec,cutoff_mask);
1062 velec = _mm_andnot_ps(dummy_mask,velec);
1063 velecsum = _mm_add_ps(velecsum,velec);
1067 fscal = _mm_and_ps(fscal,cutoff_mask);
1069 fscal = _mm_andnot_ps(dummy_mask,fscal);
1071 /* Update vectorial force */
1072 fix3 = _mm_macc_ps(dx32,fscal,fix3);
1073 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
1074 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
1076 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
1077 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
1078 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
1082 /**************************
1083 * CALCULATE INTERACTIONS *
1084 **************************/
1086 if (gmx_mm_any_lt(rsq33,rcutoff2))
1089 /* REACTION-FIELD ELECTROSTATICS */
1090 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_macc_ps(krf,rsq33,rinv33),crf));
1091 felec = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
1093 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
1095 /* Update potential sum for this i atom from the interaction with this j atom. */
1096 velec = _mm_and_ps(velec,cutoff_mask);
1097 velec = _mm_andnot_ps(dummy_mask,velec);
1098 velecsum = _mm_add_ps(velecsum,velec);
1102 fscal = _mm_and_ps(fscal,cutoff_mask);
1104 fscal = _mm_andnot_ps(dummy_mask,fscal);
1106 /* Update vectorial force */
1107 fix3 = _mm_macc_ps(dx33,fscal,fix3);
1108 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
1109 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
1111 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
1112 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
1113 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
1117 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1118 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1119 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1120 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1122 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1123 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1124 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1126 /* Inner loop uses 398 flops */
1129 /* End of innermost loop */
1131 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1132 f+i_coord_offset,fshift+i_shift_offset);
1135 /* Update potential energies */
1136 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1137 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1139 /* Increment number of inner iterations */
1140 inneriter += j_index_end - j_index_start;
1142 /* Outer loop uses 26 flops */
1145 /* Increment number of outer iterations */
1148 /* Update outer/inner flops */
1150 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*26 + inneriter*398);
1153 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW4W4_F_avx_128_fma_single
1154 * Electrostatics interaction: ReactionField
1155 * VdW interaction: LennardJones
1156 * Geometry: Water4-Water4
1157 * Calculate force/pot: Force
1160 nb_kernel_ElecRFCut_VdwLJSh_GeomW4W4_F_avx_128_fma_single
1161 (t_nblist * gmx_restrict nlist,
1162 rvec * gmx_restrict xx,
1163 rvec * gmx_restrict ff,
1164 struct t_forcerec * gmx_restrict fr,
1165 t_mdatoms * gmx_restrict mdatoms,
1166 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1167 t_nrnb * gmx_restrict nrnb)
1169 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1170 * just 0 for non-waters.
1171 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
1172 * jnr indices corresponding to data put in the four positions in the SIMD register.
1174 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1175 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1176 int jnrA,jnrB,jnrC,jnrD;
1177 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1178 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1179 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1180 real rcutoff_scalar;
1181 real *shiftvec,*fshift,*x,*f;
1182 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1183 real scratch[4*DIM];
1184 __m128 fscal,rcutoff,rcutoff2,jidxall;
1186 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1188 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1190 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1192 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1193 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1194 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1195 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1196 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1197 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1198 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1199 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
1200 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1201 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1202 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1203 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1204 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1205 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1206 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1207 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1208 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1209 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1210 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1211 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1214 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1217 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1218 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1219 __m128 dummy_mask,cutoff_mask;
1220 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1221 __m128 one = _mm_set1_ps(1.0);
1222 __m128 two = _mm_set1_ps(2.0);
1228 jindex = nlist->jindex;
1230 shiftidx = nlist->shift;
1232 shiftvec = fr->shift_vec[0];
1233 fshift = fr->fshift[0];
1234 facel = _mm_set1_ps(fr->ic->epsfac);
1235 charge = mdatoms->chargeA;
1236 krf = _mm_set1_ps(fr->ic->k_rf);
1237 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1238 crf = _mm_set1_ps(fr->ic->c_rf);
1239 nvdwtype = fr->ntype;
1240 vdwparam = fr->nbfp;
1241 vdwtype = mdatoms->typeA;
1243 /* Setup water-specific parameters */
1244 inr = nlist->iinr[0];
1245 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1246 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1247 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
1248 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1250 jq1 = _mm_set1_ps(charge[inr+1]);
1251 jq2 = _mm_set1_ps(charge[inr+2]);
1252 jq3 = _mm_set1_ps(charge[inr+3]);
1253 vdwjidx0A = 2*vdwtype[inr+0];
1254 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1255 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1256 qq11 = _mm_mul_ps(iq1,jq1);
1257 qq12 = _mm_mul_ps(iq1,jq2);
1258 qq13 = _mm_mul_ps(iq1,jq3);
1259 qq21 = _mm_mul_ps(iq2,jq1);
1260 qq22 = _mm_mul_ps(iq2,jq2);
1261 qq23 = _mm_mul_ps(iq2,jq3);
1262 qq31 = _mm_mul_ps(iq3,jq1);
1263 qq32 = _mm_mul_ps(iq3,jq2);
1264 qq33 = _mm_mul_ps(iq3,jq3);
1266 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1267 rcutoff_scalar = fr->ic->rcoulomb;
1268 rcutoff = _mm_set1_ps(rcutoff_scalar);
1269 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1271 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
1272 rvdw = _mm_set1_ps(fr->ic->rvdw);
1274 /* Avoid stupid compiler warnings */
1275 jnrA = jnrB = jnrC = jnrD = 0;
1276 j_coord_offsetA = 0;
1277 j_coord_offsetB = 0;
1278 j_coord_offsetC = 0;
1279 j_coord_offsetD = 0;
1284 for(iidx=0;iidx<4*DIM;iidx++)
1286 scratch[iidx] = 0.0;
1289 /* Start outer loop over neighborlists */
1290 for(iidx=0; iidx<nri; iidx++)
1292 /* Load shift vector for this list */
1293 i_shift_offset = DIM*shiftidx[iidx];
1295 /* Load limits for loop over neighbors */
1296 j_index_start = jindex[iidx];
1297 j_index_end = jindex[iidx+1];
1299 /* Get outer coordinate index */
1301 i_coord_offset = DIM*inr;
1303 /* Load i particle coords and add shift vector */
1304 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1305 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1307 fix0 = _mm_setzero_ps();
1308 fiy0 = _mm_setzero_ps();
1309 fiz0 = _mm_setzero_ps();
1310 fix1 = _mm_setzero_ps();
1311 fiy1 = _mm_setzero_ps();
1312 fiz1 = _mm_setzero_ps();
1313 fix2 = _mm_setzero_ps();
1314 fiy2 = _mm_setzero_ps();
1315 fiz2 = _mm_setzero_ps();
1316 fix3 = _mm_setzero_ps();
1317 fiy3 = _mm_setzero_ps();
1318 fiz3 = _mm_setzero_ps();
1320 /* Start inner kernel loop */
1321 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1324 /* Get j neighbor index, and coordinate index */
1326 jnrB = jjnr[jidx+1];
1327 jnrC = jjnr[jidx+2];
1328 jnrD = jjnr[jidx+3];
1329 j_coord_offsetA = DIM*jnrA;
1330 j_coord_offsetB = DIM*jnrB;
1331 j_coord_offsetC = DIM*jnrC;
1332 j_coord_offsetD = DIM*jnrD;
1334 /* load j atom coordinates */
1335 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1336 x+j_coord_offsetC,x+j_coord_offsetD,
1337 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1338 &jy2,&jz2,&jx3,&jy3,&jz3);
1340 /* Calculate displacement vector */
1341 dx00 = _mm_sub_ps(ix0,jx0);
1342 dy00 = _mm_sub_ps(iy0,jy0);
1343 dz00 = _mm_sub_ps(iz0,jz0);
1344 dx11 = _mm_sub_ps(ix1,jx1);
1345 dy11 = _mm_sub_ps(iy1,jy1);
1346 dz11 = _mm_sub_ps(iz1,jz1);
1347 dx12 = _mm_sub_ps(ix1,jx2);
1348 dy12 = _mm_sub_ps(iy1,jy2);
1349 dz12 = _mm_sub_ps(iz1,jz2);
1350 dx13 = _mm_sub_ps(ix1,jx3);
1351 dy13 = _mm_sub_ps(iy1,jy3);
1352 dz13 = _mm_sub_ps(iz1,jz3);
1353 dx21 = _mm_sub_ps(ix2,jx1);
1354 dy21 = _mm_sub_ps(iy2,jy1);
1355 dz21 = _mm_sub_ps(iz2,jz1);
1356 dx22 = _mm_sub_ps(ix2,jx2);
1357 dy22 = _mm_sub_ps(iy2,jy2);
1358 dz22 = _mm_sub_ps(iz2,jz2);
1359 dx23 = _mm_sub_ps(ix2,jx3);
1360 dy23 = _mm_sub_ps(iy2,jy3);
1361 dz23 = _mm_sub_ps(iz2,jz3);
1362 dx31 = _mm_sub_ps(ix3,jx1);
1363 dy31 = _mm_sub_ps(iy3,jy1);
1364 dz31 = _mm_sub_ps(iz3,jz1);
1365 dx32 = _mm_sub_ps(ix3,jx2);
1366 dy32 = _mm_sub_ps(iy3,jy2);
1367 dz32 = _mm_sub_ps(iz3,jz2);
1368 dx33 = _mm_sub_ps(ix3,jx3);
1369 dy33 = _mm_sub_ps(iy3,jy3);
1370 dz33 = _mm_sub_ps(iz3,jz3);
1372 /* Calculate squared distance and things based on it */
1373 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1374 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1375 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1376 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1377 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1378 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1379 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1380 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1381 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1382 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1384 rinv11 = avx128fma_invsqrt_f(rsq11);
1385 rinv12 = avx128fma_invsqrt_f(rsq12);
1386 rinv13 = avx128fma_invsqrt_f(rsq13);
1387 rinv21 = avx128fma_invsqrt_f(rsq21);
1388 rinv22 = avx128fma_invsqrt_f(rsq22);
1389 rinv23 = avx128fma_invsqrt_f(rsq23);
1390 rinv31 = avx128fma_invsqrt_f(rsq31);
1391 rinv32 = avx128fma_invsqrt_f(rsq32);
1392 rinv33 = avx128fma_invsqrt_f(rsq33);
1394 rinvsq00 = avx128fma_inv_f(rsq00);
1395 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1396 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1397 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1398 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1399 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1400 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1401 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1402 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1403 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1405 fjx0 = _mm_setzero_ps();
1406 fjy0 = _mm_setzero_ps();
1407 fjz0 = _mm_setzero_ps();
1408 fjx1 = _mm_setzero_ps();
1409 fjy1 = _mm_setzero_ps();
1410 fjz1 = _mm_setzero_ps();
1411 fjx2 = _mm_setzero_ps();
1412 fjy2 = _mm_setzero_ps();
1413 fjz2 = _mm_setzero_ps();
1414 fjx3 = _mm_setzero_ps();
1415 fjy3 = _mm_setzero_ps();
1416 fjz3 = _mm_setzero_ps();
1418 /**************************
1419 * CALCULATE INTERACTIONS *
1420 **************************/
1422 if (gmx_mm_any_lt(rsq00,rcutoff2))
1425 /* LENNARD-JONES DISPERSION/REPULSION */
1427 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1428 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1430 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1434 fscal = _mm_and_ps(fscal,cutoff_mask);
1436 /* Update vectorial force */
1437 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1438 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1439 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1441 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1442 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1443 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1447 /**************************
1448 * CALCULATE INTERACTIONS *
1449 **************************/
1451 if (gmx_mm_any_lt(rsq11,rcutoff2))
1454 /* REACTION-FIELD ELECTROSTATICS */
1455 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1457 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1461 fscal = _mm_and_ps(fscal,cutoff_mask);
1463 /* Update vectorial force */
1464 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1465 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1466 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1468 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1469 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1470 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1474 /**************************
1475 * CALCULATE INTERACTIONS *
1476 **************************/
1478 if (gmx_mm_any_lt(rsq12,rcutoff2))
1481 /* REACTION-FIELD ELECTROSTATICS */
1482 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1484 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1488 fscal = _mm_and_ps(fscal,cutoff_mask);
1490 /* Update vectorial force */
1491 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1492 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1493 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1495 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1496 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1497 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1501 /**************************
1502 * CALCULATE INTERACTIONS *
1503 **************************/
1505 if (gmx_mm_any_lt(rsq13,rcutoff2))
1508 /* REACTION-FIELD ELECTROSTATICS */
1509 felec = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
1511 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
1515 fscal = _mm_and_ps(fscal,cutoff_mask);
1517 /* Update vectorial force */
1518 fix1 = _mm_macc_ps(dx13,fscal,fix1);
1519 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
1520 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
1522 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
1523 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
1524 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
1528 /**************************
1529 * CALCULATE INTERACTIONS *
1530 **************************/
1532 if (gmx_mm_any_lt(rsq21,rcutoff2))
1535 /* REACTION-FIELD ELECTROSTATICS */
1536 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1538 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1542 fscal = _mm_and_ps(fscal,cutoff_mask);
1544 /* Update vectorial force */
1545 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1546 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1547 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1549 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1550 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1551 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1555 /**************************
1556 * CALCULATE INTERACTIONS *
1557 **************************/
1559 if (gmx_mm_any_lt(rsq22,rcutoff2))
1562 /* REACTION-FIELD ELECTROSTATICS */
1563 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1565 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1569 fscal = _mm_and_ps(fscal,cutoff_mask);
1571 /* Update vectorial force */
1572 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1573 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1574 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1576 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1577 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1578 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1582 /**************************
1583 * CALCULATE INTERACTIONS *
1584 **************************/
1586 if (gmx_mm_any_lt(rsq23,rcutoff2))
1589 /* REACTION-FIELD ELECTROSTATICS */
1590 felec = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
1592 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
1596 fscal = _mm_and_ps(fscal,cutoff_mask);
1598 /* Update vectorial force */
1599 fix2 = _mm_macc_ps(dx23,fscal,fix2);
1600 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
1601 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
1603 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
1604 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
1605 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
1609 /**************************
1610 * CALCULATE INTERACTIONS *
1611 **************************/
1613 if (gmx_mm_any_lt(rsq31,rcutoff2))
1616 /* REACTION-FIELD ELECTROSTATICS */
1617 felec = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
1619 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
1623 fscal = _mm_and_ps(fscal,cutoff_mask);
1625 /* Update vectorial force */
1626 fix3 = _mm_macc_ps(dx31,fscal,fix3);
1627 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
1628 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
1630 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
1631 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
1632 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
1636 /**************************
1637 * CALCULATE INTERACTIONS *
1638 **************************/
1640 if (gmx_mm_any_lt(rsq32,rcutoff2))
1643 /* REACTION-FIELD ELECTROSTATICS */
1644 felec = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
1646 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
1650 fscal = _mm_and_ps(fscal,cutoff_mask);
1652 /* Update vectorial force */
1653 fix3 = _mm_macc_ps(dx32,fscal,fix3);
1654 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
1655 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
1657 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
1658 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
1659 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
1663 /**************************
1664 * CALCULATE INTERACTIONS *
1665 **************************/
1667 if (gmx_mm_any_lt(rsq33,rcutoff2))
1670 /* REACTION-FIELD ELECTROSTATICS */
1671 felec = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
1673 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
1677 fscal = _mm_and_ps(fscal,cutoff_mask);
1679 /* Update vectorial force */
1680 fix3 = _mm_macc_ps(dx33,fscal,fix3);
1681 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
1682 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
1684 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
1685 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
1686 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
1690 fjptrA = f+j_coord_offsetA;
1691 fjptrB = f+j_coord_offsetB;
1692 fjptrC = f+j_coord_offsetC;
1693 fjptrD = f+j_coord_offsetD;
1695 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1696 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1697 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1699 /* Inner loop uses 333 flops */
1702 if(jidx<j_index_end)
1705 /* Get j neighbor index, and coordinate index */
1706 jnrlistA = jjnr[jidx];
1707 jnrlistB = jjnr[jidx+1];
1708 jnrlistC = jjnr[jidx+2];
1709 jnrlistD = jjnr[jidx+3];
1710 /* Sign of each element will be negative for non-real atoms.
1711 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1712 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1714 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1715 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1716 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1717 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1718 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1719 j_coord_offsetA = DIM*jnrA;
1720 j_coord_offsetB = DIM*jnrB;
1721 j_coord_offsetC = DIM*jnrC;
1722 j_coord_offsetD = DIM*jnrD;
1724 /* load j atom coordinates */
1725 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1726 x+j_coord_offsetC,x+j_coord_offsetD,
1727 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1728 &jy2,&jz2,&jx3,&jy3,&jz3);
1730 /* Calculate displacement vector */
1731 dx00 = _mm_sub_ps(ix0,jx0);
1732 dy00 = _mm_sub_ps(iy0,jy0);
1733 dz00 = _mm_sub_ps(iz0,jz0);
1734 dx11 = _mm_sub_ps(ix1,jx1);
1735 dy11 = _mm_sub_ps(iy1,jy1);
1736 dz11 = _mm_sub_ps(iz1,jz1);
1737 dx12 = _mm_sub_ps(ix1,jx2);
1738 dy12 = _mm_sub_ps(iy1,jy2);
1739 dz12 = _mm_sub_ps(iz1,jz2);
1740 dx13 = _mm_sub_ps(ix1,jx3);
1741 dy13 = _mm_sub_ps(iy1,jy3);
1742 dz13 = _mm_sub_ps(iz1,jz3);
1743 dx21 = _mm_sub_ps(ix2,jx1);
1744 dy21 = _mm_sub_ps(iy2,jy1);
1745 dz21 = _mm_sub_ps(iz2,jz1);
1746 dx22 = _mm_sub_ps(ix2,jx2);
1747 dy22 = _mm_sub_ps(iy2,jy2);
1748 dz22 = _mm_sub_ps(iz2,jz2);
1749 dx23 = _mm_sub_ps(ix2,jx3);
1750 dy23 = _mm_sub_ps(iy2,jy3);
1751 dz23 = _mm_sub_ps(iz2,jz3);
1752 dx31 = _mm_sub_ps(ix3,jx1);
1753 dy31 = _mm_sub_ps(iy3,jy1);
1754 dz31 = _mm_sub_ps(iz3,jz1);
1755 dx32 = _mm_sub_ps(ix3,jx2);
1756 dy32 = _mm_sub_ps(iy3,jy2);
1757 dz32 = _mm_sub_ps(iz3,jz2);
1758 dx33 = _mm_sub_ps(ix3,jx3);
1759 dy33 = _mm_sub_ps(iy3,jy3);
1760 dz33 = _mm_sub_ps(iz3,jz3);
1762 /* Calculate squared distance and things based on it */
1763 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1764 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1765 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1766 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1767 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1768 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1769 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1770 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1771 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1772 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1774 rinv11 = avx128fma_invsqrt_f(rsq11);
1775 rinv12 = avx128fma_invsqrt_f(rsq12);
1776 rinv13 = avx128fma_invsqrt_f(rsq13);
1777 rinv21 = avx128fma_invsqrt_f(rsq21);
1778 rinv22 = avx128fma_invsqrt_f(rsq22);
1779 rinv23 = avx128fma_invsqrt_f(rsq23);
1780 rinv31 = avx128fma_invsqrt_f(rsq31);
1781 rinv32 = avx128fma_invsqrt_f(rsq32);
1782 rinv33 = avx128fma_invsqrt_f(rsq33);
1784 rinvsq00 = avx128fma_inv_f(rsq00);
1785 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1786 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1787 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1788 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1789 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1790 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1791 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1792 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1793 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1795 fjx0 = _mm_setzero_ps();
1796 fjy0 = _mm_setzero_ps();
1797 fjz0 = _mm_setzero_ps();
1798 fjx1 = _mm_setzero_ps();
1799 fjy1 = _mm_setzero_ps();
1800 fjz1 = _mm_setzero_ps();
1801 fjx2 = _mm_setzero_ps();
1802 fjy2 = _mm_setzero_ps();
1803 fjz2 = _mm_setzero_ps();
1804 fjx3 = _mm_setzero_ps();
1805 fjy3 = _mm_setzero_ps();
1806 fjz3 = _mm_setzero_ps();
1808 /**************************
1809 * CALCULATE INTERACTIONS *
1810 **************************/
1812 if (gmx_mm_any_lt(rsq00,rcutoff2))
1815 /* LENNARD-JONES DISPERSION/REPULSION */
1817 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1818 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1820 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1824 fscal = _mm_and_ps(fscal,cutoff_mask);
1826 fscal = _mm_andnot_ps(dummy_mask,fscal);
1828 /* Update vectorial force */
1829 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1830 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1831 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1833 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1834 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1835 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1839 /**************************
1840 * CALCULATE INTERACTIONS *
1841 **************************/
1843 if (gmx_mm_any_lt(rsq11,rcutoff2))
1846 /* REACTION-FIELD ELECTROSTATICS */
1847 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1849 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1853 fscal = _mm_and_ps(fscal,cutoff_mask);
1855 fscal = _mm_andnot_ps(dummy_mask,fscal);
1857 /* Update vectorial force */
1858 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1859 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1860 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1862 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1863 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1864 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1868 /**************************
1869 * CALCULATE INTERACTIONS *
1870 **************************/
1872 if (gmx_mm_any_lt(rsq12,rcutoff2))
1875 /* REACTION-FIELD ELECTROSTATICS */
1876 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1878 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1882 fscal = _mm_and_ps(fscal,cutoff_mask);
1884 fscal = _mm_andnot_ps(dummy_mask,fscal);
1886 /* Update vectorial force */
1887 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1888 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1889 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1891 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1892 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1893 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1897 /**************************
1898 * CALCULATE INTERACTIONS *
1899 **************************/
1901 if (gmx_mm_any_lt(rsq13,rcutoff2))
1904 /* REACTION-FIELD ELECTROSTATICS */
1905 felec = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
1907 cutoff_mask = _mm_cmplt_ps(rsq13,rcutoff2);
1911 fscal = _mm_and_ps(fscal,cutoff_mask);
1913 fscal = _mm_andnot_ps(dummy_mask,fscal);
1915 /* Update vectorial force */
1916 fix1 = _mm_macc_ps(dx13,fscal,fix1);
1917 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
1918 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
1920 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
1921 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
1922 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
1926 /**************************
1927 * CALCULATE INTERACTIONS *
1928 **************************/
1930 if (gmx_mm_any_lt(rsq21,rcutoff2))
1933 /* REACTION-FIELD ELECTROSTATICS */
1934 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1936 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1940 fscal = _mm_and_ps(fscal,cutoff_mask);
1942 fscal = _mm_andnot_ps(dummy_mask,fscal);
1944 /* Update vectorial force */
1945 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1946 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1947 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1949 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1950 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1951 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1955 /**************************
1956 * CALCULATE INTERACTIONS *
1957 **************************/
1959 if (gmx_mm_any_lt(rsq22,rcutoff2))
1962 /* REACTION-FIELD ELECTROSTATICS */
1963 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1965 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1969 fscal = _mm_and_ps(fscal,cutoff_mask);
1971 fscal = _mm_andnot_ps(dummy_mask,fscal);
1973 /* Update vectorial force */
1974 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1975 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1976 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1978 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1979 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1980 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1984 /**************************
1985 * CALCULATE INTERACTIONS *
1986 **************************/
1988 if (gmx_mm_any_lt(rsq23,rcutoff2))
1991 /* REACTION-FIELD ELECTROSTATICS */
1992 felec = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
1994 cutoff_mask = _mm_cmplt_ps(rsq23,rcutoff2);
1998 fscal = _mm_and_ps(fscal,cutoff_mask);
2000 fscal = _mm_andnot_ps(dummy_mask,fscal);
2002 /* Update vectorial force */
2003 fix2 = _mm_macc_ps(dx23,fscal,fix2);
2004 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
2005 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
2007 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
2008 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
2009 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
2013 /**************************
2014 * CALCULATE INTERACTIONS *
2015 **************************/
2017 if (gmx_mm_any_lt(rsq31,rcutoff2))
2020 /* REACTION-FIELD ELECTROSTATICS */
2021 felec = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
2023 cutoff_mask = _mm_cmplt_ps(rsq31,rcutoff2);
2027 fscal = _mm_and_ps(fscal,cutoff_mask);
2029 fscal = _mm_andnot_ps(dummy_mask,fscal);
2031 /* Update vectorial force */
2032 fix3 = _mm_macc_ps(dx31,fscal,fix3);
2033 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
2034 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
2036 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
2037 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
2038 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
2042 /**************************
2043 * CALCULATE INTERACTIONS *
2044 **************************/
2046 if (gmx_mm_any_lt(rsq32,rcutoff2))
2049 /* REACTION-FIELD ELECTROSTATICS */
2050 felec = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
2052 cutoff_mask = _mm_cmplt_ps(rsq32,rcutoff2);
2056 fscal = _mm_and_ps(fscal,cutoff_mask);
2058 fscal = _mm_andnot_ps(dummy_mask,fscal);
2060 /* Update vectorial force */
2061 fix3 = _mm_macc_ps(dx32,fscal,fix3);
2062 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
2063 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
2065 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
2066 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
2067 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
2071 /**************************
2072 * CALCULATE INTERACTIONS *
2073 **************************/
2075 if (gmx_mm_any_lt(rsq33,rcutoff2))
2078 /* REACTION-FIELD ELECTROSTATICS */
2079 felec = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
2081 cutoff_mask = _mm_cmplt_ps(rsq33,rcutoff2);
2085 fscal = _mm_and_ps(fscal,cutoff_mask);
2087 fscal = _mm_andnot_ps(dummy_mask,fscal);
2089 /* Update vectorial force */
2090 fix3 = _mm_macc_ps(dx33,fscal,fix3);
2091 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
2092 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
2094 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
2095 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
2096 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
2100 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2101 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2102 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2103 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2105 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
2106 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
2107 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
2109 /* Inner loop uses 333 flops */
2112 /* End of innermost loop */
2114 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
2115 f+i_coord_offset,fshift+i_shift_offset);
2117 /* Increment number of inner iterations */
2118 inneriter += j_index_end - j_index_start;
2120 /* Outer loop uses 24 flops */
2123 /* Increment number of outer iterations */
2126 /* Update outer/inner flops */
2128 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*24 + inneriter*333);