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_ElecEwSh_VdwNone_GeomW4P1_VF_avx_128_fma_single
52 * Electrostatics interaction: Ewald
53 * VdW interaction: None
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEwSh_VdwNone_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 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
86 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
94 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
97 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
98 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
100 __m128 dummy_mask,cutoff_mask;
101 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
102 __m128 one = _mm_set1_ps(1.0);
103 __m128 two = _mm_set1_ps(2.0);
109 jindex = nlist->jindex;
111 shiftidx = nlist->shift;
113 shiftvec = fr->shift_vec[0];
114 fshift = fr->fshift[0];
115 facel = _mm_set1_ps(fr->epsfac);
116 charge = mdatoms->chargeA;
118 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
119 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
120 beta2 = _mm_mul_ps(beta,beta);
121 beta3 = _mm_mul_ps(beta,beta2);
122 ewtab = fr->ic->tabq_coul_FDV0;
123 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
124 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
126 /* Setup water-specific parameters */
127 inr = nlist->iinr[0];
128 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
129 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
130 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
132 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
133 rcutoff_scalar = fr->rcoulomb;
134 rcutoff = _mm_set1_ps(rcutoff_scalar);
135 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
137 /* Avoid stupid compiler warnings */
138 jnrA = jnrB = jnrC = jnrD = 0;
147 for(iidx=0;iidx<4*DIM;iidx++)
152 /* Start outer loop over neighborlists */
153 for(iidx=0; iidx<nri; iidx++)
155 /* Load shift vector for this list */
156 i_shift_offset = DIM*shiftidx[iidx];
158 /* Load limits for loop over neighbors */
159 j_index_start = jindex[iidx];
160 j_index_end = jindex[iidx+1];
162 /* Get outer coordinate index */
164 i_coord_offset = DIM*inr;
166 /* Load i particle coords and add shift vector */
167 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
168 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
170 fix1 = _mm_setzero_ps();
171 fiy1 = _mm_setzero_ps();
172 fiz1 = _mm_setzero_ps();
173 fix2 = _mm_setzero_ps();
174 fiy2 = _mm_setzero_ps();
175 fiz2 = _mm_setzero_ps();
176 fix3 = _mm_setzero_ps();
177 fiy3 = _mm_setzero_ps();
178 fiz3 = _mm_setzero_ps();
180 /* Reset potential sums */
181 velecsum = _mm_setzero_ps();
183 /* Start inner kernel loop */
184 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
187 /* Get j neighbor index, and coordinate index */
192 j_coord_offsetA = DIM*jnrA;
193 j_coord_offsetB = DIM*jnrB;
194 j_coord_offsetC = DIM*jnrC;
195 j_coord_offsetD = DIM*jnrD;
197 /* load j atom coordinates */
198 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
199 x+j_coord_offsetC,x+j_coord_offsetD,
202 /* Calculate displacement vector */
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);
209 dx30 = _mm_sub_ps(ix3,jx0);
210 dy30 = _mm_sub_ps(iy3,jy0);
211 dz30 = _mm_sub_ps(iz3,jz0);
213 /* Calculate squared distance and things based on it */
214 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
215 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
216 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
218 rinv10 = gmx_mm_invsqrt_ps(rsq10);
219 rinv20 = gmx_mm_invsqrt_ps(rsq20);
220 rinv30 = gmx_mm_invsqrt_ps(rsq30);
222 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
223 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
224 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
226 /* Load parameters for j particles */
227 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
228 charge+jnrC+0,charge+jnrD+0);
230 fjx0 = _mm_setzero_ps();
231 fjy0 = _mm_setzero_ps();
232 fjz0 = _mm_setzero_ps();
234 /**************************
235 * CALCULATE INTERACTIONS *
236 **************************/
238 if (gmx_mm_any_lt(rsq10,rcutoff2))
241 r10 = _mm_mul_ps(rsq10,rinv10);
243 /* Compute parameters for interactions between i and j atoms */
244 qq10 = _mm_mul_ps(iq1,jq0);
246 /* EWALD ELECTROSTATICS */
248 /* Analytical PME correction */
249 zeta2 = _mm_mul_ps(beta2,rsq10);
250 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
251 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
252 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
253 felec = _mm_mul_ps(qq10,felec);
254 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
255 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
256 velec = _mm_mul_ps(qq10,velec);
258 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
260 /* Update potential sum for this i atom from the interaction with this j atom. */
261 velec = _mm_and_ps(velec,cutoff_mask);
262 velecsum = _mm_add_ps(velecsum,velec);
266 fscal = _mm_and_ps(fscal,cutoff_mask);
268 /* Update vectorial force */
269 fix1 = _mm_macc_ps(dx10,fscal,fix1);
270 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
271 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
273 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
274 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
275 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
279 /**************************
280 * CALCULATE INTERACTIONS *
281 **************************/
283 if (gmx_mm_any_lt(rsq20,rcutoff2))
286 r20 = _mm_mul_ps(rsq20,rinv20);
288 /* Compute parameters for interactions between i and j atoms */
289 qq20 = _mm_mul_ps(iq2,jq0);
291 /* EWALD ELECTROSTATICS */
293 /* Analytical PME correction */
294 zeta2 = _mm_mul_ps(beta2,rsq20);
295 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
296 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
297 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
298 felec = _mm_mul_ps(qq20,felec);
299 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
300 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
301 velec = _mm_mul_ps(qq20,velec);
303 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
305 /* Update potential sum for this i atom from the interaction with this j atom. */
306 velec = _mm_and_ps(velec,cutoff_mask);
307 velecsum = _mm_add_ps(velecsum,velec);
311 fscal = _mm_and_ps(fscal,cutoff_mask);
313 /* Update vectorial force */
314 fix2 = _mm_macc_ps(dx20,fscal,fix2);
315 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
316 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
318 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
319 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
320 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
324 /**************************
325 * CALCULATE INTERACTIONS *
326 **************************/
328 if (gmx_mm_any_lt(rsq30,rcutoff2))
331 r30 = _mm_mul_ps(rsq30,rinv30);
333 /* Compute parameters for interactions between i and j atoms */
334 qq30 = _mm_mul_ps(iq3,jq0);
336 /* EWALD ELECTROSTATICS */
338 /* Analytical PME correction */
339 zeta2 = _mm_mul_ps(beta2,rsq30);
340 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
341 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
342 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
343 felec = _mm_mul_ps(qq30,felec);
344 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
345 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
346 velec = _mm_mul_ps(qq30,velec);
348 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
350 /* Update potential sum for this i atom from the interaction with this j atom. */
351 velec = _mm_and_ps(velec,cutoff_mask);
352 velecsum = _mm_add_ps(velecsum,velec);
356 fscal = _mm_and_ps(fscal,cutoff_mask);
358 /* Update vectorial force */
359 fix3 = _mm_macc_ps(dx30,fscal,fix3);
360 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
361 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
363 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
364 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
365 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
369 fjptrA = f+j_coord_offsetA;
370 fjptrB = f+j_coord_offsetB;
371 fjptrC = f+j_coord_offsetC;
372 fjptrD = f+j_coord_offsetD;
374 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
376 /* Inner loop uses 99 flops */
382 /* Get j neighbor index, and coordinate index */
383 jnrlistA = jjnr[jidx];
384 jnrlistB = jjnr[jidx+1];
385 jnrlistC = jjnr[jidx+2];
386 jnrlistD = jjnr[jidx+3];
387 /* Sign of each element will be negative for non-real atoms.
388 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
389 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
391 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
392 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
393 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
394 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
395 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
396 j_coord_offsetA = DIM*jnrA;
397 j_coord_offsetB = DIM*jnrB;
398 j_coord_offsetC = DIM*jnrC;
399 j_coord_offsetD = DIM*jnrD;
401 /* load j atom coordinates */
402 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
403 x+j_coord_offsetC,x+j_coord_offsetD,
406 /* Calculate displacement vector */
407 dx10 = _mm_sub_ps(ix1,jx0);
408 dy10 = _mm_sub_ps(iy1,jy0);
409 dz10 = _mm_sub_ps(iz1,jz0);
410 dx20 = _mm_sub_ps(ix2,jx0);
411 dy20 = _mm_sub_ps(iy2,jy0);
412 dz20 = _mm_sub_ps(iz2,jz0);
413 dx30 = _mm_sub_ps(ix3,jx0);
414 dy30 = _mm_sub_ps(iy3,jy0);
415 dz30 = _mm_sub_ps(iz3,jz0);
417 /* Calculate squared distance and things based on it */
418 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
419 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
420 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
422 rinv10 = gmx_mm_invsqrt_ps(rsq10);
423 rinv20 = gmx_mm_invsqrt_ps(rsq20);
424 rinv30 = gmx_mm_invsqrt_ps(rsq30);
426 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
427 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
428 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
430 /* Load parameters for j particles */
431 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
432 charge+jnrC+0,charge+jnrD+0);
434 fjx0 = _mm_setzero_ps();
435 fjy0 = _mm_setzero_ps();
436 fjz0 = _mm_setzero_ps();
438 /**************************
439 * CALCULATE INTERACTIONS *
440 **************************/
442 if (gmx_mm_any_lt(rsq10,rcutoff2))
445 r10 = _mm_mul_ps(rsq10,rinv10);
446 r10 = _mm_andnot_ps(dummy_mask,r10);
448 /* Compute parameters for interactions between i and j atoms */
449 qq10 = _mm_mul_ps(iq1,jq0);
451 /* EWALD ELECTROSTATICS */
453 /* Analytical PME correction */
454 zeta2 = _mm_mul_ps(beta2,rsq10);
455 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
456 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
457 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
458 felec = _mm_mul_ps(qq10,felec);
459 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
460 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
461 velec = _mm_mul_ps(qq10,velec);
463 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
465 /* Update potential sum for this i atom from the interaction with this j atom. */
466 velec = _mm_and_ps(velec,cutoff_mask);
467 velec = _mm_andnot_ps(dummy_mask,velec);
468 velecsum = _mm_add_ps(velecsum,velec);
472 fscal = _mm_and_ps(fscal,cutoff_mask);
474 fscal = _mm_andnot_ps(dummy_mask,fscal);
476 /* Update vectorial force */
477 fix1 = _mm_macc_ps(dx10,fscal,fix1);
478 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
479 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
481 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
482 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
483 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
487 /**************************
488 * CALCULATE INTERACTIONS *
489 **************************/
491 if (gmx_mm_any_lt(rsq20,rcutoff2))
494 r20 = _mm_mul_ps(rsq20,rinv20);
495 r20 = _mm_andnot_ps(dummy_mask,r20);
497 /* Compute parameters for interactions between i and j atoms */
498 qq20 = _mm_mul_ps(iq2,jq0);
500 /* EWALD ELECTROSTATICS */
502 /* Analytical PME correction */
503 zeta2 = _mm_mul_ps(beta2,rsq20);
504 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
505 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
506 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
507 felec = _mm_mul_ps(qq20,felec);
508 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
509 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
510 velec = _mm_mul_ps(qq20,velec);
512 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
514 /* Update potential sum for this i atom from the interaction with this j atom. */
515 velec = _mm_and_ps(velec,cutoff_mask);
516 velec = _mm_andnot_ps(dummy_mask,velec);
517 velecsum = _mm_add_ps(velecsum,velec);
521 fscal = _mm_and_ps(fscal,cutoff_mask);
523 fscal = _mm_andnot_ps(dummy_mask,fscal);
525 /* Update vectorial force */
526 fix2 = _mm_macc_ps(dx20,fscal,fix2);
527 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
528 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
530 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
531 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
532 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
536 /**************************
537 * CALCULATE INTERACTIONS *
538 **************************/
540 if (gmx_mm_any_lt(rsq30,rcutoff2))
543 r30 = _mm_mul_ps(rsq30,rinv30);
544 r30 = _mm_andnot_ps(dummy_mask,r30);
546 /* Compute parameters for interactions between i and j atoms */
547 qq30 = _mm_mul_ps(iq3,jq0);
549 /* EWALD ELECTROSTATICS */
551 /* Analytical PME correction */
552 zeta2 = _mm_mul_ps(beta2,rsq30);
553 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
554 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
555 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
556 felec = _mm_mul_ps(qq30,felec);
557 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
558 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv30,sh_ewald));
559 velec = _mm_mul_ps(qq30,velec);
561 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
563 /* Update potential sum for this i atom from the interaction with this j atom. */
564 velec = _mm_and_ps(velec,cutoff_mask);
565 velec = _mm_andnot_ps(dummy_mask,velec);
566 velecsum = _mm_add_ps(velecsum,velec);
570 fscal = _mm_and_ps(fscal,cutoff_mask);
572 fscal = _mm_andnot_ps(dummy_mask,fscal);
574 /* Update vectorial force */
575 fix3 = _mm_macc_ps(dx30,fscal,fix3);
576 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
577 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
579 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
580 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
581 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
585 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
586 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
587 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
588 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
590 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
592 /* Inner loop uses 102 flops */
595 /* End of innermost loop */
597 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
598 f+i_coord_offset+DIM,fshift+i_shift_offset);
601 /* Update potential energies */
602 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
604 /* Increment number of inner iterations */
605 inneriter += j_index_end - j_index_start;
607 /* Outer loop uses 19 flops */
610 /* Increment number of outer iterations */
613 /* Update outer/inner flops */
615 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*102);
618 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomW4P1_F_avx_128_fma_single
619 * Electrostatics interaction: Ewald
620 * VdW interaction: None
621 * Geometry: Water4-Particle
622 * Calculate force/pot: Force
625 nb_kernel_ElecEwSh_VdwNone_GeomW4P1_F_avx_128_fma_single
626 (t_nblist * gmx_restrict nlist,
627 rvec * gmx_restrict xx,
628 rvec * gmx_restrict ff,
629 t_forcerec * gmx_restrict fr,
630 t_mdatoms * gmx_restrict mdatoms,
631 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
632 t_nrnb * gmx_restrict nrnb)
634 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
635 * just 0 for non-waters.
636 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
637 * jnr indices corresponding to data put in the four positions in the SIMD register.
639 int i_shift_offset,i_coord_offset,outeriter,inneriter;
640 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
641 int jnrA,jnrB,jnrC,jnrD;
642 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
643 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
644 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
646 real *shiftvec,*fshift,*x,*f;
647 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
649 __m128 fscal,rcutoff,rcutoff2,jidxall;
651 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
653 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
655 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
656 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
657 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
658 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
659 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
660 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
661 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
664 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
665 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
667 __m128 dummy_mask,cutoff_mask;
668 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
669 __m128 one = _mm_set1_ps(1.0);
670 __m128 two = _mm_set1_ps(2.0);
676 jindex = nlist->jindex;
678 shiftidx = nlist->shift;
680 shiftvec = fr->shift_vec[0];
681 fshift = fr->fshift[0];
682 facel = _mm_set1_ps(fr->epsfac);
683 charge = mdatoms->chargeA;
685 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
686 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
687 beta2 = _mm_mul_ps(beta,beta);
688 beta3 = _mm_mul_ps(beta,beta2);
689 ewtab = fr->ic->tabq_coul_F;
690 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
691 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
693 /* Setup water-specific parameters */
694 inr = nlist->iinr[0];
695 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
696 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
697 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
699 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
700 rcutoff_scalar = fr->rcoulomb;
701 rcutoff = _mm_set1_ps(rcutoff_scalar);
702 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
704 /* Avoid stupid compiler warnings */
705 jnrA = jnrB = jnrC = jnrD = 0;
714 for(iidx=0;iidx<4*DIM;iidx++)
719 /* Start outer loop over neighborlists */
720 for(iidx=0; iidx<nri; iidx++)
722 /* Load shift vector for this list */
723 i_shift_offset = DIM*shiftidx[iidx];
725 /* Load limits for loop over neighbors */
726 j_index_start = jindex[iidx];
727 j_index_end = jindex[iidx+1];
729 /* Get outer coordinate index */
731 i_coord_offset = DIM*inr;
733 /* Load i particle coords and add shift vector */
734 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
735 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
737 fix1 = _mm_setzero_ps();
738 fiy1 = _mm_setzero_ps();
739 fiz1 = _mm_setzero_ps();
740 fix2 = _mm_setzero_ps();
741 fiy2 = _mm_setzero_ps();
742 fiz2 = _mm_setzero_ps();
743 fix3 = _mm_setzero_ps();
744 fiy3 = _mm_setzero_ps();
745 fiz3 = _mm_setzero_ps();
747 /* Start inner kernel loop */
748 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
751 /* Get j neighbor index, and coordinate index */
756 j_coord_offsetA = DIM*jnrA;
757 j_coord_offsetB = DIM*jnrB;
758 j_coord_offsetC = DIM*jnrC;
759 j_coord_offsetD = DIM*jnrD;
761 /* load j atom coordinates */
762 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
763 x+j_coord_offsetC,x+j_coord_offsetD,
766 /* Calculate displacement vector */
767 dx10 = _mm_sub_ps(ix1,jx0);
768 dy10 = _mm_sub_ps(iy1,jy0);
769 dz10 = _mm_sub_ps(iz1,jz0);
770 dx20 = _mm_sub_ps(ix2,jx0);
771 dy20 = _mm_sub_ps(iy2,jy0);
772 dz20 = _mm_sub_ps(iz2,jz0);
773 dx30 = _mm_sub_ps(ix3,jx0);
774 dy30 = _mm_sub_ps(iy3,jy0);
775 dz30 = _mm_sub_ps(iz3,jz0);
777 /* Calculate squared distance and things based on it */
778 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
779 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
780 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
782 rinv10 = gmx_mm_invsqrt_ps(rsq10);
783 rinv20 = gmx_mm_invsqrt_ps(rsq20);
784 rinv30 = gmx_mm_invsqrt_ps(rsq30);
786 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
787 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
788 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
790 /* Load parameters for j particles */
791 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
792 charge+jnrC+0,charge+jnrD+0);
794 fjx0 = _mm_setzero_ps();
795 fjy0 = _mm_setzero_ps();
796 fjz0 = _mm_setzero_ps();
798 /**************************
799 * CALCULATE INTERACTIONS *
800 **************************/
802 if (gmx_mm_any_lt(rsq10,rcutoff2))
805 r10 = _mm_mul_ps(rsq10,rinv10);
807 /* Compute parameters for interactions between i and j atoms */
808 qq10 = _mm_mul_ps(iq1,jq0);
810 /* EWALD ELECTROSTATICS */
812 /* Analytical PME correction */
813 zeta2 = _mm_mul_ps(beta2,rsq10);
814 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
815 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
816 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
817 felec = _mm_mul_ps(qq10,felec);
819 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
823 fscal = _mm_and_ps(fscal,cutoff_mask);
825 /* Update vectorial force */
826 fix1 = _mm_macc_ps(dx10,fscal,fix1);
827 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
828 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
830 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
831 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
832 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
836 /**************************
837 * CALCULATE INTERACTIONS *
838 **************************/
840 if (gmx_mm_any_lt(rsq20,rcutoff2))
843 r20 = _mm_mul_ps(rsq20,rinv20);
845 /* Compute parameters for interactions between i and j atoms */
846 qq20 = _mm_mul_ps(iq2,jq0);
848 /* EWALD ELECTROSTATICS */
850 /* Analytical PME correction */
851 zeta2 = _mm_mul_ps(beta2,rsq20);
852 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
853 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
854 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
855 felec = _mm_mul_ps(qq20,felec);
857 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
861 fscal = _mm_and_ps(fscal,cutoff_mask);
863 /* Update vectorial force */
864 fix2 = _mm_macc_ps(dx20,fscal,fix2);
865 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
866 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
868 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
869 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
870 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
874 /**************************
875 * CALCULATE INTERACTIONS *
876 **************************/
878 if (gmx_mm_any_lt(rsq30,rcutoff2))
881 r30 = _mm_mul_ps(rsq30,rinv30);
883 /* Compute parameters for interactions between i and j atoms */
884 qq30 = _mm_mul_ps(iq3,jq0);
886 /* EWALD ELECTROSTATICS */
888 /* Analytical PME correction */
889 zeta2 = _mm_mul_ps(beta2,rsq30);
890 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
891 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
892 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
893 felec = _mm_mul_ps(qq30,felec);
895 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
899 fscal = _mm_and_ps(fscal,cutoff_mask);
901 /* Update vectorial force */
902 fix3 = _mm_macc_ps(dx30,fscal,fix3);
903 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
904 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
906 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
907 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
908 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
912 fjptrA = f+j_coord_offsetA;
913 fjptrB = f+j_coord_offsetB;
914 fjptrC = f+j_coord_offsetC;
915 fjptrD = f+j_coord_offsetD;
917 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
919 /* Inner loop uses 93 flops */
925 /* Get j neighbor index, and coordinate index */
926 jnrlistA = jjnr[jidx];
927 jnrlistB = jjnr[jidx+1];
928 jnrlistC = jjnr[jidx+2];
929 jnrlistD = jjnr[jidx+3];
930 /* Sign of each element will be negative for non-real atoms.
931 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
932 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
934 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
935 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
936 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
937 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
938 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
939 j_coord_offsetA = DIM*jnrA;
940 j_coord_offsetB = DIM*jnrB;
941 j_coord_offsetC = DIM*jnrC;
942 j_coord_offsetD = DIM*jnrD;
944 /* load j atom coordinates */
945 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
946 x+j_coord_offsetC,x+j_coord_offsetD,
949 /* Calculate displacement vector */
950 dx10 = _mm_sub_ps(ix1,jx0);
951 dy10 = _mm_sub_ps(iy1,jy0);
952 dz10 = _mm_sub_ps(iz1,jz0);
953 dx20 = _mm_sub_ps(ix2,jx0);
954 dy20 = _mm_sub_ps(iy2,jy0);
955 dz20 = _mm_sub_ps(iz2,jz0);
956 dx30 = _mm_sub_ps(ix3,jx0);
957 dy30 = _mm_sub_ps(iy3,jy0);
958 dz30 = _mm_sub_ps(iz3,jz0);
960 /* Calculate squared distance and things based on it */
961 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
962 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
963 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
965 rinv10 = gmx_mm_invsqrt_ps(rsq10);
966 rinv20 = gmx_mm_invsqrt_ps(rsq20);
967 rinv30 = gmx_mm_invsqrt_ps(rsq30);
969 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
970 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
971 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
973 /* Load parameters for j particles */
974 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
975 charge+jnrC+0,charge+jnrD+0);
977 fjx0 = _mm_setzero_ps();
978 fjy0 = _mm_setzero_ps();
979 fjz0 = _mm_setzero_ps();
981 /**************************
982 * CALCULATE INTERACTIONS *
983 **************************/
985 if (gmx_mm_any_lt(rsq10,rcutoff2))
988 r10 = _mm_mul_ps(rsq10,rinv10);
989 r10 = _mm_andnot_ps(dummy_mask,r10);
991 /* Compute parameters for interactions between i and j atoms */
992 qq10 = _mm_mul_ps(iq1,jq0);
994 /* EWALD ELECTROSTATICS */
996 /* Analytical PME correction */
997 zeta2 = _mm_mul_ps(beta2,rsq10);
998 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
999 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1000 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1001 felec = _mm_mul_ps(qq10,felec);
1003 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1007 fscal = _mm_and_ps(fscal,cutoff_mask);
1009 fscal = _mm_andnot_ps(dummy_mask,fscal);
1011 /* Update vectorial force */
1012 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1013 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1014 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1016 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1017 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1018 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1022 /**************************
1023 * CALCULATE INTERACTIONS *
1024 **************************/
1026 if (gmx_mm_any_lt(rsq20,rcutoff2))
1029 r20 = _mm_mul_ps(rsq20,rinv20);
1030 r20 = _mm_andnot_ps(dummy_mask,r20);
1032 /* Compute parameters for interactions between i and j atoms */
1033 qq20 = _mm_mul_ps(iq2,jq0);
1035 /* EWALD ELECTROSTATICS */
1037 /* Analytical PME correction */
1038 zeta2 = _mm_mul_ps(beta2,rsq20);
1039 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1040 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1041 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1042 felec = _mm_mul_ps(qq20,felec);
1044 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1048 fscal = _mm_and_ps(fscal,cutoff_mask);
1050 fscal = _mm_andnot_ps(dummy_mask,fscal);
1052 /* Update vectorial force */
1053 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1054 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1055 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1057 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1058 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1059 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1063 /**************************
1064 * CALCULATE INTERACTIONS *
1065 **************************/
1067 if (gmx_mm_any_lt(rsq30,rcutoff2))
1070 r30 = _mm_mul_ps(rsq30,rinv30);
1071 r30 = _mm_andnot_ps(dummy_mask,r30);
1073 /* Compute parameters for interactions between i and j atoms */
1074 qq30 = _mm_mul_ps(iq3,jq0);
1076 /* EWALD ELECTROSTATICS */
1078 /* Analytical PME correction */
1079 zeta2 = _mm_mul_ps(beta2,rsq30);
1080 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
1081 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1082 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1083 felec = _mm_mul_ps(qq30,felec);
1085 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1089 fscal = _mm_and_ps(fscal,cutoff_mask);
1091 fscal = _mm_andnot_ps(dummy_mask,fscal);
1093 /* Update vectorial force */
1094 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1095 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1096 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1098 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1099 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1100 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1104 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1105 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1106 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1107 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1109 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1111 /* Inner loop uses 96 flops */
1114 /* End of innermost loop */
1116 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1117 f+i_coord_offset+DIM,fshift+i_shift_offset);
1119 /* Increment number of inner iterations */
1120 inneriter += j_index_end - j_index_start;
1122 /* Outer loop uses 18 flops */
1125 /* Increment number of outer iterations */
1128 /* Update outer/inner flops */
1130 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*96);