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_ElecRFCut_VdwCSTab_GeomW4P1_VF_avx_128_fma_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: CubicSplineTable
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_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 krf = _mm_set1_ps(fr->ic->k_rf);
127 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
128 crf = _mm_set1_ps(fr->ic->c_rf);
129 nvdwtype = fr->ntype;
131 vdwtype = mdatoms->typeA;
133 vftab = kernel_data->table_vdw->data;
134 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
136 /* Setup water-specific parameters */
137 inr = nlist->iinr[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 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
141 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
143 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
144 rcutoff_scalar = fr->rcoulomb;
145 rcutoff = _mm_set1_ps(rcutoff_scalar);
146 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
148 /* Avoid stupid compiler warnings */
149 jnrA = jnrB = jnrC = jnrD = 0;
158 for(iidx=0;iidx<4*DIM;iidx++)
163 /* Start outer loop over neighborlists */
164 for(iidx=0; iidx<nri; iidx++)
166 /* Load shift vector for this list */
167 i_shift_offset = DIM*shiftidx[iidx];
169 /* Load limits for loop over neighbors */
170 j_index_start = jindex[iidx];
171 j_index_end = jindex[iidx+1];
173 /* Get outer coordinate index */
175 i_coord_offset = DIM*inr;
177 /* Load i particle coords and add shift vector */
178 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
179 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
181 fix0 = _mm_setzero_ps();
182 fiy0 = _mm_setzero_ps();
183 fiz0 = _mm_setzero_ps();
184 fix1 = _mm_setzero_ps();
185 fiy1 = _mm_setzero_ps();
186 fiz1 = _mm_setzero_ps();
187 fix2 = _mm_setzero_ps();
188 fiy2 = _mm_setzero_ps();
189 fiz2 = _mm_setzero_ps();
190 fix3 = _mm_setzero_ps();
191 fiy3 = _mm_setzero_ps();
192 fiz3 = _mm_setzero_ps();
194 /* Reset potential sums */
195 velecsum = _mm_setzero_ps();
196 vvdwsum = _mm_setzero_ps();
198 /* Start inner kernel loop */
199 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
202 /* Get j neighbor index, and coordinate index */
207 j_coord_offsetA = DIM*jnrA;
208 j_coord_offsetB = DIM*jnrB;
209 j_coord_offsetC = DIM*jnrC;
210 j_coord_offsetD = DIM*jnrD;
212 /* load j atom coordinates */
213 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
214 x+j_coord_offsetC,x+j_coord_offsetD,
217 /* Calculate displacement vector */
218 dx00 = _mm_sub_ps(ix0,jx0);
219 dy00 = _mm_sub_ps(iy0,jy0);
220 dz00 = _mm_sub_ps(iz0,jz0);
221 dx10 = _mm_sub_ps(ix1,jx0);
222 dy10 = _mm_sub_ps(iy1,jy0);
223 dz10 = _mm_sub_ps(iz1,jz0);
224 dx20 = _mm_sub_ps(ix2,jx0);
225 dy20 = _mm_sub_ps(iy2,jy0);
226 dz20 = _mm_sub_ps(iz2,jz0);
227 dx30 = _mm_sub_ps(ix3,jx0);
228 dy30 = _mm_sub_ps(iy3,jy0);
229 dz30 = _mm_sub_ps(iz3,jz0);
231 /* Calculate squared distance and things based on it */
232 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
233 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
234 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
235 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
237 rinv00 = gmx_mm_invsqrt_ps(rsq00);
238 rinv10 = gmx_mm_invsqrt_ps(rsq10);
239 rinv20 = gmx_mm_invsqrt_ps(rsq20);
240 rinv30 = gmx_mm_invsqrt_ps(rsq30);
242 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
243 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
244 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
246 /* Load parameters for j particles */
247 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
248 charge+jnrC+0,charge+jnrD+0);
249 vdwjidx0A = 2*vdwtype[jnrA+0];
250 vdwjidx0B = 2*vdwtype[jnrB+0];
251 vdwjidx0C = 2*vdwtype[jnrC+0];
252 vdwjidx0D = 2*vdwtype[jnrD+0];
254 fjx0 = _mm_setzero_ps();
255 fjy0 = _mm_setzero_ps();
256 fjz0 = _mm_setzero_ps();
258 /**************************
259 * CALCULATE INTERACTIONS *
260 **************************/
262 r00 = _mm_mul_ps(rsq00,rinv00);
264 /* Compute parameters for interactions between i and j atoms */
265 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
266 vdwparam+vdwioffset0+vdwjidx0B,
267 vdwparam+vdwioffset0+vdwjidx0C,
268 vdwparam+vdwioffset0+vdwjidx0D,
271 /* Calculate table index by multiplying r with table scale and truncate to integer */
272 rt = _mm_mul_ps(r00,vftabscale);
273 vfitab = _mm_cvttps_epi32(rt);
275 vfeps = _mm_frcz_ps(rt);
277 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
279 twovfeps = _mm_add_ps(vfeps,vfeps);
280 vfitab = _mm_slli_epi32(vfitab,3);
282 /* CUBIC SPLINE TABLE DISPERSION */
283 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
284 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
285 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
286 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
287 _MM_TRANSPOSE4_PS(Y,F,G,H);
288 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
289 VV = _mm_macc_ps(vfeps,Fp,Y);
290 vvdw6 = _mm_mul_ps(c6_00,VV);
291 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
292 fvdw6 = _mm_mul_ps(c6_00,FF);
294 /* CUBIC SPLINE TABLE REPULSION */
295 vfitab = _mm_add_epi32(vfitab,ifour);
296 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
297 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
298 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
299 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
300 _MM_TRANSPOSE4_PS(Y,F,G,H);
301 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
302 VV = _mm_macc_ps(vfeps,Fp,Y);
303 vvdw12 = _mm_mul_ps(c12_00,VV);
304 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
305 fvdw12 = _mm_mul_ps(c12_00,FF);
306 vvdw = _mm_add_ps(vvdw12,vvdw6);
307 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
309 /* Update potential sum for this i atom from the interaction with this j atom. */
310 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
314 /* Update vectorial force */
315 fix0 = _mm_macc_ps(dx00,fscal,fix0);
316 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
317 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
319 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
320 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
321 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
323 /**************************
324 * CALCULATE INTERACTIONS *
325 **************************/
327 if (gmx_mm_any_lt(rsq10,rcutoff2))
330 /* Compute parameters for interactions between i and j atoms */
331 qq10 = _mm_mul_ps(iq1,jq0);
333 /* REACTION-FIELD ELECTROSTATICS */
334 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
335 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
337 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
339 /* Update potential sum for this i atom from the interaction with this j atom. */
340 velec = _mm_and_ps(velec,cutoff_mask);
341 velecsum = _mm_add_ps(velecsum,velec);
345 fscal = _mm_and_ps(fscal,cutoff_mask);
347 /* Update vectorial force */
348 fix1 = _mm_macc_ps(dx10,fscal,fix1);
349 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
350 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
352 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
353 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
354 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
358 /**************************
359 * CALCULATE INTERACTIONS *
360 **************************/
362 if (gmx_mm_any_lt(rsq20,rcutoff2))
365 /* Compute parameters for interactions between i and j atoms */
366 qq20 = _mm_mul_ps(iq2,jq0);
368 /* REACTION-FIELD ELECTROSTATICS */
369 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
370 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
372 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
374 /* Update potential sum for this i atom from the interaction with this j atom. */
375 velec = _mm_and_ps(velec,cutoff_mask);
376 velecsum = _mm_add_ps(velecsum,velec);
380 fscal = _mm_and_ps(fscal,cutoff_mask);
382 /* Update vectorial force */
383 fix2 = _mm_macc_ps(dx20,fscal,fix2);
384 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
385 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
387 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
388 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
389 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
393 /**************************
394 * CALCULATE INTERACTIONS *
395 **************************/
397 if (gmx_mm_any_lt(rsq30,rcutoff2))
400 /* Compute parameters for interactions between i and j atoms */
401 qq30 = _mm_mul_ps(iq3,jq0);
403 /* REACTION-FIELD ELECTROSTATICS */
404 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
405 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
407 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
409 /* Update potential sum for this i atom from the interaction with this j atom. */
410 velec = _mm_and_ps(velec,cutoff_mask);
411 velecsum = _mm_add_ps(velecsum,velec);
415 fscal = _mm_and_ps(fscal,cutoff_mask);
417 /* Update vectorial force */
418 fix3 = _mm_macc_ps(dx30,fscal,fix3);
419 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
420 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
422 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
423 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
424 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
428 fjptrA = f+j_coord_offsetA;
429 fjptrB = f+j_coord_offsetB;
430 fjptrC = f+j_coord_offsetC;
431 fjptrD = f+j_coord_offsetD;
433 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
435 /* Inner loop uses 176 flops */
441 /* Get j neighbor index, and coordinate index */
442 jnrlistA = jjnr[jidx];
443 jnrlistB = jjnr[jidx+1];
444 jnrlistC = jjnr[jidx+2];
445 jnrlistD = jjnr[jidx+3];
446 /* Sign of each element will be negative for non-real atoms.
447 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
448 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
450 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
451 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
452 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
453 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
454 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
455 j_coord_offsetA = DIM*jnrA;
456 j_coord_offsetB = DIM*jnrB;
457 j_coord_offsetC = DIM*jnrC;
458 j_coord_offsetD = DIM*jnrD;
460 /* load j atom coordinates */
461 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
462 x+j_coord_offsetC,x+j_coord_offsetD,
465 /* Calculate displacement vector */
466 dx00 = _mm_sub_ps(ix0,jx0);
467 dy00 = _mm_sub_ps(iy0,jy0);
468 dz00 = _mm_sub_ps(iz0,jz0);
469 dx10 = _mm_sub_ps(ix1,jx0);
470 dy10 = _mm_sub_ps(iy1,jy0);
471 dz10 = _mm_sub_ps(iz1,jz0);
472 dx20 = _mm_sub_ps(ix2,jx0);
473 dy20 = _mm_sub_ps(iy2,jy0);
474 dz20 = _mm_sub_ps(iz2,jz0);
475 dx30 = _mm_sub_ps(ix3,jx0);
476 dy30 = _mm_sub_ps(iy3,jy0);
477 dz30 = _mm_sub_ps(iz3,jz0);
479 /* Calculate squared distance and things based on it */
480 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
481 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
482 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
483 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
485 rinv00 = gmx_mm_invsqrt_ps(rsq00);
486 rinv10 = gmx_mm_invsqrt_ps(rsq10);
487 rinv20 = gmx_mm_invsqrt_ps(rsq20);
488 rinv30 = gmx_mm_invsqrt_ps(rsq30);
490 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
491 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
492 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
494 /* Load parameters for j particles */
495 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
496 charge+jnrC+0,charge+jnrD+0);
497 vdwjidx0A = 2*vdwtype[jnrA+0];
498 vdwjidx0B = 2*vdwtype[jnrB+0];
499 vdwjidx0C = 2*vdwtype[jnrC+0];
500 vdwjidx0D = 2*vdwtype[jnrD+0];
502 fjx0 = _mm_setzero_ps();
503 fjy0 = _mm_setzero_ps();
504 fjz0 = _mm_setzero_ps();
506 /**************************
507 * CALCULATE INTERACTIONS *
508 **************************/
510 r00 = _mm_mul_ps(rsq00,rinv00);
511 r00 = _mm_andnot_ps(dummy_mask,r00);
513 /* Compute parameters for interactions between i and j atoms */
514 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
515 vdwparam+vdwioffset0+vdwjidx0B,
516 vdwparam+vdwioffset0+vdwjidx0C,
517 vdwparam+vdwioffset0+vdwjidx0D,
520 /* Calculate table index by multiplying r with table scale and truncate to integer */
521 rt = _mm_mul_ps(r00,vftabscale);
522 vfitab = _mm_cvttps_epi32(rt);
524 vfeps = _mm_frcz_ps(rt);
526 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
528 twovfeps = _mm_add_ps(vfeps,vfeps);
529 vfitab = _mm_slli_epi32(vfitab,3);
531 /* CUBIC SPLINE TABLE DISPERSION */
532 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
533 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
534 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
535 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
536 _MM_TRANSPOSE4_PS(Y,F,G,H);
537 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
538 VV = _mm_macc_ps(vfeps,Fp,Y);
539 vvdw6 = _mm_mul_ps(c6_00,VV);
540 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
541 fvdw6 = _mm_mul_ps(c6_00,FF);
543 /* CUBIC SPLINE TABLE REPULSION */
544 vfitab = _mm_add_epi32(vfitab,ifour);
545 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
546 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
547 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
548 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
549 _MM_TRANSPOSE4_PS(Y,F,G,H);
550 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
551 VV = _mm_macc_ps(vfeps,Fp,Y);
552 vvdw12 = _mm_mul_ps(c12_00,VV);
553 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
554 fvdw12 = _mm_mul_ps(c12_00,FF);
555 vvdw = _mm_add_ps(vvdw12,vvdw6);
556 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
558 /* Update potential sum for this i atom from the interaction with this j atom. */
559 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
560 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
564 fscal = _mm_andnot_ps(dummy_mask,fscal);
566 /* Update vectorial force */
567 fix0 = _mm_macc_ps(dx00,fscal,fix0);
568 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
569 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
571 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
572 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
573 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
575 /**************************
576 * CALCULATE INTERACTIONS *
577 **************************/
579 if (gmx_mm_any_lt(rsq10,rcutoff2))
582 /* Compute parameters for interactions between i and j atoms */
583 qq10 = _mm_mul_ps(iq1,jq0);
585 /* REACTION-FIELD ELECTROSTATICS */
586 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
587 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
589 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
591 /* Update potential sum for this i atom from the interaction with this j atom. */
592 velec = _mm_and_ps(velec,cutoff_mask);
593 velec = _mm_andnot_ps(dummy_mask,velec);
594 velecsum = _mm_add_ps(velecsum,velec);
598 fscal = _mm_and_ps(fscal,cutoff_mask);
600 fscal = _mm_andnot_ps(dummy_mask,fscal);
602 /* Update vectorial force */
603 fix1 = _mm_macc_ps(dx10,fscal,fix1);
604 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
605 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
607 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
608 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
609 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
613 /**************************
614 * CALCULATE INTERACTIONS *
615 **************************/
617 if (gmx_mm_any_lt(rsq20,rcutoff2))
620 /* Compute parameters for interactions between i and j atoms */
621 qq20 = _mm_mul_ps(iq2,jq0);
623 /* REACTION-FIELD ELECTROSTATICS */
624 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
625 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
627 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
629 /* Update potential sum for this i atom from the interaction with this j atom. */
630 velec = _mm_and_ps(velec,cutoff_mask);
631 velec = _mm_andnot_ps(dummy_mask,velec);
632 velecsum = _mm_add_ps(velecsum,velec);
636 fscal = _mm_and_ps(fscal,cutoff_mask);
638 fscal = _mm_andnot_ps(dummy_mask,fscal);
640 /* Update vectorial force */
641 fix2 = _mm_macc_ps(dx20,fscal,fix2);
642 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
643 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
645 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
646 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
647 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
651 /**************************
652 * CALCULATE INTERACTIONS *
653 **************************/
655 if (gmx_mm_any_lt(rsq30,rcutoff2))
658 /* Compute parameters for interactions between i and j atoms */
659 qq30 = _mm_mul_ps(iq3,jq0);
661 /* REACTION-FIELD ELECTROSTATICS */
662 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
663 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
665 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
667 /* Update potential sum for this i atom from the interaction with this j atom. */
668 velec = _mm_and_ps(velec,cutoff_mask);
669 velec = _mm_andnot_ps(dummy_mask,velec);
670 velecsum = _mm_add_ps(velecsum,velec);
674 fscal = _mm_and_ps(fscal,cutoff_mask);
676 fscal = _mm_andnot_ps(dummy_mask,fscal);
678 /* Update vectorial force */
679 fix3 = _mm_macc_ps(dx30,fscal,fix3);
680 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
681 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
683 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
684 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
685 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
689 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
690 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
691 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
692 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
694 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
696 /* Inner loop uses 177 flops */
699 /* End of innermost loop */
701 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
702 f+i_coord_offset,fshift+i_shift_offset);
705 /* Update potential energies */
706 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
707 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
709 /* Increment number of inner iterations */
710 inneriter += j_index_end - j_index_start;
712 /* Outer loop uses 26 flops */
715 /* Increment number of outer iterations */
718 /* Update outer/inner flops */
720 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*177);
723 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_F_avx_128_fma_single
724 * Electrostatics interaction: ReactionField
725 * VdW interaction: CubicSplineTable
726 * Geometry: Water4-Particle
727 * Calculate force/pot: Force
730 nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_F_avx_128_fma_single
731 (t_nblist * gmx_restrict nlist,
732 rvec * gmx_restrict xx,
733 rvec * gmx_restrict ff,
734 t_forcerec * gmx_restrict fr,
735 t_mdatoms * gmx_restrict mdatoms,
736 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
737 t_nrnb * gmx_restrict nrnb)
739 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
740 * just 0 for non-waters.
741 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
742 * jnr indices corresponding to data put in the four positions in the SIMD register.
744 int i_shift_offset,i_coord_offset,outeriter,inneriter;
745 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
746 int jnrA,jnrB,jnrC,jnrD;
747 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
748 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
749 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
751 real *shiftvec,*fshift,*x,*f;
752 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
754 __m128 fscal,rcutoff,rcutoff2,jidxall;
756 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
758 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
760 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
762 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
763 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
764 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
765 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
766 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
767 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
768 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
769 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
772 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
775 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
776 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
778 __m128i ifour = _mm_set1_epi32(4);
779 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
781 __m128 dummy_mask,cutoff_mask;
782 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
783 __m128 one = _mm_set1_ps(1.0);
784 __m128 two = _mm_set1_ps(2.0);
790 jindex = nlist->jindex;
792 shiftidx = nlist->shift;
794 shiftvec = fr->shift_vec[0];
795 fshift = fr->fshift[0];
796 facel = _mm_set1_ps(fr->epsfac);
797 charge = mdatoms->chargeA;
798 krf = _mm_set1_ps(fr->ic->k_rf);
799 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
800 crf = _mm_set1_ps(fr->ic->c_rf);
801 nvdwtype = fr->ntype;
803 vdwtype = mdatoms->typeA;
805 vftab = kernel_data->table_vdw->data;
806 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
808 /* Setup water-specific parameters */
809 inr = nlist->iinr[0];
810 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
811 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
812 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
813 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
815 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
816 rcutoff_scalar = fr->rcoulomb;
817 rcutoff = _mm_set1_ps(rcutoff_scalar);
818 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
820 /* Avoid stupid compiler warnings */
821 jnrA = jnrB = jnrC = jnrD = 0;
830 for(iidx=0;iidx<4*DIM;iidx++)
835 /* Start outer loop over neighborlists */
836 for(iidx=0; iidx<nri; iidx++)
838 /* Load shift vector for this list */
839 i_shift_offset = DIM*shiftidx[iidx];
841 /* Load limits for loop over neighbors */
842 j_index_start = jindex[iidx];
843 j_index_end = jindex[iidx+1];
845 /* Get outer coordinate index */
847 i_coord_offset = DIM*inr;
849 /* Load i particle coords and add shift vector */
850 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
851 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
853 fix0 = _mm_setzero_ps();
854 fiy0 = _mm_setzero_ps();
855 fiz0 = _mm_setzero_ps();
856 fix1 = _mm_setzero_ps();
857 fiy1 = _mm_setzero_ps();
858 fiz1 = _mm_setzero_ps();
859 fix2 = _mm_setzero_ps();
860 fiy2 = _mm_setzero_ps();
861 fiz2 = _mm_setzero_ps();
862 fix3 = _mm_setzero_ps();
863 fiy3 = _mm_setzero_ps();
864 fiz3 = _mm_setzero_ps();
866 /* Start inner kernel loop */
867 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
870 /* Get j neighbor index, and coordinate index */
875 j_coord_offsetA = DIM*jnrA;
876 j_coord_offsetB = DIM*jnrB;
877 j_coord_offsetC = DIM*jnrC;
878 j_coord_offsetD = DIM*jnrD;
880 /* load j atom coordinates */
881 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
882 x+j_coord_offsetC,x+j_coord_offsetD,
885 /* Calculate displacement vector */
886 dx00 = _mm_sub_ps(ix0,jx0);
887 dy00 = _mm_sub_ps(iy0,jy0);
888 dz00 = _mm_sub_ps(iz0,jz0);
889 dx10 = _mm_sub_ps(ix1,jx0);
890 dy10 = _mm_sub_ps(iy1,jy0);
891 dz10 = _mm_sub_ps(iz1,jz0);
892 dx20 = _mm_sub_ps(ix2,jx0);
893 dy20 = _mm_sub_ps(iy2,jy0);
894 dz20 = _mm_sub_ps(iz2,jz0);
895 dx30 = _mm_sub_ps(ix3,jx0);
896 dy30 = _mm_sub_ps(iy3,jy0);
897 dz30 = _mm_sub_ps(iz3,jz0);
899 /* Calculate squared distance and things based on it */
900 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
901 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
902 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
903 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
905 rinv00 = gmx_mm_invsqrt_ps(rsq00);
906 rinv10 = gmx_mm_invsqrt_ps(rsq10);
907 rinv20 = gmx_mm_invsqrt_ps(rsq20);
908 rinv30 = gmx_mm_invsqrt_ps(rsq30);
910 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
911 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
912 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
914 /* Load parameters for j particles */
915 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
916 charge+jnrC+0,charge+jnrD+0);
917 vdwjidx0A = 2*vdwtype[jnrA+0];
918 vdwjidx0B = 2*vdwtype[jnrB+0];
919 vdwjidx0C = 2*vdwtype[jnrC+0];
920 vdwjidx0D = 2*vdwtype[jnrD+0];
922 fjx0 = _mm_setzero_ps();
923 fjy0 = _mm_setzero_ps();
924 fjz0 = _mm_setzero_ps();
926 /**************************
927 * CALCULATE INTERACTIONS *
928 **************************/
930 r00 = _mm_mul_ps(rsq00,rinv00);
932 /* Compute parameters for interactions between i and j atoms */
933 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
934 vdwparam+vdwioffset0+vdwjidx0B,
935 vdwparam+vdwioffset0+vdwjidx0C,
936 vdwparam+vdwioffset0+vdwjidx0D,
939 /* Calculate table index by multiplying r with table scale and truncate to integer */
940 rt = _mm_mul_ps(r00,vftabscale);
941 vfitab = _mm_cvttps_epi32(rt);
943 vfeps = _mm_frcz_ps(rt);
945 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
947 twovfeps = _mm_add_ps(vfeps,vfeps);
948 vfitab = _mm_slli_epi32(vfitab,3);
950 /* CUBIC SPLINE TABLE DISPERSION */
951 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
952 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
953 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
954 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
955 _MM_TRANSPOSE4_PS(Y,F,G,H);
956 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
957 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
958 fvdw6 = _mm_mul_ps(c6_00,FF);
960 /* CUBIC SPLINE TABLE REPULSION */
961 vfitab = _mm_add_epi32(vfitab,ifour);
962 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
963 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
964 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
965 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
966 _MM_TRANSPOSE4_PS(Y,F,G,H);
967 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
968 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
969 fvdw12 = _mm_mul_ps(c12_00,FF);
970 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
974 /* Update vectorial force */
975 fix0 = _mm_macc_ps(dx00,fscal,fix0);
976 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
977 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
979 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
980 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
981 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
983 /**************************
984 * CALCULATE INTERACTIONS *
985 **************************/
987 if (gmx_mm_any_lt(rsq10,rcutoff2))
990 /* Compute parameters for interactions between i and j atoms */
991 qq10 = _mm_mul_ps(iq1,jq0);
993 /* REACTION-FIELD ELECTROSTATICS */
994 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
996 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1000 fscal = _mm_and_ps(fscal,cutoff_mask);
1002 /* Update vectorial force */
1003 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1004 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1005 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1007 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1008 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1009 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1013 /**************************
1014 * CALCULATE INTERACTIONS *
1015 **************************/
1017 if (gmx_mm_any_lt(rsq20,rcutoff2))
1020 /* Compute parameters for interactions between i and j atoms */
1021 qq20 = _mm_mul_ps(iq2,jq0);
1023 /* REACTION-FIELD ELECTROSTATICS */
1024 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1026 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1030 fscal = _mm_and_ps(fscal,cutoff_mask);
1032 /* Update vectorial force */
1033 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1034 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1035 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1037 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1038 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1039 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1043 /**************************
1044 * CALCULATE INTERACTIONS *
1045 **************************/
1047 if (gmx_mm_any_lt(rsq30,rcutoff2))
1050 /* Compute parameters for interactions between i and j atoms */
1051 qq30 = _mm_mul_ps(iq3,jq0);
1053 /* REACTION-FIELD ELECTROSTATICS */
1054 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1056 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1060 fscal = _mm_and_ps(fscal,cutoff_mask);
1062 /* Update vectorial force */
1063 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1064 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1065 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1067 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1068 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1069 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1073 fjptrA = f+j_coord_offsetA;
1074 fjptrB = f+j_coord_offsetB;
1075 fjptrC = f+j_coord_offsetC;
1076 fjptrD = f+j_coord_offsetD;
1078 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1080 /* Inner loop uses 150 flops */
1083 if(jidx<j_index_end)
1086 /* Get j neighbor index, and coordinate index */
1087 jnrlistA = jjnr[jidx];
1088 jnrlistB = jjnr[jidx+1];
1089 jnrlistC = jjnr[jidx+2];
1090 jnrlistD = jjnr[jidx+3];
1091 /* Sign of each element will be negative for non-real atoms.
1092 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1093 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1095 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1096 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1097 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1098 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1099 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1100 j_coord_offsetA = DIM*jnrA;
1101 j_coord_offsetB = DIM*jnrB;
1102 j_coord_offsetC = DIM*jnrC;
1103 j_coord_offsetD = DIM*jnrD;
1105 /* load j atom coordinates */
1106 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1107 x+j_coord_offsetC,x+j_coord_offsetD,
1110 /* Calculate displacement vector */
1111 dx00 = _mm_sub_ps(ix0,jx0);
1112 dy00 = _mm_sub_ps(iy0,jy0);
1113 dz00 = _mm_sub_ps(iz0,jz0);
1114 dx10 = _mm_sub_ps(ix1,jx0);
1115 dy10 = _mm_sub_ps(iy1,jy0);
1116 dz10 = _mm_sub_ps(iz1,jz0);
1117 dx20 = _mm_sub_ps(ix2,jx0);
1118 dy20 = _mm_sub_ps(iy2,jy0);
1119 dz20 = _mm_sub_ps(iz2,jz0);
1120 dx30 = _mm_sub_ps(ix3,jx0);
1121 dy30 = _mm_sub_ps(iy3,jy0);
1122 dz30 = _mm_sub_ps(iz3,jz0);
1124 /* Calculate squared distance and things based on it */
1125 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1126 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1127 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1128 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1130 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1131 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1132 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1133 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1135 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1136 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1137 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1139 /* Load parameters for j particles */
1140 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1141 charge+jnrC+0,charge+jnrD+0);
1142 vdwjidx0A = 2*vdwtype[jnrA+0];
1143 vdwjidx0B = 2*vdwtype[jnrB+0];
1144 vdwjidx0C = 2*vdwtype[jnrC+0];
1145 vdwjidx0D = 2*vdwtype[jnrD+0];
1147 fjx0 = _mm_setzero_ps();
1148 fjy0 = _mm_setzero_ps();
1149 fjz0 = _mm_setzero_ps();
1151 /**************************
1152 * CALCULATE INTERACTIONS *
1153 **************************/
1155 r00 = _mm_mul_ps(rsq00,rinv00);
1156 r00 = _mm_andnot_ps(dummy_mask,r00);
1158 /* Compute parameters for interactions between i and j atoms */
1159 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1160 vdwparam+vdwioffset0+vdwjidx0B,
1161 vdwparam+vdwioffset0+vdwjidx0C,
1162 vdwparam+vdwioffset0+vdwjidx0D,
1165 /* Calculate table index by multiplying r with table scale and truncate to integer */
1166 rt = _mm_mul_ps(r00,vftabscale);
1167 vfitab = _mm_cvttps_epi32(rt);
1169 vfeps = _mm_frcz_ps(rt);
1171 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1173 twovfeps = _mm_add_ps(vfeps,vfeps);
1174 vfitab = _mm_slli_epi32(vfitab,3);
1176 /* CUBIC SPLINE TABLE DISPERSION */
1177 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1178 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1179 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1180 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1181 _MM_TRANSPOSE4_PS(Y,F,G,H);
1182 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1183 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1184 fvdw6 = _mm_mul_ps(c6_00,FF);
1186 /* CUBIC SPLINE TABLE REPULSION */
1187 vfitab = _mm_add_epi32(vfitab,ifour);
1188 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1189 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1190 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1191 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1192 _MM_TRANSPOSE4_PS(Y,F,G,H);
1193 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1194 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1195 fvdw12 = _mm_mul_ps(c12_00,FF);
1196 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1200 fscal = _mm_andnot_ps(dummy_mask,fscal);
1202 /* Update vectorial force */
1203 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1204 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1205 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1207 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1208 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1209 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1211 /**************************
1212 * CALCULATE INTERACTIONS *
1213 **************************/
1215 if (gmx_mm_any_lt(rsq10,rcutoff2))
1218 /* Compute parameters for interactions between i and j atoms */
1219 qq10 = _mm_mul_ps(iq1,jq0);
1221 /* REACTION-FIELD ELECTROSTATICS */
1222 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1224 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1228 fscal = _mm_and_ps(fscal,cutoff_mask);
1230 fscal = _mm_andnot_ps(dummy_mask,fscal);
1232 /* Update vectorial force */
1233 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1234 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1235 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1237 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1238 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1239 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1243 /**************************
1244 * CALCULATE INTERACTIONS *
1245 **************************/
1247 if (gmx_mm_any_lt(rsq20,rcutoff2))
1250 /* Compute parameters for interactions between i and j atoms */
1251 qq20 = _mm_mul_ps(iq2,jq0);
1253 /* REACTION-FIELD ELECTROSTATICS */
1254 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1256 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1260 fscal = _mm_and_ps(fscal,cutoff_mask);
1262 fscal = _mm_andnot_ps(dummy_mask,fscal);
1264 /* Update vectorial force */
1265 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1266 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1267 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1269 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1270 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1271 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1275 /**************************
1276 * CALCULATE INTERACTIONS *
1277 **************************/
1279 if (gmx_mm_any_lt(rsq30,rcutoff2))
1282 /* Compute parameters for interactions between i and j atoms */
1283 qq30 = _mm_mul_ps(iq3,jq0);
1285 /* REACTION-FIELD ELECTROSTATICS */
1286 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1288 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1292 fscal = _mm_and_ps(fscal,cutoff_mask);
1294 fscal = _mm_andnot_ps(dummy_mask,fscal);
1296 /* Update vectorial force */
1297 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1298 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1299 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1301 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1302 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1303 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1307 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1308 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1309 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1310 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1312 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1314 /* Inner loop uses 151 flops */
1317 /* End of innermost loop */
1319 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1320 f+i_coord_offset,fshift+i_shift_offset);
1322 /* Increment number of inner iterations */
1323 inneriter += j_index_end - j_index_start;
1325 /* Outer loop uses 24 flops */
1328 /* Increment number of outer iterations */
1331 /* Update outer/inner flops */
1333 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*151);