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 "gmx_math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomW3P1_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Water3-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRF_VdwLJ_GeomW3P1_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;
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 velec,felec,velecsum,facel,crf,krf,krf2;
99 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
102 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
103 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
104 __m128 dummy_mask,cutoff_mask;
105 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
106 __m128 one = _mm_set1_ps(1.0);
107 __m128 two = _mm_set1_ps(2.0);
113 jindex = nlist->jindex;
115 shiftidx = nlist->shift;
117 shiftvec = fr->shift_vec[0];
118 fshift = fr->fshift[0];
119 facel = _mm_set1_ps(fr->epsfac);
120 charge = mdatoms->chargeA;
121 krf = _mm_set1_ps(fr->ic->k_rf);
122 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
123 crf = _mm_set1_ps(fr->ic->c_rf);
124 nvdwtype = fr->ntype;
126 vdwtype = mdatoms->typeA;
128 /* Setup water-specific parameters */
129 inr = nlist->iinr[0];
130 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
131 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
132 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
133 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
135 /* Avoid stupid compiler warnings */
136 jnrA = jnrB = jnrC = jnrD = 0;
145 for(iidx=0;iidx<4*DIM;iidx++)
150 /* Start outer loop over neighborlists */
151 for(iidx=0; iidx<nri; iidx++)
153 /* Load shift vector for this list */
154 i_shift_offset = DIM*shiftidx[iidx];
156 /* Load limits for loop over neighbors */
157 j_index_start = jindex[iidx];
158 j_index_end = jindex[iidx+1];
160 /* Get outer coordinate index */
162 i_coord_offset = DIM*inr;
164 /* Load i particle coords and add shift vector */
165 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
166 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
168 fix0 = _mm_setzero_ps();
169 fiy0 = _mm_setzero_ps();
170 fiz0 = _mm_setzero_ps();
171 fix1 = _mm_setzero_ps();
172 fiy1 = _mm_setzero_ps();
173 fiz1 = _mm_setzero_ps();
174 fix2 = _mm_setzero_ps();
175 fiy2 = _mm_setzero_ps();
176 fiz2 = _mm_setzero_ps();
178 /* Reset potential sums */
179 velecsum = _mm_setzero_ps();
180 vvdwsum = _mm_setzero_ps();
182 /* Start inner kernel loop */
183 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
186 /* Get j neighbor index, and coordinate index */
191 j_coord_offsetA = DIM*jnrA;
192 j_coord_offsetB = DIM*jnrB;
193 j_coord_offsetC = DIM*jnrC;
194 j_coord_offsetD = DIM*jnrD;
196 /* load j atom coordinates */
197 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
198 x+j_coord_offsetC,x+j_coord_offsetD,
201 /* Calculate displacement vector */
202 dx00 = _mm_sub_ps(ix0,jx0);
203 dy00 = _mm_sub_ps(iy0,jy0);
204 dz00 = _mm_sub_ps(iz0,jz0);
205 dx10 = _mm_sub_ps(ix1,jx0);
206 dy10 = _mm_sub_ps(iy1,jy0);
207 dz10 = _mm_sub_ps(iz1,jz0);
208 dx20 = _mm_sub_ps(ix2,jx0);
209 dy20 = _mm_sub_ps(iy2,jy0);
210 dz20 = _mm_sub_ps(iz2,jz0);
212 /* Calculate squared distance and things based on it */
213 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
214 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
215 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
217 rinv00 = gmx_mm_invsqrt_ps(rsq00);
218 rinv10 = gmx_mm_invsqrt_ps(rsq10);
219 rinv20 = gmx_mm_invsqrt_ps(rsq20);
221 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
222 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
223 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
225 /* Load parameters for j particles */
226 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
227 charge+jnrC+0,charge+jnrD+0);
228 vdwjidx0A = 2*vdwtype[jnrA+0];
229 vdwjidx0B = 2*vdwtype[jnrB+0];
230 vdwjidx0C = 2*vdwtype[jnrC+0];
231 vdwjidx0D = 2*vdwtype[jnrD+0];
233 fjx0 = _mm_setzero_ps();
234 fjy0 = _mm_setzero_ps();
235 fjz0 = _mm_setzero_ps();
237 /**************************
238 * CALCULATE INTERACTIONS *
239 **************************/
241 /* Compute parameters for interactions between i and j atoms */
242 qq00 = _mm_mul_ps(iq0,jq0);
243 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
244 vdwparam+vdwioffset0+vdwjidx0B,
245 vdwparam+vdwioffset0+vdwjidx0C,
246 vdwparam+vdwioffset0+vdwjidx0D,
249 /* REACTION-FIELD ELECTROSTATICS */
250 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
251 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
253 /* LENNARD-JONES DISPERSION/REPULSION */
255 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
256 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
257 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
258 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
259 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
261 /* Update potential sum for this i atom from the interaction with this j atom. */
262 velecsum = _mm_add_ps(velecsum,velec);
263 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
265 fscal = _mm_add_ps(felec,fvdw);
267 /* Update vectorial force */
268 fix0 = _mm_macc_ps(dx00,fscal,fix0);
269 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
270 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
272 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
273 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
274 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
276 /**************************
277 * CALCULATE INTERACTIONS *
278 **************************/
280 /* Compute parameters for interactions between i and j atoms */
281 qq10 = _mm_mul_ps(iq1,jq0);
283 /* REACTION-FIELD ELECTROSTATICS */
284 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
285 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
287 /* Update potential sum for this i atom from the interaction with this j atom. */
288 velecsum = _mm_add_ps(velecsum,velec);
292 /* Update vectorial force */
293 fix1 = _mm_macc_ps(dx10,fscal,fix1);
294 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
295 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
297 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
298 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
299 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
301 /**************************
302 * CALCULATE INTERACTIONS *
303 **************************/
305 /* Compute parameters for interactions between i and j atoms */
306 qq20 = _mm_mul_ps(iq2,jq0);
308 /* REACTION-FIELD ELECTROSTATICS */
309 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
310 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
312 /* Update potential sum for this i atom from the interaction with this j atom. */
313 velecsum = _mm_add_ps(velecsum,velec);
317 /* Update vectorial force */
318 fix2 = _mm_macc_ps(dx20,fscal,fix2);
319 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
320 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
322 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
323 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
324 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
326 fjptrA = f+j_coord_offsetA;
327 fjptrB = f+j_coord_offsetB;
328 fjptrC = f+j_coord_offsetC;
329 fjptrD = f+j_coord_offsetD;
331 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
333 /* Inner loop uses 117 flops */
339 /* Get j neighbor index, and coordinate index */
340 jnrlistA = jjnr[jidx];
341 jnrlistB = jjnr[jidx+1];
342 jnrlistC = jjnr[jidx+2];
343 jnrlistD = jjnr[jidx+3];
344 /* Sign of each element will be negative for non-real atoms.
345 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
346 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
348 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
349 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
350 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
351 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
352 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
353 j_coord_offsetA = DIM*jnrA;
354 j_coord_offsetB = DIM*jnrB;
355 j_coord_offsetC = DIM*jnrC;
356 j_coord_offsetD = DIM*jnrD;
358 /* load j atom coordinates */
359 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
360 x+j_coord_offsetC,x+j_coord_offsetD,
363 /* Calculate displacement vector */
364 dx00 = _mm_sub_ps(ix0,jx0);
365 dy00 = _mm_sub_ps(iy0,jy0);
366 dz00 = _mm_sub_ps(iz0,jz0);
367 dx10 = _mm_sub_ps(ix1,jx0);
368 dy10 = _mm_sub_ps(iy1,jy0);
369 dz10 = _mm_sub_ps(iz1,jz0);
370 dx20 = _mm_sub_ps(ix2,jx0);
371 dy20 = _mm_sub_ps(iy2,jy0);
372 dz20 = _mm_sub_ps(iz2,jz0);
374 /* Calculate squared distance and things based on it */
375 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
376 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
377 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
379 rinv00 = gmx_mm_invsqrt_ps(rsq00);
380 rinv10 = gmx_mm_invsqrt_ps(rsq10);
381 rinv20 = gmx_mm_invsqrt_ps(rsq20);
383 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
384 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
385 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
387 /* Load parameters for j particles */
388 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
389 charge+jnrC+0,charge+jnrD+0);
390 vdwjidx0A = 2*vdwtype[jnrA+0];
391 vdwjidx0B = 2*vdwtype[jnrB+0];
392 vdwjidx0C = 2*vdwtype[jnrC+0];
393 vdwjidx0D = 2*vdwtype[jnrD+0];
395 fjx0 = _mm_setzero_ps();
396 fjy0 = _mm_setzero_ps();
397 fjz0 = _mm_setzero_ps();
399 /**************************
400 * CALCULATE INTERACTIONS *
401 **************************/
403 /* Compute parameters for interactions between i and j atoms */
404 qq00 = _mm_mul_ps(iq0,jq0);
405 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
406 vdwparam+vdwioffset0+vdwjidx0B,
407 vdwparam+vdwioffset0+vdwjidx0C,
408 vdwparam+vdwioffset0+vdwjidx0D,
411 /* REACTION-FIELD ELECTROSTATICS */
412 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
413 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
415 /* LENNARD-JONES DISPERSION/REPULSION */
417 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
418 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
419 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
420 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
421 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
423 /* Update potential sum for this i atom from the interaction with this j atom. */
424 velec = _mm_andnot_ps(dummy_mask,velec);
425 velecsum = _mm_add_ps(velecsum,velec);
426 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
427 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
429 fscal = _mm_add_ps(felec,fvdw);
431 fscal = _mm_andnot_ps(dummy_mask,fscal);
433 /* Update vectorial force */
434 fix0 = _mm_macc_ps(dx00,fscal,fix0);
435 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
436 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
438 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
439 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
440 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
442 /**************************
443 * CALCULATE INTERACTIONS *
444 **************************/
446 /* Compute parameters for interactions between i and j atoms */
447 qq10 = _mm_mul_ps(iq1,jq0);
449 /* REACTION-FIELD ELECTROSTATICS */
450 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
451 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
453 /* Update potential sum for this i atom from the interaction with this j atom. */
454 velec = _mm_andnot_ps(dummy_mask,velec);
455 velecsum = _mm_add_ps(velecsum,velec);
459 fscal = _mm_andnot_ps(dummy_mask,fscal);
461 /* Update vectorial force */
462 fix1 = _mm_macc_ps(dx10,fscal,fix1);
463 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
464 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
466 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
467 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
468 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
470 /**************************
471 * CALCULATE INTERACTIONS *
472 **************************/
474 /* Compute parameters for interactions between i and j atoms */
475 qq20 = _mm_mul_ps(iq2,jq0);
477 /* REACTION-FIELD ELECTROSTATICS */
478 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
479 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
481 /* Update potential sum for this i atom from the interaction with this j atom. */
482 velec = _mm_andnot_ps(dummy_mask,velec);
483 velecsum = _mm_add_ps(velecsum,velec);
487 fscal = _mm_andnot_ps(dummy_mask,fscal);
489 /* Update vectorial force */
490 fix2 = _mm_macc_ps(dx20,fscal,fix2);
491 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
492 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
494 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
495 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
496 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
498 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
499 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
500 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
501 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
503 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
505 /* Inner loop uses 117 flops */
508 /* End of innermost loop */
510 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
511 f+i_coord_offset,fshift+i_shift_offset);
514 /* Update potential energies */
515 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
516 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
518 /* Increment number of inner iterations */
519 inneriter += j_index_end - j_index_start;
521 /* Outer loop uses 20 flops */
524 /* Increment number of outer iterations */
527 /* Update outer/inner flops */
529 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*117);
532 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_single
533 * Electrostatics interaction: ReactionField
534 * VdW interaction: LennardJones
535 * Geometry: Water3-Particle
536 * Calculate force/pot: Force
539 nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_single
540 (t_nblist * gmx_restrict nlist,
541 rvec * gmx_restrict xx,
542 rvec * gmx_restrict ff,
543 t_forcerec * gmx_restrict fr,
544 t_mdatoms * gmx_restrict mdatoms,
545 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
546 t_nrnb * gmx_restrict nrnb)
548 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
549 * just 0 for non-waters.
550 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
551 * jnr indices corresponding to data put in the four positions in the SIMD register.
553 int i_shift_offset,i_coord_offset,outeriter,inneriter;
554 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
555 int jnrA,jnrB,jnrC,jnrD;
556 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
557 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
558 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
560 real *shiftvec,*fshift,*x,*f;
561 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
563 __m128 fscal,rcutoff,rcutoff2,jidxall;
565 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
567 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
569 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
570 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
571 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
572 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
573 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
574 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
575 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
578 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
581 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
582 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
583 __m128 dummy_mask,cutoff_mask;
584 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
585 __m128 one = _mm_set1_ps(1.0);
586 __m128 two = _mm_set1_ps(2.0);
592 jindex = nlist->jindex;
594 shiftidx = nlist->shift;
596 shiftvec = fr->shift_vec[0];
597 fshift = fr->fshift[0];
598 facel = _mm_set1_ps(fr->epsfac);
599 charge = mdatoms->chargeA;
600 krf = _mm_set1_ps(fr->ic->k_rf);
601 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
602 crf = _mm_set1_ps(fr->ic->c_rf);
603 nvdwtype = fr->ntype;
605 vdwtype = mdatoms->typeA;
607 /* Setup water-specific parameters */
608 inr = nlist->iinr[0];
609 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
610 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
611 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
612 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
614 /* Avoid stupid compiler warnings */
615 jnrA = jnrB = jnrC = jnrD = 0;
624 for(iidx=0;iidx<4*DIM;iidx++)
629 /* Start outer loop over neighborlists */
630 for(iidx=0; iidx<nri; iidx++)
632 /* Load shift vector for this list */
633 i_shift_offset = DIM*shiftidx[iidx];
635 /* Load limits for loop over neighbors */
636 j_index_start = jindex[iidx];
637 j_index_end = jindex[iidx+1];
639 /* Get outer coordinate index */
641 i_coord_offset = DIM*inr;
643 /* Load i particle coords and add shift vector */
644 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
645 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
647 fix0 = _mm_setzero_ps();
648 fiy0 = _mm_setzero_ps();
649 fiz0 = _mm_setzero_ps();
650 fix1 = _mm_setzero_ps();
651 fiy1 = _mm_setzero_ps();
652 fiz1 = _mm_setzero_ps();
653 fix2 = _mm_setzero_ps();
654 fiy2 = _mm_setzero_ps();
655 fiz2 = _mm_setzero_ps();
657 /* Start inner kernel loop */
658 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
661 /* Get j neighbor index, and coordinate index */
666 j_coord_offsetA = DIM*jnrA;
667 j_coord_offsetB = DIM*jnrB;
668 j_coord_offsetC = DIM*jnrC;
669 j_coord_offsetD = DIM*jnrD;
671 /* load j atom coordinates */
672 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
673 x+j_coord_offsetC,x+j_coord_offsetD,
676 /* Calculate displacement vector */
677 dx00 = _mm_sub_ps(ix0,jx0);
678 dy00 = _mm_sub_ps(iy0,jy0);
679 dz00 = _mm_sub_ps(iz0,jz0);
680 dx10 = _mm_sub_ps(ix1,jx0);
681 dy10 = _mm_sub_ps(iy1,jy0);
682 dz10 = _mm_sub_ps(iz1,jz0);
683 dx20 = _mm_sub_ps(ix2,jx0);
684 dy20 = _mm_sub_ps(iy2,jy0);
685 dz20 = _mm_sub_ps(iz2,jz0);
687 /* Calculate squared distance and things based on it */
688 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
689 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
690 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
692 rinv00 = gmx_mm_invsqrt_ps(rsq00);
693 rinv10 = gmx_mm_invsqrt_ps(rsq10);
694 rinv20 = gmx_mm_invsqrt_ps(rsq20);
696 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
697 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
698 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
700 /* Load parameters for j particles */
701 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
702 charge+jnrC+0,charge+jnrD+0);
703 vdwjidx0A = 2*vdwtype[jnrA+0];
704 vdwjidx0B = 2*vdwtype[jnrB+0];
705 vdwjidx0C = 2*vdwtype[jnrC+0];
706 vdwjidx0D = 2*vdwtype[jnrD+0];
708 fjx0 = _mm_setzero_ps();
709 fjy0 = _mm_setzero_ps();
710 fjz0 = _mm_setzero_ps();
712 /**************************
713 * CALCULATE INTERACTIONS *
714 **************************/
716 /* Compute parameters for interactions between i and j atoms */
717 qq00 = _mm_mul_ps(iq0,jq0);
718 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
719 vdwparam+vdwioffset0+vdwjidx0B,
720 vdwparam+vdwioffset0+vdwjidx0C,
721 vdwparam+vdwioffset0+vdwjidx0D,
724 /* REACTION-FIELD ELECTROSTATICS */
725 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
727 /* LENNARD-JONES DISPERSION/REPULSION */
729 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
730 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
732 fscal = _mm_add_ps(felec,fvdw);
734 /* Update vectorial force */
735 fix0 = _mm_macc_ps(dx00,fscal,fix0);
736 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
737 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
739 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
740 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
741 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
743 /**************************
744 * CALCULATE INTERACTIONS *
745 **************************/
747 /* Compute parameters for interactions between i and j atoms */
748 qq10 = _mm_mul_ps(iq1,jq0);
750 /* REACTION-FIELD ELECTROSTATICS */
751 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
755 /* Update vectorial force */
756 fix1 = _mm_macc_ps(dx10,fscal,fix1);
757 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
758 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
760 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
761 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
762 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
764 /**************************
765 * CALCULATE INTERACTIONS *
766 **************************/
768 /* Compute parameters for interactions between i and j atoms */
769 qq20 = _mm_mul_ps(iq2,jq0);
771 /* REACTION-FIELD ELECTROSTATICS */
772 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
776 /* Update vectorial force */
777 fix2 = _mm_macc_ps(dx20,fscal,fix2);
778 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
779 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
781 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
782 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
783 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
785 fjptrA = f+j_coord_offsetA;
786 fjptrB = f+j_coord_offsetB;
787 fjptrC = f+j_coord_offsetC;
788 fjptrD = f+j_coord_offsetD;
790 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
792 /* Inner loop uses 97 flops */
798 /* Get j neighbor index, and coordinate index */
799 jnrlistA = jjnr[jidx];
800 jnrlistB = jjnr[jidx+1];
801 jnrlistC = jjnr[jidx+2];
802 jnrlistD = jjnr[jidx+3];
803 /* Sign of each element will be negative for non-real atoms.
804 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
805 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
807 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
808 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
809 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
810 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
811 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
812 j_coord_offsetA = DIM*jnrA;
813 j_coord_offsetB = DIM*jnrB;
814 j_coord_offsetC = DIM*jnrC;
815 j_coord_offsetD = DIM*jnrD;
817 /* load j atom coordinates */
818 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
819 x+j_coord_offsetC,x+j_coord_offsetD,
822 /* Calculate displacement vector */
823 dx00 = _mm_sub_ps(ix0,jx0);
824 dy00 = _mm_sub_ps(iy0,jy0);
825 dz00 = _mm_sub_ps(iz0,jz0);
826 dx10 = _mm_sub_ps(ix1,jx0);
827 dy10 = _mm_sub_ps(iy1,jy0);
828 dz10 = _mm_sub_ps(iz1,jz0);
829 dx20 = _mm_sub_ps(ix2,jx0);
830 dy20 = _mm_sub_ps(iy2,jy0);
831 dz20 = _mm_sub_ps(iz2,jz0);
833 /* Calculate squared distance and things based on it */
834 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
835 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
836 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
838 rinv00 = gmx_mm_invsqrt_ps(rsq00);
839 rinv10 = gmx_mm_invsqrt_ps(rsq10);
840 rinv20 = gmx_mm_invsqrt_ps(rsq20);
842 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
843 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
844 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
846 /* Load parameters for j particles */
847 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
848 charge+jnrC+0,charge+jnrD+0);
849 vdwjidx0A = 2*vdwtype[jnrA+0];
850 vdwjidx0B = 2*vdwtype[jnrB+0];
851 vdwjidx0C = 2*vdwtype[jnrC+0];
852 vdwjidx0D = 2*vdwtype[jnrD+0];
854 fjx0 = _mm_setzero_ps();
855 fjy0 = _mm_setzero_ps();
856 fjz0 = _mm_setzero_ps();
858 /**************************
859 * CALCULATE INTERACTIONS *
860 **************************/
862 /* Compute parameters for interactions between i and j atoms */
863 qq00 = _mm_mul_ps(iq0,jq0);
864 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
865 vdwparam+vdwioffset0+vdwjidx0B,
866 vdwparam+vdwioffset0+vdwjidx0C,
867 vdwparam+vdwioffset0+vdwjidx0D,
870 /* REACTION-FIELD ELECTROSTATICS */
871 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
873 /* LENNARD-JONES DISPERSION/REPULSION */
875 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
876 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
878 fscal = _mm_add_ps(felec,fvdw);
880 fscal = _mm_andnot_ps(dummy_mask,fscal);
882 /* Update vectorial force */
883 fix0 = _mm_macc_ps(dx00,fscal,fix0);
884 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
885 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
887 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
888 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
889 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
891 /**************************
892 * CALCULATE INTERACTIONS *
893 **************************/
895 /* Compute parameters for interactions between i and j atoms */
896 qq10 = _mm_mul_ps(iq1,jq0);
898 /* REACTION-FIELD ELECTROSTATICS */
899 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
903 fscal = _mm_andnot_ps(dummy_mask,fscal);
905 /* Update vectorial force */
906 fix1 = _mm_macc_ps(dx10,fscal,fix1);
907 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
908 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
910 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
911 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
912 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
914 /**************************
915 * CALCULATE INTERACTIONS *
916 **************************/
918 /* Compute parameters for interactions between i and j atoms */
919 qq20 = _mm_mul_ps(iq2,jq0);
921 /* REACTION-FIELD ELECTROSTATICS */
922 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
926 fscal = _mm_andnot_ps(dummy_mask,fscal);
928 /* Update vectorial force */
929 fix2 = _mm_macc_ps(dx20,fscal,fix2);
930 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
931 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
933 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
934 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
935 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
937 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
938 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
939 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
940 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
942 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
944 /* Inner loop uses 97 flops */
947 /* End of innermost loop */
949 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
950 f+i_coord_offset,fshift+i_shift_offset);
952 /* Increment number of inner iterations */
953 inneriter += j_index_end - j_index_start;
955 /* Outer loop uses 18 flops */
958 /* Increment number of outer iterations */
961 /* Update outer/inner flops */
963 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*97);