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_GeomW3P1_VF_avx_128_fma_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: CubicSplineTable
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_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;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
99 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
100 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
102 __m128i ifour = _mm_set1_epi32(4);
103 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
105 __m128 dummy_mask,cutoff_mask;
106 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
107 __m128 one = _mm_set1_ps(1.0);
108 __m128 two = _mm_set1_ps(2.0);
114 jindex = nlist->jindex;
116 shiftidx = nlist->shift;
118 shiftvec = fr->shift_vec[0];
119 fshift = fr->fshift[0];
120 facel = _mm_set1_ps(fr->ic->epsfac);
121 charge = mdatoms->chargeA;
122 krf = _mm_set1_ps(fr->ic->k_rf);
123 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
124 crf = _mm_set1_ps(fr->ic->c_rf);
125 nvdwtype = fr->ntype;
127 vdwtype = mdatoms->typeA;
129 vftab = kernel_data->table_vdw->data;
130 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
132 /* Setup water-specific parameters */
133 inr = nlist->iinr[0];
134 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
135 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
136 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
137 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
139 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
140 rcutoff_scalar = fr->ic->rcoulomb;
141 rcutoff = _mm_set1_ps(rcutoff_scalar);
142 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
144 /* Avoid stupid compiler warnings */
145 jnrA = jnrB = jnrC = jnrD = 0;
154 for(iidx=0;iidx<4*DIM;iidx++)
159 /* Start outer loop over neighborlists */
160 for(iidx=0; iidx<nri; iidx++)
162 /* Load shift vector for this list */
163 i_shift_offset = DIM*shiftidx[iidx];
165 /* Load limits for loop over neighbors */
166 j_index_start = jindex[iidx];
167 j_index_end = jindex[iidx+1];
169 /* Get outer coordinate index */
171 i_coord_offset = DIM*inr;
173 /* Load i particle coords and add shift vector */
174 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
175 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
177 fix0 = _mm_setzero_ps();
178 fiy0 = _mm_setzero_ps();
179 fiz0 = _mm_setzero_ps();
180 fix1 = _mm_setzero_ps();
181 fiy1 = _mm_setzero_ps();
182 fiz1 = _mm_setzero_ps();
183 fix2 = _mm_setzero_ps();
184 fiy2 = _mm_setzero_ps();
185 fiz2 = _mm_setzero_ps();
187 /* Reset potential sums */
188 velecsum = _mm_setzero_ps();
189 vvdwsum = _mm_setzero_ps();
191 /* Start inner kernel loop */
192 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
195 /* Get j neighbor index, and coordinate index */
200 j_coord_offsetA = DIM*jnrA;
201 j_coord_offsetB = DIM*jnrB;
202 j_coord_offsetC = DIM*jnrC;
203 j_coord_offsetD = DIM*jnrD;
205 /* load j atom coordinates */
206 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
207 x+j_coord_offsetC,x+j_coord_offsetD,
210 /* Calculate displacement vector */
211 dx00 = _mm_sub_ps(ix0,jx0);
212 dy00 = _mm_sub_ps(iy0,jy0);
213 dz00 = _mm_sub_ps(iz0,jz0);
214 dx10 = _mm_sub_ps(ix1,jx0);
215 dy10 = _mm_sub_ps(iy1,jy0);
216 dz10 = _mm_sub_ps(iz1,jz0);
217 dx20 = _mm_sub_ps(ix2,jx0);
218 dy20 = _mm_sub_ps(iy2,jy0);
219 dz20 = _mm_sub_ps(iz2,jz0);
221 /* Calculate squared distance and things based on it */
222 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
223 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
224 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
226 rinv00 = avx128fma_invsqrt_f(rsq00);
227 rinv10 = avx128fma_invsqrt_f(rsq10);
228 rinv20 = avx128fma_invsqrt_f(rsq20);
230 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
231 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
232 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
234 /* Load parameters for j particles */
235 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
236 charge+jnrC+0,charge+jnrD+0);
237 vdwjidx0A = 2*vdwtype[jnrA+0];
238 vdwjidx0B = 2*vdwtype[jnrB+0];
239 vdwjidx0C = 2*vdwtype[jnrC+0];
240 vdwjidx0D = 2*vdwtype[jnrD+0];
242 fjx0 = _mm_setzero_ps();
243 fjy0 = _mm_setzero_ps();
244 fjz0 = _mm_setzero_ps();
246 /**************************
247 * CALCULATE INTERACTIONS *
248 **************************/
250 if (gmx_mm_any_lt(rsq00,rcutoff2))
253 r00 = _mm_mul_ps(rsq00,rinv00);
255 /* Compute parameters for interactions between i and j atoms */
256 qq00 = _mm_mul_ps(iq0,jq0);
257 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
258 vdwparam+vdwioffset0+vdwjidx0B,
259 vdwparam+vdwioffset0+vdwjidx0C,
260 vdwparam+vdwioffset0+vdwjidx0D,
263 /* Calculate table index by multiplying r with table scale and truncate to integer */
264 rt = _mm_mul_ps(r00,vftabscale);
265 vfitab = _mm_cvttps_epi32(rt);
267 vfeps = _mm_frcz_ps(rt);
269 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
271 twovfeps = _mm_add_ps(vfeps,vfeps);
272 vfitab = _mm_slli_epi32(vfitab,3);
274 /* REACTION-FIELD ELECTROSTATICS */
275 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
276 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
278 /* CUBIC SPLINE TABLE DISPERSION */
279 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
280 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
281 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
282 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
283 _MM_TRANSPOSE4_PS(Y,F,G,H);
284 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
285 VV = _mm_macc_ps(vfeps,Fp,Y);
286 vvdw6 = _mm_mul_ps(c6_00,VV);
287 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
288 fvdw6 = _mm_mul_ps(c6_00,FF);
290 /* CUBIC SPLINE TABLE REPULSION */
291 vfitab = _mm_add_epi32(vfitab,ifour);
292 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
293 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
294 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
295 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
296 _MM_TRANSPOSE4_PS(Y,F,G,H);
297 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
298 VV = _mm_macc_ps(vfeps,Fp,Y);
299 vvdw12 = _mm_mul_ps(c12_00,VV);
300 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
301 fvdw12 = _mm_mul_ps(c12_00,FF);
302 vvdw = _mm_add_ps(vvdw12,vvdw6);
303 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
305 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
307 /* Update potential sum for this i atom from the interaction with this j atom. */
308 velec = _mm_and_ps(velec,cutoff_mask);
309 velecsum = _mm_add_ps(velecsum,velec);
310 vvdw = _mm_and_ps(vvdw,cutoff_mask);
311 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
313 fscal = _mm_add_ps(felec,fvdw);
315 fscal = _mm_and_ps(fscal,cutoff_mask);
317 /* Update vectorial force */
318 fix0 = _mm_macc_ps(dx00,fscal,fix0);
319 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
320 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
322 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
323 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
324 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
328 /**************************
329 * CALCULATE INTERACTIONS *
330 **************************/
332 if (gmx_mm_any_lt(rsq10,rcutoff2))
335 /* Compute parameters for interactions between i and j atoms */
336 qq10 = _mm_mul_ps(iq1,jq0);
338 /* REACTION-FIELD ELECTROSTATICS */
339 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
340 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
342 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
344 /* Update potential sum for this i atom from the interaction with this j atom. */
345 velec = _mm_and_ps(velec,cutoff_mask);
346 velecsum = _mm_add_ps(velecsum,velec);
350 fscal = _mm_and_ps(fscal,cutoff_mask);
352 /* Update vectorial force */
353 fix1 = _mm_macc_ps(dx10,fscal,fix1);
354 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
355 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
357 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
358 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
359 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
363 /**************************
364 * CALCULATE INTERACTIONS *
365 **************************/
367 if (gmx_mm_any_lt(rsq20,rcutoff2))
370 /* Compute parameters for interactions between i and j atoms */
371 qq20 = _mm_mul_ps(iq2,jq0);
373 /* REACTION-FIELD ELECTROSTATICS */
374 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
375 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
377 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
379 /* Update potential sum for this i atom from the interaction with this j atom. */
380 velec = _mm_and_ps(velec,cutoff_mask);
381 velecsum = _mm_add_ps(velecsum,velec);
385 fscal = _mm_and_ps(fscal,cutoff_mask);
387 /* Update vectorial force */
388 fix2 = _mm_macc_ps(dx20,fscal,fix2);
389 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
390 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
392 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
393 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
394 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
398 fjptrA = f+j_coord_offsetA;
399 fjptrB = f+j_coord_offsetB;
400 fjptrC = f+j_coord_offsetC;
401 fjptrD = f+j_coord_offsetD;
403 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
405 /* Inner loop uses 153 flops */
411 /* Get j neighbor index, and coordinate index */
412 jnrlistA = jjnr[jidx];
413 jnrlistB = jjnr[jidx+1];
414 jnrlistC = jjnr[jidx+2];
415 jnrlistD = jjnr[jidx+3];
416 /* Sign of each element will be negative for non-real atoms.
417 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
418 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
420 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
421 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
422 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
423 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
424 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
425 j_coord_offsetA = DIM*jnrA;
426 j_coord_offsetB = DIM*jnrB;
427 j_coord_offsetC = DIM*jnrC;
428 j_coord_offsetD = DIM*jnrD;
430 /* load j atom coordinates */
431 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
432 x+j_coord_offsetC,x+j_coord_offsetD,
435 /* Calculate displacement vector */
436 dx00 = _mm_sub_ps(ix0,jx0);
437 dy00 = _mm_sub_ps(iy0,jy0);
438 dz00 = _mm_sub_ps(iz0,jz0);
439 dx10 = _mm_sub_ps(ix1,jx0);
440 dy10 = _mm_sub_ps(iy1,jy0);
441 dz10 = _mm_sub_ps(iz1,jz0);
442 dx20 = _mm_sub_ps(ix2,jx0);
443 dy20 = _mm_sub_ps(iy2,jy0);
444 dz20 = _mm_sub_ps(iz2,jz0);
446 /* Calculate squared distance and things based on it */
447 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
448 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
449 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
451 rinv00 = avx128fma_invsqrt_f(rsq00);
452 rinv10 = avx128fma_invsqrt_f(rsq10);
453 rinv20 = avx128fma_invsqrt_f(rsq20);
455 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
456 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
457 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
459 /* Load parameters for j particles */
460 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
461 charge+jnrC+0,charge+jnrD+0);
462 vdwjidx0A = 2*vdwtype[jnrA+0];
463 vdwjidx0B = 2*vdwtype[jnrB+0];
464 vdwjidx0C = 2*vdwtype[jnrC+0];
465 vdwjidx0D = 2*vdwtype[jnrD+0];
467 fjx0 = _mm_setzero_ps();
468 fjy0 = _mm_setzero_ps();
469 fjz0 = _mm_setzero_ps();
471 /**************************
472 * CALCULATE INTERACTIONS *
473 **************************/
475 if (gmx_mm_any_lt(rsq00,rcutoff2))
478 r00 = _mm_mul_ps(rsq00,rinv00);
479 r00 = _mm_andnot_ps(dummy_mask,r00);
481 /* Compute parameters for interactions between i and j atoms */
482 qq00 = _mm_mul_ps(iq0,jq0);
483 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
484 vdwparam+vdwioffset0+vdwjidx0B,
485 vdwparam+vdwioffset0+vdwjidx0C,
486 vdwparam+vdwioffset0+vdwjidx0D,
489 /* Calculate table index by multiplying r with table scale and truncate to integer */
490 rt = _mm_mul_ps(r00,vftabscale);
491 vfitab = _mm_cvttps_epi32(rt);
493 vfeps = _mm_frcz_ps(rt);
495 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
497 twovfeps = _mm_add_ps(vfeps,vfeps);
498 vfitab = _mm_slli_epi32(vfitab,3);
500 /* REACTION-FIELD ELECTROSTATICS */
501 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
502 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
504 /* CUBIC SPLINE TABLE DISPERSION */
505 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
506 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
507 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
508 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
509 _MM_TRANSPOSE4_PS(Y,F,G,H);
510 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
511 VV = _mm_macc_ps(vfeps,Fp,Y);
512 vvdw6 = _mm_mul_ps(c6_00,VV);
513 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
514 fvdw6 = _mm_mul_ps(c6_00,FF);
516 /* CUBIC SPLINE TABLE REPULSION */
517 vfitab = _mm_add_epi32(vfitab,ifour);
518 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
519 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
520 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
521 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
522 _MM_TRANSPOSE4_PS(Y,F,G,H);
523 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
524 VV = _mm_macc_ps(vfeps,Fp,Y);
525 vvdw12 = _mm_mul_ps(c12_00,VV);
526 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
527 fvdw12 = _mm_mul_ps(c12_00,FF);
528 vvdw = _mm_add_ps(vvdw12,vvdw6);
529 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
531 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
533 /* Update potential sum for this i atom from the interaction with this j atom. */
534 velec = _mm_and_ps(velec,cutoff_mask);
535 velec = _mm_andnot_ps(dummy_mask,velec);
536 velecsum = _mm_add_ps(velecsum,velec);
537 vvdw = _mm_and_ps(vvdw,cutoff_mask);
538 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
539 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
541 fscal = _mm_add_ps(felec,fvdw);
543 fscal = _mm_and_ps(fscal,cutoff_mask);
545 fscal = _mm_andnot_ps(dummy_mask,fscal);
547 /* Update vectorial force */
548 fix0 = _mm_macc_ps(dx00,fscal,fix0);
549 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
550 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
552 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
553 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
554 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
558 /**************************
559 * CALCULATE INTERACTIONS *
560 **************************/
562 if (gmx_mm_any_lt(rsq10,rcutoff2))
565 /* Compute parameters for interactions between i and j atoms */
566 qq10 = _mm_mul_ps(iq1,jq0);
568 /* REACTION-FIELD ELECTROSTATICS */
569 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
570 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
572 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
574 /* Update potential sum for this i atom from the interaction with this j atom. */
575 velec = _mm_and_ps(velec,cutoff_mask);
576 velec = _mm_andnot_ps(dummy_mask,velec);
577 velecsum = _mm_add_ps(velecsum,velec);
581 fscal = _mm_and_ps(fscal,cutoff_mask);
583 fscal = _mm_andnot_ps(dummy_mask,fscal);
585 /* Update vectorial force */
586 fix1 = _mm_macc_ps(dx10,fscal,fix1);
587 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
588 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
590 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
591 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
592 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
596 /**************************
597 * CALCULATE INTERACTIONS *
598 **************************/
600 if (gmx_mm_any_lt(rsq20,rcutoff2))
603 /* Compute parameters for interactions between i and j atoms */
604 qq20 = _mm_mul_ps(iq2,jq0);
606 /* REACTION-FIELD ELECTROSTATICS */
607 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
608 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
610 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
612 /* Update potential sum for this i atom from the interaction with this j atom. */
613 velec = _mm_and_ps(velec,cutoff_mask);
614 velec = _mm_andnot_ps(dummy_mask,velec);
615 velecsum = _mm_add_ps(velecsum,velec);
619 fscal = _mm_and_ps(fscal,cutoff_mask);
621 fscal = _mm_andnot_ps(dummy_mask,fscal);
623 /* Update vectorial force */
624 fix2 = _mm_macc_ps(dx20,fscal,fix2);
625 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
626 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
628 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
629 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
630 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
634 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
635 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
636 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
637 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
639 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
641 /* Inner loop uses 154 flops */
644 /* End of innermost loop */
646 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
647 f+i_coord_offset,fshift+i_shift_offset);
650 /* Update potential energies */
651 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
652 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
654 /* Increment number of inner iterations */
655 inneriter += j_index_end - j_index_start;
657 /* Outer loop uses 20 flops */
660 /* Increment number of outer iterations */
663 /* Update outer/inner flops */
665 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*154);
668 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_F_avx_128_fma_single
669 * Electrostatics interaction: ReactionField
670 * VdW interaction: CubicSplineTable
671 * Geometry: Water3-Particle
672 * Calculate force/pot: Force
675 nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_F_avx_128_fma_single
676 (t_nblist * gmx_restrict nlist,
677 rvec * gmx_restrict xx,
678 rvec * gmx_restrict ff,
679 struct t_forcerec * gmx_restrict fr,
680 t_mdatoms * gmx_restrict mdatoms,
681 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
682 t_nrnb * gmx_restrict nrnb)
684 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
685 * just 0 for non-waters.
686 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
687 * jnr indices corresponding to data put in the four positions in the SIMD register.
689 int i_shift_offset,i_coord_offset,outeriter,inneriter;
690 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
691 int jnrA,jnrB,jnrC,jnrD;
692 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
693 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
694 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
696 real *shiftvec,*fshift,*x,*f;
697 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
699 __m128 fscal,rcutoff,rcutoff2,jidxall;
701 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
703 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
705 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
706 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
707 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
708 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
709 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
710 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
711 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
714 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
717 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
718 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
720 __m128i ifour = _mm_set1_epi32(4);
721 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
723 __m128 dummy_mask,cutoff_mask;
724 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
725 __m128 one = _mm_set1_ps(1.0);
726 __m128 two = _mm_set1_ps(2.0);
732 jindex = nlist->jindex;
734 shiftidx = nlist->shift;
736 shiftvec = fr->shift_vec[0];
737 fshift = fr->fshift[0];
738 facel = _mm_set1_ps(fr->ic->epsfac);
739 charge = mdatoms->chargeA;
740 krf = _mm_set1_ps(fr->ic->k_rf);
741 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
742 crf = _mm_set1_ps(fr->ic->c_rf);
743 nvdwtype = fr->ntype;
745 vdwtype = mdatoms->typeA;
747 vftab = kernel_data->table_vdw->data;
748 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
750 /* Setup water-specific parameters */
751 inr = nlist->iinr[0];
752 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
753 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
754 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
755 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
757 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
758 rcutoff_scalar = fr->ic->rcoulomb;
759 rcutoff = _mm_set1_ps(rcutoff_scalar);
760 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
762 /* Avoid stupid compiler warnings */
763 jnrA = jnrB = jnrC = jnrD = 0;
772 for(iidx=0;iidx<4*DIM;iidx++)
777 /* Start outer loop over neighborlists */
778 for(iidx=0; iidx<nri; iidx++)
780 /* Load shift vector for this list */
781 i_shift_offset = DIM*shiftidx[iidx];
783 /* Load limits for loop over neighbors */
784 j_index_start = jindex[iidx];
785 j_index_end = jindex[iidx+1];
787 /* Get outer coordinate index */
789 i_coord_offset = DIM*inr;
791 /* Load i particle coords and add shift vector */
792 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
793 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
795 fix0 = _mm_setzero_ps();
796 fiy0 = _mm_setzero_ps();
797 fiz0 = _mm_setzero_ps();
798 fix1 = _mm_setzero_ps();
799 fiy1 = _mm_setzero_ps();
800 fiz1 = _mm_setzero_ps();
801 fix2 = _mm_setzero_ps();
802 fiy2 = _mm_setzero_ps();
803 fiz2 = _mm_setzero_ps();
805 /* Start inner kernel loop */
806 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
809 /* Get j neighbor index, and coordinate index */
814 j_coord_offsetA = DIM*jnrA;
815 j_coord_offsetB = DIM*jnrB;
816 j_coord_offsetC = DIM*jnrC;
817 j_coord_offsetD = DIM*jnrD;
819 /* load j atom coordinates */
820 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
821 x+j_coord_offsetC,x+j_coord_offsetD,
824 /* Calculate displacement vector */
825 dx00 = _mm_sub_ps(ix0,jx0);
826 dy00 = _mm_sub_ps(iy0,jy0);
827 dz00 = _mm_sub_ps(iz0,jz0);
828 dx10 = _mm_sub_ps(ix1,jx0);
829 dy10 = _mm_sub_ps(iy1,jy0);
830 dz10 = _mm_sub_ps(iz1,jz0);
831 dx20 = _mm_sub_ps(ix2,jx0);
832 dy20 = _mm_sub_ps(iy2,jy0);
833 dz20 = _mm_sub_ps(iz2,jz0);
835 /* Calculate squared distance and things based on it */
836 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
837 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
838 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
840 rinv00 = avx128fma_invsqrt_f(rsq00);
841 rinv10 = avx128fma_invsqrt_f(rsq10);
842 rinv20 = avx128fma_invsqrt_f(rsq20);
844 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
845 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
846 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
848 /* Load parameters for j particles */
849 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
850 charge+jnrC+0,charge+jnrD+0);
851 vdwjidx0A = 2*vdwtype[jnrA+0];
852 vdwjidx0B = 2*vdwtype[jnrB+0];
853 vdwjidx0C = 2*vdwtype[jnrC+0];
854 vdwjidx0D = 2*vdwtype[jnrD+0];
856 fjx0 = _mm_setzero_ps();
857 fjy0 = _mm_setzero_ps();
858 fjz0 = _mm_setzero_ps();
860 /**************************
861 * CALCULATE INTERACTIONS *
862 **************************/
864 if (gmx_mm_any_lt(rsq00,rcutoff2))
867 r00 = _mm_mul_ps(rsq00,rinv00);
869 /* Compute parameters for interactions between i and j atoms */
870 qq00 = _mm_mul_ps(iq0,jq0);
871 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
872 vdwparam+vdwioffset0+vdwjidx0B,
873 vdwparam+vdwioffset0+vdwjidx0C,
874 vdwparam+vdwioffset0+vdwjidx0D,
877 /* Calculate table index by multiplying r with table scale and truncate to integer */
878 rt = _mm_mul_ps(r00,vftabscale);
879 vfitab = _mm_cvttps_epi32(rt);
881 vfeps = _mm_frcz_ps(rt);
883 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
885 twovfeps = _mm_add_ps(vfeps,vfeps);
886 vfitab = _mm_slli_epi32(vfitab,3);
888 /* REACTION-FIELD ELECTROSTATICS */
889 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
891 /* CUBIC SPLINE TABLE DISPERSION */
892 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
893 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
894 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
895 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
896 _MM_TRANSPOSE4_PS(Y,F,G,H);
897 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
898 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
899 fvdw6 = _mm_mul_ps(c6_00,FF);
901 /* CUBIC SPLINE TABLE REPULSION */
902 vfitab = _mm_add_epi32(vfitab,ifour);
903 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
904 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
905 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
906 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
907 _MM_TRANSPOSE4_PS(Y,F,G,H);
908 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
909 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
910 fvdw12 = _mm_mul_ps(c12_00,FF);
911 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
913 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
915 fscal = _mm_add_ps(felec,fvdw);
917 fscal = _mm_and_ps(fscal,cutoff_mask);
919 /* Update vectorial force */
920 fix0 = _mm_macc_ps(dx00,fscal,fix0);
921 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
922 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
924 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
925 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
926 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
930 /**************************
931 * CALCULATE INTERACTIONS *
932 **************************/
934 if (gmx_mm_any_lt(rsq10,rcutoff2))
937 /* Compute parameters for interactions between i and j atoms */
938 qq10 = _mm_mul_ps(iq1,jq0);
940 /* REACTION-FIELD ELECTROSTATICS */
941 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
943 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
947 fscal = _mm_and_ps(fscal,cutoff_mask);
949 /* Update vectorial force */
950 fix1 = _mm_macc_ps(dx10,fscal,fix1);
951 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
952 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
954 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
955 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
956 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
960 /**************************
961 * CALCULATE INTERACTIONS *
962 **************************/
964 if (gmx_mm_any_lt(rsq20,rcutoff2))
967 /* Compute parameters for interactions between i and j atoms */
968 qq20 = _mm_mul_ps(iq2,jq0);
970 /* REACTION-FIELD ELECTROSTATICS */
971 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
973 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
977 fscal = _mm_and_ps(fscal,cutoff_mask);
979 /* Update vectorial force */
980 fix2 = _mm_macc_ps(dx20,fscal,fix2);
981 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
982 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
984 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
985 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
986 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
990 fjptrA = f+j_coord_offsetA;
991 fjptrB = f+j_coord_offsetB;
992 fjptrC = f+j_coord_offsetC;
993 fjptrD = f+j_coord_offsetD;
995 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
997 /* Inner loop uses 126 flops */
1000 if(jidx<j_index_end)
1003 /* Get j neighbor index, and coordinate index */
1004 jnrlistA = jjnr[jidx];
1005 jnrlistB = jjnr[jidx+1];
1006 jnrlistC = jjnr[jidx+2];
1007 jnrlistD = jjnr[jidx+3];
1008 /* Sign of each element will be negative for non-real atoms.
1009 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1010 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1012 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1013 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1014 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1015 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1016 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1017 j_coord_offsetA = DIM*jnrA;
1018 j_coord_offsetB = DIM*jnrB;
1019 j_coord_offsetC = DIM*jnrC;
1020 j_coord_offsetD = DIM*jnrD;
1022 /* load j atom coordinates */
1023 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1024 x+j_coord_offsetC,x+j_coord_offsetD,
1027 /* Calculate displacement vector */
1028 dx00 = _mm_sub_ps(ix0,jx0);
1029 dy00 = _mm_sub_ps(iy0,jy0);
1030 dz00 = _mm_sub_ps(iz0,jz0);
1031 dx10 = _mm_sub_ps(ix1,jx0);
1032 dy10 = _mm_sub_ps(iy1,jy0);
1033 dz10 = _mm_sub_ps(iz1,jz0);
1034 dx20 = _mm_sub_ps(ix2,jx0);
1035 dy20 = _mm_sub_ps(iy2,jy0);
1036 dz20 = _mm_sub_ps(iz2,jz0);
1038 /* Calculate squared distance and things based on it */
1039 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1040 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1041 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1043 rinv00 = avx128fma_invsqrt_f(rsq00);
1044 rinv10 = avx128fma_invsqrt_f(rsq10);
1045 rinv20 = avx128fma_invsqrt_f(rsq20);
1047 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1048 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1049 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1051 /* Load parameters for j particles */
1052 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1053 charge+jnrC+0,charge+jnrD+0);
1054 vdwjidx0A = 2*vdwtype[jnrA+0];
1055 vdwjidx0B = 2*vdwtype[jnrB+0];
1056 vdwjidx0C = 2*vdwtype[jnrC+0];
1057 vdwjidx0D = 2*vdwtype[jnrD+0];
1059 fjx0 = _mm_setzero_ps();
1060 fjy0 = _mm_setzero_ps();
1061 fjz0 = _mm_setzero_ps();
1063 /**************************
1064 * CALCULATE INTERACTIONS *
1065 **************************/
1067 if (gmx_mm_any_lt(rsq00,rcutoff2))
1070 r00 = _mm_mul_ps(rsq00,rinv00);
1071 r00 = _mm_andnot_ps(dummy_mask,r00);
1073 /* Compute parameters for interactions between i and j atoms */
1074 qq00 = _mm_mul_ps(iq0,jq0);
1075 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1076 vdwparam+vdwioffset0+vdwjidx0B,
1077 vdwparam+vdwioffset0+vdwjidx0C,
1078 vdwparam+vdwioffset0+vdwjidx0D,
1081 /* Calculate table index by multiplying r with table scale and truncate to integer */
1082 rt = _mm_mul_ps(r00,vftabscale);
1083 vfitab = _mm_cvttps_epi32(rt);
1085 vfeps = _mm_frcz_ps(rt);
1087 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1089 twovfeps = _mm_add_ps(vfeps,vfeps);
1090 vfitab = _mm_slli_epi32(vfitab,3);
1092 /* REACTION-FIELD ELECTROSTATICS */
1093 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1095 /* CUBIC SPLINE TABLE DISPERSION */
1096 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1097 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1098 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1099 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1100 _MM_TRANSPOSE4_PS(Y,F,G,H);
1101 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1102 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1103 fvdw6 = _mm_mul_ps(c6_00,FF);
1105 /* CUBIC SPLINE TABLE REPULSION */
1106 vfitab = _mm_add_epi32(vfitab,ifour);
1107 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1108 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1109 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1110 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1111 _MM_TRANSPOSE4_PS(Y,F,G,H);
1112 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1113 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1114 fvdw12 = _mm_mul_ps(c12_00,FF);
1115 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1117 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1119 fscal = _mm_add_ps(felec,fvdw);
1121 fscal = _mm_and_ps(fscal,cutoff_mask);
1123 fscal = _mm_andnot_ps(dummy_mask,fscal);
1125 /* Update vectorial force */
1126 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1127 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1128 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1130 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1131 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1132 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1136 /**************************
1137 * CALCULATE INTERACTIONS *
1138 **************************/
1140 if (gmx_mm_any_lt(rsq10,rcutoff2))
1143 /* Compute parameters for interactions between i and j atoms */
1144 qq10 = _mm_mul_ps(iq1,jq0);
1146 /* REACTION-FIELD ELECTROSTATICS */
1147 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1149 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1153 fscal = _mm_and_ps(fscal,cutoff_mask);
1155 fscal = _mm_andnot_ps(dummy_mask,fscal);
1157 /* Update vectorial force */
1158 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1159 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1160 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1162 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1163 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1164 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1168 /**************************
1169 * CALCULATE INTERACTIONS *
1170 **************************/
1172 if (gmx_mm_any_lt(rsq20,rcutoff2))
1175 /* Compute parameters for interactions between i and j atoms */
1176 qq20 = _mm_mul_ps(iq2,jq0);
1178 /* REACTION-FIELD ELECTROSTATICS */
1179 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1181 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1185 fscal = _mm_and_ps(fscal,cutoff_mask);
1187 fscal = _mm_andnot_ps(dummy_mask,fscal);
1189 /* Update vectorial force */
1190 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1191 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1192 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1194 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1195 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1196 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1200 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1201 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1202 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1203 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1205 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1207 /* Inner loop uses 127 flops */
1210 /* End of innermost loop */
1212 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1213 f+i_coord_offset,fshift+i_shift_offset);
1215 /* Increment number of inner iterations */
1216 inneriter += j_index_end - j_index_start;
1218 /* Outer loop uses 18 flops */
1221 /* Increment number of outer iterations */
1224 /* Update outer/inner flops */
1226 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*127);