2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_128_fma_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_VF_avx_128_fma_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: CubicSplineTable
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_VF_avx_128_fma_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
92 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
93 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
94 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
97 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
100 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
101 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
103 __m128i ifour = _mm_set1_epi32(4);
104 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
106 __m128 dummy_mask,cutoff_mask;
107 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
108 __m128 one = _mm_set1_ps(1.0);
109 __m128 two = _mm_set1_ps(2.0);
115 jindex = nlist->jindex;
117 shiftidx = nlist->shift;
119 shiftvec = fr->shift_vec[0];
120 fshift = fr->fshift[0];
121 facel = _mm_set1_ps(fr->epsfac);
122 charge = mdatoms->chargeA;
123 krf = _mm_set1_ps(fr->ic->k_rf);
124 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
125 crf = _mm_set1_ps(fr->ic->c_rf);
126 nvdwtype = fr->ntype;
128 vdwtype = mdatoms->typeA;
130 vftab = kernel_data->table_vdw->data;
131 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
133 /* Setup water-specific parameters */
134 inr = nlist->iinr[0];
135 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
136 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
137 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
138 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
140 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
141 rcutoff_scalar = fr->rcoulomb;
142 rcutoff = _mm_set1_ps(rcutoff_scalar);
143 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
145 /* Avoid stupid compiler warnings */
146 jnrA = jnrB = jnrC = jnrD = 0;
155 for(iidx=0;iidx<4*DIM;iidx++)
160 /* Start outer loop over neighborlists */
161 for(iidx=0; iidx<nri; iidx++)
163 /* Load shift vector for this list */
164 i_shift_offset = DIM*shiftidx[iidx];
166 /* Load limits for loop over neighbors */
167 j_index_start = jindex[iidx];
168 j_index_end = jindex[iidx+1];
170 /* Get outer coordinate index */
172 i_coord_offset = DIM*inr;
174 /* Load i particle coords and add shift vector */
175 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
176 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
178 fix0 = _mm_setzero_ps();
179 fiy0 = _mm_setzero_ps();
180 fiz0 = _mm_setzero_ps();
181 fix1 = _mm_setzero_ps();
182 fiy1 = _mm_setzero_ps();
183 fiz1 = _mm_setzero_ps();
184 fix2 = _mm_setzero_ps();
185 fiy2 = _mm_setzero_ps();
186 fiz2 = _mm_setzero_ps();
188 /* Reset potential sums */
189 velecsum = _mm_setzero_ps();
190 vvdwsum = _mm_setzero_ps();
192 /* Start inner kernel loop */
193 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
196 /* Get j neighbor index, and coordinate index */
201 j_coord_offsetA = DIM*jnrA;
202 j_coord_offsetB = DIM*jnrB;
203 j_coord_offsetC = DIM*jnrC;
204 j_coord_offsetD = DIM*jnrD;
206 /* load j atom coordinates */
207 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
208 x+j_coord_offsetC,x+j_coord_offsetD,
211 /* Calculate displacement vector */
212 dx00 = _mm_sub_ps(ix0,jx0);
213 dy00 = _mm_sub_ps(iy0,jy0);
214 dz00 = _mm_sub_ps(iz0,jz0);
215 dx10 = _mm_sub_ps(ix1,jx0);
216 dy10 = _mm_sub_ps(iy1,jy0);
217 dz10 = _mm_sub_ps(iz1,jz0);
218 dx20 = _mm_sub_ps(ix2,jx0);
219 dy20 = _mm_sub_ps(iy2,jy0);
220 dz20 = _mm_sub_ps(iz2,jz0);
222 /* Calculate squared distance and things based on it */
223 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
224 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
225 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
227 rinv00 = gmx_mm_invsqrt_ps(rsq00);
228 rinv10 = gmx_mm_invsqrt_ps(rsq10);
229 rinv20 = gmx_mm_invsqrt_ps(rsq20);
231 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
232 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
233 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
235 /* Load parameters for j particles */
236 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
237 charge+jnrC+0,charge+jnrD+0);
238 vdwjidx0A = 2*vdwtype[jnrA+0];
239 vdwjidx0B = 2*vdwtype[jnrB+0];
240 vdwjidx0C = 2*vdwtype[jnrC+0];
241 vdwjidx0D = 2*vdwtype[jnrD+0];
243 fjx0 = _mm_setzero_ps();
244 fjy0 = _mm_setzero_ps();
245 fjz0 = _mm_setzero_ps();
247 /**************************
248 * CALCULATE INTERACTIONS *
249 **************************/
251 if (gmx_mm_any_lt(rsq00,rcutoff2))
254 r00 = _mm_mul_ps(rsq00,rinv00);
256 /* Compute parameters for interactions between i and j atoms */
257 qq00 = _mm_mul_ps(iq0,jq0);
258 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
259 vdwparam+vdwioffset0+vdwjidx0B,
260 vdwparam+vdwioffset0+vdwjidx0C,
261 vdwparam+vdwioffset0+vdwjidx0D,
264 /* Calculate table index by multiplying r with table scale and truncate to integer */
265 rt = _mm_mul_ps(r00,vftabscale);
266 vfitab = _mm_cvttps_epi32(rt);
268 vfeps = _mm_frcz_ps(rt);
270 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
272 twovfeps = _mm_add_ps(vfeps,vfeps);
273 vfitab = _mm_slli_epi32(vfitab,3);
275 /* REACTION-FIELD ELECTROSTATICS */
276 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
277 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
279 /* CUBIC SPLINE TABLE DISPERSION */
280 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
281 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
282 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
283 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
284 _MM_TRANSPOSE4_PS(Y,F,G,H);
285 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
286 VV = _mm_macc_ps(vfeps,Fp,Y);
287 vvdw6 = _mm_mul_ps(c6_00,VV);
288 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
289 fvdw6 = _mm_mul_ps(c6_00,FF);
291 /* CUBIC SPLINE TABLE REPULSION */
292 vfitab = _mm_add_epi32(vfitab,ifour);
293 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
294 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
295 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
296 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
297 _MM_TRANSPOSE4_PS(Y,F,G,H);
298 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
299 VV = _mm_macc_ps(vfeps,Fp,Y);
300 vvdw12 = _mm_mul_ps(c12_00,VV);
301 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
302 fvdw12 = _mm_mul_ps(c12_00,FF);
303 vvdw = _mm_add_ps(vvdw12,vvdw6);
304 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
306 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
308 /* Update potential sum for this i atom from the interaction with this j atom. */
309 velec = _mm_and_ps(velec,cutoff_mask);
310 velecsum = _mm_add_ps(velecsum,velec);
311 vvdw = _mm_and_ps(vvdw,cutoff_mask);
312 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
314 fscal = _mm_add_ps(felec,fvdw);
316 fscal = _mm_and_ps(fscal,cutoff_mask);
318 /* Update vectorial force */
319 fix0 = _mm_macc_ps(dx00,fscal,fix0);
320 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
321 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
323 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
324 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
325 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
329 /**************************
330 * CALCULATE INTERACTIONS *
331 **************************/
333 if (gmx_mm_any_lt(rsq10,rcutoff2))
336 /* Compute parameters for interactions between i and j atoms */
337 qq10 = _mm_mul_ps(iq1,jq0);
339 /* REACTION-FIELD ELECTROSTATICS */
340 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
341 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
343 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
345 /* Update potential sum for this i atom from the interaction with this j atom. */
346 velec = _mm_and_ps(velec,cutoff_mask);
347 velecsum = _mm_add_ps(velecsum,velec);
351 fscal = _mm_and_ps(fscal,cutoff_mask);
353 /* Update vectorial force */
354 fix1 = _mm_macc_ps(dx10,fscal,fix1);
355 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
356 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
358 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
359 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
360 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
364 /**************************
365 * CALCULATE INTERACTIONS *
366 **************************/
368 if (gmx_mm_any_lt(rsq20,rcutoff2))
371 /* Compute parameters for interactions between i and j atoms */
372 qq20 = _mm_mul_ps(iq2,jq0);
374 /* REACTION-FIELD ELECTROSTATICS */
375 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
376 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
378 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
380 /* Update potential sum for this i atom from the interaction with this j atom. */
381 velec = _mm_and_ps(velec,cutoff_mask);
382 velecsum = _mm_add_ps(velecsum,velec);
386 fscal = _mm_and_ps(fscal,cutoff_mask);
388 /* Update vectorial force */
389 fix2 = _mm_macc_ps(dx20,fscal,fix2);
390 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
391 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
393 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
394 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
395 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
399 fjptrA = f+j_coord_offsetA;
400 fjptrB = f+j_coord_offsetB;
401 fjptrC = f+j_coord_offsetC;
402 fjptrD = f+j_coord_offsetD;
404 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
406 /* Inner loop uses 153 flops */
412 /* Get j neighbor index, and coordinate index */
413 jnrlistA = jjnr[jidx];
414 jnrlistB = jjnr[jidx+1];
415 jnrlistC = jjnr[jidx+2];
416 jnrlistD = jjnr[jidx+3];
417 /* Sign of each element will be negative for non-real atoms.
418 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
419 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
421 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
422 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
423 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
424 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
425 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
426 j_coord_offsetA = DIM*jnrA;
427 j_coord_offsetB = DIM*jnrB;
428 j_coord_offsetC = DIM*jnrC;
429 j_coord_offsetD = DIM*jnrD;
431 /* load j atom coordinates */
432 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
433 x+j_coord_offsetC,x+j_coord_offsetD,
436 /* Calculate displacement vector */
437 dx00 = _mm_sub_ps(ix0,jx0);
438 dy00 = _mm_sub_ps(iy0,jy0);
439 dz00 = _mm_sub_ps(iz0,jz0);
440 dx10 = _mm_sub_ps(ix1,jx0);
441 dy10 = _mm_sub_ps(iy1,jy0);
442 dz10 = _mm_sub_ps(iz1,jz0);
443 dx20 = _mm_sub_ps(ix2,jx0);
444 dy20 = _mm_sub_ps(iy2,jy0);
445 dz20 = _mm_sub_ps(iz2,jz0);
447 /* Calculate squared distance and things based on it */
448 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
449 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
450 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
452 rinv00 = gmx_mm_invsqrt_ps(rsq00);
453 rinv10 = gmx_mm_invsqrt_ps(rsq10);
454 rinv20 = gmx_mm_invsqrt_ps(rsq20);
456 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
457 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
458 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
460 /* Load parameters for j particles */
461 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
462 charge+jnrC+0,charge+jnrD+0);
463 vdwjidx0A = 2*vdwtype[jnrA+0];
464 vdwjidx0B = 2*vdwtype[jnrB+0];
465 vdwjidx0C = 2*vdwtype[jnrC+0];
466 vdwjidx0D = 2*vdwtype[jnrD+0];
468 fjx0 = _mm_setzero_ps();
469 fjy0 = _mm_setzero_ps();
470 fjz0 = _mm_setzero_ps();
472 /**************************
473 * CALCULATE INTERACTIONS *
474 **************************/
476 if (gmx_mm_any_lt(rsq00,rcutoff2))
479 r00 = _mm_mul_ps(rsq00,rinv00);
480 r00 = _mm_andnot_ps(dummy_mask,r00);
482 /* Compute parameters for interactions between i and j atoms */
483 qq00 = _mm_mul_ps(iq0,jq0);
484 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
485 vdwparam+vdwioffset0+vdwjidx0B,
486 vdwparam+vdwioffset0+vdwjidx0C,
487 vdwparam+vdwioffset0+vdwjidx0D,
490 /* Calculate table index by multiplying r with table scale and truncate to integer */
491 rt = _mm_mul_ps(r00,vftabscale);
492 vfitab = _mm_cvttps_epi32(rt);
494 vfeps = _mm_frcz_ps(rt);
496 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
498 twovfeps = _mm_add_ps(vfeps,vfeps);
499 vfitab = _mm_slli_epi32(vfitab,3);
501 /* REACTION-FIELD ELECTROSTATICS */
502 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
503 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
505 /* CUBIC SPLINE TABLE DISPERSION */
506 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
507 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
508 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
509 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
510 _MM_TRANSPOSE4_PS(Y,F,G,H);
511 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
512 VV = _mm_macc_ps(vfeps,Fp,Y);
513 vvdw6 = _mm_mul_ps(c6_00,VV);
514 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
515 fvdw6 = _mm_mul_ps(c6_00,FF);
517 /* CUBIC SPLINE TABLE REPULSION */
518 vfitab = _mm_add_epi32(vfitab,ifour);
519 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
520 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
521 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
522 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
523 _MM_TRANSPOSE4_PS(Y,F,G,H);
524 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
525 VV = _mm_macc_ps(vfeps,Fp,Y);
526 vvdw12 = _mm_mul_ps(c12_00,VV);
527 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
528 fvdw12 = _mm_mul_ps(c12_00,FF);
529 vvdw = _mm_add_ps(vvdw12,vvdw6);
530 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
532 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
534 /* Update potential sum for this i atom from the interaction with this j atom. */
535 velec = _mm_and_ps(velec,cutoff_mask);
536 velec = _mm_andnot_ps(dummy_mask,velec);
537 velecsum = _mm_add_ps(velecsum,velec);
538 vvdw = _mm_and_ps(vvdw,cutoff_mask);
539 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
540 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
542 fscal = _mm_add_ps(felec,fvdw);
544 fscal = _mm_and_ps(fscal,cutoff_mask);
546 fscal = _mm_andnot_ps(dummy_mask,fscal);
548 /* Update vectorial force */
549 fix0 = _mm_macc_ps(dx00,fscal,fix0);
550 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
551 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
553 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
554 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
555 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
559 /**************************
560 * CALCULATE INTERACTIONS *
561 **************************/
563 if (gmx_mm_any_lt(rsq10,rcutoff2))
566 /* Compute parameters for interactions between i and j atoms */
567 qq10 = _mm_mul_ps(iq1,jq0);
569 /* REACTION-FIELD ELECTROSTATICS */
570 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
571 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
573 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
575 /* Update potential sum for this i atom from the interaction with this j atom. */
576 velec = _mm_and_ps(velec,cutoff_mask);
577 velec = _mm_andnot_ps(dummy_mask,velec);
578 velecsum = _mm_add_ps(velecsum,velec);
582 fscal = _mm_and_ps(fscal,cutoff_mask);
584 fscal = _mm_andnot_ps(dummy_mask,fscal);
586 /* Update vectorial force */
587 fix1 = _mm_macc_ps(dx10,fscal,fix1);
588 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
589 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
591 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
592 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
593 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
597 /**************************
598 * CALCULATE INTERACTIONS *
599 **************************/
601 if (gmx_mm_any_lt(rsq20,rcutoff2))
604 /* Compute parameters for interactions between i and j atoms */
605 qq20 = _mm_mul_ps(iq2,jq0);
607 /* REACTION-FIELD ELECTROSTATICS */
608 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
609 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
611 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
613 /* Update potential sum for this i atom from the interaction with this j atom. */
614 velec = _mm_and_ps(velec,cutoff_mask);
615 velec = _mm_andnot_ps(dummy_mask,velec);
616 velecsum = _mm_add_ps(velecsum,velec);
620 fscal = _mm_and_ps(fscal,cutoff_mask);
622 fscal = _mm_andnot_ps(dummy_mask,fscal);
624 /* Update vectorial force */
625 fix2 = _mm_macc_ps(dx20,fscal,fix2);
626 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
627 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
629 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
630 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
631 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
635 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
636 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
637 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
638 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
640 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
642 /* Inner loop uses 154 flops */
645 /* End of innermost loop */
647 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
648 f+i_coord_offset,fshift+i_shift_offset);
651 /* Update potential energies */
652 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
653 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
655 /* Increment number of inner iterations */
656 inneriter += j_index_end - j_index_start;
658 /* Outer loop uses 20 flops */
661 /* Increment number of outer iterations */
664 /* Update outer/inner flops */
666 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*154);
669 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_F_avx_128_fma_single
670 * Electrostatics interaction: ReactionField
671 * VdW interaction: CubicSplineTable
672 * Geometry: Water3-Particle
673 * Calculate force/pot: Force
676 nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_F_avx_128_fma_single
677 (t_nblist * gmx_restrict nlist,
678 rvec * gmx_restrict xx,
679 rvec * gmx_restrict ff,
680 t_forcerec * gmx_restrict fr,
681 t_mdatoms * gmx_restrict mdatoms,
682 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
683 t_nrnb * gmx_restrict nrnb)
685 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
686 * just 0 for non-waters.
687 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
688 * jnr indices corresponding to data put in the four positions in the SIMD register.
690 int i_shift_offset,i_coord_offset,outeriter,inneriter;
691 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
692 int jnrA,jnrB,jnrC,jnrD;
693 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
694 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
695 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
697 real *shiftvec,*fshift,*x,*f;
698 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
700 __m128 fscal,rcutoff,rcutoff2,jidxall;
702 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
704 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
706 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
707 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
708 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
709 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
710 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
711 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
712 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
715 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
718 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
719 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
721 __m128i ifour = _mm_set1_epi32(4);
722 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
724 __m128 dummy_mask,cutoff_mask;
725 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
726 __m128 one = _mm_set1_ps(1.0);
727 __m128 two = _mm_set1_ps(2.0);
733 jindex = nlist->jindex;
735 shiftidx = nlist->shift;
737 shiftvec = fr->shift_vec[0];
738 fshift = fr->fshift[0];
739 facel = _mm_set1_ps(fr->epsfac);
740 charge = mdatoms->chargeA;
741 krf = _mm_set1_ps(fr->ic->k_rf);
742 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
743 crf = _mm_set1_ps(fr->ic->c_rf);
744 nvdwtype = fr->ntype;
746 vdwtype = mdatoms->typeA;
748 vftab = kernel_data->table_vdw->data;
749 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
751 /* Setup water-specific parameters */
752 inr = nlist->iinr[0];
753 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
754 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
755 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
756 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
758 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
759 rcutoff_scalar = fr->rcoulomb;
760 rcutoff = _mm_set1_ps(rcutoff_scalar);
761 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
763 /* Avoid stupid compiler warnings */
764 jnrA = jnrB = jnrC = jnrD = 0;
773 for(iidx=0;iidx<4*DIM;iidx++)
778 /* Start outer loop over neighborlists */
779 for(iidx=0; iidx<nri; iidx++)
781 /* Load shift vector for this list */
782 i_shift_offset = DIM*shiftidx[iidx];
784 /* Load limits for loop over neighbors */
785 j_index_start = jindex[iidx];
786 j_index_end = jindex[iidx+1];
788 /* Get outer coordinate index */
790 i_coord_offset = DIM*inr;
792 /* Load i particle coords and add shift vector */
793 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
794 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
796 fix0 = _mm_setzero_ps();
797 fiy0 = _mm_setzero_ps();
798 fiz0 = _mm_setzero_ps();
799 fix1 = _mm_setzero_ps();
800 fiy1 = _mm_setzero_ps();
801 fiz1 = _mm_setzero_ps();
802 fix2 = _mm_setzero_ps();
803 fiy2 = _mm_setzero_ps();
804 fiz2 = _mm_setzero_ps();
806 /* Start inner kernel loop */
807 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
810 /* Get j neighbor index, and coordinate index */
815 j_coord_offsetA = DIM*jnrA;
816 j_coord_offsetB = DIM*jnrB;
817 j_coord_offsetC = DIM*jnrC;
818 j_coord_offsetD = DIM*jnrD;
820 /* load j atom coordinates */
821 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
822 x+j_coord_offsetC,x+j_coord_offsetD,
825 /* Calculate displacement vector */
826 dx00 = _mm_sub_ps(ix0,jx0);
827 dy00 = _mm_sub_ps(iy0,jy0);
828 dz00 = _mm_sub_ps(iz0,jz0);
829 dx10 = _mm_sub_ps(ix1,jx0);
830 dy10 = _mm_sub_ps(iy1,jy0);
831 dz10 = _mm_sub_ps(iz1,jz0);
832 dx20 = _mm_sub_ps(ix2,jx0);
833 dy20 = _mm_sub_ps(iy2,jy0);
834 dz20 = _mm_sub_ps(iz2,jz0);
836 /* Calculate squared distance and things based on it */
837 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
838 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
839 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
841 rinv00 = gmx_mm_invsqrt_ps(rsq00);
842 rinv10 = gmx_mm_invsqrt_ps(rsq10);
843 rinv20 = gmx_mm_invsqrt_ps(rsq20);
845 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
846 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
847 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
849 /* Load parameters for j particles */
850 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
851 charge+jnrC+0,charge+jnrD+0);
852 vdwjidx0A = 2*vdwtype[jnrA+0];
853 vdwjidx0B = 2*vdwtype[jnrB+0];
854 vdwjidx0C = 2*vdwtype[jnrC+0];
855 vdwjidx0D = 2*vdwtype[jnrD+0];
857 fjx0 = _mm_setzero_ps();
858 fjy0 = _mm_setzero_ps();
859 fjz0 = _mm_setzero_ps();
861 /**************************
862 * CALCULATE INTERACTIONS *
863 **************************/
865 if (gmx_mm_any_lt(rsq00,rcutoff2))
868 r00 = _mm_mul_ps(rsq00,rinv00);
870 /* Compute parameters for interactions between i and j atoms */
871 qq00 = _mm_mul_ps(iq0,jq0);
872 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
873 vdwparam+vdwioffset0+vdwjidx0B,
874 vdwparam+vdwioffset0+vdwjidx0C,
875 vdwparam+vdwioffset0+vdwjidx0D,
878 /* Calculate table index by multiplying r with table scale and truncate to integer */
879 rt = _mm_mul_ps(r00,vftabscale);
880 vfitab = _mm_cvttps_epi32(rt);
882 vfeps = _mm_frcz_ps(rt);
884 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
886 twovfeps = _mm_add_ps(vfeps,vfeps);
887 vfitab = _mm_slli_epi32(vfitab,3);
889 /* REACTION-FIELD ELECTROSTATICS */
890 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
892 /* CUBIC SPLINE TABLE DISPERSION */
893 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
894 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
895 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
896 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
897 _MM_TRANSPOSE4_PS(Y,F,G,H);
898 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
899 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
900 fvdw6 = _mm_mul_ps(c6_00,FF);
902 /* CUBIC SPLINE TABLE REPULSION */
903 vfitab = _mm_add_epi32(vfitab,ifour);
904 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
905 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
906 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
907 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
908 _MM_TRANSPOSE4_PS(Y,F,G,H);
909 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
910 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
911 fvdw12 = _mm_mul_ps(c12_00,FF);
912 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
914 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
916 fscal = _mm_add_ps(felec,fvdw);
918 fscal = _mm_and_ps(fscal,cutoff_mask);
920 /* Update vectorial force */
921 fix0 = _mm_macc_ps(dx00,fscal,fix0);
922 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
923 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
925 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
926 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
927 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
931 /**************************
932 * CALCULATE INTERACTIONS *
933 **************************/
935 if (gmx_mm_any_lt(rsq10,rcutoff2))
938 /* Compute parameters for interactions between i and j atoms */
939 qq10 = _mm_mul_ps(iq1,jq0);
941 /* REACTION-FIELD ELECTROSTATICS */
942 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
944 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
948 fscal = _mm_and_ps(fscal,cutoff_mask);
950 /* Update vectorial force */
951 fix1 = _mm_macc_ps(dx10,fscal,fix1);
952 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
953 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
955 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
956 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
957 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
961 /**************************
962 * CALCULATE INTERACTIONS *
963 **************************/
965 if (gmx_mm_any_lt(rsq20,rcutoff2))
968 /* Compute parameters for interactions between i and j atoms */
969 qq20 = _mm_mul_ps(iq2,jq0);
971 /* REACTION-FIELD ELECTROSTATICS */
972 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
974 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
978 fscal = _mm_and_ps(fscal,cutoff_mask);
980 /* Update vectorial force */
981 fix2 = _mm_macc_ps(dx20,fscal,fix2);
982 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
983 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
985 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
986 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
987 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
991 fjptrA = f+j_coord_offsetA;
992 fjptrB = f+j_coord_offsetB;
993 fjptrC = f+j_coord_offsetC;
994 fjptrD = f+j_coord_offsetD;
996 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
998 /* Inner loop uses 126 flops */
1001 if(jidx<j_index_end)
1004 /* Get j neighbor index, and coordinate index */
1005 jnrlistA = jjnr[jidx];
1006 jnrlistB = jjnr[jidx+1];
1007 jnrlistC = jjnr[jidx+2];
1008 jnrlistD = jjnr[jidx+3];
1009 /* Sign of each element will be negative for non-real atoms.
1010 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1011 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1013 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1014 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1015 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1016 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1017 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1018 j_coord_offsetA = DIM*jnrA;
1019 j_coord_offsetB = DIM*jnrB;
1020 j_coord_offsetC = DIM*jnrC;
1021 j_coord_offsetD = DIM*jnrD;
1023 /* load j atom coordinates */
1024 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1025 x+j_coord_offsetC,x+j_coord_offsetD,
1028 /* Calculate displacement vector */
1029 dx00 = _mm_sub_ps(ix0,jx0);
1030 dy00 = _mm_sub_ps(iy0,jy0);
1031 dz00 = _mm_sub_ps(iz0,jz0);
1032 dx10 = _mm_sub_ps(ix1,jx0);
1033 dy10 = _mm_sub_ps(iy1,jy0);
1034 dz10 = _mm_sub_ps(iz1,jz0);
1035 dx20 = _mm_sub_ps(ix2,jx0);
1036 dy20 = _mm_sub_ps(iy2,jy0);
1037 dz20 = _mm_sub_ps(iz2,jz0);
1039 /* Calculate squared distance and things based on it */
1040 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1041 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1042 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1044 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1045 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1046 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1048 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1049 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1050 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1052 /* Load parameters for j particles */
1053 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1054 charge+jnrC+0,charge+jnrD+0);
1055 vdwjidx0A = 2*vdwtype[jnrA+0];
1056 vdwjidx0B = 2*vdwtype[jnrB+0];
1057 vdwjidx0C = 2*vdwtype[jnrC+0];
1058 vdwjidx0D = 2*vdwtype[jnrD+0];
1060 fjx0 = _mm_setzero_ps();
1061 fjy0 = _mm_setzero_ps();
1062 fjz0 = _mm_setzero_ps();
1064 /**************************
1065 * CALCULATE INTERACTIONS *
1066 **************************/
1068 if (gmx_mm_any_lt(rsq00,rcutoff2))
1071 r00 = _mm_mul_ps(rsq00,rinv00);
1072 r00 = _mm_andnot_ps(dummy_mask,r00);
1074 /* Compute parameters for interactions between i and j atoms */
1075 qq00 = _mm_mul_ps(iq0,jq0);
1076 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1077 vdwparam+vdwioffset0+vdwjidx0B,
1078 vdwparam+vdwioffset0+vdwjidx0C,
1079 vdwparam+vdwioffset0+vdwjidx0D,
1082 /* Calculate table index by multiplying r with table scale and truncate to integer */
1083 rt = _mm_mul_ps(r00,vftabscale);
1084 vfitab = _mm_cvttps_epi32(rt);
1086 vfeps = _mm_frcz_ps(rt);
1088 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1090 twovfeps = _mm_add_ps(vfeps,vfeps);
1091 vfitab = _mm_slli_epi32(vfitab,3);
1093 /* REACTION-FIELD ELECTROSTATICS */
1094 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1096 /* CUBIC SPLINE TABLE DISPERSION */
1097 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1098 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1099 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1100 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1101 _MM_TRANSPOSE4_PS(Y,F,G,H);
1102 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1103 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1104 fvdw6 = _mm_mul_ps(c6_00,FF);
1106 /* CUBIC SPLINE TABLE REPULSION */
1107 vfitab = _mm_add_epi32(vfitab,ifour);
1108 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1109 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1110 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1111 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1112 _MM_TRANSPOSE4_PS(Y,F,G,H);
1113 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1114 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1115 fvdw12 = _mm_mul_ps(c12_00,FF);
1116 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1118 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1120 fscal = _mm_add_ps(felec,fvdw);
1122 fscal = _mm_and_ps(fscal,cutoff_mask);
1124 fscal = _mm_andnot_ps(dummy_mask,fscal);
1126 /* Update vectorial force */
1127 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1128 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1129 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1131 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1132 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1133 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1137 /**************************
1138 * CALCULATE INTERACTIONS *
1139 **************************/
1141 if (gmx_mm_any_lt(rsq10,rcutoff2))
1144 /* Compute parameters for interactions between i and j atoms */
1145 qq10 = _mm_mul_ps(iq1,jq0);
1147 /* REACTION-FIELD ELECTROSTATICS */
1148 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1150 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1154 fscal = _mm_and_ps(fscal,cutoff_mask);
1156 fscal = _mm_andnot_ps(dummy_mask,fscal);
1158 /* Update vectorial force */
1159 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1160 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1161 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1163 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1164 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1165 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1169 /**************************
1170 * CALCULATE INTERACTIONS *
1171 **************************/
1173 if (gmx_mm_any_lt(rsq20,rcutoff2))
1176 /* Compute parameters for interactions between i and j atoms */
1177 qq20 = _mm_mul_ps(iq2,jq0);
1179 /* REACTION-FIELD ELECTROSTATICS */
1180 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1182 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1186 fscal = _mm_and_ps(fscal,cutoff_mask);
1188 fscal = _mm_andnot_ps(dummy_mask,fscal);
1190 /* Update vectorial force */
1191 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1192 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1193 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1195 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1196 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1197 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1201 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1202 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1203 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1204 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1206 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1208 /* Inner loop uses 127 flops */
1211 /* End of innermost loop */
1213 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1214 f+i_coord_offset,fshift+i_shift_offset);
1216 /* Increment number of inner iterations */
1217 inneriter += j_index_end - j_index_start;
1219 /* Outer loop uses 18 flops */
1222 /* Increment number of outer iterations */
1225 /* Update outer/inner flops */
1227 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*127);