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_VdwCSTab_GeomW4P1_VF_avx_128_fma_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: CubicSplineTable
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_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 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
99 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
102 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
103 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
105 __m128i ifour = _mm_set1_epi32(4);
106 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
108 __m128 dummy_mask,cutoff_mask;
109 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
110 __m128 one = _mm_set1_ps(1.0);
111 __m128 two = _mm_set1_ps(2.0);
117 jindex = nlist->jindex;
119 shiftidx = nlist->shift;
121 shiftvec = fr->shift_vec[0];
122 fshift = fr->fshift[0];
123 facel = _mm_set1_ps(fr->ic->epsfac);
124 charge = mdatoms->chargeA;
125 krf = _mm_set1_ps(fr->ic->k_rf);
126 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
127 crf = _mm_set1_ps(fr->ic->c_rf);
128 nvdwtype = fr->ntype;
130 vdwtype = mdatoms->typeA;
132 vftab = kernel_data->table_vdw->data;
133 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
135 /* Setup water-specific parameters */
136 inr = nlist->iinr[0];
137 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
138 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
139 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
140 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
142 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
143 rcutoff_scalar = fr->ic->rcoulomb;
144 rcutoff = _mm_set1_ps(rcutoff_scalar);
145 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
147 /* Avoid stupid compiler warnings */
148 jnrA = jnrB = jnrC = jnrD = 0;
157 for(iidx=0;iidx<4*DIM;iidx++)
162 /* Start outer loop over neighborlists */
163 for(iidx=0; iidx<nri; iidx++)
165 /* Load shift vector for this list */
166 i_shift_offset = DIM*shiftidx[iidx];
168 /* Load limits for loop over neighbors */
169 j_index_start = jindex[iidx];
170 j_index_end = jindex[iidx+1];
172 /* Get outer coordinate index */
174 i_coord_offset = DIM*inr;
176 /* Load i particle coords and add shift vector */
177 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
178 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
180 fix0 = _mm_setzero_ps();
181 fiy0 = _mm_setzero_ps();
182 fiz0 = _mm_setzero_ps();
183 fix1 = _mm_setzero_ps();
184 fiy1 = _mm_setzero_ps();
185 fiz1 = _mm_setzero_ps();
186 fix2 = _mm_setzero_ps();
187 fiy2 = _mm_setzero_ps();
188 fiz2 = _mm_setzero_ps();
189 fix3 = _mm_setzero_ps();
190 fiy3 = _mm_setzero_ps();
191 fiz3 = _mm_setzero_ps();
193 /* Reset potential sums */
194 velecsum = _mm_setzero_ps();
195 vvdwsum = _mm_setzero_ps();
197 /* Start inner kernel loop */
198 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
201 /* Get j neighbor index, and coordinate index */
206 j_coord_offsetA = DIM*jnrA;
207 j_coord_offsetB = DIM*jnrB;
208 j_coord_offsetC = DIM*jnrC;
209 j_coord_offsetD = DIM*jnrD;
211 /* load j atom coordinates */
212 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
213 x+j_coord_offsetC,x+j_coord_offsetD,
216 /* Calculate displacement vector */
217 dx00 = _mm_sub_ps(ix0,jx0);
218 dy00 = _mm_sub_ps(iy0,jy0);
219 dz00 = _mm_sub_ps(iz0,jz0);
220 dx10 = _mm_sub_ps(ix1,jx0);
221 dy10 = _mm_sub_ps(iy1,jy0);
222 dz10 = _mm_sub_ps(iz1,jz0);
223 dx20 = _mm_sub_ps(ix2,jx0);
224 dy20 = _mm_sub_ps(iy2,jy0);
225 dz20 = _mm_sub_ps(iz2,jz0);
226 dx30 = _mm_sub_ps(ix3,jx0);
227 dy30 = _mm_sub_ps(iy3,jy0);
228 dz30 = _mm_sub_ps(iz3,jz0);
230 /* Calculate squared distance and things based on it */
231 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
232 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
233 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
234 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
236 rinv00 = avx128fma_invsqrt_f(rsq00);
237 rinv10 = avx128fma_invsqrt_f(rsq10);
238 rinv20 = avx128fma_invsqrt_f(rsq20);
239 rinv30 = avx128fma_invsqrt_f(rsq30);
241 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
242 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
243 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
245 /* Load parameters for j particles */
246 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
247 charge+jnrC+0,charge+jnrD+0);
248 vdwjidx0A = 2*vdwtype[jnrA+0];
249 vdwjidx0B = 2*vdwtype[jnrB+0];
250 vdwjidx0C = 2*vdwtype[jnrC+0];
251 vdwjidx0D = 2*vdwtype[jnrD+0];
253 fjx0 = _mm_setzero_ps();
254 fjy0 = _mm_setzero_ps();
255 fjz0 = _mm_setzero_ps();
257 /**************************
258 * CALCULATE INTERACTIONS *
259 **************************/
261 r00 = _mm_mul_ps(rsq00,rinv00);
263 /* Compute parameters for interactions between i and j atoms */
264 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
265 vdwparam+vdwioffset0+vdwjidx0B,
266 vdwparam+vdwioffset0+vdwjidx0C,
267 vdwparam+vdwioffset0+vdwjidx0D,
270 /* Calculate table index by multiplying r with table scale and truncate to integer */
271 rt = _mm_mul_ps(r00,vftabscale);
272 vfitab = _mm_cvttps_epi32(rt);
274 vfeps = _mm_frcz_ps(rt);
276 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
278 twovfeps = _mm_add_ps(vfeps,vfeps);
279 vfitab = _mm_slli_epi32(vfitab,3);
281 /* CUBIC SPLINE TABLE DISPERSION */
282 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
283 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
284 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
285 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
286 _MM_TRANSPOSE4_PS(Y,F,G,H);
287 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
288 VV = _mm_macc_ps(vfeps,Fp,Y);
289 vvdw6 = _mm_mul_ps(c6_00,VV);
290 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
291 fvdw6 = _mm_mul_ps(c6_00,FF);
293 /* CUBIC SPLINE TABLE REPULSION */
294 vfitab = _mm_add_epi32(vfitab,ifour);
295 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
296 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
297 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
298 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
299 _MM_TRANSPOSE4_PS(Y,F,G,H);
300 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
301 VV = _mm_macc_ps(vfeps,Fp,Y);
302 vvdw12 = _mm_mul_ps(c12_00,VV);
303 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
304 fvdw12 = _mm_mul_ps(c12_00,FF);
305 vvdw = _mm_add_ps(vvdw12,vvdw6);
306 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
308 /* Update potential sum for this i atom from the interaction with this j atom. */
309 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
313 /* Update vectorial force */
314 fix0 = _mm_macc_ps(dx00,fscal,fix0);
315 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
316 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
318 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
319 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
320 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
322 /**************************
323 * CALCULATE INTERACTIONS *
324 **************************/
326 if (gmx_mm_any_lt(rsq10,rcutoff2))
329 /* Compute parameters for interactions between i and j atoms */
330 qq10 = _mm_mul_ps(iq1,jq0);
332 /* REACTION-FIELD ELECTROSTATICS */
333 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
334 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
336 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
338 /* Update potential sum for this i atom from the interaction with this j atom. */
339 velec = _mm_and_ps(velec,cutoff_mask);
340 velecsum = _mm_add_ps(velecsum,velec);
344 fscal = _mm_and_ps(fscal,cutoff_mask);
346 /* Update vectorial force */
347 fix1 = _mm_macc_ps(dx10,fscal,fix1);
348 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
349 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
351 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
352 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
353 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
357 /**************************
358 * CALCULATE INTERACTIONS *
359 **************************/
361 if (gmx_mm_any_lt(rsq20,rcutoff2))
364 /* Compute parameters for interactions between i and j atoms */
365 qq20 = _mm_mul_ps(iq2,jq0);
367 /* REACTION-FIELD ELECTROSTATICS */
368 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
369 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
371 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
373 /* Update potential sum for this i atom from the interaction with this j atom. */
374 velec = _mm_and_ps(velec,cutoff_mask);
375 velecsum = _mm_add_ps(velecsum,velec);
379 fscal = _mm_and_ps(fscal,cutoff_mask);
381 /* Update vectorial force */
382 fix2 = _mm_macc_ps(dx20,fscal,fix2);
383 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
384 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
386 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
387 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
388 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
392 /**************************
393 * CALCULATE INTERACTIONS *
394 **************************/
396 if (gmx_mm_any_lt(rsq30,rcutoff2))
399 /* Compute parameters for interactions between i and j atoms */
400 qq30 = _mm_mul_ps(iq3,jq0);
402 /* REACTION-FIELD ELECTROSTATICS */
403 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
404 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
406 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
408 /* Update potential sum for this i atom from the interaction with this j atom. */
409 velec = _mm_and_ps(velec,cutoff_mask);
410 velecsum = _mm_add_ps(velecsum,velec);
414 fscal = _mm_and_ps(fscal,cutoff_mask);
416 /* Update vectorial force */
417 fix3 = _mm_macc_ps(dx30,fscal,fix3);
418 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
419 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
421 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
422 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
423 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
427 fjptrA = f+j_coord_offsetA;
428 fjptrB = f+j_coord_offsetB;
429 fjptrC = f+j_coord_offsetC;
430 fjptrD = f+j_coord_offsetD;
432 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
434 /* Inner loop uses 176 flops */
440 /* Get j neighbor index, and coordinate index */
441 jnrlistA = jjnr[jidx];
442 jnrlistB = jjnr[jidx+1];
443 jnrlistC = jjnr[jidx+2];
444 jnrlistD = jjnr[jidx+3];
445 /* Sign of each element will be negative for non-real atoms.
446 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
447 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
449 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
450 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
451 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
452 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
453 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
454 j_coord_offsetA = DIM*jnrA;
455 j_coord_offsetB = DIM*jnrB;
456 j_coord_offsetC = DIM*jnrC;
457 j_coord_offsetD = DIM*jnrD;
459 /* load j atom coordinates */
460 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
461 x+j_coord_offsetC,x+j_coord_offsetD,
464 /* Calculate displacement vector */
465 dx00 = _mm_sub_ps(ix0,jx0);
466 dy00 = _mm_sub_ps(iy0,jy0);
467 dz00 = _mm_sub_ps(iz0,jz0);
468 dx10 = _mm_sub_ps(ix1,jx0);
469 dy10 = _mm_sub_ps(iy1,jy0);
470 dz10 = _mm_sub_ps(iz1,jz0);
471 dx20 = _mm_sub_ps(ix2,jx0);
472 dy20 = _mm_sub_ps(iy2,jy0);
473 dz20 = _mm_sub_ps(iz2,jz0);
474 dx30 = _mm_sub_ps(ix3,jx0);
475 dy30 = _mm_sub_ps(iy3,jy0);
476 dz30 = _mm_sub_ps(iz3,jz0);
478 /* Calculate squared distance and things based on it */
479 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
480 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
481 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
482 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
484 rinv00 = avx128fma_invsqrt_f(rsq00);
485 rinv10 = avx128fma_invsqrt_f(rsq10);
486 rinv20 = avx128fma_invsqrt_f(rsq20);
487 rinv30 = avx128fma_invsqrt_f(rsq30);
489 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
490 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
491 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
493 /* Load parameters for j particles */
494 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
495 charge+jnrC+0,charge+jnrD+0);
496 vdwjidx0A = 2*vdwtype[jnrA+0];
497 vdwjidx0B = 2*vdwtype[jnrB+0];
498 vdwjidx0C = 2*vdwtype[jnrC+0];
499 vdwjidx0D = 2*vdwtype[jnrD+0];
501 fjx0 = _mm_setzero_ps();
502 fjy0 = _mm_setzero_ps();
503 fjz0 = _mm_setzero_ps();
505 /**************************
506 * CALCULATE INTERACTIONS *
507 **************************/
509 r00 = _mm_mul_ps(rsq00,rinv00);
510 r00 = _mm_andnot_ps(dummy_mask,r00);
512 /* Compute parameters for interactions between i and j atoms */
513 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
514 vdwparam+vdwioffset0+vdwjidx0B,
515 vdwparam+vdwioffset0+vdwjidx0C,
516 vdwparam+vdwioffset0+vdwjidx0D,
519 /* Calculate table index by multiplying r with table scale and truncate to integer */
520 rt = _mm_mul_ps(r00,vftabscale);
521 vfitab = _mm_cvttps_epi32(rt);
523 vfeps = _mm_frcz_ps(rt);
525 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
527 twovfeps = _mm_add_ps(vfeps,vfeps);
528 vfitab = _mm_slli_epi32(vfitab,3);
530 /* CUBIC SPLINE TABLE DISPERSION */
531 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
532 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
533 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
534 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
535 _MM_TRANSPOSE4_PS(Y,F,G,H);
536 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
537 VV = _mm_macc_ps(vfeps,Fp,Y);
538 vvdw6 = _mm_mul_ps(c6_00,VV);
539 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
540 fvdw6 = _mm_mul_ps(c6_00,FF);
542 /* CUBIC SPLINE TABLE REPULSION */
543 vfitab = _mm_add_epi32(vfitab,ifour);
544 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
545 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
546 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
547 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
548 _MM_TRANSPOSE4_PS(Y,F,G,H);
549 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
550 VV = _mm_macc_ps(vfeps,Fp,Y);
551 vvdw12 = _mm_mul_ps(c12_00,VV);
552 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
553 fvdw12 = _mm_mul_ps(c12_00,FF);
554 vvdw = _mm_add_ps(vvdw12,vvdw6);
555 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
557 /* Update potential sum for this i atom from the interaction with this j atom. */
558 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
559 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
563 fscal = _mm_andnot_ps(dummy_mask,fscal);
565 /* Update vectorial force */
566 fix0 = _mm_macc_ps(dx00,fscal,fix0);
567 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
568 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
570 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
571 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
572 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
574 /**************************
575 * CALCULATE INTERACTIONS *
576 **************************/
578 if (gmx_mm_any_lt(rsq10,rcutoff2))
581 /* Compute parameters for interactions between i and j atoms */
582 qq10 = _mm_mul_ps(iq1,jq0);
584 /* REACTION-FIELD ELECTROSTATICS */
585 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
586 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
588 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
590 /* Update potential sum for this i atom from the interaction with this j atom. */
591 velec = _mm_and_ps(velec,cutoff_mask);
592 velec = _mm_andnot_ps(dummy_mask,velec);
593 velecsum = _mm_add_ps(velecsum,velec);
597 fscal = _mm_and_ps(fscal,cutoff_mask);
599 fscal = _mm_andnot_ps(dummy_mask,fscal);
601 /* Update vectorial force */
602 fix1 = _mm_macc_ps(dx10,fscal,fix1);
603 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
604 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
606 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
607 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
608 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
612 /**************************
613 * CALCULATE INTERACTIONS *
614 **************************/
616 if (gmx_mm_any_lt(rsq20,rcutoff2))
619 /* Compute parameters for interactions between i and j atoms */
620 qq20 = _mm_mul_ps(iq2,jq0);
622 /* REACTION-FIELD ELECTROSTATICS */
623 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
624 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
626 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
628 /* Update potential sum for this i atom from the interaction with this j atom. */
629 velec = _mm_and_ps(velec,cutoff_mask);
630 velec = _mm_andnot_ps(dummy_mask,velec);
631 velecsum = _mm_add_ps(velecsum,velec);
635 fscal = _mm_and_ps(fscal,cutoff_mask);
637 fscal = _mm_andnot_ps(dummy_mask,fscal);
639 /* Update vectorial force */
640 fix2 = _mm_macc_ps(dx20,fscal,fix2);
641 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
642 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
644 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
645 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
646 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
650 /**************************
651 * CALCULATE INTERACTIONS *
652 **************************/
654 if (gmx_mm_any_lt(rsq30,rcutoff2))
657 /* Compute parameters for interactions between i and j atoms */
658 qq30 = _mm_mul_ps(iq3,jq0);
660 /* REACTION-FIELD ELECTROSTATICS */
661 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
662 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
664 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
666 /* Update potential sum for this i atom from the interaction with this j atom. */
667 velec = _mm_and_ps(velec,cutoff_mask);
668 velec = _mm_andnot_ps(dummy_mask,velec);
669 velecsum = _mm_add_ps(velecsum,velec);
673 fscal = _mm_and_ps(fscal,cutoff_mask);
675 fscal = _mm_andnot_ps(dummy_mask,fscal);
677 /* Update vectorial force */
678 fix3 = _mm_macc_ps(dx30,fscal,fix3);
679 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
680 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
682 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
683 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
684 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
688 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
689 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
690 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
691 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
693 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
695 /* Inner loop uses 177 flops */
698 /* End of innermost loop */
700 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
701 f+i_coord_offset,fshift+i_shift_offset);
704 /* Update potential energies */
705 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
706 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
708 /* Increment number of inner iterations */
709 inneriter += j_index_end - j_index_start;
711 /* Outer loop uses 26 flops */
714 /* Increment number of outer iterations */
717 /* Update outer/inner flops */
719 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*177);
722 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_F_avx_128_fma_single
723 * Electrostatics interaction: ReactionField
724 * VdW interaction: CubicSplineTable
725 * Geometry: Water4-Particle
726 * Calculate force/pot: Force
729 nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_F_avx_128_fma_single
730 (t_nblist * gmx_restrict nlist,
731 rvec * gmx_restrict xx,
732 rvec * gmx_restrict ff,
733 struct t_forcerec * gmx_restrict fr,
734 t_mdatoms * gmx_restrict mdatoms,
735 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
736 t_nrnb * gmx_restrict nrnb)
738 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
739 * just 0 for non-waters.
740 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
741 * jnr indices corresponding to data put in the four positions in the SIMD register.
743 int i_shift_offset,i_coord_offset,outeriter,inneriter;
744 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
745 int jnrA,jnrB,jnrC,jnrD;
746 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
747 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
748 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
750 real *shiftvec,*fshift,*x,*f;
751 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
753 __m128 fscal,rcutoff,rcutoff2,jidxall;
755 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
757 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
759 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
761 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
762 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
763 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
764 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
765 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
766 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
767 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
768 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
771 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
774 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
775 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
777 __m128i ifour = _mm_set1_epi32(4);
778 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
780 __m128 dummy_mask,cutoff_mask;
781 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
782 __m128 one = _mm_set1_ps(1.0);
783 __m128 two = _mm_set1_ps(2.0);
789 jindex = nlist->jindex;
791 shiftidx = nlist->shift;
793 shiftvec = fr->shift_vec[0];
794 fshift = fr->fshift[0];
795 facel = _mm_set1_ps(fr->ic->epsfac);
796 charge = mdatoms->chargeA;
797 krf = _mm_set1_ps(fr->ic->k_rf);
798 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
799 crf = _mm_set1_ps(fr->ic->c_rf);
800 nvdwtype = fr->ntype;
802 vdwtype = mdatoms->typeA;
804 vftab = kernel_data->table_vdw->data;
805 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
807 /* Setup water-specific parameters */
808 inr = nlist->iinr[0];
809 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
810 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
811 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
812 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
814 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
815 rcutoff_scalar = fr->ic->rcoulomb;
816 rcutoff = _mm_set1_ps(rcutoff_scalar);
817 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
819 /* Avoid stupid compiler warnings */
820 jnrA = jnrB = jnrC = jnrD = 0;
829 for(iidx=0;iidx<4*DIM;iidx++)
834 /* Start outer loop over neighborlists */
835 for(iidx=0; iidx<nri; iidx++)
837 /* Load shift vector for this list */
838 i_shift_offset = DIM*shiftidx[iidx];
840 /* Load limits for loop over neighbors */
841 j_index_start = jindex[iidx];
842 j_index_end = jindex[iidx+1];
844 /* Get outer coordinate index */
846 i_coord_offset = DIM*inr;
848 /* Load i particle coords and add shift vector */
849 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
850 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
852 fix0 = _mm_setzero_ps();
853 fiy0 = _mm_setzero_ps();
854 fiz0 = _mm_setzero_ps();
855 fix1 = _mm_setzero_ps();
856 fiy1 = _mm_setzero_ps();
857 fiz1 = _mm_setzero_ps();
858 fix2 = _mm_setzero_ps();
859 fiy2 = _mm_setzero_ps();
860 fiz2 = _mm_setzero_ps();
861 fix3 = _mm_setzero_ps();
862 fiy3 = _mm_setzero_ps();
863 fiz3 = _mm_setzero_ps();
865 /* Start inner kernel loop */
866 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
869 /* Get j neighbor index, and coordinate index */
874 j_coord_offsetA = DIM*jnrA;
875 j_coord_offsetB = DIM*jnrB;
876 j_coord_offsetC = DIM*jnrC;
877 j_coord_offsetD = DIM*jnrD;
879 /* load j atom coordinates */
880 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
881 x+j_coord_offsetC,x+j_coord_offsetD,
884 /* Calculate displacement vector */
885 dx00 = _mm_sub_ps(ix0,jx0);
886 dy00 = _mm_sub_ps(iy0,jy0);
887 dz00 = _mm_sub_ps(iz0,jz0);
888 dx10 = _mm_sub_ps(ix1,jx0);
889 dy10 = _mm_sub_ps(iy1,jy0);
890 dz10 = _mm_sub_ps(iz1,jz0);
891 dx20 = _mm_sub_ps(ix2,jx0);
892 dy20 = _mm_sub_ps(iy2,jy0);
893 dz20 = _mm_sub_ps(iz2,jz0);
894 dx30 = _mm_sub_ps(ix3,jx0);
895 dy30 = _mm_sub_ps(iy3,jy0);
896 dz30 = _mm_sub_ps(iz3,jz0);
898 /* Calculate squared distance and things based on it */
899 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
900 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
901 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
902 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
904 rinv00 = avx128fma_invsqrt_f(rsq00);
905 rinv10 = avx128fma_invsqrt_f(rsq10);
906 rinv20 = avx128fma_invsqrt_f(rsq20);
907 rinv30 = avx128fma_invsqrt_f(rsq30);
909 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
910 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
911 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
913 /* Load parameters for j particles */
914 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
915 charge+jnrC+0,charge+jnrD+0);
916 vdwjidx0A = 2*vdwtype[jnrA+0];
917 vdwjidx0B = 2*vdwtype[jnrB+0];
918 vdwjidx0C = 2*vdwtype[jnrC+0];
919 vdwjidx0D = 2*vdwtype[jnrD+0];
921 fjx0 = _mm_setzero_ps();
922 fjy0 = _mm_setzero_ps();
923 fjz0 = _mm_setzero_ps();
925 /**************************
926 * CALCULATE INTERACTIONS *
927 **************************/
929 r00 = _mm_mul_ps(rsq00,rinv00);
931 /* Compute parameters for interactions between i and j atoms */
932 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
933 vdwparam+vdwioffset0+vdwjidx0B,
934 vdwparam+vdwioffset0+vdwjidx0C,
935 vdwparam+vdwioffset0+vdwjidx0D,
938 /* Calculate table index by multiplying r with table scale and truncate to integer */
939 rt = _mm_mul_ps(r00,vftabscale);
940 vfitab = _mm_cvttps_epi32(rt);
942 vfeps = _mm_frcz_ps(rt);
944 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
946 twovfeps = _mm_add_ps(vfeps,vfeps);
947 vfitab = _mm_slli_epi32(vfitab,3);
949 /* CUBIC SPLINE TABLE DISPERSION */
950 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
951 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
952 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
953 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
954 _MM_TRANSPOSE4_PS(Y,F,G,H);
955 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
956 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
957 fvdw6 = _mm_mul_ps(c6_00,FF);
959 /* CUBIC SPLINE TABLE REPULSION */
960 vfitab = _mm_add_epi32(vfitab,ifour);
961 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
962 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
963 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
964 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
965 _MM_TRANSPOSE4_PS(Y,F,G,H);
966 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
967 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
968 fvdw12 = _mm_mul_ps(c12_00,FF);
969 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
973 /* Update vectorial force */
974 fix0 = _mm_macc_ps(dx00,fscal,fix0);
975 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
976 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
978 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
979 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
980 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
982 /**************************
983 * CALCULATE INTERACTIONS *
984 **************************/
986 if (gmx_mm_any_lt(rsq10,rcutoff2))
989 /* Compute parameters for interactions between i and j atoms */
990 qq10 = _mm_mul_ps(iq1,jq0);
992 /* REACTION-FIELD ELECTROSTATICS */
993 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
995 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
999 fscal = _mm_and_ps(fscal,cutoff_mask);
1001 /* Update vectorial force */
1002 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1003 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1004 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1006 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1007 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1008 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1012 /**************************
1013 * CALCULATE INTERACTIONS *
1014 **************************/
1016 if (gmx_mm_any_lt(rsq20,rcutoff2))
1019 /* Compute parameters for interactions between i and j atoms */
1020 qq20 = _mm_mul_ps(iq2,jq0);
1022 /* REACTION-FIELD ELECTROSTATICS */
1023 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1025 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1029 fscal = _mm_and_ps(fscal,cutoff_mask);
1031 /* Update vectorial force */
1032 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1033 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1034 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1036 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1037 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1038 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1042 /**************************
1043 * CALCULATE INTERACTIONS *
1044 **************************/
1046 if (gmx_mm_any_lt(rsq30,rcutoff2))
1049 /* Compute parameters for interactions between i and j atoms */
1050 qq30 = _mm_mul_ps(iq3,jq0);
1052 /* REACTION-FIELD ELECTROSTATICS */
1053 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1055 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1059 fscal = _mm_and_ps(fscal,cutoff_mask);
1061 /* Update vectorial force */
1062 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1063 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1064 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1066 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1067 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1068 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1072 fjptrA = f+j_coord_offsetA;
1073 fjptrB = f+j_coord_offsetB;
1074 fjptrC = f+j_coord_offsetC;
1075 fjptrD = f+j_coord_offsetD;
1077 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1079 /* Inner loop uses 150 flops */
1082 if(jidx<j_index_end)
1085 /* Get j neighbor index, and coordinate index */
1086 jnrlistA = jjnr[jidx];
1087 jnrlistB = jjnr[jidx+1];
1088 jnrlistC = jjnr[jidx+2];
1089 jnrlistD = jjnr[jidx+3];
1090 /* Sign of each element will be negative for non-real atoms.
1091 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1092 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1094 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1095 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1096 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1097 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1098 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1099 j_coord_offsetA = DIM*jnrA;
1100 j_coord_offsetB = DIM*jnrB;
1101 j_coord_offsetC = DIM*jnrC;
1102 j_coord_offsetD = DIM*jnrD;
1104 /* load j atom coordinates */
1105 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1106 x+j_coord_offsetC,x+j_coord_offsetD,
1109 /* Calculate displacement vector */
1110 dx00 = _mm_sub_ps(ix0,jx0);
1111 dy00 = _mm_sub_ps(iy0,jy0);
1112 dz00 = _mm_sub_ps(iz0,jz0);
1113 dx10 = _mm_sub_ps(ix1,jx0);
1114 dy10 = _mm_sub_ps(iy1,jy0);
1115 dz10 = _mm_sub_ps(iz1,jz0);
1116 dx20 = _mm_sub_ps(ix2,jx0);
1117 dy20 = _mm_sub_ps(iy2,jy0);
1118 dz20 = _mm_sub_ps(iz2,jz0);
1119 dx30 = _mm_sub_ps(ix3,jx0);
1120 dy30 = _mm_sub_ps(iy3,jy0);
1121 dz30 = _mm_sub_ps(iz3,jz0);
1123 /* Calculate squared distance and things based on it */
1124 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1125 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1126 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1127 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1129 rinv00 = avx128fma_invsqrt_f(rsq00);
1130 rinv10 = avx128fma_invsqrt_f(rsq10);
1131 rinv20 = avx128fma_invsqrt_f(rsq20);
1132 rinv30 = avx128fma_invsqrt_f(rsq30);
1134 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1135 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1136 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1138 /* Load parameters for j particles */
1139 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1140 charge+jnrC+0,charge+jnrD+0);
1141 vdwjidx0A = 2*vdwtype[jnrA+0];
1142 vdwjidx0B = 2*vdwtype[jnrB+0];
1143 vdwjidx0C = 2*vdwtype[jnrC+0];
1144 vdwjidx0D = 2*vdwtype[jnrD+0];
1146 fjx0 = _mm_setzero_ps();
1147 fjy0 = _mm_setzero_ps();
1148 fjz0 = _mm_setzero_ps();
1150 /**************************
1151 * CALCULATE INTERACTIONS *
1152 **************************/
1154 r00 = _mm_mul_ps(rsq00,rinv00);
1155 r00 = _mm_andnot_ps(dummy_mask,r00);
1157 /* Compute parameters for interactions between i and j atoms */
1158 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1159 vdwparam+vdwioffset0+vdwjidx0B,
1160 vdwparam+vdwioffset0+vdwjidx0C,
1161 vdwparam+vdwioffset0+vdwjidx0D,
1164 /* Calculate table index by multiplying r with table scale and truncate to integer */
1165 rt = _mm_mul_ps(r00,vftabscale);
1166 vfitab = _mm_cvttps_epi32(rt);
1168 vfeps = _mm_frcz_ps(rt);
1170 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1172 twovfeps = _mm_add_ps(vfeps,vfeps);
1173 vfitab = _mm_slli_epi32(vfitab,3);
1175 /* CUBIC SPLINE TABLE DISPERSION */
1176 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1177 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1178 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1179 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1180 _MM_TRANSPOSE4_PS(Y,F,G,H);
1181 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1182 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1183 fvdw6 = _mm_mul_ps(c6_00,FF);
1185 /* CUBIC SPLINE TABLE REPULSION */
1186 vfitab = _mm_add_epi32(vfitab,ifour);
1187 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1188 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1189 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1190 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1191 _MM_TRANSPOSE4_PS(Y,F,G,H);
1192 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1193 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1194 fvdw12 = _mm_mul_ps(c12_00,FF);
1195 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1199 fscal = _mm_andnot_ps(dummy_mask,fscal);
1201 /* Update vectorial force */
1202 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1203 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1204 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1206 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1207 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1208 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1210 /**************************
1211 * CALCULATE INTERACTIONS *
1212 **************************/
1214 if (gmx_mm_any_lt(rsq10,rcutoff2))
1217 /* Compute parameters for interactions between i and j atoms */
1218 qq10 = _mm_mul_ps(iq1,jq0);
1220 /* REACTION-FIELD ELECTROSTATICS */
1221 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1223 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1227 fscal = _mm_and_ps(fscal,cutoff_mask);
1229 fscal = _mm_andnot_ps(dummy_mask,fscal);
1231 /* Update vectorial force */
1232 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1233 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1234 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1236 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1237 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1238 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1242 /**************************
1243 * CALCULATE INTERACTIONS *
1244 **************************/
1246 if (gmx_mm_any_lt(rsq20,rcutoff2))
1249 /* Compute parameters for interactions between i and j atoms */
1250 qq20 = _mm_mul_ps(iq2,jq0);
1252 /* REACTION-FIELD ELECTROSTATICS */
1253 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1255 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1259 fscal = _mm_and_ps(fscal,cutoff_mask);
1261 fscal = _mm_andnot_ps(dummy_mask,fscal);
1263 /* Update vectorial force */
1264 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1265 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1266 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1268 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1269 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1270 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1274 /**************************
1275 * CALCULATE INTERACTIONS *
1276 **************************/
1278 if (gmx_mm_any_lt(rsq30,rcutoff2))
1281 /* Compute parameters for interactions between i and j atoms */
1282 qq30 = _mm_mul_ps(iq3,jq0);
1284 /* REACTION-FIELD ELECTROSTATICS */
1285 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1287 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1291 fscal = _mm_and_ps(fscal,cutoff_mask);
1293 fscal = _mm_andnot_ps(dummy_mask,fscal);
1295 /* Update vectorial force */
1296 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1297 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1298 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1300 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1301 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1302 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1306 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1307 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1308 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1309 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1311 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1313 /* Inner loop uses 151 flops */
1316 /* End of innermost loop */
1318 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1319 f+i_coord_offset,fshift+i_shift_offset);
1321 /* Increment number of inner iterations */
1322 inneriter += j_index_end - j_index_start;
1324 /* Outer loop uses 24 flops */
1327 /* Increment number of outer iterations */
1330 /* Update outer/inner flops */
1332 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*151);