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.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "gromacs/math/vec.h"
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: CubicSplineTable
56 * Geometry: Water3-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_VF_avx_128_fma_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
94 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
95 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
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->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 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
138 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
139 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
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->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_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
178 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
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();
190 /* Reset potential sums */
191 velecsum = _mm_setzero_ps();
192 vvdwsum = _mm_setzero_ps();
194 /* Start inner kernel loop */
195 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
198 /* Get j neighbor index, and coordinate index */
203 j_coord_offsetA = DIM*jnrA;
204 j_coord_offsetB = DIM*jnrB;
205 j_coord_offsetC = DIM*jnrC;
206 j_coord_offsetD = DIM*jnrD;
208 /* load j atom coordinates */
209 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
210 x+j_coord_offsetC,x+j_coord_offsetD,
213 /* Calculate displacement vector */
214 dx00 = _mm_sub_ps(ix0,jx0);
215 dy00 = _mm_sub_ps(iy0,jy0);
216 dz00 = _mm_sub_ps(iz0,jz0);
217 dx10 = _mm_sub_ps(ix1,jx0);
218 dy10 = _mm_sub_ps(iy1,jy0);
219 dz10 = _mm_sub_ps(iz1,jz0);
220 dx20 = _mm_sub_ps(ix2,jx0);
221 dy20 = _mm_sub_ps(iy2,jy0);
222 dz20 = _mm_sub_ps(iz2,jz0);
224 /* Calculate squared distance and things based on it */
225 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
226 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
227 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
229 rinv00 = gmx_mm_invsqrt_ps(rsq00);
230 rinv10 = gmx_mm_invsqrt_ps(rsq10);
231 rinv20 = gmx_mm_invsqrt_ps(rsq20);
233 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
234 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
235 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
237 /* Load parameters for j particles */
238 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
239 charge+jnrC+0,charge+jnrD+0);
240 vdwjidx0A = 2*vdwtype[jnrA+0];
241 vdwjidx0B = 2*vdwtype[jnrB+0];
242 vdwjidx0C = 2*vdwtype[jnrC+0];
243 vdwjidx0D = 2*vdwtype[jnrD+0];
245 fjx0 = _mm_setzero_ps();
246 fjy0 = _mm_setzero_ps();
247 fjz0 = _mm_setzero_ps();
249 /**************************
250 * CALCULATE INTERACTIONS *
251 **************************/
253 if (gmx_mm_any_lt(rsq00,rcutoff2))
256 r00 = _mm_mul_ps(rsq00,rinv00);
258 /* Compute parameters for interactions between i and j atoms */
259 qq00 = _mm_mul_ps(iq0,jq0);
260 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
261 vdwparam+vdwioffset0+vdwjidx0B,
262 vdwparam+vdwioffset0+vdwjidx0C,
263 vdwparam+vdwioffset0+vdwjidx0D,
266 /* Calculate table index by multiplying r with table scale and truncate to integer */
267 rt = _mm_mul_ps(r00,vftabscale);
268 vfitab = _mm_cvttps_epi32(rt);
270 vfeps = _mm_frcz_ps(rt);
272 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
274 twovfeps = _mm_add_ps(vfeps,vfeps);
275 vfitab = _mm_slli_epi32(vfitab,3);
277 /* REACTION-FIELD ELECTROSTATICS */
278 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
279 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
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 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
310 /* Update potential sum for this i atom from the interaction with this j atom. */
311 velec = _mm_and_ps(velec,cutoff_mask);
312 velecsum = _mm_add_ps(velecsum,velec);
313 vvdw = _mm_and_ps(vvdw,cutoff_mask);
314 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
316 fscal = _mm_add_ps(felec,fvdw);
318 fscal = _mm_and_ps(fscal,cutoff_mask);
320 /* Update vectorial force */
321 fix0 = _mm_macc_ps(dx00,fscal,fix0);
322 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
323 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
325 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
326 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
327 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
331 /**************************
332 * CALCULATE INTERACTIONS *
333 **************************/
335 if (gmx_mm_any_lt(rsq10,rcutoff2))
338 /* Compute parameters for interactions between i and j atoms */
339 qq10 = _mm_mul_ps(iq1,jq0);
341 /* REACTION-FIELD ELECTROSTATICS */
342 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
343 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
345 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
347 /* Update potential sum for this i atom from the interaction with this j atom. */
348 velec = _mm_and_ps(velec,cutoff_mask);
349 velecsum = _mm_add_ps(velecsum,velec);
353 fscal = _mm_and_ps(fscal,cutoff_mask);
355 /* Update vectorial force */
356 fix1 = _mm_macc_ps(dx10,fscal,fix1);
357 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
358 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
360 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
361 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
362 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
366 /**************************
367 * CALCULATE INTERACTIONS *
368 **************************/
370 if (gmx_mm_any_lt(rsq20,rcutoff2))
373 /* Compute parameters for interactions between i and j atoms */
374 qq20 = _mm_mul_ps(iq2,jq0);
376 /* REACTION-FIELD ELECTROSTATICS */
377 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
378 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
380 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
382 /* Update potential sum for this i atom from the interaction with this j atom. */
383 velec = _mm_and_ps(velec,cutoff_mask);
384 velecsum = _mm_add_ps(velecsum,velec);
388 fscal = _mm_and_ps(fscal,cutoff_mask);
390 /* Update vectorial force */
391 fix2 = _mm_macc_ps(dx20,fscal,fix2);
392 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
393 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
395 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
396 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
397 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
401 fjptrA = f+j_coord_offsetA;
402 fjptrB = f+j_coord_offsetB;
403 fjptrC = f+j_coord_offsetC;
404 fjptrD = f+j_coord_offsetD;
406 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
408 /* Inner loop uses 153 flops */
414 /* Get j neighbor index, and coordinate index */
415 jnrlistA = jjnr[jidx];
416 jnrlistB = jjnr[jidx+1];
417 jnrlistC = jjnr[jidx+2];
418 jnrlistD = jjnr[jidx+3];
419 /* Sign of each element will be negative for non-real atoms.
420 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
421 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
423 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
424 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
425 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
426 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
427 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
428 j_coord_offsetA = DIM*jnrA;
429 j_coord_offsetB = DIM*jnrB;
430 j_coord_offsetC = DIM*jnrC;
431 j_coord_offsetD = DIM*jnrD;
433 /* load j atom coordinates */
434 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
435 x+j_coord_offsetC,x+j_coord_offsetD,
438 /* Calculate displacement vector */
439 dx00 = _mm_sub_ps(ix0,jx0);
440 dy00 = _mm_sub_ps(iy0,jy0);
441 dz00 = _mm_sub_ps(iz0,jz0);
442 dx10 = _mm_sub_ps(ix1,jx0);
443 dy10 = _mm_sub_ps(iy1,jy0);
444 dz10 = _mm_sub_ps(iz1,jz0);
445 dx20 = _mm_sub_ps(ix2,jx0);
446 dy20 = _mm_sub_ps(iy2,jy0);
447 dz20 = _mm_sub_ps(iz2,jz0);
449 /* Calculate squared distance and things based on it */
450 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
451 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
452 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
454 rinv00 = gmx_mm_invsqrt_ps(rsq00);
455 rinv10 = gmx_mm_invsqrt_ps(rsq10);
456 rinv20 = gmx_mm_invsqrt_ps(rsq20);
458 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
459 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
460 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
462 /* Load parameters for j particles */
463 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
464 charge+jnrC+0,charge+jnrD+0);
465 vdwjidx0A = 2*vdwtype[jnrA+0];
466 vdwjidx0B = 2*vdwtype[jnrB+0];
467 vdwjidx0C = 2*vdwtype[jnrC+0];
468 vdwjidx0D = 2*vdwtype[jnrD+0];
470 fjx0 = _mm_setzero_ps();
471 fjy0 = _mm_setzero_ps();
472 fjz0 = _mm_setzero_ps();
474 /**************************
475 * CALCULATE INTERACTIONS *
476 **************************/
478 if (gmx_mm_any_lt(rsq00,rcutoff2))
481 r00 = _mm_mul_ps(rsq00,rinv00);
482 r00 = _mm_andnot_ps(dummy_mask,r00);
484 /* Compute parameters for interactions between i and j atoms */
485 qq00 = _mm_mul_ps(iq0,jq0);
486 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
487 vdwparam+vdwioffset0+vdwjidx0B,
488 vdwparam+vdwioffset0+vdwjidx0C,
489 vdwparam+vdwioffset0+vdwjidx0D,
492 /* Calculate table index by multiplying r with table scale and truncate to integer */
493 rt = _mm_mul_ps(r00,vftabscale);
494 vfitab = _mm_cvttps_epi32(rt);
496 vfeps = _mm_frcz_ps(rt);
498 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
500 twovfeps = _mm_add_ps(vfeps,vfeps);
501 vfitab = _mm_slli_epi32(vfitab,3);
503 /* REACTION-FIELD ELECTROSTATICS */
504 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
505 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
507 /* CUBIC SPLINE TABLE DISPERSION */
508 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
509 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
510 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
511 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
512 _MM_TRANSPOSE4_PS(Y,F,G,H);
513 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
514 VV = _mm_macc_ps(vfeps,Fp,Y);
515 vvdw6 = _mm_mul_ps(c6_00,VV);
516 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
517 fvdw6 = _mm_mul_ps(c6_00,FF);
519 /* CUBIC SPLINE TABLE REPULSION */
520 vfitab = _mm_add_epi32(vfitab,ifour);
521 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
522 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
523 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
524 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
525 _MM_TRANSPOSE4_PS(Y,F,G,H);
526 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
527 VV = _mm_macc_ps(vfeps,Fp,Y);
528 vvdw12 = _mm_mul_ps(c12_00,VV);
529 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
530 fvdw12 = _mm_mul_ps(c12_00,FF);
531 vvdw = _mm_add_ps(vvdw12,vvdw6);
532 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
534 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
536 /* Update potential sum for this i atom from the interaction with this j atom. */
537 velec = _mm_and_ps(velec,cutoff_mask);
538 velec = _mm_andnot_ps(dummy_mask,velec);
539 velecsum = _mm_add_ps(velecsum,velec);
540 vvdw = _mm_and_ps(vvdw,cutoff_mask);
541 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
542 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
544 fscal = _mm_add_ps(felec,fvdw);
546 fscal = _mm_and_ps(fscal,cutoff_mask);
548 fscal = _mm_andnot_ps(dummy_mask,fscal);
550 /* Update vectorial force */
551 fix0 = _mm_macc_ps(dx00,fscal,fix0);
552 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
553 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
555 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
556 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
557 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
561 /**************************
562 * CALCULATE INTERACTIONS *
563 **************************/
565 if (gmx_mm_any_lt(rsq10,rcutoff2))
568 /* Compute parameters for interactions between i and j atoms */
569 qq10 = _mm_mul_ps(iq1,jq0);
571 /* REACTION-FIELD ELECTROSTATICS */
572 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
573 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
575 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
577 /* Update potential sum for this i atom from the interaction with this j atom. */
578 velec = _mm_and_ps(velec,cutoff_mask);
579 velec = _mm_andnot_ps(dummy_mask,velec);
580 velecsum = _mm_add_ps(velecsum,velec);
584 fscal = _mm_and_ps(fscal,cutoff_mask);
586 fscal = _mm_andnot_ps(dummy_mask,fscal);
588 /* Update vectorial force */
589 fix1 = _mm_macc_ps(dx10,fscal,fix1);
590 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
591 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
593 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
594 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
595 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
599 /**************************
600 * CALCULATE INTERACTIONS *
601 **************************/
603 if (gmx_mm_any_lt(rsq20,rcutoff2))
606 /* Compute parameters for interactions between i and j atoms */
607 qq20 = _mm_mul_ps(iq2,jq0);
609 /* REACTION-FIELD ELECTROSTATICS */
610 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
611 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
613 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
615 /* Update potential sum for this i atom from the interaction with this j atom. */
616 velec = _mm_and_ps(velec,cutoff_mask);
617 velec = _mm_andnot_ps(dummy_mask,velec);
618 velecsum = _mm_add_ps(velecsum,velec);
622 fscal = _mm_and_ps(fscal,cutoff_mask);
624 fscal = _mm_andnot_ps(dummy_mask,fscal);
626 /* Update vectorial force */
627 fix2 = _mm_macc_ps(dx20,fscal,fix2);
628 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
629 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
631 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
632 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
633 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
637 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
638 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
639 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
640 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
642 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
644 /* Inner loop uses 154 flops */
647 /* End of innermost loop */
649 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
650 f+i_coord_offset,fshift+i_shift_offset);
653 /* Update potential energies */
654 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
655 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
657 /* Increment number of inner iterations */
658 inneriter += j_index_end - j_index_start;
660 /* Outer loop uses 20 flops */
663 /* Increment number of outer iterations */
666 /* Update outer/inner flops */
668 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*154);
671 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_F_avx_128_fma_single
672 * Electrostatics interaction: ReactionField
673 * VdW interaction: CubicSplineTable
674 * Geometry: Water3-Particle
675 * Calculate force/pot: Force
678 nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_F_avx_128_fma_single
679 (t_nblist * gmx_restrict nlist,
680 rvec * gmx_restrict xx,
681 rvec * gmx_restrict ff,
682 t_forcerec * gmx_restrict fr,
683 t_mdatoms * gmx_restrict mdatoms,
684 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
685 t_nrnb * gmx_restrict nrnb)
687 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
688 * just 0 for non-waters.
689 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
690 * jnr indices corresponding to data put in the four positions in the SIMD register.
692 int i_shift_offset,i_coord_offset,outeriter,inneriter;
693 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
694 int jnrA,jnrB,jnrC,jnrD;
695 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
696 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
697 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
699 real *shiftvec,*fshift,*x,*f;
700 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
702 __m128 fscal,rcutoff,rcutoff2,jidxall;
704 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
706 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
708 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
709 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
710 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
711 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
712 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
713 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
714 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
717 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
720 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
721 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
723 __m128i ifour = _mm_set1_epi32(4);
724 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
726 __m128 dummy_mask,cutoff_mask;
727 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
728 __m128 one = _mm_set1_ps(1.0);
729 __m128 two = _mm_set1_ps(2.0);
735 jindex = nlist->jindex;
737 shiftidx = nlist->shift;
739 shiftvec = fr->shift_vec[0];
740 fshift = fr->fshift[0];
741 facel = _mm_set1_ps(fr->epsfac);
742 charge = mdatoms->chargeA;
743 krf = _mm_set1_ps(fr->ic->k_rf);
744 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
745 crf = _mm_set1_ps(fr->ic->c_rf);
746 nvdwtype = fr->ntype;
748 vdwtype = mdatoms->typeA;
750 vftab = kernel_data->table_vdw->data;
751 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
753 /* Setup water-specific parameters */
754 inr = nlist->iinr[0];
755 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
756 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
757 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
758 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
760 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
761 rcutoff_scalar = fr->rcoulomb;
762 rcutoff = _mm_set1_ps(rcutoff_scalar);
763 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
765 /* Avoid stupid compiler warnings */
766 jnrA = jnrB = jnrC = jnrD = 0;
775 for(iidx=0;iidx<4*DIM;iidx++)
780 /* Start outer loop over neighborlists */
781 for(iidx=0; iidx<nri; iidx++)
783 /* Load shift vector for this list */
784 i_shift_offset = DIM*shiftidx[iidx];
786 /* Load limits for loop over neighbors */
787 j_index_start = jindex[iidx];
788 j_index_end = jindex[iidx+1];
790 /* Get outer coordinate index */
792 i_coord_offset = DIM*inr;
794 /* Load i particle coords and add shift vector */
795 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
796 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
798 fix0 = _mm_setzero_ps();
799 fiy0 = _mm_setzero_ps();
800 fiz0 = _mm_setzero_ps();
801 fix1 = _mm_setzero_ps();
802 fiy1 = _mm_setzero_ps();
803 fiz1 = _mm_setzero_ps();
804 fix2 = _mm_setzero_ps();
805 fiy2 = _mm_setzero_ps();
806 fiz2 = _mm_setzero_ps();
808 /* Start inner kernel loop */
809 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
812 /* Get j neighbor index, and coordinate index */
817 j_coord_offsetA = DIM*jnrA;
818 j_coord_offsetB = DIM*jnrB;
819 j_coord_offsetC = DIM*jnrC;
820 j_coord_offsetD = DIM*jnrD;
822 /* load j atom coordinates */
823 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
824 x+j_coord_offsetC,x+j_coord_offsetD,
827 /* Calculate displacement vector */
828 dx00 = _mm_sub_ps(ix0,jx0);
829 dy00 = _mm_sub_ps(iy0,jy0);
830 dz00 = _mm_sub_ps(iz0,jz0);
831 dx10 = _mm_sub_ps(ix1,jx0);
832 dy10 = _mm_sub_ps(iy1,jy0);
833 dz10 = _mm_sub_ps(iz1,jz0);
834 dx20 = _mm_sub_ps(ix2,jx0);
835 dy20 = _mm_sub_ps(iy2,jy0);
836 dz20 = _mm_sub_ps(iz2,jz0);
838 /* Calculate squared distance and things based on it */
839 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
840 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
841 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
843 rinv00 = gmx_mm_invsqrt_ps(rsq00);
844 rinv10 = gmx_mm_invsqrt_ps(rsq10);
845 rinv20 = gmx_mm_invsqrt_ps(rsq20);
847 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
848 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
849 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
851 /* Load parameters for j particles */
852 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
853 charge+jnrC+0,charge+jnrD+0);
854 vdwjidx0A = 2*vdwtype[jnrA+0];
855 vdwjidx0B = 2*vdwtype[jnrB+0];
856 vdwjidx0C = 2*vdwtype[jnrC+0];
857 vdwjidx0D = 2*vdwtype[jnrD+0];
859 fjx0 = _mm_setzero_ps();
860 fjy0 = _mm_setzero_ps();
861 fjz0 = _mm_setzero_ps();
863 /**************************
864 * CALCULATE INTERACTIONS *
865 **************************/
867 if (gmx_mm_any_lt(rsq00,rcutoff2))
870 r00 = _mm_mul_ps(rsq00,rinv00);
872 /* Compute parameters for interactions between i and j atoms */
873 qq00 = _mm_mul_ps(iq0,jq0);
874 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
875 vdwparam+vdwioffset0+vdwjidx0B,
876 vdwparam+vdwioffset0+vdwjidx0C,
877 vdwparam+vdwioffset0+vdwjidx0D,
880 /* Calculate table index by multiplying r with table scale and truncate to integer */
881 rt = _mm_mul_ps(r00,vftabscale);
882 vfitab = _mm_cvttps_epi32(rt);
884 vfeps = _mm_frcz_ps(rt);
886 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
888 twovfeps = _mm_add_ps(vfeps,vfeps);
889 vfitab = _mm_slli_epi32(vfitab,3);
891 /* REACTION-FIELD ELECTROSTATICS */
892 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
894 /* CUBIC SPLINE TABLE DISPERSION */
895 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
896 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
897 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
898 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
899 _MM_TRANSPOSE4_PS(Y,F,G,H);
900 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
901 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
902 fvdw6 = _mm_mul_ps(c6_00,FF);
904 /* CUBIC SPLINE TABLE REPULSION */
905 vfitab = _mm_add_epi32(vfitab,ifour);
906 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
907 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
908 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
909 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
910 _MM_TRANSPOSE4_PS(Y,F,G,H);
911 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
912 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
913 fvdw12 = _mm_mul_ps(c12_00,FF);
914 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
916 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
918 fscal = _mm_add_ps(felec,fvdw);
920 fscal = _mm_and_ps(fscal,cutoff_mask);
922 /* Update vectorial force */
923 fix0 = _mm_macc_ps(dx00,fscal,fix0);
924 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
925 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
927 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
928 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
929 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
933 /**************************
934 * CALCULATE INTERACTIONS *
935 **************************/
937 if (gmx_mm_any_lt(rsq10,rcutoff2))
940 /* Compute parameters for interactions between i and j atoms */
941 qq10 = _mm_mul_ps(iq1,jq0);
943 /* REACTION-FIELD ELECTROSTATICS */
944 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
946 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
950 fscal = _mm_and_ps(fscal,cutoff_mask);
952 /* Update vectorial force */
953 fix1 = _mm_macc_ps(dx10,fscal,fix1);
954 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
955 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
957 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
958 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
959 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
963 /**************************
964 * CALCULATE INTERACTIONS *
965 **************************/
967 if (gmx_mm_any_lt(rsq20,rcutoff2))
970 /* Compute parameters for interactions between i and j atoms */
971 qq20 = _mm_mul_ps(iq2,jq0);
973 /* REACTION-FIELD ELECTROSTATICS */
974 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
976 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
980 fscal = _mm_and_ps(fscal,cutoff_mask);
982 /* Update vectorial force */
983 fix2 = _mm_macc_ps(dx20,fscal,fix2);
984 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
985 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
987 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
988 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
989 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
993 fjptrA = f+j_coord_offsetA;
994 fjptrB = f+j_coord_offsetB;
995 fjptrC = f+j_coord_offsetC;
996 fjptrD = f+j_coord_offsetD;
998 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1000 /* Inner loop uses 126 flops */
1003 if(jidx<j_index_end)
1006 /* Get j neighbor index, and coordinate index */
1007 jnrlistA = jjnr[jidx];
1008 jnrlistB = jjnr[jidx+1];
1009 jnrlistC = jjnr[jidx+2];
1010 jnrlistD = jjnr[jidx+3];
1011 /* Sign of each element will be negative for non-real atoms.
1012 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1013 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1015 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1016 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1017 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1018 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1019 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1020 j_coord_offsetA = DIM*jnrA;
1021 j_coord_offsetB = DIM*jnrB;
1022 j_coord_offsetC = DIM*jnrC;
1023 j_coord_offsetD = DIM*jnrD;
1025 /* load j atom coordinates */
1026 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1027 x+j_coord_offsetC,x+j_coord_offsetD,
1030 /* Calculate displacement vector */
1031 dx00 = _mm_sub_ps(ix0,jx0);
1032 dy00 = _mm_sub_ps(iy0,jy0);
1033 dz00 = _mm_sub_ps(iz0,jz0);
1034 dx10 = _mm_sub_ps(ix1,jx0);
1035 dy10 = _mm_sub_ps(iy1,jy0);
1036 dz10 = _mm_sub_ps(iz1,jz0);
1037 dx20 = _mm_sub_ps(ix2,jx0);
1038 dy20 = _mm_sub_ps(iy2,jy0);
1039 dz20 = _mm_sub_ps(iz2,jz0);
1041 /* Calculate squared distance and things based on it */
1042 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1043 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1044 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1046 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1047 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1048 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1050 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1051 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1052 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1054 /* Load parameters for j particles */
1055 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1056 charge+jnrC+0,charge+jnrD+0);
1057 vdwjidx0A = 2*vdwtype[jnrA+0];
1058 vdwjidx0B = 2*vdwtype[jnrB+0];
1059 vdwjidx0C = 2*vdwtype[jnrC+0];
1060 vdwjidx0D = 2*vdwtype[jnrD+0];
1062 fjx0 = _mm_setzero_ps();
1063 fjy0 = _mm_setzero_ps();
1064 fjz0 = _mm_setzero_ps();
1066 /**************************
1067 * CALCULATE INTERACTIONS *
1068 **************************/
1070 if (gmx_mm_any_lt(rsq00,rcutoff2))
1073 r00 = _mm_mul_ps(rsq00,rinv00);
1074 r00 = _mm_andnot_ps(dummy_mask,r00);
1076 /* Compute parameters for interactions between i and j atoms */
1077 qq00 = _mm_mul_ps(iq0,jq0);
1078 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1079 vdwparam+vdwioffset0+vdwjidx0B,
1080 vdwparam+vdwioffset0+vdwjidx0C,
1081 vdwparam+vdwioffset0+vdwjidx0D,
1084 /* Calculate table index by multiplying r with table scale and truncate to integer */
1085 rt = _mm_mul_ps(r00,vftabscale);
1086 vfitab = _mm_cvttps_epi32(rt);
1088 vfeps = _mm_frcz_ps(rt);
1090 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1092 twovfeps = _mm_add_ps(vfeps,vfeps);
1093 vfitab = _mm_slli_epi32(vfitab,3);
1095 /* REACTION-FIELD ELECTROSTATICS */
1096 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1098 /* CUBIC SPLINE TABLE DISPERSION */
1099 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1100 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1101 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1102 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1103 _MM_TRANSPOSE4_PS(Y,F,G,H);
1104 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1105 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1106 fvdw6 = _mm_mul_ps(c6_00,FF);
1108 /* CUBIC SPLINE TABLE REPULSION */
1109 vfitab = _mm_add_epi32(vfitab,ifour);
1110 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1111 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1112 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1113 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1114 _MM_TRANSPOSE4_PS(Y,F,G,H);
1115 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1116 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1117 fvdw12 = _mm_mul_ps(c12_00,FF);
1118 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1120 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1122 fscal = _mm_add_ps(felec,fvdw);
1124 fscal = _mm_and_ps(fscal,cutoff_mask);
1126 fscal = _mm_andnot_ps(dummy_mask,fscal);
1128 /* Update vectorial force */
1129 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1130 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1131 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1133 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1134 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1135 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1139 /**************************
1140 * CALCULATE INTERACTIONS *
1141 **************************/
1143 if (gmx_mm_any_lt(rsq10,rcutoff2))
1146 /* Compute parameters for interactions between i and j atoms */
1147 qq10 = _mm_mul_ps(iq1,jq0);
1149 /* REACTION-FIELD ELECTROSTATICS */
1150 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1152 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1156 fscal = _mm_and_ps(fscal,cutoff_mask);
1158 fscal = _mm_andnot_ps(dummy_mask,fscal);
1160 /* Update vectorial force */
1161 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1162 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1163 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1165 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1166 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1167 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1171 /**************************
1172 * CALCULATE INTERACTIONS *
1173 **************************/
1175 if (gmx_mm_any_lt(rsq20,rcutoff2))
1178 /* Compute parameters for interactions between i and j atoms */
1179 qq20 = _mm_mul_ps(iq2,jq0);
1181 /* REACTION-FIELD ELECTROSTATICS */
1182 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1184 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1188 fscal = _mm_and_ps(fscal,cutoff_mask);
1190 fscal = _mm_andnot_ps(dummy_mask,fscal);
1192 /* Update vectorial force */
1193 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1194 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1195 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1197 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1198 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1199 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1203 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1204 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1205 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1206 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1208 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1210 /* Inner loop uses 127 flops */
1213 /* End of innermost loop */
1215 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1216 f+i_coord_offset,fshift+i_shift_offset);
1218 /* Increment number of inner iterations */
1219 inneriter += j_index_end - j_index_start;
1221 /* Outer loop uses 18 flops */
1224 /* Increment number of outer iterations */
1227 /* Update outer/inner flops */
1229 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*127);