2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_128_fma_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
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_VdwLJSw_GeomW4P1_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwLJSw_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);
107 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
108 real rswitch_scalar,d_scalar;
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 /* 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 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
141 rcutoff_scalar = fr->rcoulomb;
142 rcutoff = _mm_set1_ps(rcutoff_scalar);
143 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
145 rswitch_scalar = fr->rvdw_switch;
146 rswitch = _mm_set1_ps(rswitch_scalar);
147 /* Setup switch parameters */
148 d_scalar = rcutoff_scalar-rswitch_scalar;
149 d = _mm_set1_ps(d_scalar);
150 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
151 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
152 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
153 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
154 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
155 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
157 /* Avoid stupid compiler warnings */
158 jnrA = jnrB = jnrC = jnrD = 0;
167 for(iidx=0;iidx<4*DIM;iidx++)
172 /* Start outer loop over neighborlists */
173 for(iidx=0; iidx<nri; iidx++)
175 /* Load shift vector for this list */
176 i_shift_offset = DIM*shiftidx[iidx];
178 /* Load limits for loop over neighbors */
179 j_index_start = jindex[iidx];
180 j_index_end = jindex[iidx+1];
182 /* Get outer coordinate index */
184 i_coord_offset = DIM*inr;
186 /* Load i particle coords and add shift vector */
187 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
188 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
190 fix0 = _mm_setzero_ps();
191 fiy0 = _mm_setzero_ps();
192 fiz0 = _mm_setzero_ps();
193 fix1 = _mm_setzero_ps();
194 fiy1 = _mm_setzero_ps();
195 fiz1 = _mm_setzero_ps();
196 fix2 = _mm_setzero_ps();
197 fiy2 = _mm_setzero_ps();
198 fiz2 = _mm_setzero_ps();
199 fix3 = _mm_setzero_ps();
200 fiy3 = _mm_setzero_ps();
201 fiz3 = _mm_setzero_ps();
203 /* Reset potential sums */
204 velecsum = _mm_setzero_ps();
205 vvdwsum = _mm_setzero_ps();
207 /* Start inner kernel loop */
208 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
211 /* Get j neighbor index, and coordinate index */
216 j_coord_offsetA = DIM*jnrA;
217 j_coord_offsetB = DIM*jnrB;
218 j_coord_offsetC = DIM*jnrC;
219 j_coord_offsetD = DIM*jnrD;
221 /* load j atom coordinates */
222 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
223 x+j_coord_offsetC,x+j_coord_offsetD,
226 /* Calculate displacement vector */
227 dx00 = _mm_sub_ps(ix0,jx0);
228 dy00 = _mm_sub_ps(iy0,jy0);
229 dz00 = _mm_sub_ps(iz0,jz0);
230 dx10 = _mm_sub_ps(ix1,jx0);
231 dy10 = _mm_sub_ps(iy1,jy0);
232 dz10 = _mm_sub_ps(iz1,jz0);
233 dx20 = _mm_sub_ps(ix2,jx0);
234 dy20 = _mm_sub_ps(iy2,jy0);
235 dz20 = _mm_sub_ps(iz2,jz0);
236 dx30 = _mm_sub_ps(ix3,jx0);
237 dy30 = _mm_sub_ps(iy3,jy0);
238 dz30 = _mm_sub_ps(iz3,jz0);
240 /* Calculate squared distance and things based on it */
241 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
242 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
243 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
244 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
246 rinv00 = gmx_mm_invsqrt_ps(rsq00);
247 rinv10 = gmx_mm_invsqrt_ps(rsq10);
248 rinv20 = gmx_mm_invsqrt_ps(rsq20);
249 rinv30 = gmx_mm_invsqrt_ps(rsq30);
251 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
252 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
253 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
254 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
256 /* Load parameters for j particles */
257 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
258 charge+jnrC+0,charge+jnrD+0);
259 vdwjidx0A = 2*vdwtype[jnrA+0];
260 vdwjidx0B = 2*vdwtype[jnrB+0];
261 vdwjidx0C = 2*vdwtype[jnrC+0];
262 vdwjidx0D = 2*vdwtype[jnrD+0];
264 fjx0 = _mm_setzero_ps();
265 fjy0 = _mm_setzero_ps();
266 fjz0 = _mm_setzero_ps();
268 /**************************
269 * CALCULATE INTERACTIONS *
270 **************************/
272 if (gmx_mm_any_lt(rsq00,rcutoff2))
275 r00 = _mm_mul_ps(rsq00,rinv00);
277 /* Compute parameters for interactions between i and j atoms */
278 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
279 vdwparam+vdwioffset0+vdwjidx0B,
280 vdwparam+vdwioffset0+vdwjidx0C,
281 vdwparam+vdwioffset0+vdwjidx0D,
284 /* LENNARD-JONES DISPERSION/REPULSION */
286 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
287 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
288 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
289 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
290 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
292 d = _mm_sub_ps(r00,rswitch);
293 d = _mm_max_ps(d,_mm_setzero_ps());
294 d2 = _mm_mul_ps(d,d);
295 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
297 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
299 /* Evaluate switch function */
300 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
301 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
302 vvdw = _mm_mul_ps(vvdw,sw);
303 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
305 /* Update potential sum for this i atom from the interaction with this j atom. */
306 vvdw = _mm_and_ps(vvdw,cutoff_mask);
307 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
311 fscal = _mm_and_ps(fscal,cutoff_mask);
313 /* Update vectorial force */
314 fix0 = _mm_macc_ps(dx00,fscal,fix0);
315 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
316 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
318 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
319 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
320 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
324 /**************************
325 * CALCULATE INTERACTIONS *
326 **************************/
328 if (gmx_mm_any_lt(rsq10,rcutoff2))
331 /* Compute parameters for interactions between i and j atoms */
332 qq10 = _mm_mul_ps(iq1,jq0);
334 /* REACTION-FIELD ELECTROSTATICS */
335 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
336 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
338 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
340 /* Update potential sum for this i atom from the interaction with this j atom. */
341 velec = _mm_and_ps(velec,cutoff_mask);
342 velecsum = _mm_add_ps(velecsum,velec);
346 fscal = _mm_and_ps(fscal,cutoff_mask);
348 /* Update vectorial force */
349 fix1 = _mm_macc_ps(dx10,fscal,fix1);
350 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
351 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
353 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
354 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
355 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
359 /**************************
360 * CALCULATE INTERACTIONS *
361 **************************/
363 if (gmx_mm_any_lt(rsq20,rcutoff2))
366 /* Compute parameters for interactions between i and j atoms */
367 qq20 = _mm_mul_ps(iq2,jq0);
369 /* REACTION-FIELD ELECTROSTATICS */
370 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
371 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
373 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
375 /* Update potential sum for this i atom from the interaction with this j atom. */
376 velec = _mm_and_ps(velec,cutoff_mask);
377 velecsum = _mm_add_ps(velecsum,velec);
381 fscal = _mm_and_ps(fscal,cutoff_mask);
383 /* Update vectorial force */
384 fix2 = _mm_macc_ps(dx20,fscal,fix2);
385 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
386 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
388 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
389 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
390 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
394 /**************************
395 * CALCULATE INTERACTIONS *
396 **************************/
398 if (gmx_mm_any_lt(rsq30,rcutoff2))
401 /* Compute parameters for interactions between i and j atoms */
402 qq30 = _mm_mul_ps(iq3,jq0);
404 /* REACTION-FIELD ELECTROSTATICS */
405 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
406 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
408 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
410 /* Update potential sum for this i atom from the interaction with this j atom. */
411 velec = _mm_and_ps(velec,cutoff_mask);
412 velecsum = _mm_add_ps(velecsum,velec);
416 fscal = _mm_and_ps(fscal,cutoff_mask);
418 /* Update vectorial force */
419 fix3 = _mm_macc_ps(dx30,fscal,fix3);
420 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
421 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
423 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
424 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
425 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
429 fjptrA = f+j_coord_offsetA;
430 fjptrB = f+j_coord_offsetB;
431 fjptrC = f+j_coord_offsetC;
432 fjptrD = f+j_coord_offsetD;
434 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
436 /* Inner loop uses 179 flops */
442 /* Get j neighbor index, and coordinate index */
443 jnrlistA = jjnr[jidx];
444 jnrlistB = jjnr[jidx+1];
445 jnrlistC = jjnr[jidx+2];
446 jnrlistD = jjnr[jidx+3];
447 /* Sign of each element will be negative for non-real atoms.
448 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
449 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
451 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
452 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
453 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
454 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
455 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
456 j_coord_offsetA = DIM*jnrA;
457 j_coord_offsetB = DIM*jnrB;
458 j_coord_offsetC = DIM*jnrC;
459 j_coord_offsetD = DIM*jnrD;
461 /* load j atom coordinates */
462 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
463 x+j_coord_offsetC,x+j_coord_offsetD,
466 /* Calculate displacement vector */
467 dx00 = _mm_sub_ps(ix0,jx0);
468 dy00 = _mm_sub_ps(iy0,jy0);
469 dz00 = _mm_sub_ps(iz0,jz0);
470 dx10 = _mm_sub_ps(ix1,jx0);
471 dy10 = _mm_sub_ps(iy1,jy0);
472 dz10 = _mm_sub_ps(iz1,jz0);
473 dx20 = _mm_sub_ps(ix2,jx0);
474 dy20 = _mm_sub_ps(iy2,jy0);
475 dz20 = _mm_sub_ps(iz2,jz0);
476 dx30 = _mm_sub_ps(ix3,jx0);
477 dy30 = _mm_sub_ps(iy3,jy0);
478 dz30 = _mm_sub_ps(iz3,jz0);
480 /* Calculate squared distance and things based on it */
481 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
482 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
483 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
484 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
486 rinv00 = gmx_mm_invsqrt_ps(rsq00);
487 rinv10 = gmx_mm_invsqrt_ps(rsq10);
488 rinv20 = gmx_mm_invsqrt_ps(rsq20);
489 rinv30 = gmx_mm_invsqrt_ps(rsq30);
491 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
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 if (gmx_mm_any_lt(rsq00,rcutoff2))
515 r00 = _mm_mul_ps(rsq00,rinv00);
516 r00 = _mm_andnot_ps(dummy_mask,r00);
518 /* Compute parameters for interactions between i and j atoms */
519 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
520 vdwparam+vdwioffset0+vdwjidx0B,
521 vdwparam+vdwioffset0+vdwjidx0C,
522 vdwparam+vdwioffset0+vdwjidx0D,
525 /* LENNARD-JONES DISPERSION/REPULSION */
527 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
528 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
529 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
530 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
531 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
533 d = _mm_sub_ps(r00,rswitch);
534 d = _mm_max_ps(d,_mm_setzero_ps());
535 d2 = _mm_mul_ps(d,d);
536 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
538 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
540 /* Evaluate switch function */
541 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
542 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
543 vvdw = _mm_mul_ps(vvdw,sw);
544 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
546 /* Update potential sum for this i atom from the interaction with this j atom. */
547 vvdw = _mm_and_ps(vvdw,cutoff_mask);
548 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
549 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
553 fscal = _mm_and_ps(fscal,cutoff_mask);
555 fscal = _mm_andnot_ps(dummy_mask,fscal);
557 /* Update vectorial force */
558 fix0 = _mm_macc_ps(dx00,fscal,fix0);
559 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
560 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
562 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
563 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
564 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
568 /**************************
569 * CALCULATE INTERACTIONS *
570 **************************/
572 if (gmx_mm_any_lt(rsq10,rcutoff2))
575 /* Compute parameters for interactions between i and j atoms */
576 qq10 = _mm_mul_ps(iq1,jq0);
578 /* REACTION-FIELD ELECTROSTATICS */
579 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
580 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
582 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
584 /* Update potential sum for this i atom from the interaction with this j atom. */
585 velec = _mm_and_ps(velec,cutoff_mask);
586 velec = _mm_andnot_ps(dummy_mask,velec);
587 velecsum = _mm_add_ps(velecsum,velec);
591 fscal = _mm_and_ps(fscal,cutoff_mask);
593 fscal = _mm_andnot_ps(dummy_mask,fscal);
595 /* Update vectorial force */
596 fix1 = _mm_macc_ps(dx10,fscal,fix1);
597 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
598 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
600 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
601 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
602 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
606 /**************************
607 * CALCULATE INTERACTIONS *
608 **************************/
610 if (gmx_mm_any_lt(rsq20,rcutoff2))
613 /* Compute parameters for interactions between i and j atoms */
614 qq20 = _mm_mul_ps(iq2,jq0);
616 /* REACTION-FIELD ELECTROSTATICS */
617 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
618 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
620 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
622 /* Update potential sum for this i atom from the interaction with this j atom. */
623 velec = _mm_and_ps(velec,cutoff_mask);
624 velec = _mm_andnot_ps(dummy_mask,velec);
625 velecsum = _mm_add_ps(velecsum,velec);
629 fscal = _mm_and_ps(fscal,cutoff_mask);
631 fscal = _mm_andnot_ps(dummy_mask,fscal);
633 /* Update vectorial force */
634 fix2 = _mm_macc_ps(dx20,fscal,fix2);
635 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
636 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
638 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
639 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
640 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
644 /**************************
645 * CALCULATE INTERACTIONS *
646 **************************/
648 if (gmx_mm_any_lt(rsq30,rcutoff2))
651 /* Compute parameters for interactions between i and j atoms */
652 qq30 = _mm_mul_ps(iq3,jq0);
654 /* REACTION-FIELD ELECTROSTATICS */
655 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
656 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
658 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
660 /* Update potential sum for this i atom from the interaction with this j atom. */
661 velec = _mm_and_ps(velec,cutoff_mask);
662 velec = _mm_andnot_ps(dummy_mask,velec);
663 velecsum = _mm_add_ps(velecsum,velec);
667 fscal = _mm_and_ps(fscal,cutoff_mask);
669 fscal = _mm_andnot_ps(dummy_mask,fscal);
671 /* Update vectorial force */
672 fix3 = _mm_macc_ps(dx30,fscal,fix3);
673 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
674 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
676 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
677 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
678 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
682 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
683 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
684 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
685 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
687 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
689 /* Inner loop uses 180 flops */
692 /* End of innermost loop */
694 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
695 f+i_coord_offset,fshift+i_shift_offset);
698 /* Update potential energies */
699 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
700 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
702 /* Increment number of inner iterations */
703 inneriter += j_index_end - j_index_start;
705 /* Outer loop uses 26 flops */
708 /* Increment number of outer iterations */
711 /* Update outer/inner flops */
713 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*180);
716 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_avx_128_fma_single
717 * Electrostatics interaction: ReactionField
718 * VdW interaction: LennardJones
719 * Geometry: Water4-Particle
720 * Calculate force/pot: Force
723 nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_avx_128_fma_single
724 (t_nblist * gmx_restrict nlist,
725 rvec * gmx_restrict xx,
726 rvec * gmx_restrict ff,
727 t_forcerec * gmx_restrict fr,
728 t_mdatoms * gmx_restrict mdatoms,
729 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
730 t_nrnb * gmx_restrict nrnb)
732 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
733 * just 0 for non-waters.
734 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
735 * jnr indices corresponding to data put in the four positions in the SIMD register.
737 int i_shift_offset,i_coord_offset,outeriter,inneriter;
738 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
739 int jnrA,jnrB,jnrC,jnrD;
740 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
741 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
742 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
744 real *shiftvec,*fshift,*x,*f;
745 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
747 __m128 fscal,rcutoff,rcutoff2,jidxall;
749 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
751 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
753 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
755 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
756 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
757 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
758 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
759 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
760 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
761 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
762 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
765 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
768 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
769 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
770 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
771 real rswitch_scalar,d_scalar;
772 __m128 dummy_mask,cutoff_mask;
773 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
774 __m128 one = _mm_set1_ps(1.0);
775 __m128 two = _mm_set1_ps(2.0);
781 jindex = nlist->jindex;
783 shiftidx = nlist->shift;
785 shiftvec = fr->shift_vec[0];
786 fshift = fr->fshift[0];
787 facel = _mm_set1_ps(fr->epsfac);
788 charge = mdatoms->chargeA;
789 krf = _mm_set1_ps(fr->ic->k_rf);
790 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
791 crf = _mm_set1_ps(fr->ic->c_rf);
792 nvdwtype = fr->ntype;
794 vdwtype = mdatoms->typeA;
796 /* Setup water-specific parameters */
797 inr = nlist->iinr[0];
798 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
799 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
800 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
801 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
803 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
804 rcutoff_scalar = fr->rcoulomb;
805 rcutoff = _mm_set1_ps(rcutoff_scalar);
806 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
808 rswitch_scalar = fr->rvdw_switch;
809 rswitch = _mm_set1_ps(rswitch_scalar);
810 /* Setup switch parameters */
811 d_scalar = rcutoff_scalar-rswitch_scalar;
812 d = _mm_set1_ps(d_scalar);
813 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
814 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
815 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
816 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
817 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
818 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
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 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
911 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
912 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
913 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
915 /* Load parameters for j particles */
916 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
917 charge+jnrC+0,charge+jnrD+0);
918 vdwjidx0A = 2*vdwtype[jnrA+0];
919 vdwjidx0B = 2*vdwtype[jnrB+0];
920 vdwjidx0C = 2*vdwtype[jnrC+0];
921 vdwjidx0D = 2*vdwtype[jnrD+0];
923 fjx0 = _mm_setzero_ps();
924 fjy0 = _mm_setzero_ps();
925 fjz0 = _mm_setzero_ps();
927 /**************************
928 * CALCULATE INTERACTIONS *
929 **************************/
931 if (gmx_mm_any_lt(rsq00,rcutoff2))
934 r00 = _mm_mul_ps(rsq00,rinv00);
936 /* Compute parameters for interactions between i and j atoms */
937 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
938 vdwparam+vdwioffset0+vdwjidx0B,
939 vdwparam+vdwioffset0+vdwjidx0C,
940 vdwparam+vdwioffset0+vdwjidx0D,
943 /* LENNARD-JONES DISPERSION/REPULSION */
945 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
946 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
947 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
948 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
949 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
951 d = _mm_sub_ps(r00,rswitch);
952 d = _mm_max_ps(d,_mm_setzero_ps());
953 d2 = _mm_mul_ps(d,d);
954 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
956 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
958 /* Evaluate switch function */
959 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
960 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
961 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
965 fscal = _mm_and_ps(fscal,cutoff_mask);
967 /* Update vectorial force */
968 fix0 = _mm_macc_ps(dx00,fscal,fix0);
969 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
970 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
972 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
973 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
974 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
978 /**************************
979 * CALCULATE INTERACTIONS *
980 **************************/
982 if (gmx_mm_any_lt(rsq10,rcutoff2))
985 /* Compute parameters for interactions between i and j atoms */
986 qq10 = _mm_mul_ps(iq1,jq0);
988 /* REACTION-FIELD ELECTROSTATICS */
989 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
991 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
995 fscal = _mm_and_ps(fscal,cutoff_mask);
997 /* Update vectorial force */
998 fix1 = _mm_macc_ps(dx10,fscal,fix1);
999 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1000 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1002 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1003 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1004 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1008 /**************************
1009 * CALCULATE INTERACTIONS *
1010 **************************/
1012 if (gmx_mm_any_lt(rsq20,rcutoff2))
1015 /* Compute parameters for interactions between i and j atoms */
1016 qq20 = _mm_mul_ps(iq2,jq0);
1018 /* REACTION-FIELD ELECTROSTATICS */
1019 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1021 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1025 fscal = _mm_and_ps(fscal,cutoff_mask);
1027 /* Update vectorial force */
1028 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1029 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1030 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1032 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1033 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1034 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1038 /**************************
1039 * CALCULATE INTERACTIONS *
1040 **************************/
1042 if (gmx_mm_any_lt(rsq30,rcutoff2))
1045 /* Compute parameters for interactions between i and j atoms */
1046 qq30 = _mm_mul_ps(iq3,jq0);
1048 /* REACTION-FIELD ELECTROSTATICS */
1049 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1051 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1055 fscal = _mm_and_ps(fscal,cutoff_mask);
1057 /* Update vectorial force */
1058 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1059 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1060 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1062 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1063 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1064 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1068 fjptrA = f+j_coord_offsetA;
1069 fjptrB = f+j_coord_offsetB;
1070 fjptrC = f+j_coord_offsetC;
1071 fjptrD = f+j_coord_offsetD;
1073 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1075 /* Inner loop uses 158 flops */
1078 if(jidx<j_index_end)
1081 /* Get j neighbor index, and coordinate index */
1082 jnrlistA = jjnr[jidx];
1083 jnrlistB = jjnr[jidx+1];
1084 jnrlistC = jjnr[jidx+2];
1085 jnrlistD = jjnr[jidx+3];
1086 /* Sign of each element will be negative for non-real atoms.
1087 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1088 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1090 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1091 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1092 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1093 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1094 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1095 j_coord_offsetA = DIM*jnrA;
1096 j_coord_offsetB = DIM*jnrB;
1097 j_coord_offsetC = DIM*jnrC;
1098 j_coord_offsetD = DIM*jnrD;
1100 /* load j atom coordinates */
1101 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1102 x+j_coord_offsetC,x+j_coord_offsetD,
1105 /* Calculate displacement vector */
1106 dx00 = _mm_sub_ps(ix0,jx0);
1107 dy00 = _mm_sub_ps(iy0,jy0);
1108 dz00 = _mm_sub_ps(iz0,jz0);
1109 dx10 = _mm_sub_ps(ix1,jx0);
1110 dy10 = _mm_sub_ps(iy1,jy0);
1111 dz10 = _mm_sub_ps(iz1,jz0);
1112 dx20 = _mm_sub_ps(ix2,jx0);
1113 dy20 = _mm_sub_ps(iy2,jy0);
1114 dz20 = _mm_sub_ps(iz2,jz0);
1115 dx30 = _mm_sub_ps(ix3,jx0);
1116 dy30 = _mm_sub_ps(iy3,jy0);
1117 dz30 = _mm_sub_ps(iz3,jz0);
1119 /* Calculate squared distance and things based on it */
1120 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1121 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1122 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1123 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1125 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1126 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1127 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1128 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1130 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1131 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1132 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1133 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1135 /* Load parameters for j particles */
1136 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1137 charge+jnrC+0,charge+jnrD+0);
1138 vdwjidx0A = 2*vdwtype[jnrA+0];
1139 vdwjidx0B = 2*vdwtype[jnrB+0];
1140 vdwjidx0C = 2*vdwtype[jnrC+0];
1141 vdwjidx0D = 2*vdwtype[jnrD+0];
1143 fjx0 = _mm_setzero_ps();
1144 fjy0 = _mm_setzero_ps();
1145 fjz0 = _mm_setzero_ps();
1147 /**************************
1148 * CALCULATE INTERACTIONS *
1149 **************************/
1151 if (gmx_mm_any_lt(rsq00,rcutoff2))
1154 r00 = _mm_mul_ps(rsq00,rinv00);
1155 r00 = _mm_andnot_ps(dummy_mask,r00);
1157 /* Compute parameters for interactions between i and j atoms */
1158 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1159 vdwparam+vdwioffset0+vdwjidx0B,
1160 vdwparam+vdwioffset0+vdwjidx0C,
1161 vdwparam+vdwioffset0+vdwjidx0D,
1164 /* LENNARD-JONES DISPERSION/REPULSION */
1166 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1167 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
1168 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
1169 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
1170 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
1172 d = _mm_sub_ps(r00,rswitch);
1173 d = _mm_max_ps(d,_mm_setzero_ps());
1174 d2 = _mm_mul_ps(d,d);
1175 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
1177 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
1179 /* Evaluate switch function */
1180 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1181 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
1182 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1186 fscal = _mm_and_ps(fscal,cutoff_mask);
1188 fscal = _mm_andnot_ps(dummy_mask,fscal);
1190 /* Update vectorial force */
1191 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1192 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1193 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1195 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1196 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1197 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1201 /**************************
1202 * CALCULATE INTERACTIONS *
1203 **************************/
1205 if (gmx_mm_any_lt(rsq10,rcutoff2))
1208 /* Compute parameters for interactions between i and j atoms */
1209 qq10 = _mm_mul_ps(iq1,jq0);
1211 /* REACTION-FIELD ELECTROSTATICS */
1212 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1214 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1218 fscal = _mm_and_ps(fscal,cutoff_mask);
1220 fscal = _mm_andnot_ps(dummy_mask,fscal);
1222 /* Update vectorial force */
1223 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1224 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1225 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1227 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1228 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1229 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1233 /**************************
1234 * CALCULATE INTERACTIONS *
1235 **************************/
1237 if (gmx_mm_any_lt(rsq20,rcutoff2))
1240 /* Compute parameters for interactions between i and j atoms */
1241 qq20 = _mm_mul_ps(iq2,jq0);
1243 /* REACTION-FIELD ELECTROSTATICS */
1244 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1246 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1250 fscal = _mm_and_ps(fscal,cutoff_mask);
1252 fscal = _mm_andnot_ps(dummy_mask,fscal);
1254 /* Update vectorial force */
1255 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1256 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1257 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1259 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1260 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1261 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1265 /**************************
1266 * CALCULATE INTERACTIONS *
1267 **************************/
1269 if (gmx_mm_any_lt(rsq30,rcutoff2))
1272 /* Compute parameters for interactions between i and j atoms */
1273 qq30 = _mm_mul_ps(iq3,jq0);
1275 /* REACTION-FIELD ELECTROSTATICS */
1276 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1278 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1282 fscal = _mm_and_ps(fscal,cutoff_mask);
1284 fscal = _mm_andnot_ps(dummy_mask,fscal);
1286 /* Update vectorial force */
1287 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1288 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1289 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1291 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1292 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1293 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1297 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1298 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1299 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1300 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1302 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1304 /* Inner loop uses 159 flops */
1307 /* End of innermost loop */
1309 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1310 f+i_coord_offset,fshift+i_shift_offset);
1312 /* Increment number of inner iterations */
1313 inneriter += j_index_end - j_index_start;
1315 /* Outer loop uses 24 flops */
1318 /* Increment number of outer iterations */
1321 /* Update outer/inner flops */
1323 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*159);