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 "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.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_ElecCoul_VdwCSTab_GeomW4P1_VF_avx_128_fma_single
52 * Electrostatics interaction: Coulomb
53 * VdW interaction: CubicSplineTable
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_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;
90 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
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 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
97 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
100 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
104 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
106 __m128i ifour = _mm_set1_epi32(4);
107 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
109 __m128 dummy_mask,cutoff_mask;
110 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
111 __m128 one = _mm_set1_ps(1.0);
112 __m128 two = _mm_set1_ps(2.0);
118 jindex = nlist->jindex;
120 shiftidx = nlist->shift;
122 shiftvec = fr->shift_vec[0];
123 fshift = fr->fshift[0];
124 facel = _mm_set1_ps(fr->epsfac);
125 charge = mdatoms->chargeA;
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 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
136 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
137 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
138 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
140 /* Avoid stupid compiler warnings */
141 jnrA = jnrB = jnrC = jnrD = 0;
150 for(iidx=0;iidx<4*DIM;iidx++)
155 /* Start outer loop over neighborlists */
156 for(iidx=0; iidx<nri; iidx++)
158 /* Load shift vector for this list */
159 i_shift_offset = DIM*shiftidx[iidx];
161 /* Load limits for loop over neighbors */
162 j_index_start = jindex[iidx];
163 j_index_end = jindex[iidx+1];
165 /* Get outer coordinate index */
167 i_coord_offset = DIM*inr;
169 /* Load i particle coords and add shift vector */
170 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
171 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
173 fix0 = _mm_setzero_ps();
174 fiy0 = _mm_setzero_ps();
175 fiz0 = _mm_setzero_ps();
176 fix1 = _mm_setzero_ps();
177 fiy1 = _mm_setzero_ps();
178 fiz1 = _mm_setzero_ps();
179 fix2 = _mm_setzero_ps();
180 fiy2 = _mm_setzero_ps();
181 fiz2 = _mm_setzero_ps();
182 fix3 = _mm_setzero_ps();
183 fiy3 = _mm_setzero_ps();
184 fiz3 = _mm_setzero_ps();
186 /* Reset potential sums */
187 velecsum = _mm_setzero_ps();
188 vvdwsum = _mm_setzero_ps();
190 /* Start inner kernel loop */
191 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
194 /* Get j neighbor index, and coordinate index */
199 j_coord_offsetA = DIM*jnrA;
200 j_coord_offsetB = DIM*jnrB;
201 j_coord_offsetC = DIM*jnrC;
202 j_coord_offsetD = DIM*jnrD;
204 /* load j atom coordinates */
205 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
206 x+j_coord_offsetC,x+j_coord_offsetD,
209 /* Calculate displacement vector */
210 dx00 = _mm_sub_ps(ix0,jx0);
211 dy00 = _mm_sub_ps(iy0,jy0);
212 dz00 = _mm_sub_ps(iz0,jz0);
213 dx10 = _mm_sub_ps(ix1,jx0);
214 dy10 = _mm_sub_ps(iy1,jy0);
215 dz10 = _mm_sub_ps(iz1,jz0);
216 dx20 = _mm_sub_ps(ix2,jx0);
217 dy20 = _mm_sub_ps(iy2,jy0);
218 dz20 = _mm_sub_ps(iz2,jz0);
219 dx30 = _mm_sub_ps(ix3,jx0);
220 dy30 = _mm_sub_ps(iy3,jy0);
221 dz30 = _mm_sub_ps(iz3,jz0);
223 /* Calculate squared distance and things based on it */
224 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
225 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
226 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
227 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
229 rinv00 = gmx_mm_invsqrt_ps(rsq00);
230 rinv10 = gmx_mm_invsqrt_ps(rsq10);
231 rinv20 = gmx_mm_invsqrt_ps(rsq20);
232 rinv30 = gmx_mm_invsqrt_ps(rsq30);
234 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
235 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
236 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
238 /* Load parameters for j particles */
239 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
240 charge+jnrC+0,charge+jnrD+0);
241 vdwjidx0A = 2*vdwtype[jnrA+0];
242 vdwjidx0B = 2*vdwtype[jnrB+0];
243 vdwjidx0C = 2*vdwtype[jnrC+0];
244 vdwjidx0D = 2*vdwtype[jnrD+0];
246 fjx0 = _mm_setzero_ps();
247 fjy0 = _mm_setzero_ps();
248 fjz0 = _mm_setzero_ps();
250 /**************************
251 * CALCULATE INTERACTIONS *
252 **************************/
254 r00 = _mm_mul_ps(rsq00,rinv00);
256 /* Compute parameters for interactions between i and j atoms */
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 /* CUBIC SPLINE TABLE DISPERSION */
275 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
276 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
277 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
278 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
279 _MM_TRANSPOSE4_PS(Y,F,G,H);
280 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
281 VV = _mm_macc_ps(vfeps,Fp,Y);
282 vvdw6 = _mm_mul_ps(c6_00,VV);
283 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
284 fvdw6 = _mm_mul_ps(c6_00,FF);
286 /* CUBIC SPLINE TABLE REPULSION */
287 vfitab = _mm_add_epi32(vfitab,ifour);
288 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
289 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
290 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
291 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
292 _MM_TRANSPOSE4_PS(Y,F,G,H);
293 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
294 VV = _mm_macc_ps(vfeps,Fp,Y);
295 vvdw12 = _mm_mul_ps(c12_00,VV);
296 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
297 fvdw12 = _mm_mul_ps(c12_00,FF);
298 vvdw = _mm_add_ps(vvdw12,vvdw6);
299 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
301 /* Update potential sum for this i atom from the interaction with this j atom. */
302 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
306 /* Update vectorial force */
307 fix0 = _mm_macc_ps(dx00,fscal,fix0);
308 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
309 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
311 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
312 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
313 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
315 /**************************
316 * CALCULATE INTERACTIONS *
317 **************************/
319 /* Compute parameters for interactions between i and j atoms */
320 qq10 = _mm_mul_ps(iq1,jq0);
322 /* COULOMB ELECTROSTATICS */
323 velec = _mm_mul_ps(qq10,rinv10);
324 felec = _mm_mul_ps(velec,rinvsq10);
326 /* Update potential sum for this i atom from the interaction with this j atom. */
327 velecsum = _mm_add_ps(velecsum,velec);
331 /* Update vectorial force */
332 fix1 = _mm_macc_ps(dx10,fscal,fix1);
333 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
334 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
336 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
337 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
338 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
340 /**************************
341 * CALCULATE INTERACTIONS *
342 **************************/
344 /* Compute parameters for interactions between i and j atoms */
345 qq20 = _mm_mul_ps(iq2,jq0);
347 /* COULOMB ELECTROSTATICS */
348 velec = _mm_mul_ps(qq20,rinv20);
349 felec = _mm_mul_ps(velec,rinvsq20);
351 /* Update potential sum for this i atom from the interaction with this j atom. */
352 velecsum = _mm_add_ps(velecsum,velec);
356 /* Update vectorial force */
357 fix2 = _mm_macc_ps(dx20,fscal,fix2);
358 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
359 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
361 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
362 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
363 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
365 /**************************
366 * CALCULATE INTERACTIONS *
367 **************************/
369 /* Compute parameters for interactions between i and j atoms */
370 qq30 = _mm_mul_ps(iq3,jq0);
372 /* COULOMB ELECTROSTATICS */
373 velec = _mm_mul_ps(qq30,rinv30);
374 felec = _mm_mul_ps(velec,rinvsq30);
376 /* Update potential sum for this i atom from the interaction with this j atom. */
377 velecsum = _mm_add_ps(velecsum,velec);
381 /* Update vectorial force */
382 fix3 = _mm_macc_ps(dx30,fscal,fix3);
383 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
384 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
386 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
387 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
388 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
390 fjptrA = f+j_coord_offsetA;
391 fjptrB = f+j_coord_offsetB;
392 fjptrC = f+j_coord_offsetC;
393 fjptrD = f+j_coord_offsetD;
395 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
397 /* Inner loop uses 152 flops */
403 /* Get j neighbor index, and coordinate index */
404 jnrlistA = jjnr[jidx];
405 jnrlistB = jjnr[jidx+1];
406 jnrlistC = jjnr[jidx+2];
407 jnrlistD = jjnr[jidx+3];
408 /* Sign of each element will be negative for non-real atoms.
409 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
410 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
412 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
413 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
414 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
415 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
416 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
417 j_coord_offsetA = DIM*jnrA;
418 j_coord_offsetB = DIM*jnrB;
419 j_coord_offsetC = DIM*jnrC;
420 j_coord_offsetD = DIM*jnrD;
422 /* load j atom coordinates */
423 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
424 x+j_coord_offsetC,x+j_coord_offsetD,
427 /* Calculate displacement vector */
428 dx00 = _mm_sub_ps(ix0,jx0);
429 dy00 = _mm_sub_ps(iy0,jy0);
430 dz00 = _mm_sub_ps(iz0,jz0);
431 dx10 = _mm_sub_ps(ix1,jx0);
432 dy10 = _mm_sub_ps(iy1,jy0);
433 dz10 = _mm_sub_ps(iz1,jz0);
434 dx20 = _mm_sub_ps(ix2,jx0);
435 dy20 = _mm_sub_ps(iy2,jy0);
436 dz20 = _mm_sub_ps(iz2,jz0);
437 dx30 = _mm_sub_ps(ix3,jx0);
438 dy30 = _mm_sub_ps(iy3,jy0);
439 dz30 = _mm_sub_ps(iz3,jz0);
441 /* Calculate squared distance and things based on it */
442 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
443 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
444 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
445 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
447 rinv00 = gmx_mm_invsqrt_ps(rsq00);
448 rinv10 = gmx_mm_invsqrt_ps(rsq10);
449 rinv20 = gmx_mm_invsqrt_ps(rsq20);
450 rinv30 = gmx_mm_invsqrt_ps(rsq30);
452 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
453 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
454 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
456 /* Load parameters for j particles */
457 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
458 charge+jnrC+0,charge+jnrD+0);
459 vdwjidx0A = 2*vdwtype[jnrA+0];
460 vdwjidx0B = 2*vdwtype[jnrB+0];
461 vdwjidx0C = 2*vdwtype[jnrC+0];
462 vdwjidx0D = 2*vdwtype[jnrD+0];
464 fjx0 = _mm_setzero_ps();
465 fjy0 = _mm_setzero_ps();
466 fjz0 = _mm_setzero_ps();
468 /**************************
469 * CALCULATE INTERACTIONS *
470 **************************/
472 r00 = _mm_mul_ps(rsq00,rinv00);
473 r00 = _mm_andnot_ps(dummy_mask,r00);
475 /* Compute parameters for interactions between i and j atoms */
476 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
477 vdwparam+vdwioffset0+vdwjidx0B,
478 vdwparam+vdwioffset0+vdwjidx0C,
479 vdwparam+vdwioffset0+vdwjidx0D,
482 /* Calculate table index by multiplying r with table scale and truncate to integer */
483 rt = _mm_mul_ps(r00,vftabscale);
484 vfitab = _mm_cvttps_epi32(rt);
486 vfeps = _mm_frcz_ps(rt);
488 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
490 twovfeps = _mm_add_ps(vfeps,vfeps);
491 vfitab = _mm_slli_epi32(vfitab,3);
493 /* CUBIC SPLINE TABLE DISPERSION */
494 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
495 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
496 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
497 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
498 _MM_TRANSPOSE4_PS(Y,F,G,H);
499 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
500 VV = _mm_macc_ps(vfeps,Fp,Y);
501 vvdw6 = _mm_mul_ps(c6_00,VV);
502 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
503 fvdw6 = _mm_mul_ps(c6_00,FF);
505 /* CUBIC SPLINE TABLE REPULSION */
506 vfitab = _mm_add_epi32(vfitab,ifour);
507 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
508 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
509 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
510 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
511 _MM_TRANSPOSE4_PS(Y,F,G,H);
512 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
513 VV = _mm_macc_ps(vfeps,Fp,Y);
514 vvdw12 = _mm_mul_ps(c12_00,VV);
515 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
516 fvdw12 = _mm_mul_ps(c12_00,FF);
517 vvdw = _mm_add_ps(vvdw12,vvdw6);
518 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
520 /* Update potential sum for this i atom from the interaction with this j atom. */
521 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
522 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
526 fscal = _mm_andnot_ps(dummy_mask,fscal);
528 /* Update vectorial force */
529 fix0 = _mm_macc_ps(dx00,fscal,fix0);
530 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
531 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
533 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
534 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
535 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
537 /**************************
538 * CALCULATE INTERACTIONS *
539 **************************/
541 /* Compute parameters for interactions between i and j atoms */
542 qq10 = _mm_mul_ps(iq1,jq0);
544 /* COULOMB ELECTROSTATICS */
545 velec = _mm_mul_ps(qq10,rinv10);
546 felec = _mm_mul_ps(velec,rinvsq10);
548 /* Update potential sum for this i atom from the interaction with this j atom. */
549 velec = _mm_andnot_ps(dummy_mask,velec);
550 velecsum = _mm_add_ps(velecsum,velec);
554 fscal = _mm_andnot_ps(dummy_mask,fscal);
556 /* Update vectorial force */
557 fix1 = _mm_macc_ps(dx10,fscal,fix1);
558 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
559 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
561 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
562 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
563 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
565 /**************************
566 * CALCULATE INTERACTIONS *
567 **************************/
569 /* Compute parameters for interactions between i and j atoms */
570 qq20 = _mm_mul_ps(iq2,jq0);
572 /* COULOMB ELECTROSTATICS */
573 velec = _mm_mul_ps(qq20,rinv20);
574 felec = _mm_mul_ps(velec,rinvsq20);
576 /* Update potential sum for this i atom from the interaction with this j atom. */
577 velec = _mm_andnot_ps(dummy_mask,velec);
578 velecsum = _mm_add_ps(velecsum,velec);
582 fscal = _mm_andnot_ps(dummy_mask,fscal);
584 /* Update vectorial force */
585 fix2 = _mm_macc_ps(dx20,fscal,fix2);
586 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
587 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
589 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
590 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
591 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
593 /**************************
594 * CALCULATE INTERACTIONS *
595 **************************/
597 /* Compute parameters for interactions between i and j atoms */
598 qq30 = _mm_mul_ps(iq3,jq0);
600 /* COULOMB ELECTROSTATICS */
601 velec = _mm_mul_ps(qq30,rinv30);
602 felec = _mm_mul_ps(velec,rinvsq30);
604 /* Update potential sum for this i atom from the interaction with this j atom. */
605 velec = _mm_andnot_ps(dummy_mask,velec);
606 velecsum = _mm_add_ps(velecsum,velec);
610 fscal = _mm_andnot_ps(dummy_mask,fscal);
612 /* Update vectorial force */
613 fix3 = _mm_macc_ps(dx30,fscal,fix3);
614 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
615 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
617 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
618 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
619 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
621 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
622 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
623 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
624 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
626 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
628 /* Inner loop uses 153 flops */
631 /* End of innermost loop */
633 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
634 f+i_coord_offset,fshift+i_shift_offset);
637 /* Update potential energies */
638 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
639 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
641 /* Increment number of inner iterations */
642 inneriter += j_index_end - j_index_start;
644 /* Outer loop uses 26 flops */
647 /* Increment number of outer iterations */
650 /* Update outer/inner flops */
652 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*153);
655 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_avx_128_fma_single
656 * Electrostatics interaction: Coulomb
657 * VdW interaction: CubicSplineTable
658 * Geometry: Water4-Particle
659 * Calculate force/pot: Force
662 nb_kernel_ElecCoul_VdwCSTab_GeomW4P1_F_avx_128_fma_single
663 (t_nblist * gmx_restrict nlist,
664 rvec * gmx_restrict xx,
665 rvec * gmx_restrict ff,
666 t_forcerec * gmx_restrict fr,
667 t_mdatoms * gmx_restrict mdatoms,
668 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
669 t_nrnb * gmx_restrict nrnb)
671 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
672 * just 0 for non-waters.
673 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
674 * jnr indices corresponding to data put in the four positions in the SIMD register.
676 int i_shift_offset,i_coord_offset,outeriter,inneriter;
677 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
678 int jnrA,jnrB,jnrC,jnrD;
679 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
680 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
681 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
683 real *shiftvec,*fshift,*x,*f;
684 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
686 __m128 fscal,rcutoff,rcutoff2,jidxall;
688 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
690 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
692 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
694 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
695 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
696 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
697 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
698 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
699 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
700 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
701 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
704 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
707 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
708 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
710 __m128i ifour = _mm_set1_epi32(4);
711 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
713 __m128 dummy_mask,cutoff_mask;
714 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
715 __m128 one = _mm_set1_ps(1.0);
716 __m128 two = _mm_set1_ps(2.0);
722 jindex = nlist->jindex;
724 shiftidx = nlist->shift;
726 shiftvec = fr->shift_vec[0];
727 fshift = fr->fshift[0];
728 facel = _mm_set1_ps(fr->epsfac);
729 charge = mdatoms->chargeA;
730 nvdwtype = fr->ntype;
732 vdwtype = mdatoms->typeA;
734 vftab = kernel_data->table_vdw->data;
735 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
737 /* Setup water-specific parameters */
738 inr = nlist->iinr[0];
739 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
740 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
741 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
742 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
744 /* Avoid stupid compiler warnings */
745 jnrA = jnrB = jnrC = jnrD = 0;
754 for(iidx=0;iidx<4*DIM;iidx++)
759 /* Start outer loop over neighborlists */
760 for(iidx=0; iidx<nri; iidx++)
762 /* Load shift vector for this list */
763 i_shift_offset = DIM*shiftidx[iidx];
765 /* Load limits for loop over neighbors */
766 j_index_start = jindex[iidx];
767 j_index_end = jindex[iidx+1];
769 /* Get outer coordinate index */
771 i_coord_offset = DIM*inr;
773 /* Load i particle coords and add shift vector */
774 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
775 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
777 fix0 = _mm_setzero_ps();
778 fiy0 = _mm_setzero_ps();
779 fiz0 = _mm_setzero_ps();
780 fix1 = _mm_setzero_ps();
781 fiy1 = _mm_setzero_ps();
782 fiz1 = _mm_setzero_ps();
783 fix2 = _mm_setzero_ps();
784 fiy2 = _mm_setzero_ps();
785 fiz2 = _mm_setzero_ps();
786 fix3 = _mm_setzero_ps();
787 fiy3 = _mm_setzero_ps();
788 fiz3 = _mm_setzero_ps();
790 /* Start inner kernel loop */
791 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
794 /* Get j neighbor index, and coordinate index */
799 j_coord_offsetA = DIM*jnrA;
800 j_coord_offsetB = DIM*jnrB;
801 j_coord_offsetC = DIM*jnrC;
802 j_coord_offsetD = DIM*jnrD;
804 /* load j atom coordinates */
805 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
806 x+j_coord_offsetC,x+j_coord_offsetD,
809 /* Calculate displacement vector */
810 dx00 = _mm_sub_ps(ix0,jx0);
811 dy00 = _mm_sub_ps(iy0,jy0);
812 dz00 = _mm_sub_ps(iz0,jz0);
813 dx10 = _mm_sub_ps(ix1,jx0);
814 dy10 = _mm_sub_ps(iy1,jy0);
815 dz10 = _mm_sub_ps(iz1,jz0);
816 dx20 = _mm_sub_ps(ix2,jx0);
817 dy20 = _mm_sub_ps(iy2,jy0);
818 dz20 = _mm_sub_ps(iz2,jz0);
819 dx30 = _mm_sub_ps(ix3,jx0);
820 dy30 = _mm_sub_ps(iy3,jy0);
821 dz30 = _mm_sub_ps(iz3,jz0);
823 /* Calculate squared distance and things based on it */
824 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
825 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
826 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
827 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
829 rinv00 = gmx_mm_invsqrt_ps(rsq00);
830 rinv10 = gmx_mm_invsqrt_ps(rsq10);
831 rinv20 = gmx_mm_invsqrt_ps(rsq20);
832 rinv30 = gmx_mm_invsqrt_ps(rsq30);
834 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
835 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
836 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
838 /* Load parameters for j particles */
839 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
840 charge+jnrC+0,charge+jnrD+0);
841 vdwjidx0A = 2*vdwtype[jnrA+0];
842 vdwjidx0B = 2*vdwtype[jnrB+0];
843 vdwjidx0C = 2*vdwtype[jnrC+0];
844 vdwjidx0D = 2*vdwtype[jnrD+0];
846 fjx0 = _mm_setzero_ps();
847 fjy0 = _mm_setzero_ps();
848 fjz0 = _mm_setzero_ps();
850 /**************************
851 * CALCULATE INTERACTIONS *
852 **************************/
854 r00 = _mm_mul_ps(rsq00,rinv00);
856 /* Compute parameters for interactions between i and j atoms */
857 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
858 vdwparam+vdwioffset0+vdwjidx0B,
859 vdwparam+vdwioffset0+vdwjidx0C,
860 vdwparam+vdwioffset0+vdwjidx0D,
863 /* Calculate table index by multiplying r with table scale and truncate to integer */
864 rt = _mm_mul_ps(r00,vftabscale);
865 vfitab = _mm_cvttps_epi32(rt);
867 vfeps = _mm_frcz_ps(rt);
869 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
871 twovfeps = _mm_add_ps(vfeps,vfeps);
872 vfitab = _mm_slli_epi32(vfitab,3);
874 /* CUBIC SPLINE TABLE DISPERSION */
875 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
876 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
877 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
878 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
879 _MM_TRANSPOSE4_PS(Y,F,G,H);
880 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
881 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
882 fvdw6 = _mm_mul_ps(c6_00,FF);
884 /* CUBIC SPLINE TABLE REPULSION */
885 vfitab = _mm_add_epi32(vfitab,ifour);
886 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
887 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
888 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
889 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
890 _MM_TRANSPOSE4_PS(Y,F,G,H);
891 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
892 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
893 fvdw12 = _mm_mul_ps(c12_00,FF);
894 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
898 /* Update vectorial force */
899 fix0 = _mm_macc_ps(dx00,fscal,fix0);
900 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
901 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
903 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
904 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
905 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
907 /**************************
908 * CALCULATE INTERACTIONS *
909 **************************/
911 /* Compute parameters for interactions between i and j atoms */
912 qq10 = _mm_mul_ps(iq1,jq0);
914 /* COULOMB ELECTROSTATICS */
915 velec = _mm_mul_ps(qq10,rinv10);
916 felec = _mm_mul_ps(velec,rinvsq10);
920 /* Update vectorial force */
921 fix1 = _mm_macc_ps(dx10,fscal,fix1);
922 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
923 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
925 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
926 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
927 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
929 /**************************
930 * CALCULATE INTERACTIONS *
931 **************************/
933 /* Compute parameters for interactions between i and j atoms */
934 qq20 = _mm_mul_ps(iq2,jq0);
936 /* COULOMB ELECTROSTATICS */
937 velec = _mm_mul_ps(qq20,rinv20);
938 felec = _mm_mul_ps(velec,rinvsq20);
942 /* Update vectorial force */
943 fix2 = _mm_macc_ps(dx20,fscal,fix2);
944 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
945 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
947 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
948 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
949 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
951 /**************************
952 * CALCULATE INTERACTIONS *
953 **************************/
955 /* Compute parameters for interactions between i and j atoms */
956 qq30 = _mm_mul_ps(iq3,jq0);
958 /* COULOMB ELECTROSTATICS */
959 velec = _mm_mul_ps(qq30,rinv30);
960 felec = _mm_mul_ps(velec,rinvsq30);
964 /* Update vectorial force */
965 fix3 = _mm_macc_ps(dx30,fscal,fix3);
966 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
967 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
969 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
970 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
971 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
973 fjptrA = f+j_coord_offsetA;
974 fjptrB = f+j_coord_offsetB;
975 fjptrC = f+j_coord_offsetC;
976 fjptrD = f+j_coord_offsetD;
978 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
980 /* Inner loop uses 141 flops */
986 /* Get j neighbor index, and coordinate index */
987 jnrlistA = jjnr[jidx];
988 jnrlistB = jjnr[jidx+1];
989 jnrlistC = jjnr[jidx+2];
990 jnrlistD = jjnr[jidx+3];
991 /* Sign of each element will be negative for non-real atoms.
992 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
993 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
995 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
996 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
997 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
998 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
999 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1000 j_coord_offsetA = DIM*jnrA;
1001 j_coord_offsetB = DIM*jnrB;
1002 j_coord_offsetC = DIM*jnrC;
1003 j_coord_offsetD = DIM*jnrD;
1005 /* load j atom coordinates */
1006 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1007 x+j_coord_offsetC,x+j_coord_offsetD,
1010 /* Calculate displacement vector */
1011 dx00 = _mm_sub_ps(ix0,jx0);
1012 dy00 = _mm_sub_ps(iy0,jy0);
1013 dz00 = _mm_sub_ps(iz0,jz0);
1014 dx10 = _mm_sub_ps(ix1,jx0);
1015 dy10 = _mm_sub_ps(iy1,jy0);
1016 dz10 = _mm_sub_ps(iz1,jz0);
1017 dx20 = _mm_sub_ps(ix2,jx0);
1018 dy20 = _mm_sub_ps(iy2,jy0);
1019 dz20 = _mm_sub_ps(iz2,jz0);
1020 dx30 = _mm_sub_ps(ix3,jx0);
1021 dy30 = _mm_sub_ps(iy3,jy0);
1022 dz30 = _mm_sub_ps(iz3,jz0);
1024 /* Calculate squared distance and things based on it */
1025 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1026 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1027 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1028 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1030 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1031 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1032 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1033 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1035 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1036 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1037 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1039 /* Load parameters for j particles */
1040 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1041 charge+jnrC+0,charge+jnrD+0);
1042 vdwjidx0A = 2*vdwtype[jnrA+0];
1043 vdwjidx0B = 2*vdwtype[jnrB+0];
1044 vdwjidx0C = 2*vdwtype[jnrC+0];
1045 vdwjidx0D = 2*vdwtype[jnrD+0];
1047 fjx0 = _mm_setzero_ps();
1048 fjy0 = _mm_setzero_ps();
1049 fjz0 = _mm_setzero_ps();
1051 /**************************
1052 * CALCULATE INTERACTIONS *
1053 **************************/
1055 r00 = _mm_mul_ps(rsq00,rinv00);
1056 r00 = _mm_andnot_ps(dummy_mask,r00);
1058 /* Compute parameters for interactions between i and j atoms */
1059 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1060 vdwparam+vdwioffset0+vdwjidx0B,
1061 vdwparam+vdwioffset0+vdwjidx0C,
1062 vdwparam+vdwioffset0+vdwjidx0D,
1065 /* Calculate table index by multiplying r with table scale and truncate to integer */
1066 rt = _mm_mul_ps(r00,vftabscale);
1067 vfitab = _mm_cvttps_epi32(rt);
1069 vfeps = _mm_frcz_ps(rt);
1071 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1073 twovfeps = _mm_add_ps(vfeps,vfeps);
1074 vfitab = _mm_slli_epi32(vfitab,3);
1076 /* CUBIC SPLINE TABLE DISPERSION */
1077 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1078 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1079 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1080 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1081 _MM_TRANSPOSE4_PS(Y,F,G,H);
1082 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1083 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1084 fvdw6 = _mm_mul_ps(c6_00,FF);
1086 /* CUBIC SPLINE TABLE REPULSION */
1087 vfitab = _mm_add_epi32(vfitab,ifour);
1088 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1089 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1090 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1091 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1092 _MM_TRANSPOSE4_PS(Y,F,G,H);
1093 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1094 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1095 fvdw12 = _mm_mul_ps(c12_00,FF);
1096 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1100 fscal = _mm_andnot_ps(dummy_mask,fscal);
1102 /* Update vectorial force */
1103 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1104 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1105 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1107 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1108 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1109 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1111 /**************************
1112 * CALCULATE INTERACTIONS *
1113 **************************/
1115 /* Compute parameters for interactions between i and j atoms */
1116 qq10 = _mm_mul_ps(iq1,jq0);
1118 /* COULOMB ELECTROSTATICS */
1119 velec = _mm_mul_ps(qq10,rinv10);
1120 felec = _mm_mul_ps(velec,rinvsq10);
1124 fscal = _mm_andnot_ps(dummy_mask,fscal);
1126 /* Update vectorial force */
1127 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1128 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1129 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1131 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1132 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1133 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1135 /**************************
1136 * CALCULATE INTERACTIONS *
1137 **************************/
1139 /* Compute parameters for interactions between i and j atoms */
1140 qq20 = _mm_mul_ps(iq2,jq0);
1142 /* COULOMB ELECTROSTATICS */
1143 velec = _mm_mul_ps(qq20,rinv20);
1144 felec = _mm_mul_ps(velec,rinvsq20);
1148 fscal = _mm_andnot_ps(dummy_mask,fscal);
1150 /* Update vectorial force */
1151 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1152 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1153 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1155 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1156 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1157 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1159 /**************************
1160 * CALCULATE INTERACTIONS *
1161 **************************/
1163 /* Compute parameters for interactions between i and j atoms */
1164 qq30 = _mm_mul_ps(iq3,jq0);
1166 /* COULOMB ELECTROSTATICS */
1167 velec = _mm_mul_ps(qq30,rinv30);
1168 felec = _mm_mul_ps(velec,rinvsq30);
1172 fscal = _mm_andnot_ps(dummy_mask,fscal);
1174 /* Update vectorial force */
1175 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1176 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1177 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1179 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1180 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1181 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1183 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1184 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1185 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1186 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1188 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1190 /* Inner loop uses 142 flops */
1193 /* End of innermost loop */
1195 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1196 f+i_coord_offset,fshift+i_shift_offset);
1198 /* Increment number of inner iterations */
1199 inneriter += j_index_end - j_index_start;
1201 /* Outer loop uses 24 flops */
1204 /* Increment number of outer iterations */
1207 /* Update outer/inner flops */
1209 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*142);