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 "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.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_GeomW4P1_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: CubicSplineTable
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_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;
92 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
97 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
98 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
99 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
102 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
105 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
106 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
108 __m128i ifour = _mm_set1_epi32(4);
109 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
111 __m128 dummy_mask,cutoff_mask;
112 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
113 __m128 one = _mm_set1_ps(1.0);
114 __m128 two = _mm_set1_ps(2.0);
120 jindex = nlist->jindex;
122 shiftidx = nlist->shift;
124 shiftvec = fr->shift_vec[0];
125 fshift = fr->fshift[0];
126 facel = _mm_set1_ps(fr->epsfac);
127 charge = mdatoms->chargeA;
128 krf = _mm_set1_ps(fr->ic->k_rf);
129 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
130 crf = _mm_set1_ps(fr->ic->c_rf);
131 nvdwtype = fr->ntype;
133 vdwtype = mdatoms->typeA;
135 vftab = kernel_data->table_vdw->data;
136 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
138 /* Setup water-specific parameters */
139 inr = nlist->iinr[0];
140 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
141 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
142 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
143 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
145 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
146 rcutoff_scalar = fr->rcoulomb;
147 rcutoff = _mm_set1_ps(rcutoff_scalar);
148 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
150 /* Avoid stupid compiler warnings */
151 jnrA = jnrB = jnrC = jnrD = 0;
160 for(iidx=0;iidx<4*DIM;iidx++)
165 /* Start outer loop over neighborlists */
166 for(iidx=0; iidx<nri; iidx++)
168 /* Load shift vector for this list */
169 i_shift_offset = DIM*shiftidx[iidx];
171 /* Load limits for loop over neighbors */
172 j_index_start = jindex[iidx];
173 j_index_end = jindex[iidx+1];
175 /* Get outer coordinate index */
177 i_coord_offset = DIM*inr;
179 /* Load i particle coords and add shift vector */
180 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
181 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
183 fix0 = _mm_setzero_ps();
184 fiy0 = _mm_setzero_ps();
185 fiz0 = _mm_setzero_ps();
186 fix1 = _mm_setzero_ps();
187 fiy1 = _mm_setzero_ps();
188 fiz1 = _mm_setzero_ps();
189 fix2 = _mm_setzero_ps();
190 fiy2 = _mm_setzero_ps();
191 fiz2 = _mm_setzero_ps();
192 fix3 = _mm_setzero_ps();
193 fiy3 = _mm_setzero_ps();
194 fiz3 = _mm_setzero_ps();
196 /* Reset potential sums */
197 velecsum = _mm_setzero_ps();
198 vvdwsum = _mm_setzero_ps();
200 /* Start inner kernel loop */
201 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
204 /* Get j neighbor index, and coordinate index */
209 j_coord_offsetA = DIM*jnrA;
210 j_coord_offsetB = DIM*jnrB;
211 j_coord_offsetC = DIM*jnrC;
212 j_coord_offsetD = DIM*jnrD;
214 /* load j atom coordinates */
215 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
216 x+j_coord_offsetC,x+j_coord_offsetD,
219 /* Calculate displacement vector */
220 dx00 = _mm_sub_ps(ix0,jx0);
221 dy00 = _mm_sub_ps(iy0,jy0);
222 dz00 = _mm_sub_ps(iz0,jz0);
223 dx10 = _mm_sub_ps(ix1,jx0);
224 dy10 = _mm_sub_ps(iy1,jy0);
225 dz10 = _mm_sub_ps(iz1,jz0);
226 dx20 = _mm_sub_ps(ix2,jx0);
227 dy20 = _mm_sub_ps(iy2,jy0);
228 dz20 = _mm_sub_ps(iz2,jz0);
229 dx30 = _mm_sub_ps(ix3,jx0);
230 dy30 = _mm_sub_ps(iy3,jy0);
231 dz30 = _mm_sub_ps(iz3,jz0);
233 /* Calculate squared distance and things based on it */
234 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
235 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
236 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
237 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
239 rinv00 = gmx_mm_invsqrt_ps(rsq00);
240 rinv10 = gmx_mm_invsqrt_ps(rsq10);
241 rinv20 = gmx_mm_invsqrt_ps(rsq20);
242 rinv30 = gmx_mm_invsqrt_ps(rsq30);
244 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
245 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
246 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
248 /* Load parameters for j particles */
249 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
250 charge+jnrC+0,charge+jnrD+0);
251 vdwjidx0A = 2*vdwtype[jnrA+0];
252 vdwjidx0B = 2*vdwtype[jnrB+0];
253 vdwjidx0C = 2*vdwtype[jnrC+0];
254 vdwjidx0D = 2*vdwtype[jnrD+0];
256 fjx0 = _mm_setzero_ps();
257 fjy0 = _mm_setzero_ps();
258 fjz0 = _mm_setzero_ps();
260 /**************************
261 * CALCULATE INTERACTIONS *
262 **************************/
264 r00 = _mm_mul_ps(rsq00,rinv00);
266 /* Compute parameters for interactions between i and j atoms */
267 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
268 vdwparam+vdwioffset0+vdwjidx0B,
269 vdwparam+vdwioffset0+vdwjidx0C,
270 vdwparam+vdwioffset0+vdwjidx0D,
273 /* Calculate table index by multiplying r with table scale and truncate to integer */
274 rt = _mm_mul_ps(r00,vftabscale);
275 vfitab = _mm_cvttps_epi32(rt);
277 vfeps = _mm_frcz_ps(rt);
279 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
281 twovfeps = _mm_add_ps(vfeps,vfeps);
282 vfitab = _mm_slli_epi32(vfitab,3);
284 /* CUBIC SPLINE TABLE DISPERSION */
285 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
286 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
287 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
288 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
289 _MM_TRANSPOSE4_PS(Y,F,G,H);
290 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
291 VV = _mm_macc_ps(vfeps,Fp,Y);
292 vvdw6 = _mm_mul_ps(c6_00,VV);
293 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
294 fvdw6 = _mm_mul_ps(c6_00,FF);
296 /* CUBIC SPLINE TABLE REPULSION */
297 vfitab = _mm_add_epi32(vfitab,ifour);
298 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
299 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
300 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
301 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
302 _MM_TRANSPOSE4_PS(Y,F,G,H);
303 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
304 VV = _mm_macc_ps(vfeps,Fp,Y);
305 vvdw12 = _mm_mul_ps(c12_00,VV);
306 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
307 fvdw12 = _mm_mul_ps(c12_00,FF);
308 vvdw = _mm_add_ps(vvdw12,vvdw6);
309 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
311 /* Update potential sum for this i atom from the interaction with this j atom. */
312 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
316 /* Update vectorial force */
317 fix0 = _mm_macc_ps(dx00,fscal,fix0);
318 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
319 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
321 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
322 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
323 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
325 /**************************
326 * CALCULATE INTERACTIONS *
327 **************************/
329 if (gmx_mm_any_lt(rsq10,rcutoff2))
332 /* Compute parameters for interactions between i and j atoms */
333 qq10 = _mm_mul_ps(iq1,jq0);
335 /* REACTION-FIELD ELECTROSTATICS */
336 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
337 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
339 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
341 /* Update potential sum for this i atom from the interaction with this j atom. */
342 velec = _mm_and_ps(velec,cutoff_mask);
343 velecsum = _mm_add_ps(velecsum,velec);
347 fscal = _mm_and_ps(fscal,cutoff_mask);
349 /* Update vectorial force */
350 fix1 = _mm_macc_ps(dx10,fscal,fix1);
351 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
352 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
354 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
355 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
356 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
360 /**************************
361 * CALCULATE INTERACTIONS *
362 **************************/
364 if (gmx_mm_any_lt(rsq20,rcutoff2))
367 /* Compute parameters for interactions between i and j atoms */
368 qq20 = _mm_mul_ps(iq2,jq0);
370 /* REACTION-FIELD ELECTROSTATICS */
371 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
372 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
374 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
376 /* Update potential sum for this i atom from the interaction with this j atom. */
377 velec = _mm_and_ps(velec,cutoff_mask);
378 velecsum = _mm_add_ps(velecsum,velec);
382 fscal = _mm_and_ps(fscal,cutoff_mask);
384 /* Update vectorial force */
385 fix2 = _mm_macc_ps(dx20,fscal,fix2);
386 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
387 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
389 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
390 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
391 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
395 /**************************
396 * CALCULATE INTERACTIONS *
397 **************************/
399 if (gmx_mm_any_lt(rsq30,rcutoff2))
402 /* Compute parameters for interactions between i and j atoms */
403 qq30 = _mm_mul_ps(iq3,jq0);
405 /* REACTION-FIELD ELECTROSTATICS */
406 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
407 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
409 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
411 /* Update potential sum for this i atom from the interaction with this j atom. */
412 velec = _mm_and_ps(velec,cutoff_mask);
413 velecsum = _mm_add_ps(velecsum,velec);
417 fscal = _mm_and_ps(fscal,cutoff_mask);
419 /* Update vectorial force */
420 fix3 = _mm_macc_ps(dx30,fscal,fix3);
421 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
422 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
424 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
425 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
426 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
430 fjptrA = f+j_coord_offsetA;
431 fjptrB = f+j_coord_offsetB;
432 fjptrC = f+j_coord_offsetC;
433 fjptrD = f+j_coord_offsetD;
435 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
437 /* Inner loop uses 176 flops */
443 /* Get j neighbor index, and coordinate index */
444 jnrlistA = jjnr[jidx];
445 jnrlistB = jjnr[jidx+1];
446 jnrlistC = jjnr[jidx+2];
447 jnrlistD = jjnr[jidx+3];
448 /* Sign of each element will be negative for non-real atoms.
449 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
450 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
452 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
453 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
454 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
455 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
456 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
457 j_coord_offsetA = DIM*jnrA;
458 j_coord_offsetB = DIM*jnrB;
459 j_coord_offsetC = DIM*jnrC;
460 j_coord_offsetD = DIM*jnrD;
462 /* load j atom coordinates */
463 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
464 x+j_coord_offsetC,x+j_coord_offsetD,
467 /* Calculate displacement vector */
468 dx00 = _mm_sub_ps(ix0,jx0);
469 dy00 = _mm_sub_ps(iy0,jy0);
470 dz00 = _mm_sub_ps(iz0,jz0);
471 dx10 = _mm_sub_ps(ix1,jx0);
472 dy10 = _mm_sub_ps(iy1,jy0);
473 dz10 = _mm_sub_ps(iz1,jz0);
474 dx20 = _mm_sub_ps(ix2,jx0);
475 dy20 = _mm_sub_ps(iy2,jy0);
476 dz20 = _mm_sub_ps(iz2,jz0);
477 dx30 = _mm_sub_ps(ix3,jx0);
478 dy30 = _mm_sub_ps(iy3,jy0);
479 dz30 = _mm_sub_ps(iz3,jz0);
481 /* Calculate squared distance and things based on it */
482 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
483 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
484 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
485 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
487 rinv00 = gmx_mm_invsqrt_ps(rsq00);
488 rinv10 = gmx_mm_invsqrt_ps(rsq10);
489 rinv20 = gmx_mm_invsqrt_ps(rsq20);
490 rinv30 = gmx_mm_invsqrt_ps(rsq30);
492 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
493 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
494 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
496 /* Load parameters for j particles */
497 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
498 charge+jnrC+0,charge+jnrD+0);
499 vdwjidx0A = 2*vdwtype[jnrA+0];
500 vdwjidx0B = 2*vdwtype[jnrB+0];
501 vdwjidx0C = 2*vdwtype[jnrC+0];
502 vdwjidx0D = 2*vdwtype[jnrD+0];
504 fjx0 = _mm_setzero_ps();
505 fjy0 = _mm_setzero_ps();
506 fjz0 = _mm_setzero_ps();
508 /**************************
509 * CALCULATE INTERACTIONS *
510 **************************/
512 r00 = _mm_mul_ps(rsq00,rinv00);
513 r00 = _mm_andnot_ps(dummy_mask,r00);
515 /* Compute parameters for interactions between i and j atoms */
516 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
517 vdwparam+vdwioffset0+vdwjidx0B,
518 vdwparam+vdwioffset0+vdwjidx0C,
519 vdwparam+vdwioffset0+vdwjidx0D,
522 /* Calculate table index by multiplying r with table scale and truncate to integer */
523 rt = _mm_mul_ps(r00,vftabscale);
524 vfitab = _mm_cvttps_epi32(rt);
526 vfeps = _mm_frcz_ps(rt);
528 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
530 twovfeps = _mm_add_ps(vfeps,vfeps);
531 vfitab = _mm_slli_epi32(vfitab,3);
533 /* CUBIC SPLINE TABLE DISPERSION */
534 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
535 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
536 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
537 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
538 _MM_TRANSPOSE4_PS(Y,F,G,H);
539 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
540 VV = _mm_macc_ps(vfeps,Fp,Y);
541 vvdw6 = _mm_mul_ps(c6_00,VV);
542 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
543 fvdw6 = _mm_mul_ps(c6_00,FF);
545 /* CUBIC SPLINE TABLE REPULSION */
546 vfitab = _mm_add_epi32(vfitab,ifour);
547 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
548 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
549 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
550 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
551 _MM_TRANSPOSE4_PS(Y,F,G,H);
552 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
553 VV = _mm_macc_ps(vfeps,Fp,Y);
554 vvdw12 = _mm_mul_ps(c12_00,VV);
555 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
556 fvdw12 = _mm_mul_ps(c12_00,FF);
557 vvdw = _mm_add_ps(vvdw12,vvdw6);
558 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
560 /* Update potential sum for this i atom from the interaction with this j atom. */
561 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
562 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
566 fscal = _mm_andnot_ps(dummy_mask,fscal);
568 /* Update vectorial force */
569 fix0 = _mm_macc_ps(dx00,fscal,fix0);
570 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
571 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
573 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
574 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
575 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
577 /**************************
578 * CALCULATE INTERACTIONS *
579 **************************/
581 if (gmx_mm_any_lt(rsq10,rcutoff2))
584 /* Compute parameters for interactions between i and j atoms */
585 qq10 = _mm_mul_ps(iq1,jq0);
587 /* REACTION-FIELD ELECTROSTATICS */
588 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
589 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
591 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
593 /* Update potential sum for this i atom from the interaction with this j atom. */
594 velec = _mm_and_ps(velec,cutoff_mask);
595 velec = _mm_andnot_ps(dummy_mask,velec);
596 velecsum = _mm_add_ps(velecsum,velec);
600 fscal = _mm_and_ps(fscal,cutoff_mask);
602 fscal = _mm_andnot_ps(dummy_mask,fscal);
604 /* Update vectorial force */
605 fix1 = _mm_macc_ps(dx10,fscal,fix1);
606 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
607 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
609 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
610 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
611 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
615 /**************************
616 * CALCULATE INTERACTIONS *
617 **************************/
619 if (gmx_mm_any_lt(rsq20,rcutoff2))
622 /* Compute parameters for interactions between i and j atoms */
623 qq20 = _mm_mul_ps(iq2,jq0);
625 /* REACTION-FIELD ELECTROSTATICS */
626 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
627 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
629 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
631 /* Update potential sum for this i atom from the interaction with this j atom. */
632 velec = _mm_and_ps(velec,cutoff_mask);
633 velec = _mm_andnot_ps(dummy_mask,velec);
634 velecsum = _mm_add_ps(velecsum,velec);
638 fscal = _mm_and_ps(fscal,cutoff_mask);
640 fscal = _mm_andnot_ps(dummy_mask,fscal);
642 /* Update vectorial force */
643 fix2 = _mm_macc_ps(dx20,fscal,fix2);
644 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
645 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
647 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
648 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
649 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
653 /**************************
654 * CALCULATE INTERACTIONS *
655 **************************/
657 if (gmx_mm_any_lt(rsq30,rcutoff2))
660 /* Compute parameters for interactions between i and j atoms */
661 qq30 = _mm_mul_ps(iq3,jq0);
663 /* REACTION-FIELD ELECTROSTATICS */
664 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
665 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
667 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
669 /* Update potential sum for this i atom from the interaction with this j atom. */
670 velec = _mm_and_ps(velec,cutoff_mask);
671 velec = _mm_andnot_ps(dummy_mask,velec);
672 velecsum = _mm_add_ps(velecsum,velec);
676 fscal = _mm_and_ps(fscal,cutoff_mask);
678 fscal = _mm_andnot_ps(dummy_mask,fscal);
680 /* Update vectorial force */
681 fix3 = _mm_macc_ps(dx30,fscal,fix3);
682 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
683 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
685 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
686 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
687 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
691 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
692 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
693 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
694 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
696 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
698 /* Inner loop uses 177 flops */
701 /* End of innermost loop */
703 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
704 f+i_coord_offset,fshift+i_shift_offset);
707 /* Update potential energies */
708 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
709 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
711 /* Increment number of inner iterations */
712 inneriter += j_index_end - j_index_start;
714 /* Outer loop uses 26 flops */
717 /* Increment number of outer iterations */
720 /* Update outer/inner flops */
722 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*177);
725 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_F_avx_128_fma_single
726 * Electrostatics interaction: ReactionField
727 * VdW interaction: CubicSplineTable
728 * Geometry: Water4-Particle
729 * Calculate force/pot: Force
732 nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_F_avx_128_fma_single
733 (t_nblist * gmx_restrict nlist,
734 rvec * gmx_restrict xx,
735 rvec * gmx_restrict ff,
736 t_forcerec * gmx_restrict fr,
737 t_mdatoms * gmx_restrict mdatoms,
738 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
739 t_nrnb * gmx_restrict nrnb)
741 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
742 * just 0 for non-waters.
743 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
744 * jnr indices corresponding to data put in the four positions in the SIMD register.
746 int i_shift_offset,i_coord_offset,outeriter,inneriter;
747 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
748 int jnrA,jnrB,jnrC,jnrD;
749 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
750 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
751 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
753 real *shiftvec,*fshift,*x,*f;
754 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
756 __m128 fscal,rcutoff,rcutoff2,jidxall;
758 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
760 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
762 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
764 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
765 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
766 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
767 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
768 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
769 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
770 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
771 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
774 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
777 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
778 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
780 __m128i ifour = _mm_set1_epi32(4);
781 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
783 __m128 dummy_mask,cutoff_mask;
784 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
785 __m128 one = _mm_set1_ps(1.0);
786 __m128 two = _mm_set1_ps(2.0);
792 jindex = nlist->jindex;
794 shiftidx = nlist->shift;
796 shiftvec = fr->shift_vec[0];
797 fshift = fr->fshift[0];
798 facel = _mm_set1_ps(fr->epsfac);
799 charge = mdatoms->chargeA;
800 krf = _mm_set1_ps(fr->ic->k_rf);
801 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
802 crf = _mm_set1_ps(fr->ic->c_rf);
803 nvdwtype = fr->ntype;
805 vdwtype = mdatoms->typeA;
807 vftab = kernel_data->table_vdw->data;
808 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
810 /* Setup water-specific parameters */
811 inr = nlist->iinr[0];
812 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
813 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
814 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
815 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
817 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
818 rcutoff_scalar = fr->rcoulomb;
819 rcutoff = _mm_set1_ps(rcutoff_scalar);
820 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
822 /* Avoid stupid compiler warnings */
823 jnrA = jnrB = jnrC = jnrD = 0;
832 for(iidx=0;iidx<4*DIM;iidx++)
837 /* Start outer loop over neighborlists */
838 for(iidx=0; iidx<nri; iidx++)
840 /* Load shift vector for this list */
841 i_shift_offset = DIM*shiftidx[iidx];
843 /* Load limits for loop over neighbors */
844 j_index_start = jindex[iidx];
845 j_index_end = jindex[iidx+1];
847 /* Get outer coordinate index */
849 i_coord_offset = DIM*inr;
851 /* Load i particle coords and add shift vector */
852 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
853 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
855 fix0 = _mm_setzero_ps();
856 fiy0 = _mm_setzero_ps();
857 fiz0 = _mm_setzero_ps();
858 fix1 = _mm_setzero_ps();
859 fiy1 = _mm_setzero_ps();
860 fiz1 = _mm_setzero_ps();
861 fix2 = _mm_setzero_ps();
862 fiy2 = _mm_setzero_ps();
863 fiz2 = _mm_setzero_ps();
864 fix3 = _mm_setzero_ps();
865 fiy3 = _mm_setzero_ps();
866 fiz3 = _mm_setzero_ps();
868 /* Start inner kernel loop */
869 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
872 /* Get j neighbor index, and coordinate index */
877 j_coord_offsetA = DIM*jnrA;
878 j_coord_offsetB = DIM*jnrB;
879 j_coord_offsetC = DIM*jnrC;
880 j_coord_offsetD = DIM*jnrD;
882 /* load j atom coordinates */
883 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
884 x+j_coord_offsetC,x+j_coord_offsetD,
887 /* Calculate displacement vector */
888 dx00 = _mm_sub_ps(ix0,jx0);
889 dy00 = _mm_sub_ps(iy0,jy0);
890 dz00 = _mm_sub_ps(iz0,jz0);
891 dx10 = _mm_sub_ps(ix1,jx0);
892 dy10 = _mm_sub_ps(iy1,jy0);
893 dz10 = _mm_sub_ps(iz1,jz0);
894 dx20 = _mm_sub_ps(ix2,jx0);
895 dy20 = _mm_sub_ps(iy2,jy0);
896 dz20 = _mm_sub_ps(iz2,jz0);
897 dx30 = _mm_sub_ps(ix3,jx0);
898 dy30 = _mm_sub_ps(iy3,jy0);
899 dz30 = _mm_sub_ps(iz3,jz0);
901 /* Calculate squared distance and things based on it */
902 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
903 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
904 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
905 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
907 rinv00 = gmx_mm_invsqrt_ps(rsq00);
908 rinv10 = gmx_mm_invsqrt_ps(rsq10);
909 rinv20 = gmx_mm_invsqrt_ps(rsq20);
910 rinv30 = gmx_mm_invsqrt_ps(rsq30);
912 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
913 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
914 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
916 /* Load parameters for j particles */
917 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
918 charge+jnrC+0,charge+jnrD+0);
919 vdwjidx0A = 2*vdwtype[jnrA+0];
920 vdwjidx0B = 2*vdwtype[jnrB+0];
921 vdwjidx0C = 2*vdwtype[jnrC+0];
922 vdwjidx0D = 2*vdwtype[jnrD+0];
924 fjx0 = _mm_setzero_ps();
925 fjy0 = _mm_setzero_ps();
926 fjz0 = _mm_setzero_ps();
928 /**************************
929 * CALCULATE INTERACTIONS *
930 **************************/
932 r00 = _mm_mul_ps(rsq00,rinv00);
934 /* Compute parameters for interactions between i and j atoms */
935 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
936 vdwparam+vdwioffset0+vdwjidx0B,
937 vdwparam+vdwioffset0+vdwjidx0C,
938 vdwparam+vdwioffset0+vdwjidx0D,
941 /* Calculate table index by multiplying r with table scale and truncate to integer */
942 rt = _mm_mul_ps(r00,vftabscale);
943 vfitab = _mm_cvttps_epi32(rt);
945 vfeps = _mm_frcz_ps(rt);
947 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
949 twovfeps = _mm_add_ps(vfeps,vfeps);
950 vfitab = _mm_slli_epi32(vfitab,3);
952 /* CUBIC SPLINE TABLE DISPERSION */
953 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
954 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
955 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
956 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
957 _MM_TRANSPOSE4_PS(Y,F,G,H);
958 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
959 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
960 fvdw6 = _mm_mul_ps(c6_00,FF);
962 /* CUBIC SPLINE TABLE REPULSION */
963 vfitab = _mm_add_epi32(vfitab,ifour);
964 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
965 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
966 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
967 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
968 _MM_TRANSPOSE4_PS(Y,F,G,H);
969 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
970 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
971 fvdw12 = _mm_mul_ps(c12_00,FF);
972 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
976 /* Update vectorial force */
977 fix0 = _mm_macc_ps(dx00,fscal,fix0);
978 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
979 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
981 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
982 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
983 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
985 /**************************
986 * CALCULATE INTERACTIONS *
987 **************************/
989 if (gmx_mm_any_lt(rsq10,rcutoff2))
992 /* Compute parameters for interactions between i and j atoms */
993 qq10 = _mm_mul_ps(iq1,jq0);
995 /* REACTION-FIELD ELECTROSTATICS */
996 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
998 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1002 fscal = _mm_and_ps(fscal,cutoff_mask);
1004 /* Update vectorial force */
1005 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1006 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1007 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1009 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1010 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1011 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1015 /**************************
1016 * CALCULATE INTERACTIONS *
1017 **************************/
1019 if (gmx_mm_any_lt(rsq20,rcutoff2))
1022 /* Compute parameters for interactions between i and j atoms */
1023 qq20 = _mm_mul_ps(iq2,jq0);
1025 /* REACTION-FIELD ELECTROSTATICS */
1026 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1028 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1032 fscal = _mm_and_ps(fscal,cutoff_mask);
1034 /* Update vectorial force */
1035 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1036 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1037 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1039 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1040 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1041 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1045 /**************************
1046 * CALCULATE INTERACTIONS *
1047 **************************/
1049 if (gmx_mm_any_lt(rsq30,rcutoff2))
1052 /* Compute parameters for interactions between i and j atoms */
1053 qq30 = _mm_mul_ps(iq3,jq0);
1055 /* REACTION-FIELD ELECTROSTATICS */
1056 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1058 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1062 fscal = _mm_and_ps(fscal,cutoff_mask);
1064 /* Update vectorial force */
1065 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1066 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1067 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1069 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1070 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1071 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1075 fjptrA = f+j_coord_offsetA;
1076 fjptrB = f+j_coord_offsetB;
1077 fjptrC = f+j_coord_offsetC;
1078 fjptrD = f+j_coord_offsetD;
1080 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1082 /* Inner loop uses 150 flops */
1085 if(jidx<j_index_end)
1088 /* Get j neighbor index, and coordinate index */
1089 jnrlistA = jjnr[jidx];
1090 jnrlistB = jjnr[jidx+1];
1091 jnrlistC = jjnr[jidx+2];
1092 jnrlistD = jjnr[jidx+3];
1093 /* Sign of each element will be negative for non-real atoms.
1094 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1095 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1097 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1098 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1099 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1100 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1101 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1102 j_coord_offsetA = DIM*jnrA;
1103 j_coord_offsetB = DIM*jnrB;
1104 j_coord_offsetC = DIM*jnrC;
1105 j_coord_offsetD = DIM*jnrD;
1107 /* load j atom coordinates */
1108 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1109 x+j_coord_offsetC,x+j_coord_offsetD,
1112 /* Calculate displacement vector */
1113 dx00 = _mm_sub_ps(ix0,jx0);
1114 dy00 = _mm_sub_ps(iy0,jy0);
1115 dz00 = _mm_sub_ps(iz0,jz0);
1116 dx10 = _mm_sub_ps(ix1,jx0);
1117 dy10 = _mm_sub_ps(iy1,jy0);
1118 dz10 = _mm_sub_ps(iz1,jz0);
1119 dx20 = _mm_sub_ps(ix2,jx0);
1120 dy20 = _mm_sub_ps(iy2,jy0);
1121 dz20 = _mm_sub_ps(iz2,jz0);
1122 dx30 = _mm_sub_ps(ix3,jx0);
1123 dy30 = _mm_sub_ps(iy3,jy0);
1124 dz30 = _mm_sub_ps(iz3,jz0);
1126 /* Calculate squared distance and things based on it */
1127 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1128 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1129 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1130 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1132 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1133 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1134 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1135 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1137 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1138 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1139 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1141 /* Load parameters for j particles */
1142 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1143 charge+jnrC+0,charge+jnrD+0);
1144 vdwjidx0A = 2*vdwtype[jnrA+0];
1145 vdwjidx0B = 2*vdwtype[jnrB+0];
1146 vdwjidx0C = 2*vdwtype[jnrC+0];
1147 vdwjidx0D = 2*vdwtype[jnrD+0];
1149 fjx0 = _mm_setzero_ps();
1150 fjy0 = _mm_setzero_ps();
1151 fjz0 = _mm_setzero_ps();
1153 /**************************
1154 * CALCULATE INTERACTIONS *
1155 **************************/
1157 r00 = _mm_mul_ps(rsq00,rinv00);
1158 r00 = _mm_andnot_ps(dummy_mask,r00);
1160 /* Compute parameters for interactions between i and j atoms */
1161 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1162 vdwparam+vdwioffset0+vdwjidx0B,
1163 vdwparam+vdwioffset0+vdwjidx0C,
1164 vdwparam+vdwioffset0+vdwjidx0D,
1167 /* Calculate table index by multiplying r with table scale and truncate to integer */
1168 rt = _mm_mul_ps(r00,vftabscale);
1169 vfitab = _mm_cvttps_epi32(rt);
1171 vfeps = _mm_frcz_ps(rt);
1173 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1175 twovfeps = _mm_add_ps(vfeps,vfeps);
1176 vfitab = _mm_slli_epi32(vfitab,3);
1178 /* CUBIC SPLINE TABLE DISPERSION */
1179 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1180 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1181 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1182 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1183 _MM_TRANSPOSE4_PS(Y,F,G,H);
1184 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1185 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1186 fvdw6 = _mm_mul_ps(c6_00,FF);
1188 /* CUBIC SPLINE TABLE REPULSION */
1189 vfitab = _mm_add_epi32(vfitab,ifour);
1190 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1191 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1192 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1193 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1194 _MM_TRANSPOSE4_PS(Y,F,G,H);
1195 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1196 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1197 fvdw12 = _mm_mul_ps(c12_00,FF);
1198 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1202 fscal = _mm_andnot_ps(dummy_mask,fscal);
1204 /* Update vectorial force */
1205 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1206 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1207 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1209 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1210 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1211 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1213 /**************************
1214 * CALCULATE INTERACTIONS *
1215 **************************/
1217 if (gmx_mm_any_lt(rsq10,rcutoff2))
1220 /* Compute parameters for interactions between i and j atoms */
1221 qq10 = _mm_mul_ps(iq1,jq0);
1223 /* REACTION-FIELD ELECTROSTATICS */
1224 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1226 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1230 fscal = _mm_and_ps(fscal,cutoff_mask);
1232 fscal = _mm_andnot_ps(dummy_mask,fscal);
1234 /* Update vectorial force */
1235 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1236 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1237 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1239 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1240 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1241 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1245 /**************************
1246 * CALCULATE INTERACTIONS *
1247 **************************/
1249 if (gmx_mm_any_lt(rsq20,rcutoff2))
1252 /* Compute parameters for interactions between i and j atoms */
1253 qq20 = _mm_mul_ps(iq2,jq0);
1255 /* REACTION-FIELD ELECTROSTATICS */
1256 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1258 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1262 fscal = _mm_and_ps(fscal,cutoff_mask);
1264 fscal = _mm_andnot_ps(dummy_mask,fscal);
1266 /* Update vectorial force */
1267 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1268 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1269 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1271 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1272 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1273 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1277 /**************************
1278 * CALCULATE INTERACTIONS *
1279 **************************/
1281 if (gmx_mm_any_lt(rsq30,rcutoff2))
1284 /* Compute parameters for interactions between i and j atoms */
1285 qq30 = _mm_mul_ps(iq3,jq0);
1287 /* REACTION-FIELD ELECTROSTATICS */
1288 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1290 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1294 fscal = _mm_and_ps(fscal,cutoff_mask);
1296 fscal = _mm_andnot_ps(dummy_mask,fscal);
1298 /* Update vectorial force */
1299 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1300 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1301 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1303 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1304 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1305 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1309 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1310 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1311 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1312 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1314 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1316 /* Inner loop uses 151 flops */
1319 /* End of innermost loop */
1321 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1322 f+i_coord_offset,fshift+i_shift_offset);
1324 /* Increment number of inner iterations */
1325 inneriter += j_index_end - j_index_start;
1327 /* Outer loop uses 24 flops */
1330 /* Increment number of outer iterations */
1333 /* Update outer/inner flops */
1335 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*151);