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 "types/simple.h"
44 #include "gromacs/math/vec.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_VdwLJSw_GeomW4P1_VF_avx_128_fma_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwLJSw_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);
105 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
106 real rswitch_scalar,d_scalar;
107 __m128 dummy_mask,cutoff_mask;
108 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
109 __m128 one = _mm_set1_ps(1.0);
110 __m128 two = _mm_set1_ps(2.0);
116 jindex = nlist->jindex;
118 shiftidx = nlist->shift;
120 shiftvec = fr->shift_vec[0];
121 fshift = fr->fshift[0];
122 facel = _mm_set1_ps(fr->epsfac);
123 charge = mdatoms->chargeA;
124 krf = _mm_set1_ps(fr->ic->k_rf);
125 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
126 crf = _mm_set1_ps(fr->ic->c_rf);
127 nvdwtype = fr->ntype;
129 vdwtype = mdatoms->typeA;
131 /* Setup water-specific parameters */
132 inr = nlist->iinr[0];
133 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
134 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
135 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
136 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
138 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
139 rcutoff_scalar = fr->rcoulomb;
140 rcutoff = _mm_set1_ps(rcutoff_scalar);
141 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
143 rswitch_scalar = fr->rvdw_switch;
144 rswitch = _mm_set1_ps(rswitch_scalar);
145 /* Setup switch parameters */
146 d_scalar = rcutoff_scalar-rswitch_scalar;
147 d = _mm_set1_ps(d_scalar);
148 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
149 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
150 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
151 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
152 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
153 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
155 /* Avoid stupid compiler warnings */
156 jnrA = jnrB = jnrC = jnrD = 0;
165 for(iidx=0;iidx<4*DIM;iidx++)
170 /* Start outer loop over neighborlists */
171 for(iidx=0; iidx<nri; iidx++)
173 /* Load shift vector for this list */
174 i_shift_offset = DIM*shiftidx[iidx];
176 /* Load limits for loop over neighbors */
177 j_index_start = jindex[iidx];
178 j_index_end = jindex[iidx+1];
180 /* Get outer coordinate index */
182 i_coord_offset = DIM*inr;
184 /* Load i particle coords and add shift vector */
185 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
186 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
188 fix0 = _mm_setzero_ps();
189 fiy0 = _mm_setzero_ps();
190 fiz0 = _mm_setzero_ps();
191 fix1 = _mm_setzero_ps();
192 fiy1 = _mm_setzero_ps();
193 fiz1 = _mm_setzero_ps();
194 fix2 = _mm_setzero_ps();
195 fiy2 = _mm_setzero_ps();
196 fiz2 = _mm_setzero_ps();
197 fix3 = _mm_setzero_ps();
198 fiy3 = _mm_setzero_ps();
199 fiz3 = _mm_setzero_ps();
201 /* Reset potential sums */
202 velecsum = _mm_setzero_ps();
203 vvdwsum = _mm_setzero_ps();
205 /* Start inner kernel loop */
206 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
209 /* Get j neighbor index, and coordinate index */
214 j_coord_offsetA = DIM*jnrA;
215 j_coord_offsetB = DIM*jnrB;
216 j_coord_offsetC = DIM*jnrC;
217 j_coord_offsetD = DIM*jnrD;
219 /* load j atom coordinates */
220 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
221 x+j_coord_offsetC,x+j_coord_offsetD,
224 /* Calculate displacement vector */
225 dx00 = _mm_sub_ps(ix0,jx0);
226 dy00 = _mm_sub_ps(iy0,jy0);
227 dz00 = _mm_sub_ps(iz0,jz0);
228 dx10 = _mm_sub_ps(ix1,jx0);
229 dy10 = _mm_sub_ps(iy1,jy0);
230 dz10 = _mm_sub_ps(iz1,jz0);
231 dx20 = _mm_sub_ps(ix2,jx0);
232 dy20 = _mm_sub_ps(iy2,jy0);
233 dz20 = _mm_sub_ps(iz2,jz0);
234 dx30 = _mm_sub_ps(ix3,jx0);
235 dy30 = _mm_sub_ps(iy3,jy0);
236 dz30 = _mm_sub_ps(iz3,jz0);
238 /* Calculate squared distance and things based on it */
239 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
240 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
241 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
242 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
244 rinv00 = gmx_mm_invsqrt_ps(rsq00);
245 rinv10 = gmx_mm_invsqrt_ps(rsq10);
246 rinv20 = gmx_mm_invsqrt_ps(rsq20);
247 rinv30 = gmx_mm_invsqrt_ps(rsq30);
249 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
250 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
251 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
252 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
254 /* Load parameters for j particles */
255 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
256 charge+jnrC+0,charge+jnrD+0);
257 vdwjidx0A = 2*vdwtype[jnrA+0];
258 vdwjidx0B = 2*vdwtype[jnrB+0];
259 vdwjidx0C = 2*vdwtype[jnrC+0];
260 vdwjidx0D = 2*vdwtype[jnrD+0];
262 fjx0 = _mm_setzero_ps();
263 fjy0 = _mm_setzero_ps();
264 fjz0 = _mm_setzero_ps();
266 /**************************
267 * CALCULATE INTERACTIONS *
268 **************************/
270 if (gmx_mm_any_lt(rsq00,rcutoff2))
273 r00 = _mm_mul_ps(rsq00,rinv00);
275 /* Compute parameters for interactions between i and j atoms */
276 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
277 vdwparam+vdwioffset0+vdwjidx0B,
278 vdwparam+vdwioffset0+vdwjidx0C,
279 vdwparam+vdwioffset0+vdwjidx0D,
282 /* LENNARD-JONES DISPERSION/REPULSION */
284 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
285 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
286 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
287 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
288 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
290 d = _mm_sub_ps(r00,rswitch);
291 d = _mm_max_ps(d,_mm_setzero_ps());
292 d2 = _mm_mul_ps(d,d);
293 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
295 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
297 /* Evaluate switch function */
298 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
299 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
300 vvdw = _mm_mul_ps(vvdw,sw);
301 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
303 /* Update potential sum for this i atom from the interaction with this j atom. */
304 vvdw = _mm_and_ps(vvdw,cutoff_mask);
305 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
309 fscal = _mm_and_ps(fscal,cutoff_mask);
311 /* Update vectorial force */
312 fix0 = _mm_macc_ps(dx00,fscal,fix0);
313 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
314 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
316 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
317 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
318 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
322 /**************************
323 * CALCULATE INTERACTIONS *
324 **************************/
326 if (gmx_mm_any_lt(rsq10,rcutoff2))
329 /* Compute parameters for interactions between i and j atoms */
330 qq10 = _mm_mul_ps(iq1,jq0);
332 /* REACTION-FIELD ELECTROSTATICS */
333 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
334 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
336 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
338 /* Update potential sum for this i atom from the interaction with this j atom. */
339 velec = _mm_and_ps(velec,cutoff_mask);
340 velecsum = _mm_add_ps(velecsum,velec);
344 fscal = _mm_and_ps(fscal,cutoff_mask);
346 /* Update vectorial force */
347 fix1 = _mm_macc_ps(dx10,fscal,fix1);
348 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
349 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
351 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
352 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
353 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
357 /**************************
358 * CALCULATE INTERACTIONS *
359 **************************/
361 if (gmx_mm_any_lt(rsq20,rcutoff2))
364 /* Compute parameters for interactions between i and j atoms */
365 qq20 = _mm_mul_ps(iq2,jq0);
367 /* REACTION-FIELD ELECTROSTATICS */
368 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
369 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
371 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
373 /* Update potential sum for this i atom from the interaction with this j atom. */
374 velec = _mm_and_ps(velec,cutoff_mask);
375 velecsum = _mm_add_ps(velecsum,velec);
379 fscal = _mm_and_ps(fscal,cutoff_mask);
381 /* Update vectorial force */
382 fix2 = _mm_macc_ps(dx20,fscal,fix2);
383 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
384 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
386 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
387 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
388 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
392 /**************************
393 * CALCULATE INTERACTIONS *
394 **************************/
396 if (gmx_mm_any_lt(rsq30,rcutoff2))
399 /* Compute parameters for interactions between i and j atoms */
400 qq30 = _mm_mul_ps(iq3,jq0);
402 /* REACTION-FIELD ELECTROSTATICS */
403 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
404 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
406 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
408 /* Update potential sum for this i atom from the interaction with this j atom. */
409 velec = _mm_and_ps(velec,cutoff_mask);
410 velecsum = _mm_add_ps(velecsum,velec);
414 fscal = _mm_and_ps(fscal,cutoff_mask);
416 /* Update vectorial force */
417 fix3 = _mm_macc_ps(dx30,fscal,fix3);
418 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
419 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
421 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
422 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
423 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
427 fjptrA = f+j_coord_offsetA;
428 fjptrB = f+j_coord_offsetB;
429 fjptrC = f+j_coord_offsetC;
430 fjptrD = f+j_coord_offsetD;
432 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
434 /* Inner loop uses 179 flops */
440 /* Get j neighbor index, and coordinate index */
441 jnrlistA = jjnr[jidx];
442 jnrlistB = jjnr[jidx+1];
443 jnrlistC = jjnr[jidx+2];
444 jnrlistD = jjnr[jidx+3];
445 /* Sign of each element will be negative for non-real atoms.
446 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
447 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
449 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
450 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
451 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
452 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
453 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
454 j_coord_offsetA = DIM*jnrA;
455 j_coord_offsetB = DIM*jnrB;
456 j_coord_offsetC = DIM*jnrC;
457 j_coord_offsetD = DIM*jnrD;
459 /* load j atom coordinates */
460 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
461 x+j_coord_offsetC,x+j_coord_offsetD,
464 /* Calculate displacement vector */
465 dx00 = _mm_sub_ps(ix0,jx0);
466 dy00 = _mm_sub_ps(iy0,jy0);
467 dz00 = _mm_sub_ps(iz0,jz0);
468 dx10 = _mm_sub_ps(ix1,jx0);
469 dy10 = _mm_sub_ps(iy1,jy0);
470 dz10 = _mm_sub_ps(iz1,jz0);
471 dx20 = _mm_sub_ps(ix2,jx0);
472 dy20 = _mm_sub_ps(iy2,jy0);
473 dz20 = _mm_sub_ps(iz2,jz0);
474 dx30 = _mm_sub_ps(ix3,jx0);
475 dy30 = _mm_sub_ps(iy3,jy0);
476 dz30 = _mm_sub_ps(iz3,jz0);
478 /* Calculate squared distance and things based on it */
479 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
480 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
481 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
482 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
484 rinv00 = gmx_mm_invsqrt_ps(rsq00);
485 rinv10 = gmx_mm_invsqrt_ps(rsq10);
486 rinv20 = gmx_mm_invsqrt_ps(rsq20);
487 rinv30 = gmx_mm_invsqrt_ps(rsq30);
489 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
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 if (gmx_mm_any_lt(rsq00,rcutoff2))
513 r00 = _mm_mul_ps(rsq00,rinv00);
514 r00 = _mm_andnot_ps(dummy_mask,r00);
516 /* Compute parameters for interactions between i and j atoms */
517 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
518 vdwparam+vdwioffset0+vdwjidx0B,
519 vdwparam+vdwioffset0+vdwjidx0C,
520 vdwparam+vdwioffset0+vdwjidx0D,
523 /* LENNARD-JONES DISPERSION/REPULSION */
525 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
526 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
527 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
528 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
529 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
531 d = _mm_sub_ps(r00,rswitch);
532 d = _mm_max_ps(d,_mm_setzero_ps());
533 d2 = _mm_mul_ps(d,d);
534 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
536 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
538 /* Evaluate switch function */
539 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
540 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
541 vvdw = _mm_mul_ps(vvdw,sw);
542 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
544 /* Update potential sum for this i atom from the interaction with this j atom. */
545 vvdw = _mm_and_ps(vvdw,cutoff_mask);
546 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
547 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
551 fscal = _mm_and_ps(fscal,cutoff_mask);
553 fscal = _mm_andnot_ps(dummy_mask,fscal);
555 /* Update vectorial force */
556 fix0 = _mm_macc_ps(dx00,fscal,fix0);
557 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
558 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
560 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
561 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
562 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
566 /**************************
567 * CALCULATE INTERACTIONS *
568 **************************/
570 if (gmx_mm_any_lt(rsq10,rcutoff2))
573 /* Compute parameters for interactions between i and j atoms */
574 qq10 = _mm_mul_ps(iq1,jq0);
576 /* REACTION-FIELD ELECTROSTATICS */
577 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
578 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
580 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
582 /* Update potential sum for this i atom from the interaction with this j atom. */
583 velec = _mm_and_ps(velec,cutoff_mask);
584 velec = _mm_andnot_ps(dummy_mask,velec);
585 velecsum = _mm_add_ps(velecsum,velec);
589 fscal = _mm_and_ps(fscal,cutoff_mask);
591 fscal = _mm_andnot_ps(dummy_mask,fscal);
593 /* Update vectorial force */
594 fix1 = _mm_macc_ps(dx10,fscal,fix1);
595 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
596 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
598 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
599 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
600 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
604 /**************************
605 * CALCULATE INTERACTIONS *
606 **************************/
608 if (gmx_mm_any_lt(rsq20,rcutoff2))
611 /* Compute parameters for interactions between i and j atoms */
612 qq20 = _mm_mul_ps(iq2,jq0);
614 /* REACTION-FIELD ELECTROSTATICS */
615 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
616 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
618 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
620 /* Update potential sum for this i atom from the interaction with this j atom. */
621 velec = _mm_and_ps(velec,cutoff_mask);
622 velec = _mm_andnot_ps(dummy_mask,velec);
623 velecsum = _mm_add_ps(velecsum,velec);
627 fscal = _mm_and_ps(fscal,cutoff_mask);
629 fscal = _mm_andnot_ps(dummy_mask,fscal);
631 /* Update vectorial force */
632 fix2 = _mm_macc_ps(dx20,fscal,fix2);
633 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
634 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
636 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
637 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
638 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
642 /**************************
643 * CALCULATE INTERACTIONS *
644 **************************/
646 if (gmx_mm_any_lt(rsq30,rcutoff2))
649 /* Compute parameters for interactions between i and j atoms */
650 qq30 = _mm_mul_ps(iq3,jq0);
652 /* REACTION-FIELD ELECTROSTATICS */
653 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
654 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
656 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
658 /* Update potential sum for this i atom from the interaction with this j atom. */
659 velec = _mm_and_ps(velec,cutoff_mask);
660 velec = _mm_andnot_ps(dummy_mask,velec);
661 velecsum = _mm_add_ps(velecsum,velec);
665 fscal = _mm_and_ps(fscal,cutoff_mask);
667 fscal = _mm_andnot_ps(dummy_mask,fscal);
669 /* Update vectorial force */
670 fix3 = _mm_macc_ps(dx30,fscal,fix3);
671 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
672 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
674 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
675 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
676 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
680 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
681 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
682 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
683 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
685 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
687 /* Inner loop uses 180 flops */
690 /* End of innermost loop */
692 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
693 f+i_coord_offset,fshift+i_shift_offset);
696 /* Update potential energies */
697 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
698 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
700 /* Increment number of inner iterations */
701 inneriter += j_index_end - j_index_start;
703 /* Outer loop uses 26 flops */
706 /* Increment number of outer iterations */
709 /* Update outer/inner flops */
711 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*180);
714 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_avx_128_fma_single
715 * Electrostatics interaction: ReactionField
716 * VdW interaction: LennardJones
717 * Geometry: Water4-Particle
718 * Calculate force/pot: Force
721 nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_avx_128_fma_single
722 (t_nblist * gmx_restrict nlist,
723 rvec * gmx_restrict xx,
724 rvec * gmx_restrict ff,
725 t_forcerec * gmx_restrict fr,
726 t_mdatoms * gmx_restrict mdatoms,
727 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
728 t_nrnb * gmx_restrict nrnb)
730 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
731 * just 0 for non-waters.
732 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
733 * jnr indices corresponding to data put in the four positions in the SIMD register.
735 int i_shift_offset,i_coord_offset,outeriter,inneriter;
736 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
737 int jnrA,jnrB,jnrC,jnrD;
738 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
739 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
740 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
742 real *shiftvec,*fshift,*x,*f;
743 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
745 __m128 fscal,rcutoff,rcutoff2,jidxall;
747 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
749 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
751 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
753 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
754 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
755 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
756 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
757 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
758 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
759 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
760 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
763 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
766 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
767 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
768 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
769 real rswitch_scalar,d_scalar;
770 __m128 dummy_mask,cutoff_mask;
771 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
772 __m128 one = _mm_set1_ps(1.0);
773 __m128 two = _mm_set1_ps(2.0);
779 jindex = nlist->jindex;
781 shiftidx = nlist->shift;
783 shiftvec = fr->shift_vec[0];
784 fshift = fr->fshift[0];
785 facel = _mm_set1_ps(fr->epsfac);
786 charge = mdatoms->chargeA;
787 krf = _mm_set1_ps(fr->ic->k_rf);
788 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
789 crf = _mm_set1_ps(fr->ic->c_rf);
790 nvdwtype = fr->ntype;
792 vdwtype = mdatoms->typeA;
794 /* Setup water-specific parameters */
795 inr = nlist->iinr[0];
796 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
797 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
798 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
799 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
801 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
802 rcutoff_scalar = fr->rcoulomb;
803 rcutoff = _mm_set1_ps(rcutoff_scalar);
804 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
806 rswitch_scalar = fr->rvdw_switch;
807 rswitch = _mm_set1_ps(rswitch_scalar);
808 /* Setup switch parameters */
809 d_scalar = rcutoff_scalar-rswitch_scalar;
810 d = _mm_set1_ps(d_scalar);
811 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
812 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
813 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
814 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
815 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
816 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
818 /* Avoid stupid compiler warnings */
819 jnrA = jnrB = jnrC = jnrD = 0;
828 for(iidx=0;iidx<4*DIM;iidx++)
833 /* Start outer loop over neighborlists */
834 for(iidx=0; iidx<nri; iidx++)
836 /* Load shift vector for this list */
837 i_shift_offset = DIM*shiftidx[iidx];
839 /* Load limits for loop over neighbors */
840 j_index_start = jindex[iidx];
841 j_index_end = jindex[iidx+1];
843 /* Get outer coordinate index */
845 i_coord_offset = DIM*inr;
847 /* Load i particle coords and add shift vector */
848 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
849 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
851 fix0 = _mm_setzero_ps();
852 fiy0 = _mm_setzero_ps();
853 fiz0 = _mm_setzero_ps();
854 fix1 = _mm_setzero_ps();
855 fiy1 = _mm_setzero_ps();
856 fiz1 = _mm_setzero_ps();
857 fix2 = _mm_setzero_ps();
858 fiy2 = _mm_setzero_ps();
859 fiz2 = _mm_setzero_ps();
860 fix3 = _mm_setzero_ps();
861 fiy3 = _mm_setzero_ps();
862 fiz3 = _mm_setzero_ps();
864 /* Start inner kernel loop */
865 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
868 /* Get j neighbor index, and coordinate index */
873 j_coord_offsetA = DIM*jnrA;
874 j_coord_offsetB = DIM*jnrB;
875 j_coord_offsetC = DIM*jnrC;
876 j_coord_offsetD = DIM*jnrD;
878 /* load j atom coordinates */
879 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
880 x+j_coord_offsetC,x+j_coord_offsetD,
883 /* Calculate displacement vector */
884 dx00 = _mm_sub_ps(ix0,jx0);
885 dy00 = _mm_sub_ps(iy0,jy0);
886 dz00 = _mm_sub_ps(iz0,jz0);
887 dx10 = _mm_sub_ps(ix1,jx0);
888 dy10 = _mm_sub_ps(iy1,jy0);
889 dz10 = _mm_sub_ps(iz1,jz0);
890 dx20 = _mm_sub_ps(ix2,jx0);
891 dy20 = _mm_sub_ps(iy2,jy0);
892 dz20 = _mm_sub_ps(iz2,jz0);
893 dx30 = _mm_sub_ps(ix3,jx0);
894 dy30 = _mm_sub_ps(iy3,jy0);
895 dz30 = _mm_sub_ps(iz3,jz0);
897 /* Calculate squared distance and things based on it */
898 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
899 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
900 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
901 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
903 rinv00 = gmx_mm_invsqrt_ps(rsq00);
904 rinv10 = gmx_mm_invsqrt_ps(rsq10);
905 rinv20 = gmx_mm_invsqrt_ps(rsq20);
906 rinv30 = gmx_mm_invsqrt_ps(rsq30);
908 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
909 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
910 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
911 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
913 /* Load parameters for j particles */
914 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
915 charge+jnrC+0,charge+jnrD+0);
916 vdwjidx0A = 2*vdwtype[jnrA+0];
917 vdwjidx0B = 2*vdwtype[jnrB+0];
918 vdwjidx0C = 2*vdwtype[jnrC+0];
919 vdwjidx0D = 2*vdwtype[jnrD+0];
921 fjx0 = _mm_setzero_ps();
922 fjy0 = _mm_setzero_ps();
923 fjz0 = _mm_setzero_ps();
925 /**************************
926 * CALCULATE INTERACTIONS *
927 **************************/
929 if (gmx_mm_any_lt(rsq00,rcutoff2))
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 /* LENNARD-JONES DISPERSION/REPULSION */
943 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
944 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
945 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
946 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
947 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
949 d = _mm_sub_ps(r00,rswitch);
950 d = _mm_max_ps(d,_mm_setzero_ps());
951 d2 = _mm_mul_ps(d,d);
952 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
954 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
956 /* Evaluate switch function */
957 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
958 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
959 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
963 fscal = _mm_and_ps(fscal,cutoff_mask);
965 /* Update vectorial force */
966 fix0 = _mm_macc_ps(dx00,fscal,fix0);
967 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
968 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
970 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
971 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
972 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
976 /**************************
977 * CALCULATE INTERACTIONS *
978 **************************/
980 if (gmx_mm_any_lt(rsq10,rcutoff2))
983 /* Compute parameters for interactions between i and j atoms */
984 qq10 = _mm_mul_ps(iq1,jq0);
986 /* REACTION-FIELD ELECTROSTATICS */
987 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
989 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
993 fscal = _mm_and_ps(fscal,cutoff_mask);
995 /* Update vectorial force */
996 fix1 = _mm_macc_ps(dx10,fscal,fix1);
997 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
998 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1000 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1001 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1002 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1006 /**************************
1007 * CALCULATE INTERACTIONS *
1008 **************************/
1010 if (gmx_mm_any_lt(rsq20,rcutoff2))
1013 /* Compute parameters for interactions between i and j atoms */
1014 qq20 = _mm_mul_ps(iq2,jq0);
1016 /* REACTION-FIELD ELECTROSTATICS */
1017 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1019 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1023 fscal = _mm_and_ps(fscal,cutoff_mask);
1025 /* Update vectorial force */
1026 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1027 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1028 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1030 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1031 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1032 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1036 /**************************
1037 * CALCULATE INTERACTIONS *
1038 **************************/
1040 if (gmx_mm_any_lt(rsq30,rcutoff2))
1043 /* Compute parameters for interactions between i and j atoms */
1044 qq30 = _mm_mul_ps(iq3,jq0);
1046 /* REACTION-FIELD ELECTROSTATICS */
1047 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1049 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1053 fscal = _mm_and_ps(fscal,cutoff_mask);
1055 /* Update vectorial force */
1056 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1057 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1058 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1060 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1061 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1062 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1066 fjptrA = f+j_coord_offsetA;
1067 fjptrB = f+j_coord_offsetB;
1068 fjptrC = f+j_coord_offsetC;
1069 fjptrD = f+j_coord_offsetD;
1071 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1073 /* Inner loop uses 158 flops */
1076 if(jidx<j_index_end)
1079 /* Get j neighbor index, and coordinate index */
1080 jnrlistA = jjnr[jidx];
1081 jnrlistB = jjnr[jidx+1];
1082 jnrlistC = jjnr[jidx+2];
1083 jnrlistD = jjnr[jidx+3];
1084 /* Sign of each element will be negative for non-real atoms.
1085 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1086 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1088 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1089 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1090 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1091 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1092 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1093 j_coord_offsetA = DIM*jnrA;
1094 j_coord_offsetB = DIM*jnrB;
1095 j_coord_offsetC = DIM*jnrC;
1096 j_coord_offsetD = DIM*jnrD;
1098 /* load j atom coordinates */
1099 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1100 x+j_coord_offsetC,x+j_coord_offsetD,
1103 /* Calculate displacement vector */
1104 dx00 = _mm_sub_ps(ix0,jx0);
1105 dy00 = _mm_sub_ps(iy0,jy0);
1106 dz00 = _mm_sub_ps(iz0,jz0);
1107 dx10 = _mm_sub_ps(ix1,jx0);
1108 dy10 = _mm_sub_ps(iy1,jy0);
1109 dz10 = _mm_sub_ps(iz1,jz0);
1110 dx20 = _mm_sub_ps(ix2,jx0);
1111 dy20 = _mm_sub_ps(iy2,jy0);
1112 dz20 = _mm_sub_ps(iz2,jz0);
1113 dx30 = _mm_sub_ps(ix3,jx0);
1114 dy30 = _mm_sub_ps(iy3,jy0);
1115 dz30 = _mm_sub_ps(iz3,jz0);
1117 /* Calculate squared distance and things based on it */
1118 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1119 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1120 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1121 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1123 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1124 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1125 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1126 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1128 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1129 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1130 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1131 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1133 /* Load parameters for j particles */
1134 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1135 charge+jnrC+0,charge+jnrD+0);
1136 vdwjidx0A = 2*vdwtype[jnrA+0];
1137 vdwjidx0B = 2*vdwtype[jnrB+0];
1138 vdwjidx0C = 2*vdwtype[jnrC+0];
1139 vdwjidx0D = 2*vdwtype[jnrD+0];
1141 fjx0 = _mm_setzero_ps();
1142 fjy0 = _mm_setzero_ps();
1143 fjz0 = _mm_setzero_ps();
1145 /**************************
1146 * CALCULATE INTERACTIONS *
1147 **************************/
1149 if (gmx_mm_any_lt(rsq00,rcutoff2))
1152 r00 = _mm_mul_ps(rsq00,rinv00);
1153 r00 = _mm_andnot_ps(dummy_mask,r00);
1155 /* Compute parameters for interactions between i and j atoms */
1156 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1157 vdwparam+vdwioffset0+vdwjidx0B,
1158 vdwparam+vdwioffset0+vdwjidx0C,
1159 vdwparam+vdwioffset0+vdwjidx0D,
1162 /* LENNARD-JONES DISPERSION/REPULSION */
1164 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1165 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
1166 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
1167 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
1168 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
1170 d = _mm_sub_ps(r00,rswitch);
1171 d = _mm_max_ps(d,_mm_setzero_ps());
1172 d2 = _mm_mul_ps(d,d);
1173 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
1175 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
1177 /* Evaluate switch function */
1178 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1179 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
1180 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1184 fscal = _mm_and_ps(fscal,cutoff_mask);
1186 fscal = _mm_andnot_ps(dummy_mask,fscal);
1188 /* Update vectorial force */
1189 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1190 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1191 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1193 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1194 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1195 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1199 /**************************
1200 * CALCULATE INTERACTIONS *
1201 **************************/
1203 if (gmx_mm_any_lt(rsq10,rcutoff2))
1206 /* Compute parameters for interactions between i and j atoms */
1207 qq10 = _mm_mul_ps(iq1,jq0);
1209 /* REACTION-FIELD ELECTROSTATICS */
1210 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1212 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1216 fscal = _mm_and_ps(fscal,cutoff_mask);
1218 fscal = _mm_andnot_ps(dummy_mask,fscal);
1220 /* Update vectorial force */
1221 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1222 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1223 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1225 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1226 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1227 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1231 /**************************
1232 * CALCULATE INTERACTIONS *
1233 **************************/
1235 if (gmx_mm_any_lt(rsq20,rcutoff2))
1238 /* Compute parameters for interactions between i and j atoms */
1239 qq20 = _mm_mul_ps(iq2,jq0);
1241 /* REACTION-FIELD ELECTROSTATICS */
1242 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1244 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1248 fscal = _mm_and_ps(fscal,cutoff_mask);
1250 fscal = _mm_andnot_ps(dummy_mask,fscal);
1252 /* Update vectorial force */
1253 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1254 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1255 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1257 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1258 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1259 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1263 /**************************
1264 * CALCULATE INTERACTIONS *
1265 **************************/
1267 if (gmx_mm_any_lt(rsq30,rcutoff2))
1270 /* Compute parameters for interactions between i and j atoms */
1271 qq30 = _mm_mul_ps(iq3,jq0);
1273 /* REACTION-FIELD ELECTROSTATICS */
1274 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1276 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1280 fscal = _mm_and_ps(fscal,cutoff_mask);
1282 fscal = _mm_andnot_ps(dummy_mask,fscal);
1284 /* Update vectorial force */
1285 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1286 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1287 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1289 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1290 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1291 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1295 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1296 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1297 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1298 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1300 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1302 /* Inner loop uses 159 flops */
1305 /* End of innermost loop */
1307 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1308 f+i_coord_offset,fshift+i_shift_offset);
1310 /* Increment number of inner iterations */
1311 inneriter += j_index_end - j_index_start;
1313 /* Outer loop uses 24 flops */
1316 /* Increment number of outer iterations */
1319 /* Update outer/inner flops */
1321 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*159);