2 * Note: this file was generated by the Gromacs avx_128_fma_single kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_avx_128_fma_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_VF_avx_128_fma_single
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: LennardJones
40 * Geometry: Water3-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_VF_avx_128_fma_single
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60 int jnrA,jnrB,jnrC,jnrD;
61 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
65 real *shiftvec,*fshift,*x,*f;
66 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
68 __m128 fscal,rcutoff,rcutoff2,jidxall;
70 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
75 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
76 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
77 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
78 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
79 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
80 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
83 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
86 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
87 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
88 __m128 dummy_mask,cutoff_mask;
89 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
90 __m128 one = _mm_set1_ps(1.0);
91 __m128 two = _mm_set1_ps(2.0);
97 jindex = nlist->jindex;
99 shiftidx = nlist->shift;
101 shiftvec = fr->shift_vec[0];
102 fshift = fr->fshift[0];
103 facel = _mm_set1_ps(fr->epsfac);
104 charge = mdatoms->chargeA;
105 krf = _mm_set1_ps(fr->ic->k_rf);
106 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
107 crf = _mm_set1_ps(fr->ic->c_rf);
108 nvdwtype = fr->ntype;
110 vdwtype = mdatoms->typeA;
112 /* Setup water-specific parameters */
113 inr = nlist->iinr[0];
114 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
115 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
116 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
117 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
119 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
120 rcutoff_scalar = fr->rcoulomb;
121 rcutoff = _mm_set1_ps(rcutoff_scalar);
122 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
124 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
125 rvdw = _mm_set1_ps(fr->rvdw);
127 /* Avoid stupid compiler warnings */
128 jnrA = jnrB = jnrC = jnrD = 0;
137 for(iidx=0;iidx<4*DIM;iidx++)
142 /* Start outer loop over neighborlists */
143 for(iidx=0; iidx<nri; iidx++)
145 /* Load shift vector for this list */
146 i_shift_offset = DIM*shiftidx[iidx];
148 /* Load limits for loop over neighbors */
149 j_index_start = jindex[iidx];
150 j_index_end = jindex[iidx+1];
152 /* Get outer coordinate index */
154 i_coord_offset = DIM*inr;
156 /* Load i particle coords and add shift vector */
157 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
158 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
160 fix0 = _mm_setzero_ps();
161 fiy0 = _mm_setzero_ps();
162 fiz0 = _mm_setzero_ps();
163 fix1 = _mm_setzero_ps();
164 fiy1 = _mm_setzero_ps();
165 fiz1 = _mm_setzero_ps();
166 fix2 = _mm_setzero_ps();
167 fiy2 = _mm_setzero_ps();
168 fiz2 = _mm_setzero_ps();
170 /* Reset potential sums */
171 velecsum = _mm_setzero_ps();
172 vvdwsum = _mm_setzero_ps();
174 /* Start inner kernel loop */
175 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
178 /* Get j neighbor index, and coordinate index */
183 j_coord_offsetA = DIM*jnrA;
184 j_coord_offsetB = DIM*jnrB;
185 j_coord_offsetC = DIM*jnrC;
186 j_coord_offsetD = DIM*jnrD;
188 /* load j atom coordinates */
189 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
190 x+j_coord_offsetC,x+j_coord_offsetD,
193 /* Calculate displacement vector */
194 dx00 = _mm_sub_ps(ix0,jx0);
195 dy00 = _mm_sub_ps(iy0,jy0);
196 dz00 = _mm_sub_ps(iz0,jz0);
197 dx10 = _mm_sub_ps(ix1,jx0);
198 dy10 = _mm_sub_ps(iy1,jy0);
199 dz10 = _mm_sub_ps(iz1,jz0);
200 dx20 = _mm_sub_ps(ix2,jx0);
201 dy20 = _mm_sub_ps(iy2,jy0);
202 dz20 = _mm_sub_ps(iz2,jz0);
204 /* Calculate squared distance and things based on it */
205 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
206 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
207 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
209 rinv00 = gmx_mm_invsqrt_ps(rsq00);
210 rinv10 = gmx_mm_invsqrt_ps(rsq10);
211 rinv20 = gmx_mm_invsqrt_ps(rsq20);
213 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
214 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
215 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
217 /* Load parameters for j particles */
218 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
219 charge+jnrC+0,charge+jnrD+0);
220 vdwjidx0A = 2*vdwtype[jnrA+0];
221 vdwjidx0B = 2*vdwtype[jnrB+0];
222 vdwjidx0C = 2*vdwtype[jnrC+0];
223 vdwjidx0D = 2*vdwtype[jnrD+0];
225 fjx0 = _mm_setzero_ps();
226 fjy0 = _mm_setzero_ps();
227 fjz0 = _mm_setzero_ps();
229 /**************************
230 * CALCULATE INTERACTIONS *
231 **************************/
233 if (gmx_mm_any_lt(rsq00,rcutoff2))
236 /* Compute parameters for interactions between i and j atoms */
237 qq00 = _mm_mul_ps(iq0,jq0);
238 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
239 vdwparam+vdwioffset0+vdwjidx0B,
240 vdwparam+vdwioffset0+vdwjidx0C,
241 vdwparam+vdwioffset0+vdwjidx0D,
244 /* REACTION-FIELD ELECTROSTATICS */
245 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
246 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
248 /* LENNARD-JONES DISPERSION/REPULSION */
250 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
251 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
252 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
253 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
254 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
255 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
257 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
259 /* Update potential sum for this i atom from the interaction with this j atom. */
260 velec = _mm_and_ps(velec,cutoff_mask);
261 velecsum = _mm_add_ps(velecsum,velec);
262 vvdw = _mm_and_ps(vvdw,cutoff_mask);
263 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
265 fscal = _mm_add_ps(felec,fvdw);
267 fscal = _mm_and_ps(fscal,cutoff_mask);
269 /* Update vectorial force */
270 fix0 = _mm_macc_ps(dx00,fscal,fix0);
271 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
272 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
274 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
275 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
276 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
280 /**************************
281 * CALCULATE INTERACTIONS *
282 **************************/
284 if (gmx_mm_any_lt(rsq10,rcutoff2))
287 /* Compute parameters for interactions between i and j atoms */
288 qq10 = _mm_mul_ps(iq1,jq0);
290 /* REACTION-FIELD ELECTROSTATICS */
291 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
292 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
294 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
296 /* Update potential sum for this i atom from the interaction with this j atom. */
297 velec = _mm_and_ps(velec,cutoff_mask);
298 velecsum = _mm_add_ps(velecsum,velec);
302 fscal = _mm_and_ps(fscal,cutoff_mask);
304 /* Update vectorial force */
305 fix1 = _mm_macc_ps(dx10,fscal,fix1);
306 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
307 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
309 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
310 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
311 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
315 /**************************
316 * CALCULATE INTERACTIONS *
317 **************************/
319 if (gmx_mm_any_lt(rsq20,rcutoff2))
322 /* Compute parameters for interactions between i and j atoms */
323 qq20 = _mm_mul_ps(iq2,jq0);
325 /* REACTION-FIELD ELECTROSTATICS */
326 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
327 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
329 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
331 /* Update potential sum for this i atom from the interaction with this j atom. */
332 velec = _mm_and_ps(velec,cutoff_mask);
333 velecsum = _mm_add_ps(velecsum,velec);
337 fscal = _mm_and_ps(fscal,cutoff_mask);
339 /* Update vectorial force */
340 fix2 = _mm_macc_ps(dx20,fscal,fix2);
341 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
342 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
344 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
345 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
346 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
350 fjptrA = f+j_coord_offsetA;
351 fjptrB = f+j_coord_offsetB;
352 fjptrC = f+j_coord_offsetC;
353 fjptrD = f+j_coord_offsetD;
355 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
357 /* Inner loop uses 135 flops */
363 /* Get j neighbor index, and coordinate index */
364 jnrlistA = jjnr[jidx];
365 jnrlistB = jjnr[jidx+1];
366 jnrlistC = jjnr[jidx+2];
367 jnrlistD = jjnr[jidx+3];
368 /* Sign of each element will be negative for non-real atoms.
369 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
370 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
372 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
373 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
374 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
375 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
376 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
377 j_coord_offsetA = DIM*jnrA;
378 j_coord_offsetB = DIM*jnrB;
379 j_coord_offsetC = DIM*jnrC;
380 j_coord_offsetD = DIM*jnrD;
382 /* load j atom coordinates */
383 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
384 x+j_coord_offsetC,x+j_coord_offsetD,
387 /* Calculate displacement vector */
388 dx00 = _mm_sub_ps(ix0,jx0);
389 dy00 = _mm_sub_ps(iy0,jy0);
390 dz00 = _mm_sub_ps(iz0,jz0);
391 dx10 = _mm_sub_ps(ix1,jx0);
392 dy10 = _mm_sub_ps(iy1,jy0);
393 dz10 = _mm_sub_ps(iz1,jz0);
394 dx20 = _mm_sub_ps(ix2,jx0);
395 dy20 = _mm_sub_ps(iy2,jy0);
396 dz20 = _mm_sub_ps(iz2,jz0);
398 /* Calculate squared distance and things based on it */
399 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
400 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
401 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
403 rinv00 = gmx_mm_invsqrt_ps(rsq00);
404 rinv10 = gmx_mm_invsqrt_ps(rsq10);
405 rinv20 = gmx_mm_invsqrt_ps(rsq20);
407 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
408 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
409 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
411 /* Load parameters for j particles */
412 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
413 charge+jnrC+0,charge+jnrD+0);
414 vdwjidx0A = 2*vdwtype[jnrA+0];
415 vdwjidx0B = 2*vdwtype[jnrB+0];
416 vdwjidx0C = 2*vdwtype[jnrC+0];
417 vdwjidx0D = 2*vdwtype[jnrD+0];
419 fjx0 = _mm_setzero_ps();
420 fjy0 = _mm_setzero_ps();
421 fjz0 = _mm_setzero_ps();
423 /**************************
424 * CALCULATE INTERACTIONS *
425 **************************/
427 if (gmx_mm_any_lt(rsq00,rcutoff2))
430 /* Compute parameters for interactions between i and j atoms */
431 qq00 = _mm_mul_ps(iq0,jq0);
432 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
433 vdwparam+vdwioffset0+vdwjidx0B,
434 vdwparam+vdwioffset0+vdwjidx0C,
435 vdwparam+vdwioffset0+vdwjidx0D,
438 /* REACTION-FIELD ELECTROSTATICS */
439 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
440 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
442 /* LENNARD-JONES DISPERSION/REPULSION */
444 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
445 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
446 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
447 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
448 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
449 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
451 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
453 /* Update potential sum for this i atom from the interaction with this j atom. */
454 velec = _mm_and_ps(velec,cutoff_mask);
455 velec = _mm_andnot_ps(dummy_mask,velec);
456 velecsum = _mm_add_ps(velecsum,velec);
457 vvdw = _mm_and_ps(vvdw,cutoff_mask);
458 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
459 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
461 fscal = _mm_add_ps(felec,fvdw);
463 fscal = _mm_and_ps(fscal,cutoff_mask);
465 fscal = _mm_andnot_ps(dummy_mask,fscal);
467 /* Update vectorial force */
468 fix0 = _mm_macc_ps(dx00,fscal,fix0);
469 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
470 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
472 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
473 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
474 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
478 /**************************
479 * CALCULATE INTERACTIONS *
480 **************************/
482 if (gmx_mm_any_lt(rsq10,rcutoff2))
485 /* Compute parameters for interactions between i and j atoms */
486 qq10 = _mm_mul_ps(iq1,jq0);
488 /* REACTION-FIELD ELECTROSTATICS */
489 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
490 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
492 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
494 /* Update potential sum for this i atom from the interaction with this j atom. */
495 velec = _mm_and_ps(velec,cutoff_mask);
496 velec = _mm_andnot_ps(dummy_mask,velec);
497 velecsum = _mm_add_ps(velecsum,velec);
501 fscal = _mm_and_ps(fscal,cutoff_mask);
503 fscal = _mm_andnot_ps(dummy_mask,fscal);
505 /* Update vectorial force */
506 fix1 = _mm_macc_ps(dx10,fscal,fix1);
507 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
508 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
510 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
511 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
512 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
516 /**************************
517 * CALCULATE INTERACTIONS *
518 **************************/
520 if (gmx_mm_any_lt(rsq20,rcutoff2))
523 /* Compute parameters for interactions between i and j atoms */
524 qq20 = _mm_mul_ps(iq2,jq0);
526 /* REACTION-FIELD ELECTROSTATICS */
527 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
528 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
530 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
532 /* Update potential sum for this i atom from the interaction with this j atom. */
533 velec = _mm_and_ps(velec,cutoff_mask);
534 velec = _mm_andnot_ps(dummy_mask,velec);
535 velecsum = _mm_add_ps(velecsum,velec);
539 fscal = _mm_and_ps(fscal,cutoff_mask);
541 fscal = _mm_andnot_ps(dummy_mask,fscal);
543 /* Update vectorial force */
544 fix2 = _mm_macc_ps(dx20,fscal,fix2);
545 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
546 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
548 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
549 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
550 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
554 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
555 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
556 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
557 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
559 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
561 /* Inner loop uses 135 flops */
564 /* End of innermost loop */
566 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
567 f+i_coord_offset,fshift+i_shift_offset);
570 /* Update potential energies */
571 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
572 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
574 /* Increment number of inner iterations */
575 inneriter += j_index_end - j_index_start;
577 /* Outer loop uses 20 flops */
580 /* Increment number of outer iterations */
583 /* Update outer/inner flops */
585 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*135);
588 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_single
589 * Electrostatics interaction: ReactionField
590 * VdW interaction: LennardJones
591 * Geometry: Water3-Particle
592 * Calculate force/pot: Force
595 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_single
596 (t_nblist * gmx_restrict nlist,
597 rvec * gmx_restrict xx,
598 rvec * gmx_restrict ff,
599 t_forcerec * gmx_restrict fr,
600 t_mdatoms * gmx_restrict mdatoms,
601 nb_kernel_data_t * gmx_restrict kernel_data,
602 t_nrnb * gmx_restrict nrnb)
604 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
605 * just 0 for non-waters.
606 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
607 * jnr indices corresponding to data put in the four positions in the SIMD register.
609 int i_shift_offset,i_coord_offset,outeriter,inneriter;
610 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
611 int jnrA,jnrB,jnrC,jnrD;
612 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
613 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
614 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
616 real *shiftvec,*fshift,*x,*f;
617 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
619 __m128 fscal,rcutoff,rcutoff2,jidxall;
621 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
623 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
625 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
626 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
627 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
628 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
629 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
630 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
631 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
634 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
637 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
638 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
639 __m128 dummy_mask,cutoff_mask;
640 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
641 __m128 one = _mm_set1_ps(1.0);
642 __m128 two = _mm_set1_ps(2.0);
648 jindex = nlist->jindex;
650 shiftidx = nlist->shift;
652 shiftvec = fr->shift_vec[0];
653 fshift = fr->fshift[0];
654 facel = _mm_set1_ps(fr->epsfac);
655 charge = mdatoms->chargeA;
656 krf = _mm_set1_ps(fr->ic->k_rf);
657 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
658 crf = _mm_set1_ps(fr->ic->c_rf);
659 nvdwtype = fr->ntype;
661 vdwtype = mdatoms->typeA;
663 /* Setup water-specific parameters */
664 inr = nlist->iinr[0];
665 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
666 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
667 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
668 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
670 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
671 rcutoff_scalar = fr->rcoulomb;
672 rcutoff = _mm_set1_ps(rcutoff_scalar);
673 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
675 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
676 rvdw = _mm_set1_ps(fr->rvdw);
678 /* Avoid stupid compiler warnings */
679 jnrA = jnrB = jnrC = jnrD = 0;
688 for(iidx=0;iidx<4*DIM;iidx++)
693 /* Start outer loop over neighborlists */
694 for(iidx=0; iidx<nri; iidx++)
696 /* Load shift vector for this list */
697 i_shift_offset = DIM*shiftidx[iidx];
699 /* Load limits for loop over neighbors */
700 j_index_start = jindex[iidx];
701 j_index_end = jindex[iidx+1];
703 /* Get outer coordinate index */
705 i_coord_offset = DIM*inr;
707 /* Load i particle coords and add shift vector */
708 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
709 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
711 fix0 = _mm_setzero_ps();
712 fiy0 = _mm_setzero_ps();
713 fiz0 = _mm_setzero_ps();
714 fix1 = _mm_setzero_ps();
715 fiy1 = _mm_setzero_ps();
716 fiz1 = _mm_setzero_ps();
717 fix2 = _mm_setzero_ps();
718 fiy2 = _mm_setzero_ps();
719 fiz2 = _mm_setzero_ps();
721 /* Start inner kernel loop */
722 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
725 /* Get j neighbor index, and coordinate index */
730 j_coord_offsetA = DIM*jnrA;
731 j_coord_offsetB = DIM*jnrB;
732 j_coord_offsetC = DIM*jnrC;
733 j_coord_offsetD = DIM*jnrD;
735 /* load j atom coordinates */
736 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
737 x+j_coord_offsetC,x+j_coord_offsetD,
740 /* Calculate displacement vector */
741 dx00 = _mm_sub_ps(ix0,jx0);
742 dy00 = _mm_sub_ps(iy0,jy0);
743 dz00 = _mm_sub_ps(iz0,jz0);
744 dx10 = _mm_sub_ps(ix1,jx0);
745 dy10 = _mm_sub_ps(iy1,jy0);
746 dz10 = _mm_sub_ps(iz1,jz0);
747 dx20 = _mm_sub_ps(ix2,jx0);
748 dy20 = _mm_sub_ps(iy2,jy0);
749 dz20 = _mm_sub_ps(iz2,jz0);
751 /* Calculate squared distance and things based on it */
752 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
753 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
754 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
756 rinv00 = gmx_mm_invsqrt_ps(rsq00);
757 rinv10 = gmx_mm_invsqrt_ps(rsq10);
758 rinv20 = gmx_mm_invsqrt_ps(rsq20);
760 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
761 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
762 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
764 /* Load parameters for j particles */
765 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
766 charge+jnrC+0,charge+jnrD+0);
767 vdwjidx0A = 2*vdwtype[jnrA+0];
768 vdwjidx0B = 2*vdwtype[jnrB+0];
769 vdwjidx0C = 2*vdwtype[jnrC+0];
770 vdwjidx0D = 2*vdwtype[jnrD+0];
772 fjx0 = _mm_setzero_ps();
773 fjy0 = _mm_setzero_ps();
774 fjz0 = _mm_setzero_ps();
776 /**************************
777 * CALCULATE INTERACTIONS *
778 **************************/
780 if (gmx_mm_any_lt(rsq00,rcutoff2))
783 /* Compute parameters for interactions between i and j atoms */
784 qq00 = _mm_mul_ps(iq0,jq0);
785 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
786 vdwparam+vdwioffset0+vdwjidx0B,
787 vdwparam+vdwioffset0+vdwjidx0C,
788 vdwparam+vdwioffset0+vdwjidx0D,
791 /* REACTION-FIELD ELECTROSTATICS */
792 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
794 /* LENNARD-JONES DISPERSION/REPULSION */
796 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
797 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
799 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
801 fscal = _mm_add_ps(felec,fvdw);
803 fscal = _mm_and_ps(fscal,cutoff_mask);
805 /* Update vectorial force */
806 fix0 = _mm_macc_ps(dx00,fscal,fix0);
807 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
808 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
810 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
811 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
812 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
816 /**************************
817 * CALCULATE INTERACTIONS *
818 **************************/
820 if (gmx_mm_any_lt(rsq10,rcutoff2))
823 /* Compute parameters for interactions between i and j atoms */
824 qq10 = _mm_mul_ps(iq1,jq0);
826 /* REACTION-FIELD ELECTROSTATICS */
827 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
829 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
833 fscal = _mm_and_ps(fscal,cutoff_mask);
835 /* Update vectorial force */
836 fix1 = _mm_macc_ps(dx10,fscal,fix1);
837 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
838 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
840 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
841 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
842 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
846 /**************************
847 * CALCULATE INTERACTIONS *
848 **************************/
850 if (gmx_mm_any_lt(rsq20,rcutoff2))
853 /* Compute parameters for interactions between i and j atoms */
854 qq20 = _mm_mul_ps(iq2,jq0);
856 /* REACTION-FIELD ELECTROSTATICS */
857 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
859 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
863 fscal = _mm_and_ps(fscal,cutoff_mask);
865 /* Update vectorial force */
866 fix2 = _mm_macc_ps(dx20,fscal,fix2);
867 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
868 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
870 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
871 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
872 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
876 fjptrA = f+j_coord_offsetA;
877 fjptrB = f+j_coord_offsetB;
878 fjptrC = f+j_coord_offsetC;
879 fjptrD = f+j_coord_offsetD;
881 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
883 /* Inner loop uses 106 flops */
889 /* Get j neighbor index, and coordinate index */
890 jnrlistA = jjnr[jidx];
891 jnrlistB = jjnr[jidx+1];
892 jnrlistC = jjnr[jidx+2];
893 jnrlistD = jjnr[jidx+3];
894 /* Sign of each element will be negative for non-real atoms.
895 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
896 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
898 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
899 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
900 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
901 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
902 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
903 j_coord_offsetA = DIM*jnrA;
904 j_coord_offsetB = DIM*jnrB;
905 j_coord_offsetC = DIM*jnrC;
906 j_coord_offsetD = DIM*jnrD;
908 /* load j atom coordinates */
909 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
910 x+j_coord_offsetC,x+j_coord_offsetD,
913 /* Calculate displacement vector */
914 dx00 = _mm_sub_ps(ix0,jx0);
915 dy00 = _mm_sub_ps(iy0,jy0);
916 dz00 = _mm_sub_ps(iz0,jz0);
917 dx10 = _mm_sub_ps(ix1,jx0);
918 dy10 = _mm_sub_ps(iy1,jy0);
919 dz10 = _mm_sub_ps(iz1,jz0);
920 dx20 = _mm_sub_ps(ix2,jx0);
921 dy20 = _mm_sub_ps(iy2,jy0);
922 dz20 = _mm_sub_ps(iz2,jz0);
924 /* Calculate squared distance and things based on it */
925 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
926 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
927 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
929 rinv00 = gmx_mm_invsqrt_ps(rsq00);
930 rinv10 = gmx_mm_invsqrt_ps(rsq10);
931 rinv20 = gmx_mm_invsqrt_ps(rsq20);
933 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
934 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
935 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
937 /* Load parameters for j particles */
938 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
939 charge+jnrC+0,charge+jnrD+0);
940 vdwjidx0A = 2*vdwtype[jnrA+0];
941 vdwjidx0B = 2*vdwtype[jnrB+0];
942 vdwjidx0C = 2*vdwtype[jnrC+0];
943 vdwjidx0D = 2*vdwtype[jnrD+0];
945 fjx0 = _mm_setzero_ps();
946 fjy0 = _mm_setzero_ps();
947 fjz0 = _mm_setzero_ps();
949 /**************************
950 * CALCULATE INTERACTIONS *
951 **************************/
953 if (gmx_mm_any_lt(rsq00,rcutoff2))
956 /* Compute parameters for interactions between i and j atoms */
957 qq00 = _mm_mul_ps(iq0,jq0);
958 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
959 vdwparam+vdwioffset0+vdwjidx0B,
960 vdwparam+vdwioffset0+vdwjidx0C,
961 vdwparam+vdwioffset0+vdwjidx0D,
964 /* REACTION-FIELD ELECTROSTATICS */
965 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
967 /* LENNARD-JONES DISPERSION/REPULSION */
969 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
970 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
972 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
974 fscal = _mm_add_ps(felec,fvdw);
976 fscal = _mm_and_ps(fscal,cutoff_mask);
978 fscal = _mm_andnot_ps(dummy_mask,fscal);
980 /* Update vectorial force */
981 fix0 = _mm_macc_ps(dx00,fscal,fix0);
982 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
983 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
985 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
986 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
987 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
991 /**************************
992 * CALCULATE INTERACTIONS *
993 **************************/
995 if (gmx_mm_any_lt(rsq10,rcutoff2))
998 /* Compute parameters for interactions between i and j atoms */
999 qq10 = _mm_mul_ps(iq1,jq0);
1001 /* REACTION-FIELD ELECTROSTATICS */
1002 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1004 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1008 fscal = _mm_and_ps(fscal,cutoff_mask);
1010 fscal = _mm_andnot_ps(dummy_mask,fscal);
1012 /* Update vectorial force */
1013 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1014 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1015 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1017 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1018 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1019 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1023 /**************************
1024 * CALCULATE INTERACTIONS *
1025 **************************/
1027 if (gmx_mm_any_lt(rsq20,rcutoff2))
1030 /* Compute parameters for interactions between i and j atoms */
1031 qq20 = _mm_mul_ps(iq2,jq0);
1033 /* REACTION-FIELD ELECTROSTATICS */
1034 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1036 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1040 fscal = _mm_and_ps(fscal,cutoff_mask);
1042 fscal = _mm_andnot_ps(dummy_mask,fscal);
1044 /* Update vectorial force */
1045 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1046 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1047 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1049 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1050 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1051 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1055 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1056 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1057 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1058 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1060 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1062 /* Inner loop uses 106 flops */
1065 /* End of innermost loop */
1067 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1068 f+i_coord_offset,fshift+i_shift_offset);
1070 /* Increment number of inner iterations */
1071 inneriter += j_index_end - j_index_start;
1073 /* Outer loop uses 18 flops */
1076 /* Increment number of outer iterations */
1079 /* Update outer/inner flops */
1081 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*106);