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_ElecRF_VdwLJ_GeomW3P1_VF_avx_128_fma_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRF_VdwLJ_GeomW3P1_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;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
92 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
93 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
94 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
97 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
100 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
101 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
102 __m128 dummy_mask,cutoff_mask;
103 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
104 __m128 one = _mm_set1_ps(1.0);
105 __m128 two = _mm_set1_ps(2.0);
111 jindex = nlist->jindex;
113 shiftidx = nlist->shift;
115 shiftvec = fr->shift_vec[0];
116 fshift = fr->fshift[0];
117 facel = _mm_set1_ps(fr->epsfac);
118 charge = mdatoms->chargeA;
119 krf = _mm_set1_ps(fr->ic->k_rf);
120 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
121 crf = _mm_set1_ps(fr->ic->c_rf);
122 nvdwtype = fr->ntype;
124 vdwtype = mdatoms->typeA;
126 /* Setup water-specific parameters */
127 inr = nlist->iinr[0];
128 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
129 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
130 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
131 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
133 /* Avoid stupid compiler warnings */
134 jnrA = jnrB = jnrC = jnrD = 0;
143 for(iidx=0;iidx<4*DIM;iidx++)
148 /* Start outer loop over neighborlists */
149 for(iidx=0; iidx<nri; iidx++)
151 /* Load shift vector for this list */
152 i_shift_offset = DIM*shiftidx[iidx];
154 /* Load limits for loop over neighbors */
155 j_index_start = jindex[iidx];
156 j_index_end = jindex[iidx+1];
158 /* Get outer coordinate index */
160 i_coord_offset = DIM*inr;
162 /* Load i particle coords and add shift vector */
163 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
164 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
166 fix0 = _mm_setzero_ps();
167 fiy0 = _mm_setzero_ps();
168 fiz0 = _mm_setzero_ps();
169 fix1 = _mm_setzero_ps();
170 fiy1 = _mm_setzero_ps();
171 fiz1 = _mm_setzero_ps();
172 fix2 = _mm_setzero_ps();
173 fiy2 = _mm_setzero_ps();
174 fiz2 = _mm_setzero_ps();
176 /* Reset potential sums */
177 velecsum = _mm_setzero_ps();
178 vvdwsum = _mm_setzero_ps();
180 /* Start inner kernel loop */
181 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
184 /* Get j neighbor index, and coordinate index */
189 j_coord_offsetA = DIM*jnrA;
190 j_coord_offsetB = DIM*jnrB;
191 j_coord_offsetC = DIM*jnrC;
192 j_coord_offsetD = DIM*jnrD;
194 /* load j atom coordinates */
195 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
196 x+j_coord_offsetC,x+j_coord_offsetD,
199 /* Calculate displacement vector */
200 dx00 = _mm_sub_ps(ix0,jx0);
201 dy00 = _mm_sub_ps(iy0,jy0);
202 dz00 = _mm_sub_ps(iz0,jz0);
203 dx10 = _mm_sub_ps(ix1,jx0);
204 dy10 = _mm_sub_ps(iy1,jy0);
205 dz10 = _mm_sub_ps(iz1,jz0);
206 dx20 = _mm_sub_ps(ix2,jx0);
207 dy20 = _mm_sub_ps(iy2,jy0);
208 dz20 = _mm_sub_ps(iz2,jz0);
210 /* Calculate squared distance and things based on it */
211 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
212 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
213 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
215 rinv00 = gmx_mm_invsqrt_ps(rsq00);
216 rinv10 = gmx_mm_invsqrt_ps(rsq10);
217 rinv20 = gmx_mm_invsqrt_ps(rsq20);
219 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
220 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
221 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
223 /* Load parameters for j particles */
224 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
225 charge+jnrC+0,charge+jnrD+0);
226 vdwjidx0A = 2*vdwtype[jnrA+0];
227 vdwjidx0B = 2*vdwtype[jnrB+0];
228 vdwjidx0C = 2*vdwtype[jnrC+0];
229 vdwjidx0D = 2*vdwtype[jnrD+0];
231 fjx0 = _mm_setzero_ps();
232 fjy0 = _mm_setzero_ps();
233 fjz0 = _mm_setzero_ps();
235 /**************************
236 * CALCULATE INTERACTIONS *
237 **************************/
239 /* Compute parameters for interactions between i and j atoms */
240 qq00 = _mm_mul_ps(iq0,jq0);
241 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
242 vdwparam+vdwioffset0+vdwjidx0B,
243 vdwparam+vdwioffset0+vdwjidx0C,
244 vdwparam+vdwioffset0+vdwjidx0D,
247 /* REACTION-FIELD ELECTROSTATICS */
248 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
249 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
251 /* LENNARD-JONES DISPERSION/REPULSION */
253 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
254 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
255 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
256 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
257 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
259 /* Update potential sum for this i atom from the interaction with this j atom. */
260 velecsum = _mm_add_ps(velecsum,velec);
261 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
263 fscal = _mm_add_ps(felec,fvdw);
265 /* Update vectorial force */
266 fix0 = _mm_macc_ps(dx00,fscal,fix0);
267 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
268 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
270 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
271 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
272 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
274 /**************************
275 * CALCULATE INTERACTIONS *
276 **************************/
278 /* Compute parameters for interactions between i and j atoms */
279 qq10 = _mm_mul_ps(iq1,jq0);
281 /* REACTION-FIELD ELECTROSTATICS */
282 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
283 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
285 /* Update potential sum for this i atom from the interaction with this j atom. */
286 velecsum = _mm_add_ps(velecsum,velec);
290 /* Update vectorial force */
291 fix1 = _mm_macc_ps(dx10,fscal,fix1);
292 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
293 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
295 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
296 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
297 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
299 /**************************
300 * CALCULATE INTERACTIONS *
301 **************************/
303 /* Compute parameters for interactions between i and j atoms */
304 qq20 = _mm_mul_ps(iq2,jq0);
306 /* REACTION-FIELD ELECTROSTATICS */
307 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
308 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
310 /* Update potential sum for this i atom from the interaction with this j atom. */
311 velecsum = _mm_add_ps(velecsum,velec);
315 /* Update vectorial force */
316 fix2 = _mm_macc_ps(dx20,fscal,fix2);
317 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
318 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
320 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
321 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
322 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
324 fjptrA = f+j_coord_offsetA;
325 fjptrB = f+j_coord_offsetB;
326 fjptrC = f+j_coord_offsetC;
327 fjptrD = f+j_coord_offsetD;
329 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
331 /* Inner loop uses 117 flops */
337 /* Get j neighbor index, and coordinate index */
338 jnrlistA = jjnr[jidx];
339 jnrlistB = jjnr[jidx+1];
340 jnrlistC = jjnr[jidx+2];
341 jnrlistD = jjnr[jidx+3];
342 /* Sign of each element will be negative for non-real atoms.
343 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
344 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
346 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
347 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
348 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
349 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
350 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
351 j_coord_offsetA = DIM*jnrA;
352 j_coord_offsetB = DIM*jnrB;
353 j_coord_offsetC = DIM*jnrC;
354 j_coord_offsetD = DIM*jnrD;
356 /* load j atom coordinates */
357 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
358 x+j_coord_offsetC,x+j_coord_offsetD,
361 /* Calculate displacement vector */
362 dx00 = _mm_sub_ps(ix0,jx0);
363 dy00 = _mm_sub_ps(iy0,jy0);
364 dz00 = _mm_sub_ps(iz0,jz0);
365 dx10 = _mm_sub_ps(ix1,jx0);
366 dy10 = _mm_sub_ps(iy1,jy0);
367 dz10 = _mm_sub_ps(iz1,jz0);
368 dx20 = _mm_sub_ps(ix2,jx0);
369 dy20 = _mm_sub_ps(iy2,jy0);
370 dz20 = _mm_sub_ps(iz2,jz0);
372 /* Calculate squared distance and things based on it */
373 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
374 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
375 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
377 rinv00 = gmx_mm_invsqrt_ps(rsq00);
378 rinv10 = gmx_mm_invsqrt_ps(rsq10);
379 rinv20 = gmx_mm_invsqrt_ps(rsq20);
381 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
382 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
383 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
385 /* Load parameters for j particles */
386 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
387 charge+jnrC+0,charge+jnrD+0);
388 vdwjidx0A = 2*vdwtype[jnrA+0];
389 vdwjidx0B = 2*vdwtype[jnrB+0];
390 vdwjidx0C = 2*vdwtype[jnrC+0];
391 vdwjidx0D = 2*vdwtype[jnrD+0];
393 fjx0 = _mm_setzero_ps();
394 fjy0 = _mm_setzero_ps();
395 fjz0 = _mm_setzero_ps();
397 /**************************
398 * CALCULATE INTERACTIONS *
399 **************************/
401 /* Compute parameters for interactions between i and j atoms */
402 qq00 = _mm_mul_ps(iq0,jq0);
403 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
404 vdwparam+vdwioffset0+vdwjidx0B,
405 vdwparam+vdwioffset0+vdwjidx0C,
406 vdwparam+vdwioffset0+vdwjidx0D,
409 /* REACTION-FIELD ELECTROSTATICS */
410 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
411 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
413 /* LENNARD-JONES DISPERSION/REPULSION */
415 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
416 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
417 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
418 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
419 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
421 /* Update potential sum for this i atom from the interaction with this j atom. */
422 velec = _mm_andnot_ps(dummy_mask,velec);
423 velecsum = _mm_add_ps(velecsum,velec);
424 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
425 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
427 fscal = _mm_add_ps(felec,fvdw);
429 fscal = _mm_andnot_ps(dummy_mask,fscal);
431 /* Update vectorial force */
432 fix0 = _mm_macc_ps(dx00,fscal,fix0);
433 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
434 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
436 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
437 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
438 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
440 /**************************
441 * CALCULATE INTERACTIONS *
442 **************************/
444 /* Compute parameters for interactions between i and j atoms */
445 qq10 = _mm_mul_ps(iq1,jq0);
447 /* REACTION-FIELD ELECTROSTATICS */
448 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
449 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
451 /* Update potential sum for this i atom from the interaction with this j atom. */
452 velec = _mm_andnot_ps(dummy_mask,velec);
453 velecsum = _mm_add_ps(velecsum,velec);
457 fscal = _mm_andnot_ps(dummy_mask,fscal);
459 /* Update vectorial force */
460 fix1 = _mm_macc_ps(dx10,fscal,fix1);
461 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
462 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
464 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
465 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
466 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
468 /**************************
469 * CALCULATE INTERACTIONS *
470 **************************/
472 /* Compute parameters for interactions between i and j atoms */
473 qq20 = _mm_mul_ps(iq2,jq0);
475 /* REACTION-FIELD ELECTROSTATICS */
476 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
477 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
479 /* Update potential sum for this i atom from the interaction with this j atom. */
480 velec = _mm_andnot_ps(dummy_mask,velec);
481 velecsum = _mm_add_ps(velecsum,velec);
485 fscal = _mm_andnot_ps(dummy_mask,fscal);
487 /* Update vectorial force */
488 fix2 = _mm_macc_ps(dx20,fscal,fix2);
489 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
490 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
492 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
493 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
494 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
496 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
497 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
498 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
499 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
501 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
503 /* Inner loop uses 117 flops */
506 /* End of innermost loop */
508 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
509 f+i_coord_offset,fshift+i_shift_offset);
512 /* Update potential energies */
513 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
514 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
516 /* Increment number of inner iterations */
517 inneriter += j_index_end - j_index_start;
519 /* Outer loop uses 20 flops */
522 /* Increment number of outer iterations */
525 /* Update outer/inner flops */
527 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*117);
530 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_single
531 * Electrostatics interaction: ReactionField
532 * VdW interaction: LennardJones
533 * Geometry: Water3-Particle
534 * Calculate force/pot: Force
537 nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_single
538 (t_nblist * gmx_restrict nlist,
539 rvec * gmx_restrict xx,
540 rvec * gmx_restrict ff,
541 t_forcerec * gmx_restrict fr,
542 t_mdatoms * gmx_restrict mdatoms,
543 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
544 t_nrnb * gmx_restrict nrnb)
546 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
547 * just 0 for non-waters.
548 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
549 * jnr indices corresponding to data put in the four positions in the SIMD register.
551 int i_shift_offset,i_coord_offset,outeriter,inneriter;
552 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
553 int jnrA,jnrB,jnrC,jnrD;
554 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
555 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
556 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
558 real *shiftvec,*fshift,*x,*f;
559 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
561 __m128 fscal,rcutoff,rcutoff2,jidxall;
563 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
565 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
567 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
568 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
569 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
570 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
571 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
572 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
573 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
576 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
579 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
580 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
581 __m128 dummy_mask,cutoff_mask;
582 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
583 __m128 one = _mm_set1_ps(1.0);
584 __m128 two = _mm_set1_ps(2.0);
590 jindex = nlist->jindex;
592 shiftidx = nlist->shift;
594 shiftvec = fr->shift_vec[0];
595 fshift = fr->fshift[0];
596 facel = _mm_set1_ps(fr->epsfac);
597 charge = mdatoms->chargeA;
598 krf = _mm_set1_ps(fr->ic->k_rf);
599 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
600 crf = _mm_set1_ps(fr->ic->c_rf);
601 nvdwtype = fr->ntype;
603 vdwtype = mdatoms->typeA;
605 /* Setup water-specific parameters */
606 inr = nlist->iinr[0];
607 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
608 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
609 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
610 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
612 /* Avoid stupid compiler warnings */
613 jnrA = jnrB = jnrC = jnrD = 0;
622 for(iidx=0;iidx<4*DIM;iidx++)
627 /* Start outer loop over neighborlists */
628 for(iidx=0; iidx<nri; iidx++)
630 /* Load shift vector for this list */
631 i_shift_offset = DIM*shiftidx[iidx];
633 /* Load limits for loop over neighbors */
634 j_index_start = jindex[iidx];
635 j_index_end = jindex[iidx+1];
637 /* Get outer coordinate index */
639 i_coord_offset = DIM*inr;
641 /* Load i particle coords and add shift vector */
642 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
643 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
645 fix0 = _mm_setzero_ps();
646 fiy0 = _mm_setzero_ps();
647 fiz0 = _mm_setzero_ps();
648 fix1 = _mm_setzero_ps();
649 fiy1 = _mm_setzero_ps();
650 fiz1 = _mm_setzero_ps();
651 fix2 = _mm_setzero_ps();
652 fiy2 = _mm_setzero_ps();
653 fiz2 = _mm_setzero_ps();
655 /* Start inner kernel loop */
656 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
659 /* Get j neighbor index, and coordinate index */
664 j_coord_offsetA = DIM*jnrA;
665 j_coord_offsetB = DIM*jnrB;
666 j_coord_offsetC = DIM*jnrC;
667 j_coord_offsetD = DIM*jnrD;
669 /* load j atom coordinates */
670 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
671 x+j_coord_offsetC,x+j_coord_offsetD,
674 /* Calculate displacement vector */
675 dx00 = _mm_sub_ps(ix0,jx0);
676 dy00 = _mm_sub_ps(iy0,jy0);
677 dz00 = _mm_sub_ps(iz0,jz0);
678 dx10 = _mm_sub_ps(ix1,jx0);
679 dy10 = _mm_sub_ps(iy1,jy0);
680 dz10 = _mm_sub_ps(iz1,jz0);
681 dx20 = _mm_sub_ps(ix2,jx0);
682 dy20 = _mm_sub_ps(iy2,jy0);
683 dz20 = _mm_sub_ps(iz2,jz0);
685 /* Calculate squared distance and things based on it */
686 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
687 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
688 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
690 rinv00 = gmx_mm_invsqrt_ps(rsq00);
691 rinv10 = gmx_mm_invsqrt_ps(rsq10);
692 rinv20 = gmx_mm_invsqrt_ps(rsq20);
694 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
695 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
696 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
698 /* Load parameters for j particles */
699 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
700 charge+jnrC+0,charge+jnrD+0);
701 vdwjidx0A = 2*vdwtype[jnrA+0];
702 vdwjidx0B = 2*vdwtype[jnrB+0];
703 vdwjidx0C = 2*vdwtype[jnrC+0];
704 vdwjidx0D = 2*vdwtype[jnrD+0];
706 fjx0 = _mm_setzero_ps();
707 fjy0 = _mm_setzero_ps();
708 fjz0 = _mm_setzero_ps();
710 /**************************
711 * CALCULATE INTERACTIONS *
712 **************************/
714 /* Compute parameters for interactions between i and j atoms */
715 qq00 = _mm_mul_ps(iq0,jq0);
716 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
717 vdwparam+vdwioffset0+vdwjidx0B,
718 vdwparam+vdwioffset0+vdwjidx0C,
719 vdwparam+vdwioffset0+vdwjidx0D,
722 /* REACTION-FIELD ELECTROSTATICS */
723 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
725 /* LENNARD-JONES DISPERSION/REPULSION */
727 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
728 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
730 fscal = _mm_add_ps(felec,fvdw);
732 /* Update vectorial force */
733 fix0 = _mm_macc_ps(dx00,fscal,fix0);
734 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
735 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
737 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
738 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
739 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
741 /**************************
742 * CALCULATE INTERACTIONS *
743 **************************/
745 /* Compute parameters for interactions between i and j atoms */
746 qq10 = _mm_mul_ps(iq1,jq0);
748 /* REACTION-FIELD ELECTROSTATICS */
749 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
753 /* Update vectorial force */
754 fix1 = _mm_macc_ps(dx10,fscal,fix1);
755 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
756 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
758 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
759 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
760 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
762 /**************************
763 * CALCULATE INTERACTIONS *
764 **************************/
766 /* Compute parameters for interactions between i and j atoms */
767 qq20 = _mm_mul_ps(iq2,jq0);
769 /* REACTION-FIELD ELECTROSTATICS */
770 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
774 /* Update vectorial force */
775 fix2 = _mm_macc_ps(dx20,fscal,fix2);
776 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
777 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
779 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
780 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
781 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
783 fjptrA = f+j_coord_offsetA;
784 fjptrB = f+j_coord_offsetB;
785 fjptrC = f+j_coord_offsetC;
786 fjptrD = f+j_coord_offsetD;
788 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
790 /* Inner loop uses 97 flops */
796 /* Get j neighbor index, and coordinate index */
797 jnrlistA = jjnr[jidx];
798 jnrlistB = jjnr[jidx+1];
799 jnrlistC = jjnr[jidx+2];
800 jnrlistD = jjnr[jidx+3];
801 /* Sign of each element will be negative for non-real atoms.
802 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
803 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
805 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
806 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
807 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
808 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
809 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
810 j_coord_offsetA = DIM*jnrA;
811 j_coord_offsetB = DIM*jnrB;
812 j_coord_offsetC = DIM*jnrC;
813 j_coord_offsetD = DIM*jnrD;
815 /* load j atom coordinates */
816 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
817 x+j_coord_offsetC,x+j_coord_offsetD,
820 /* Calculate displacement vector */
821 dx00 = _mm_sub_ps(ix0,jx0);
822 dy00 = _mm_sub_ps(iy0,jy0);
823 dz00 = _mm_sub_ps(iz0,jz0);
824 dx10 = _mm_sub_ps(ix1,jx0);
825 dy10 = _mm_sub_ps(iy1,jy0);
826 dz10 = _mm_sub_ps(iz1,jz0);
827 dx20 = _mm_sub_ps(ix2,jx0);
828 dy20 = _mm_sub_ps(iy2,jy0);
829 dz20 = _mm_sub_ps(iz2,jz0);
831 /* Calculate squared distance and things based on it */
832 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
833 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
834 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
836 rinv00 = gmx_mm_invsqrt_ps(rsq00);
837 rinv10 = gmx_mm_invsqrt_ps(rsq10);
838 rinv20 = gmx_mm_invsqrt_ps(rsq20);
840 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
841 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
842 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
844 /* Load parameters for j particles */
845 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
846 charge+jnrC+0,charge+jnrD+0);
847 vdwjidx0A = 2*vdwtype[jnrA+0];
848 vdwjidx0B = 2*vdwtype[jnrB+0];
849 vdwjidx0C = 2*vdwtype[jnrC+0];
850 vdwjidx0D = 2*vdwtype[jnrD+0];
852 fjx0 = _mm_setzero_ps();
853 fjy0 = _mm_setzero_ps();
854 fjz0 = _mm_setzero_ps();
856 /**************************
857 * CALCULATE INTERACTIONS *
858 **************************/
860 /* Compute parameters for interactions between i and j atoms */
861 qq00 = _mm_mul_ps(iq0,jq0);
862 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
863 vdwparam+vdwioffset0+vdwjidx0B,
864 vdwparam+vdwioffset0+vdwjidx0C,
865 vdwparam+vdwioffset0+vdwjidx0D,
868 /* REACTION-FIELD ELECTROSTATICS */
869 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
871 /* LENNARD-JONES DISPERSION/REPULSION */
873 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
874 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
876 fscal = _mm_add_ps(felec,fvdw);
878 fscal = _mm_andnot_ps(dummy_mask,fscal);
880 /* Update vectorial force */
881 fix0 = _mm_macc_ps(dx00,fscal,fix0);
882 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
883 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
885 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
886 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
887 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
889 /**************************
890 * CALCULATE INTERACTIONS *
891 **************************/
893 /* Compute parameters for interactions between i and j atoms */
894 qq10 = _mm_mul_ps(iq1,jq0);
896 /* REACTION-FIELD ELECTROSTATICS */
897 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
901 fscal = _mm_andnot_ps(dummy_mask,fscal);
903 /* Update vectorial force */
904 fix1 = _mm_macc_ps(dx10,fscal,fix1);
905 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
906 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
908 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
909 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
910 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
912 /**************************
913 * CALCULATE INTERACTIONS *
914 **************************/
916 /* Compute parameters for interactions between i and j atoms */
917 qq20 = _mm_mul_ps(iq2,jq0);
919 /* REACTION-FIELD ELECTROSTATICS */
920 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
924 fscal = _mm_andnot_ps(dummy_mask,fscal);
926 /* Update vectorial force */
927 fix2 = _mm_macc_ps(dx20,fscal,fix2);
928 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
929 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
931 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
932 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
933 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
935 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
936 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
937 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
938 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
940 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
942 /* Inner loop uses 97 flops */
945 /* End of innermost loop */
947 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
948 f+i_coord_offset,fshift+i_shift_offset);
950 /* Increment number of inner iterations */
951 inneriter += j_index_end - j_index_start;
953 /* Outer loop uses 18 flops */
956 /* Increment number of outer iterations */
959 /* Update outer/inner flops */
961 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*97);