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 "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomW3P1_VF_avx_128_fma_single
54 * Electrostatics interaction: Ewald
55 * VdW interaction: None
56 * Geometry: Water3-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEwSh_VdwNone_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 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
100 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
102 __m128 dummy_mask,cutoff_mask;
103 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
104 __m128 one = _mm_set1_ps(1.0);
105 __m128 two = _mm_set1_ps(2.0);
111 jindex = nlist->jindex;
113 shiftidx = nlist->shift;
115 shiftvec = fr->shift_vec[0];
116 fshift = fr->fshift[0];
117 facel = _mm_set1_ps(fr->epsfac);
118 charge = mdatoms->chargeA;
120 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
121 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
122 beta2 = _mm_mul_ps(beta,beta);
123 beta3 = _mm_mul_ps(beta,beta2);
124 ewtab = fr->ic->tabq_coul_FDV0;
125 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
126 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
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]));
134 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
135 rcutoff_scalar = fr->rcoulomb;
136 rcutoff = _mm_set1_ps(rcutoff_scalar);
137 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
139 /* Avoid stupid compiler warnings */
140 jnrA = jnrB = jnrC = jnrD = 0;
149 for(iidx=0;iidx<4*DIM;iidx++)
154 /* Start outer loop over neighborlists */
155 for(iidx=0; iidx<nri; iidx++)
157 /* Load shift vector for this list */
158 i_shift_offset = DIM*shiftidx[iidx];
160 /* Load limits for loop over neighbors */
161 j_index_start = jindex[iidx];
162 j_index_end = jindex[iidx+1];
164 /* Get outer coordinate index */
166 i_coord_offset = DIM*inr;
168 /* Load i particle coords and add shift vector */
169 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
170 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
172 fix0 = _mm_setzero_ps();
173 fiy0 = _mm_setzero_ps();
174 fiz0 = _mm_setzero_ps();
175 fix1 = _mm_setzero_ps();
176 fiy1 = _mm_setzero_ps();
177 fiz1 = _mm_setzero_ps();
178 fix2 = _mm_setzero_ps();
179 fiy2 = _mm_setzero_ps();
180 fiz2 = _mm_setzero_ps();
182 /* Reset potential sums */
183 velecsum = _mm_setzero_ps();
185 /* Start inner kernel loop */
186 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
189 /* Get j neighbor index, and coordinate index */
194 j_coord_offsetA = DIM*jnrA;
195 j_coord_offsetB = DIM*jnrB;
196 j_coord_offsetC = DIM*jnrC;
197 j_coord_offsetD = DIM*jnrD;
199 /* load j atom coordinates */
200 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
201 x+j_coord_offsetC,x+j_coord_offsetD,
204 /* Calculate displacement vector */
205 dx00 = _mm_sub_ps(ix0,jx0);
206 dy00 = _mm_sub_ps(iy0,jy0);
207 dz00 = _mm_sub_ps(iz0,jz0);
208 dx10 = _mm_sub_ps(ix1,jx0);
209 dy10 = _mm_sub_ps(iy1,jy0);
210 dz10 = _mm_sub_ps(iz1,jz0);
211 dx20 = _mm_sub_ps(ix2,jx0);
212 dy20 = _mm_sub_ps(iy2,jy0);
213 dz20 = _mm_sub_ps(iz2,jz0);
215 /* Calculate squared distance and things based on it */
216 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
217 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
218 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
220 rinv00 = gmx_mm_invsqrt_ps(rsq00);
221 rinv10 = gmx_mm_invsqrt_ps(rsq10);
222 rinv20 = gmx_mm_invsqrt_ps(rsq20);
224 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
225 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
226 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
228 /* Load parameters for j particles */
229 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
230 charge+jnrC+0,charge+jnrD+0);
232 fjx0 = _mm_setzero_ps();
233 fjy0 = _mm_setzero_ps();
234 fjz0 = _mm_setzero_ps();
236 /**************************
237 * CALCULATE INTERACTIONS *
238 **************************/
240 if (gmx_mm_any_lt(rsq00,rcutoff2))
243 r00 = _mm_mul_ps(rsq00,rinv00);
245 /* Compute parameters for interactions between i and j atoms */
246 qq00 = _mm_mul_ps(iq0,jq0);
248 /* EWALD ELECTROSTATICS */
250 /* Analytical PME correction */
251 zeta2 = _mm_mul_ps(beta2,rsq00);
252 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
253 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
254 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
255 felec = _mm_mul_ps(qq00,felec);
256 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
257 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
258 velec = _mm_mul_ps(qq00,velec);
260 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
262 /* Update potential sum for this i atom from the interaction with this j atom. */
263 velec = _mm_and_ps(velec,cutoff_mask);
264 velecsum = _mm_add_ps(velecsum,velec);
268 fscal = _mm_and_ps(fscal,cutoff_mask);
270 /* Update vectorial force */
271 fix0 = _mm_macc_ps(dx00,fscal,fix0);
272 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
273 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
275 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
276 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
277 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
281 /**************************
282 * CALCULATE INTERACTIONS *
283 **************************/
285 if (gmx_mm_any_lt(rsq10,rcutoff2))
288 r10 = _mm_mul_ps(rsq10,rinv10);
290 /* Compute parameters for interactions between i and j atoms */
291 qq10 = _mm_mul_ps(iq1,jq0);
293 /* EWALD ELECTROSTATICS */
295 /* Analytical PME correction */
296 zeta2 = _mm_mul_ps(beta2,rsq10);
297 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
298 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
299 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
300 felec = _mm_mul_ps(qq10,felec);
301 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
302 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
303 velec = _mm_mul_ps(qq10,velec);
305 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
307 /* Update potential sum for this i atom from the interaction with this j atom. */
308 velec = _mm_and_ps(velec,cutoff_mask);
309 velecsum = _mm_add_ps(velecsum,velec);
313 fscal = _mm_and_ps(fscal,cutoff_mask);
315 /* Update vectorial force */
316 fix1 = _mm_macc_ps(dx10,fscal,fix1);
317 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
318 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
320 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
321 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
322 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
326 /**************************
327 * CALCULATE INTERACTIONS *
328 **************************/
330 if (gmx_mm_any_lt(rsq20,rcutoff2))
333 r20 = _mm_mul_ps(rsq20,rinv20);
335 /* Compute parameters for interactions between i and j atoms */
336 qq20 = _mm_mul_ps(iq2,jq0);
338 /* EWALD ELECTROSTATICS */
340 /* Analytical PME correction */
341 zeta2 = _mm_mul_ps(beta2,rsq20);
342 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
343 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
344 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
345 felec = _mm_mul_ps(qq20,felec);
346 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
347 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
348 velec = _mm_mul_ps(qq20,velec);
350 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
352 /* Update potential sum for this i atom from the interaction with this j atom. */
353 velec = _mm_and_ps(velec,cutoff_mask);
354 velecsum = _mm_add_ps(velecsum,velec);
358 fscal = _mm_and_ps(fscal,cutoff_mask);
360 /* Update vectorial force */
361 fix2 = _mm_macc_ps(dx20,fscal,fix2);
362 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
363 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
365 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
366 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
367 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
371 fjptrA = f+j_coord_offsetA;
372 fjptrB = f+j_coord_offsetB;
373 fjptrC = f+j_coord_offsetC;
374 fjptrD = f+j_coord_offsetD;
376 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
378 /* Inner loop uses 99 flops */
384 /* Get j neighbor index, and coordinate index */
385 jnrlistA = jjnr[jidx];
386 jnrlistB = jjnr[jidx+1];
387 jnrlistC = jjnr[jidx+2];
388 jnrlistD = jjnr[jidx+3];
389 /* Sign of each element will be negative for non-real atoms.
390 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
391 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
393 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
394 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
395 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
396 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
397 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
398 j_coord_offsetA = DIM*jnrA;
399 j_coord_offsetB = DIM*jnrB;
400 j_coord_offsetC = DIM*jnrC;
401 j_coord_offsetD = DIM*jnrD;
403 /* load j atom coordinates */
404 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
405 x+j_coord_offsetC,x+j_coord_offsetD,
408 /* Calculate displacement vector */
409 dx00 = _mm_sub_ps(ix0,jx0);
410 dy00 = _mm_sub_ps(iy0,jy0);
411 dz00 = _mm_sub_ps(iz0,jz0);
412 dx10 = _mm_sub_ps(ix1,jx0);
413 dy10 = _mm_sub_ps(iy1,jy0);
414 dz10 = _mm_sub_ps(iz1,jz0);
415 dx20 = _mm_sub_ps(ix2,jx0);
416 dy20 = _mm_sub_ps(iy2,jy0);
417 dz20 = _mm_sub_ps(iz2,jz0);
419 /* Calculate squared distance and things based on it */
420 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
421 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
422 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
424 rinv00 = gmx_mm_invsqrt_ps(rsq00);
425 rinv10 = gmx_mm_invsqrt_ps(rsq10);
426 rinv20 = gmx_mm_invsqrt_ps(rsq20);
428 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
429 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
430 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
432 /* Load parameters for j particles */
433 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
434 charge+jnrC+0,charge+jnrD+0);
436 fjx0 = _mm_setzero_ps();
437 fjy0 = _mm_setzero_ps();
438 fjz0 = _mm_setzero_ps();
440 /**************************
441 * CALCULATE INTERACTIONS *
442 **************************/
444 if (gmx_mm_any_lt(rsq00,rcutoff2))
447 r00 = _mm_mul_ps(rsq00,rinv00);
448 r00 = _mm_andnot_ps(dummy_mask,r00);
450 /* Compute parameters for interactions between i and j atoms */
451 qq00 = _mm_mul_ps(iq0,jq0);
453 /* EWALD ELECTROSTATICS */
455 /* Analytical PME correction */
456 zeta2 = _mm_mul_ps(beta2,rsq00);
457 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
458 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
459 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
460 felec = _mm_mul_ps(qq00,felec);
461 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
462 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
463 velec = _mm_mul_ps(qq00,velec);
465 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
467 /* Update potential sum for this i atom from the interaction with this j atom. */
468 velec = _mm_and_ps(velec,cutoff_mask);
469 velec = _mm_andnot_ps(dummy_mask,velec);
470 velecsum = _mm_add_ps(velecsum,velec);
474 fscal = _mm_and_ps(fscal,cutoff_mask);
476 fscal = _mm_andnot_ps(dummy_mask,fscal);
478 /* Update vectorial force */
479 fix0 = _mm_macc_ps(dx00,fscal,fix0);
480 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
481 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
483 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
484 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
485 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
489 /**************************
490 * CALCULATE INTERACTIONS *
491 **************************/
493 if (gmx_mm_any_lt(rsq10,rcutoff2))
496 r10 = _mm_mul_ps(rsq10,rinv10);
497 r10 = _mm_andnot_ps(dummy_mask,r10);
499 /* Compute parameters for interactions between i and j atoms */
500 qq10 = _mm_mul_ps(iq1,jq0);
502 /* EWALD ELECTROSTATICS */
504 /* Analytical PME correction */
505 zeta2 = _mm_mul_ps(beta2,rsq10);
506 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
507 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
508 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
509 felec = _mm_mul_ps(qq10,felec);
510 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
511 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
512 velec = _mm_mul_ps(qq10,velec);
514 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
516 /* Update potential sum for this i atom from the interaction with this j atom. */
517 velec = _mm_and_ps(velec,cutoff_mask);
518 velec = _mm_andnot_ps(dummy_mask,velec);
519 velecsum = _mm_add_ps(velecsum,velec);
523 fscal = _mm_and_ps(fscal,cutoff_mask);
525 fscal = _mm_andnot_ps(dummy_mask,fscal);
527 /* Update vectorial force */
528 fix1 = _mm_macc_ps(dx10,fscal,fix1);
529 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
530 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
532 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
533 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
534 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
538 /**************************
539 * CALCULATE INTERACTIONS *
540 **************************/
542 if (gmx_mm_any_lt(rsq20,rcutoff2))
545 r20 = _mm_mul_ps(rsq20,rinv20);
546 r20 = _mm_andnot_ps(dummy_mask,r20);
548 /* Compute parameters for interactions between i and j atoms */
549 qq20 = _mm_mul_ps(iq2,jq0);
551 /* EWALD ELECTROSTATICS */
553 /* Analytical PME correction */
554 zeta2 = _mm_mul_ps(beta2,rsq20);
555 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
556 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
557 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
558 felec = _mm_mul_ps(qq20,felec);
559 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
560 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
561 velec = _mm_mul_ps(qq20,velec);
563 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
565 /* Update potential sum for this i atom from the interaction with this j atom. */
566 velec = _mm_and_ps(velec,cutoff_mask);
567 velec = _mm_andnot_ps(dummy_mask,velec);
568 velecsum = _mm_add_ps(velecsum,velec);
572 fscal = _mm_and_ps(fscal,cutoff_mask);
574 fscal = _mm_andnot_ps(dummy_mask,fscal);
576 /* Update vectorial force */
577 fix2 = _mm_macc_ps(dx20,fscal,fix2);
578 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
579 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
581 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
582 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
583 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
587 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
588 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
589 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
590 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
592 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
594 /* Inner loop uses 102 flops */
597 /* End of innermost loop */
599 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
600 f+i_coord_offset,fshift+i_shift_offset);
603 /* Update potential energies */
604 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
606 /* Increment number of inner iterations */
607 inneriter += j_index_end - j_index_start;
609 /* Outer loop uses 19 flops */
612 /* Increment number of outer iterations */
615 /* Update outer/inner flops */
617 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*102);
620 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomW3P1_F_avx_128_fma_single
621 * Electrostatics interaction: Ewald
622 * VdW interaction: None
623 * Geometry: Water3-Particle
624 * Calculate force/pot: Force
627 nb_kernel_ElecEwSh_VdwNone_GeomW3P1_F_avx_128_fma_single
628 (t_nblist * gmx_restrict nlist,
629 rvec * gmx_restrict xx,
630 rvec * gmx_restrict ff,
631 t_forcerec * gmx_restrict fr,
632 t_mdatoms * gmx_restrict mdatoms,
633 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
634 t_nrnb * gmx_restrict nrnb)
636 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
637 * just 0 for non-waters.
638 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
639 * jnr indices corresponding to data put in the four positions in the SIMD register.
641 int i_shift_offset,i_coord_offset,outeriter,inneriter;
642 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
643 int jnrA,jnrB,jnrC,jnrD;
644 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
645 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
646 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
648 real *shiftvec,*fshift,*x,*f;
649 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
651 __m128 fscal,rcutoff,rcutoff2,jidxall;
653 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
655 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
657 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
658 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
659 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
660 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
661 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
662 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
663 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
666 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
667 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
669 __m128 dummy_mask,cutoff_mask;
670 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
671 __m128 one = _mm_set1_ps(1.0);
672 __m128 two = _mm_set1_ps(2.0);
678 jindex = nlist->jindex;
680 shiftidx = nlist->shift;
682 shiftvec = fr->shift_vec[0];
683 fshift = fr->fshift[0];
684 facel = _mm_set1_ps(fr->epsfac);
685 charge = mdatoms->chargeA;
687 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
688 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
689 beta2 = _mm_mul_ps(beta,beta);
690 beta3 = _mm_mul_ps(beta,beta2);
691 ewtab = fr->ic->tabq_coul_F;
692 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
693 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
695 /* Setup water-specific parameters */
696 inr = nlist->iinr[0];
697 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
698 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
699 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
701 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
702 rcutoff_scalar = fr->rcoulomb;
703 rcutoff = _mm_set1_ps(rcutoff_scalar);
704 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
706 /* Avoid stupid compiler warnings */
707 jnrA = jnrB = jnrC = jnrD = 0;
716 for(iidx=0;iidx<4*DIM;iidx++)
721 /* Start outer loop over neighborlists */
722 for(iidx=0; iidx<nri; iidx++)
724 /* Load shift vector for this list */
725 i_shift_offset = DIM*shiftidx[iidx];
727 /* Load limits for loop over neighbors */
728 j_index_start = jindex[iidx];
729 j_index_end = jindex[iidx+1];
731 /* Get outer coordinate index */
733 i_coord_offset = DIM*inr;
735 /* Load i particle coords and add shift vector */
736 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
737 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
739 fix0 = _mm_setzero_ps();
740 fiy0 = _mm_setzero_ps();
741 fiz0 = _mm_setzero_ps();
742 fix1 = _mm_setzero_ps();
743 fiy1 = _mm_setzero_ps();
744 fiz1 = _mm_setzero_ps();
745 fix2 = _mm_setzero_ps();
746 fiy2 = _mm_setzero_ps();
747 fiz2 = _mm_setzero_ps();
749 /* Start inner kernel loop */
750 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
753 /* Get j neighbor index, and coordinate index */
758 j_coord_offsetA = DIM*jnrA;
759 j_coord_offsetB = DIM*jnrB;
760 j_coord_offsetC = DIM*jnrC;
761 j_coord_offsetD = DIM*jnrD;
763 /* load j atom coordinates */
764 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
765 x+j_coord_offsetC,x+j_coord_offsetD,
768 /* Calculate displacement vector */
769 dx00 = _mm_sub_ps(ix0,jx0);
770 dy00 = _mm_sub_ps(iy0,jy0);
771 dz00 = _mm_sub_ps(iz0,jz0);
772 dx10 = _mm_sub_ps(ix1,jx0);
773 dy10 = _mm_sub_ps(iy1,jy0);
774 dz10 = _mm_sub_ps(iz1,jz0);
775 dx20 = _mm_sub_ps(ix2,jx0);
776 dy20 = _mm_sub_ps(iy2,jy0);
777 dz20 = _mm_sub_ps(iz2,jz0);
779 /* Calculate squared distance and things based on it */
780 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
781 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
782 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
784 rinv00 = gmx_mm_invsqrt_ps(rsq00);
785 rinv10 = gmx_mm_invsqrt_ps(rsq10);
786 rinv20 = gmx_mm_invsqrt_ps(rsq20);
788 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
789 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
790 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
792 /* Load parameters for j particles */
793 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
794 charge+jnrC+0,charge+jnrD+0);
796 fjx0 = _mm_setzero_ps();
797 fjy0 = _mm_setzero_ps();
798 fjz0 = _mm_setzero_ps();
800 /**************************
801 * CALCULATE INTERACTIONS *
802 **************************/
804 if (gmx_mm_any_lt(rsq00,rcutoff2))
807 r00 = _mm_mul_ps(rsq00,rinv00);
809 /* Compute parameters for interactions between i and j atoms */
810 qq00 = _mm_mul_ps(iq0,jq0);
812 /* EWALD ELECTROSTATICS */
814 /* Analytical PME correction */
815 zeta2 = _mm_mul_ps(beta2,rsq00);
816 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
817 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
818 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
819 felec = _mm_mul_ps(qq00,felec);
821 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
825 fscal = _mm_and_ps(fscal,cutoff_mask);
827 /* Update vectorial force */
828 fix0 = _mm_macc_ps(dx00,fscal,fix0);
829 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
830 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
832 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
833 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
834 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
838 /**************************
839 * CALCULATE INTERACTIONS *
840 **************************/
842 if (gmx_mm_any_lt(rsq10,rcutoff2))
845 r10 = _mm_mul_ps(rsq10,rinv10);
847 /* Compute parameters for interactions between i and j atoms */
848 qq10 = _mm_mul_ps(iq1,jq0);
850 /* EWALD ELECTROSTATICS */
852 /* Analytical PME correction */
853 zeta2 = _mm_mul_ps(beta2,rsq10);
854 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
855 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
856 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
857 felec = _mm_mul_ps(qq10,felec);
859 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
863 fscal = _mm_and_ps(fscal,cutoff_mask);
865 /* Update vectorial force */
866 fix1 = _mm_macc_ps(dx10,fscal,fix1);
867 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
868 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
870 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
871 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
872 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
876 /**************************
877 * CALCULATE INTERACTIONS *
878 **************************/
880 if (gmx_mm_any_lt(rsq20,rcutoff2))
883 r20 = _mm_mul_ps(rsq20,rinv20);
885 /* Compute parameters for interactions between i and j atoms */
886 qq20 = _mm_mul_ps(iq2,jq0);
888 /* EWALD ELECTROSTATICS */
890 /* Analytical PME correction */
891 zeta2 = _mm_mul_ps(beta2,rsq20);
892 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
893 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
894 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
895 felec = _mm_mul_ps(qq20,felec);
897 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
901 fscal = _mm_and_ps(fscal,cutoff_mask);
903 /* Update vectorial force */
904 fix2 = _mm_macc_ps(dx20,fscal,fix2);
905 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
906 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
908 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
909 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
910 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
914 fjptrA = f+j_coord_offsetA;
915 fjptrB = f+j_coord_offsetB;
916 fjptrC = f+j_coord_offsetC;
917 fjptrD = f+j_coord_offsetD;
919 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
921 /* Inner loop uses 93 flops */
927 /* Get j neighbor index, and coordinate index */
928 jnrlistA = jjnr[jidx];
929 jnrlistB = jjnr[jidx+1];
930 jnrlistC = jjnr[jidx+2];
931 jnrlistD = jjnr[jidx+3];
932 /* Sign of each element will be negative for non-real atoms.
933 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
934 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
936 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
937 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
938 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
939 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
940 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
941 j_coord_offsetA = DIM*jnrA;
942 j_coord_offsetB = DIM*jnrB;
943 j_coord_offsetC = DIM*jnrC;
944 j_coord_offsetD = DIM*jnrD;
946 /* load j atom coordinates */
947 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
948 x+j_coord_offsetC,x+j_coord_offsetD,
951 /* Calculate displacement vector */
952 dx00 = _mm_sub_ps(ix0,jx0);
953 dy00 = _mm_sub_ps(iy0,jy0);
954 dz00 = _mm_sub_ps(iz0,jz0);
955 dx10 = _mm_sub_ps(ix1,jx0);
956 dy10 = _mm_sub_ps(iy1,jy0);
957 dz10 = _mm_sub_ps(iz1,jz0);
958 dx20 = _mm_sub_ps(ix2,jx0);
959 dy20 = _mm_sub_ps(iy2,jy0);
960 dz20 = _mm_sub_ps(iz2,jz0);
962 /* Calculate squared distance and things based on it */
963 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
964 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
965 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
967 rinv00 = gmx_mm_invsqrt_ps(rsq00);
968 rinv10 = gmx_mm_invsqrt_ps(rsq10);
969 rinv20 = gmx_mm_invsqrt_ps(rsq20);
971 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
972 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
973 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
975 /* Load parameters for j particles */
976 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
977 charge+jnrC+0,charge+jnrD+0);
979 fjx0 = _mm_setzero_ps();
980 fjy0 = _mm_setzero_ps();
981 fjz0 = _mm_setzero_ps();
983 /**************************
984 * CALCULATE INTERACTIONS *
985 **************************/
987 if (gmx_mm_any_lt(rsq00,rcutoff2))
990 r00 = _mm_mul_ps(rsq00,rinv00);
991 r00 = _mm_andnot_ps(dummy_mask,r00);
993 /* Compute parameters for interactions between i and j atoms */
994 qq00 = _mm_mul_ps(iq0,jq0);
996 /* EWALD ELECTROSTATICS */
998 /* Analytical PME correction */
999 zeta2 = _mm_mul_ps(beta2,rsq00);
1000 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
1001 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1002 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1003 felec = _mm_mul_ps(qq00,felec);
1005 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1009 fscal = _mm_and_ps(fscal,cutoff_mask);
1011 fscal = _mm_andnot_ps(dummy_mask,fscal);
1013 /* Update vectorial force */
1014 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1015 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1016 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1018 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1019 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1020 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1024 /**************************
1025 * CALCULATE INTERACTIONS *
1026 **************************/
1028 if (gmx_mm_any_lt(rsq10,rcutoff2))
1031 r10 = _mm_mul_ps(rsq10,rinv10);
1032 r10 = _mm_andnot_ps(dummy_mask,r10);
1034 /* Compute parameters for interactions between i and j atoms */
1035 qq10 = _mm_mul_ps(iq1,jq0);
1037 /* EWALD ELECTROSTATICS */
1039 /* Analytical PME correction */
1040 zeta2 = _mm_mul_ps(beta2,rsq10);
1041 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
1042 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1043 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1044 felec = _mm_mul_ps(qq10,felec);
1046 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1050 fscal = _mm_and_ps(fscal,cutoff_mask);
1052 fscal = _mm_andnot_ps(dummy_mask,fscal);
1054 /* Update vectorial force */
1055 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1056 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1057 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1059 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1060 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1061 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1065 /**************************
1066 * CALCULATE INTERACTIONS *
1067 **************************/
1069 if (gmx_mm_any_lt(rsq20,rcutoff2))
1072 r20 = _mm_mul_ps(rsq20,rinv20);
1073 r20 = _mm_andnot_ps(dummy_mask,r20);
1075 /* Compute parameters for interactions between i and j atoms */
1076 qq20 = _mm_mul_ps(iq2,jq0);
1078 /* EWALD ELECTROSTATICS */
1080 /* Analytical PME correction */
1081 zeta2 = _mm_mul_ps(beta2,rsq20);
1082 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
1083 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
1084 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
1085 felec = _mm_mul_ps(qq20,felec);
1087 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1091 fscal = _mm_and_ps(fscal,cutoff_mask);
1093 fscal = _mm_andnot_ps(dummy_mask,fscal);
1095 /* Update vectorial force */
1096 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1097 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1098 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1100 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1101 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1102 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1106 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1107 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1108 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1109 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1111 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1113 /* Inner loop uses 96 flops */
1116 /* End of innermost loop */
1118 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1119 f+i_coord_offset,fshift+i_shift_offset);
1121 /* Increment number of inner iterations */
1122 inneriter += j_index_end - j_index_start;
1124 /* Outer loop uses 18 flops */
1127 /* Increment number of outer iterations */
1130 /* Update outer/inner flops */
1132 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*96);