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_256_double 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_256_double.h"
48 #include "kernelutil_x86_avx_256_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomW3P1_VF_avx_256_double
52 * Electrostatics interaction: Ewald
53 * VdW interaction: None
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEwSh_VdwNone_GeomW3P1_VF_avx_256_double
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, 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 jnrlistE,jnrlistF,jnrlistG,jnrlistH;
77 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
78 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
80 real *shiftvec,*fshift,*x,*f;
81 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
83 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
84 real * vdwioffsetptr0;
85 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 real * vdwioffsetptr1;
87 __m256d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 real * vdwioffsetptr2;
89 __m256d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
91 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93 __m256d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m256d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
98 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
99 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
101 __m256d dummy_mask,cutoff_mask;
102 __m128 tmpmask0,tmpmask1;
103 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
104 __m256d one = _mm256_set1_pd(1.0);
105 __m256d two = _mm256_set1_pd(2.0);
111 jindex = nlist->jindex;
113 shiftidx = nlist->shift;
115 shiftvec = fr->shift_vec[0];
116 fshift = fr->fshift[0];
117 facel = _mm256_set1_pd(fr->epsfac);
118 charge = mdatoms->chargeA;
120 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
121 beta = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
122 beta2 = _mm256_mul_pd(beta,beta);
123 beta3 = _mm256_mul_pd(beta,beta2);
125 ewtab = fr->ic->tabq_coul_FDV0;
126 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
127 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
129 /* Setup water-specific parameters */
130 inr = nlist->iinr[0];
131 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
132 iq1 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+1]));
133 iq2 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+2]));
135 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
136 rcutoff_scalar = fr->rcoulomb;
137 rcutoff = _mm256_set1_pd(rcutoff_scalar);
138 rcutoff2 = _mm256_mul_pd(rcutoff,rcutoff);
140 /* Avoid stupid compiler warnings */
141 jnrA = jnrB = jnrC = jnrD = 0;
150 for(iidx=0;iidx<4*DIM;iidx++)
155 /* Start outer loop over neighborlists */
156 for(iidx=0; iidx<nri; iidx++)
158 /* Load shift vector for this list */
159 i_shift_offset = DIM*shiftidx[iidx];
161 /* Load limits for loop over neighbors */
162 j_index_start = jindex[iidx];
163 j_index_end = jindex[iidx+1];
165 /* Get outer coordinate index */
167 i_coord_offset = DIM*inr;
169 /* Load i particle coords and add shift vector */
170 gmx_mm256_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
171 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
173 fix0 = _mm256_setzero_pd();
174 fiy0 = _mm256_setzero_pd();
175 fiz0 = _mm256_setzero_pd();
176 fix1 = _mm256_setzero_pd();
177 fiy1 = _mm256_setzero_pd();
178 fiz1 = _mm256_setzero_pd();
179 fix2 = _mm256_setzero_pd();
180 fiy2 = _mm256_setzero_pd();
181 fiz2 = _mm256_setzero_pd();
183 /* Reset potential sums */
184 velecsum = _mm256_setzero_pd();
186 /* Start inner kernel loop */
187 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
190 /* Get j neighbor index, and coordinate index */
195 j_coord_offsetA = DIM*jnrA;
196 j_coord_offsetB = DIM*jnrB;
197 j_coord_offsetC = DIM*jnrC;
198 j_coord_offsetD = DIM*jnrD;
200 /* load j atom coordinates */
201 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
202 x+j_coord_offsetC,x+j_coord_offsetD,
205 /* Calculate displacement vector */
206 dx00 = _mm256_sub_pd(ix0,jx0);
207 dy00 = _mm256_sub_pd(iy0,jy0);
208 dz00 = _mm256_sub_pd(iz0,jz0);
209 dx10 = _mm256_sub_pd(ix1,jx0);
210 dy10 = _mm256_sub_pd(iy1,jy0);
211 dz10 = _mm256_sub_pd(iz1,jz0);
212 dx20 = _mm256_sub_pd(ix2,jx0);
213 dy20 = _mm256_sub_pd(iy2,jy0);
214 dz20 = _mm256_sub_pd(iz2,jz0);
216 /* Calculate squared distance and things based on it */
217 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
218 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
219 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
221 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
222 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
223 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
225 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
226 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
227 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
229 /* Load parameters for j particles */
230 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
231 charge+jnrC+0,charge+jnrD+0);
233 fjx0 = _mm256_setzero_pd();
234 fjy0 = _mm256_setzero_pd();
235 fjz0 = _mm256_setzero_pd();
237 /**************************
238 * CALCULATE INTERACTIONS *
239 **************************/
241 if (gmx_mm256_any_lt(rsq00,rcutoff2))
244 r00 = _mm256_mul_pd(rsq00,rinv00);
246 /* Compute parameters for interactions between i and j atoms */
247 qq00 = _mm256_mul_pd(iq0,jq0);
249 /* EWALD ELECTROSTATICS */
251 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
252 ewrt = _mm256_mul_pd(r00,ewtabscale);
253 ewitab = _mm256_cvttpd_epi32(ewrt);
254 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
255 ewitab = _mm_slli_epi32(ewitab,2);
256 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
257 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
258 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
259 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
260 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
261 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
262 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
263 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_sub_pd(rinv00,sh_ewald),velec));
264 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
266 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
268 /* Update potential sum for this i atom from the interaction with this j atom. */
269 velec = _mm256_and_pd(velec,cutoff_mask);
270 velecsum = _mm256_add_pd(velecsum,velec);
274 fscal = _mm256_and_pd(fscal,cutoff_mask);
276 /* Calculate temporary vectorial force */
277 tx = _mm256_mul_pd(fscal,dx00);
278 ty = _mm256_mul_pd(fscal,dy00);
279 tz = _mm256_mul_pd(fscal,dz00);
281 /* Update vectorial force */
282 fix0 = _mm256_add_pd(fix0,tx);
283 fiy0 = _mm256_add_pd(fiy0,ty);
284 fiz0 = _mm256_add_pd(fiz0,tz);
286 fjx0 = _mm256_add_pd(fjx0,tx);
287 fjy0 = _mm256_add_pd(fjy0,ty);
288 fjz0 = _mm256_add_pd(fjz0,tz);
292 /**************************
293 * CALCULATE INTERACTIONS *
294 **************************/
296 if (gmx_mm256_any_lt(rsq10,rcutoff2))
299 r10 = _mm256_mul_pd(rsq10,rinv10);
301 /* Compute parameters for interactions between i and j atoms */
302 qq10 = _mm256_mul_pd(iq1,jq0);
304 /* EWALD ELECTROSTATICS */
306 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
307 ewrt = _mm256_mul_pd(r10,ewtabscale);
308 ewitab = _mm256_cvttpd_epi32(ewrt);
309 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
310 ewitab = _mm_slli_epi32(ewitab,2);
311 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
312 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
313 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
314 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
315 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
316 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
317 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
318 velec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_sub_pd(rinv10,sh_ewald),velec));
319 felec = _mm256_mul_pd(_mm256_mul_pd(qq10,rinv10),_mm256_sub_pd(rinvsq10,felec));
321 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
323 /* Update potential sum for this i atom from the interaction with this j atom. */
324 velec = _mm256_and_pd(velec,cutoff_mask);
325 velecsum = _mm256_add_pd(velecsum,velec);
329 fscal = _mm256_and_pd(fscal,cutoff_mask);
331 /* Calculate temporary vectorial force */
332 tx = _mm256_mul_pd(fscal,dx10);
333 ty = _mm256_mul_pd(fscal,dy10);
334 tz = _mm256_mul_pd(fscal,dz10);
336 /* Update vectorial force */
337 fix1 = _mm256_add_pd(fix1,tx);
338 fiy1 = _mm256_add_pd(fiy1,ty);
339 fiz1 = _mm256_add_pd(fiz1,tz);
341 fjx0 = _mm256_add_pd(fjx0,tx);
342 fjy0 = _mm256_add_pd(fjy0,ty);
343 fjz0 = _mm256_add_pd(fjz0,tz);
347 /**************************
348 * CALCULATE INTERACTIONS *
349 **************************/
351 if (gmx_mm256_any_lt(rsq20,rcutoff2))
354 r20 = _mm256_mul_pd(rsq20,rinv20);
356 /* Compute parameters for interactions between i and j atoms */
357 qq20 = _mm256_mul_pd(iq2,jq0);
359 /* EWALD ELECTROSTATICS */
361 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
362 ewrt = _mm256_mul_pd(r20,ewtabscale);
363 ewitab = _mm256_cvttpd_epi32(ewrt);
364 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
365 ewitab = _mm_slli_epi32(ewitab,2);
366 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
367 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
368 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
369 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
370 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
371 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
372 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
373 velec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_sub_pd(rinv20,sh_ewald),velec));
374 felec = _mm256_mul_pd(_mm256_mul_pd(qq20,rinv20),_mm256_sub_pd(rinvsq20,felec));
376 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
378 /* Update potential sum for this i atom from the interaction with this j atom. */
379 velec = _mm256_and_pd(velec,cutoff_mask);
380 velecsum = _mm256_add_pd(velecsum,velec);
384 fscal = _mm256_and_pd(fscal,cutoff_mask);
386 /* Calculate temporary vectorial force */
387 tx = _mm256_mul_pd(fscal,dx20);
388 ty = _mm256_mul_pd(fscal,dy20);
389 tz = _mm256_mul_pd(fscal,dz20);
391 /* Update vectorial force */
392 fix2 = _mm256_add_pd(fix2,tx);
393 fiy2 = _mm256_add_pd(fiy2,ty);
394 fiz2 = _mm256_add_pd(fiz2,tz);
396 fjx0 = _mm256_add_pd(fjx0,tx);
397 fjy0 = _mm256_add_pd(fjy0,ty);
398 fjz0 = _mm256_add_pd(fjz0,tz);
402 fjptrA = f+j_coord_offsetA;
403 fjptrB = f+j_coord_offsetB;
404 fjptrC = f+j_coord_offsetC;
405 fjptrD = f+j_coord_offsetD;
407 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
409 /* Inner loop uses 141 flops */
415 /* Get j neighbor index, and coordinate index */
416 jnrlistA = jjnr[jidx];
417 jnrlistB = jjnr[jidx+1];
418 jnrlistC = jjnr[jidx+2];
419 jnrlistD = jjnr[jidx+3];
420 /* Sign of each element will be negative for non-real atoms.
421 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
422 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
424 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
426 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
427 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
428 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
430 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
431 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
432 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
433 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
434 j_coord_offsetA = DIM*jnrA;
435 j_coord_offsetB = DIM*jnrB;
436 j_coord_offsetC = DIM*jnrC;
437 j_coord_offsetD = DIM*jnrD;
439 /* load j atom coordinates */
440 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
441 x+j_coord_offsetC,x+j_coord_offsetD,
444 /* Calculate displacement vector */
445 dx00 = _mm256_sub_pd(ix0,jx0);
446 dy00 = _mm256_sub_pd(iy0,jy0);
447 dz00 = _mm256_sub_pd(iz0,jz0);
448 dx10 = _mm256_sub_pd(ix1,jx0);
449 dy10 = _mm256_sub_pd(iy1,jy0);
450 dz10 = _mm256_sub_pd(iz1,jz0);
451 dx20 = _mm256_sub_pd(ix2,jx0);
452 dy20 = _mm256_sub_pd(iy2,jy0);
453 dz20 = _mm256_sub_pd(iz2,jz0);
455 /* Calculate squared distance and things based on it */
456 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
457 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
458 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
460 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
461 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
462 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
464 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
465 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
466 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
468 /* Load parameters for j particles */
469 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
470 charge+jnrC+0,charge+jnrD+0);
472 fjx0 = _mm256_setzero_pd();
473 fjy0 = _mm256_setzero_pd();
474 fjz0 = _mm256_setzero_pd();
476 /**************************
477 * CALCULATE INTERACTIONS *
478 **************************/
480 if (gmx_mm256_any_lt(rsq00,rcutoff2))
483 r00 = _mm256_mul_pd(rsq00,rinv00);
484 r00 = _mm256_andnot_pd(dummy_mask,r00);
486 /* Compute parameters for interactions between i and j atoms */
487 qq00 = _mm256_mul_pd(iq0,jq0);
489 /* EWALD ELECTROSTATICS */
491 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
492 ewrt = _mm256_mul_pd(r00,ewtabscale);
493 ewitab = _mm256_cvttpd_epi32(ewrt);
494 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
495 ewitab = _mm_slli_epi32(ewitab,2);
496 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
497 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
498 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
499 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
500 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
501 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
502 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
503 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_sub_pd(rinv00,sh_ewald),velec));
504 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
506 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
508 /* Update potential sum for this i atom from the interaction with this j atom. */
509 velec = _mm256_and_pd(velec,cutoff_mask);
510 velec = _mm256_andnot_pd(dummy_mask,velec);
511 velecsum = _mm256_add_pd(velecsum,velec);
515 fscal = _mm256_and_pd(fscal,cutoff_mask);
517 fscal = _mm256_andnot_pd(dummy_mask,fscal);
519 /* Calculate temporary vectorial force */
520 tx = _mm256_mul_pd(fscal,dx00);
521 ty = _mm256_mul_pd(fscal,dy00);
522 tz = _mm256_mul_pd(fscal,dz00);
524 /* Update vectorial force */
525 fix0 = _mm256_add_pd(fix0,tx);
526 fiy0 = _mm256_add_pd(fiy0,ty);
527 fiz0 = _mm256_add_pd(fiz0,tz);
529 fjx0 = _mm256_add_pd(fjx0,tx);
530 fjy0 = _mm256_add_pd(fjy0,ty);
531 fjz0 = _mm256_add_pd(fjz0,tz);
535 /**************************
536 * CALCULATE INTERACTIONS *
537 **************************/
539 if (gmx_mm256_any_lt(rsq10,rcutoff2))
542 r10 = _mm256_mul_pd(rsq10,rinv10);
543 r10 = _mm256_andnot_pd(dummy_mask,r10);
545 /* Compute parameters for interactions between i and j atoms */
546 qq10 = _mm256_mul_pd(iq1,jq0);
548 /* EWALD ELECTROSTATICS */
550 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
551 ewrt = _mm256_mul_pd(r10,ewtabscale);
552 ewitab = _mm256_cvttpd_epi32(ewrt);
553 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
554 ewitab = _mm_slli_epi32(ewitab,2);
555 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
556 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
557 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
558 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
559 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
560 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
561 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
562 velec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_sub_pd(rinv10,sh_ewald),velec));
563 felec = _mm256_mul_pd(_mm256_mul_pd(qq10,rinv10),_mm256_sub_pd(rinvsq10,felec));
565 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
567 /* Update potential sum for this i atom from the interaction with this j atom. */
568 velec = _mm256_and_pd(velec,cutoff_mask);
569 velec = _mm256_andnot_pd(dummy_mask,velec);
570 velecsum = _mm256_add_pd(velecsum,velec);
574 fscal = _mm256_and_pd(fscal,cutoff_mask);
576 fscal = _mm256_andnot_pd(dummy_mask,fscal);
578 /* Calculate temporary vectorial force */
579 tx = _mm256_mul_pd(fscal,dx10);
580 ty = _mm256_mul_pd(fscal,dy10);
581 tz = _mm256_mul_pd(fscal,dz10);
583 /* Update vectorial force */
584 fix1 = _mm256_add_pd(fix1,tx);
585 fiy1 = _mm256_add_pd(fiy1,ty);
586 fiz1 = _mm256_add_pd(fiz1,tz);
588 fjx0 = _mm256_add_pd(fjx0,tx);
589 fjy0 = _mm256_add_pd(fjy0,ty);
590 fjz0 = _mm256_add_pd(fjz0,tz);
594 /**************************
595 * CALCULATE INTERACTIONS *
596 **************************/
598 if (gmx_mm256_any_lt(rsq20,rcutoff2))
601 r20 = _mm256_mul_pd(rsq20,rinv20);
602 r20 = _mm256_andnot_pd(dummy_mask,r20);
604 /* Compute parameters for interactions between i and j atoms */
605 qq20 = _mm256_mul_pd(iq2,jq0);
607 /* EWALD ELECTROSTATICS */
609 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
610 ewrt = _mm256_mul_pd(r20,ewtabscale);
611 ewitab = _mm256_cvttpd_epi32(ewrt);
612 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
613 ewitab = _mm_slli_epi32(ewitab,2);
614 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
615 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
616 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
617 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
618 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
619 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
620 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
621 velec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_sub_pd(rinv20,sh_ewald),velec));
622 felec = _mm256_mul_pd(_mm256_mul_pd(qq20,rinv20),_mm256_sub_pd(rinvsq20,felec));
624 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
626 /* Update potential sum for this i atom from the interaction with this j atom. */
627 velec = _mm256_and_pd(velec,cutoff_mask);
628 velec = _mm256_andnot_pd(dummy_mask,velec);
629 velecsum = _mm256_add_pd(velecsum,velec);
633 fscal = _mm256_and_pd(fscal,cutoff_mask);
635 fscal = _mm256_andnot_pd(dummy_mask,fscal);
637 /* Calculate temporary vectorial force */
638 tx = _mm256_mul_pd(fscal,dx20);
639 ty = _mm256_mul_pd(fscal,dy20);
640 tz = _mm256_mul_pd(fscal,dz20);
642 /* Update vectorial force */
643 fix2 = _mm256_add_pd(fix2,tx);
644 fiy2 = _mm256_add_pd(fiy2,ty);
645 fiz2 = _mm256_add_pd(fiz2,tz);
647 fjx0 = _mm256_add_pd(fjx0,tx);
648 fjy0 = _mm256_add_pd(fjy0,ty);
649 fjz0 = _mm256_add_pd(fjz0,tz);
653 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
654 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
655 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
656 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
658 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
660 /* Inner loop uses 144 flops */
663 /* End of innermost loop */
665 gmx_mm256_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
666 f+i_coord_offset,fshift+i_shift_offset);
669 /* Update potential energies */
670 gmx_mm256_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
672 /* Increment number of inner iterations */
673 inneriter += j_index_end - j_index_start;
675 /* Outer loop uses 19 flops */
678 /* Increment number of outer iterations */
681 /* Update outer/inner flops */
683 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*144);
686 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomW3P1_F_avx_256_double
687 * Electrostatics interaction: Ewald
688 * VdW interaction: None
689 * Geometry: Water3-Particle
690 * Calculate force/pot: Force
693 nb_kernel_ElecEwSh_VdwNone_GeomW3P1_F_avx_256_double
694 (t_nblist * gmx_restrict nlist,
695 rvec * gmx_restrict xx,
696 rvec * gmx_restrict ff,
697 t_forcerec * gmx_restrict fr,
698 t_mdatoms * gmx_restrict mdatoms,
699 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
700 t_nrnb * gmx_restrict nrnb)
702 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
703 * just 0 for non-waters.
704 * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
705 * jnr indices corresponding to data put in the four positions in the SIMD register.
707 int i_shift_offset,i_coord_offset,outeriter,inneriter;
708 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
709 int jnrA,jnrB,jnrC,jnrD;
710 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
711 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
712 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
713 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
715 real *shiftvec,*fshift,*x,*f;
716 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
718 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
719 real * vdwioffsetptr0;
720 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
721 real * vdwioffsetptr1;
722 __m256d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
723 real * vdwioffsetptr2;
724 __m256d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
725 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
726 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
727 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
728 __m256d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
729 __m256d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
730 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
733 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
734 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
736 __m256d dummy_mask,cutoff_mask;
737 __m128 tmpmask0,tmpmask1;
738 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
739 __m256d one = _mm256_set1_pd(1.0);
740 __m256d two = _mm256_set1_pd(2.0);
746 jindex = nlist->jindex;
748 shiftidx = nlist->shift;
750 shiftvec = fr->shift_vec[0];
751 fshift = fr->fshift[0];
752 facel = _mm256_set1_pd(fr->epsfac);
753 charge = mdatoms->chargeA;
755 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
756 beta = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
757 beta2 = _mm256_mul_pd(beta,beta);
758 beta3 = _mm256_mul_pd(beta,beta2);
760 ewtab = fr->ic->tabq_coul_F;
761 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
762 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
764 /* Setup water-specific parameters */
765 inr = nlist->iinr[0];
766 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
767 iq1 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+1]));
768 iq2 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+2]));
770 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
771 rcutoff_scalar = fr->rcoulomb;
772 rcutoff = _mm256_set1_pd(rcutoff_scalar);
773 rcutoff2 = _mm256_mul_pd(rcutoff,rcutoff);
775 /* Avoid stupid compiler warnings */
776 jnrA = jnrB = jnrC = jnrD = 0;
785 for(iidx=0;iidx<4*DIM;iidx++)
790 /* Start outer loop over neighborlists */
791 for(iidx=0; iidx<nri; iidx++)
793 /* Load shift vector for this list */
794 i_shift_offset = DIM*shiftidx[iidx];
796 /* Load limits for loop over neighbors */
797 j_index_start = jindex[iidx];
798 j_index_end = jindex[iidx+1];
800 /* Get outer coordinate index */
802 i_coord_offset = DIM*inr;
804 /* Load i particle coords and add shift vector */
805 gmx_mm256_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
806 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
808 fix0 = _mm256_setzero_pd();
809 fiy0 = _mm256_setzero_pd();
810 fiz0 = _mm256_setzero_pd();
811 fix1 = _mm256_setzero_pd();
812 fiy1 = _mm256_setzero_pd();
813 fiz1 = _mm256_setzero_pd();
814 fix2 = _mm256_setzero_pd();
815 fiy2 = _mm256_setzero_pd();
816 fiz2 = _mm256_setzero_pd();
818 /* Start inner kernel loop */
819 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
822 /* Get j neighbor index, and coordinate index */
827 j_coord_offsetA = DIM*jnrA;
828 j_coord_offsetB = DIM*jnrB;
829 j_coord_offsetC = DIM*jnrC;
830 j_coord_offsetD = DIM*jnrD;
832 /* load j atom coordinates */
833 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
834 x+j_coord_offsetC,x+j_coord_offsetD,
837 /* Calculate displacement vector */
838 dx00 = _mm256_sub_pd(ix0,jx0);
839 dy00 = _mm256_sub_pd(iy0,jy0);
840 dz00 = _mm256_sub_pd(iz0,jz0);
841 dx10 = _mm256_sub_pd(ix1,jx0);
842 dy10 = _mm256_sub_pd(iy1,jy0);
843 dz10 = _mm256_sub_pd(iz1,jz0);
844 dx20 = _mm256_sub_pd(ix2,jx0);
845 dy20 = _mm256_sub_pd(iy2,jy0);
846 dz20 = _mm256_sub_pd(iz2,jz0);
848 /* Calculate squared distance and things based on it */
849 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
850 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
851 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
853 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
854 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
855 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
857 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
858 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
859 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
861 /* Load parameters for j particles */
862 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
863 charge+jnrC+0,charge+jnrD+0);
865 fjx0 = _mm256_setzero_pd();
866 fjy0 = _mm256_setzero_pd();
867 fjz0 = _mm256_setzero_pd();
869 /**************************
870 * CALCULATE INTERACTIONS *
871 **************************/
873 if (gmx_mm256_any_lt(rsq00,rcutoff2))
876 r00 = _mm256_mul_pd(rsq00,rinv00);
878 /* Compute parameters for interactions between i and j atoms */
879 qq00 = _mm256_mul_pd(iq0,jq0);
881 /* EWALD ELECTROSTATICS */
883 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
884 ewrt = _mm256_mul_pd(r00,ewtabscale);
885 ewitab = _mm256_cvttpd_epi32(ewrt);
886 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
887 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
888 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
890 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
891 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
893 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
897 fscal = _mm256_and_pd(fscal,cutoff_mask);
899 /* Calculate temporary vectorial force */
900 tx = _mm256_mul_pd(fscal,dx00);
901 ty = _mm256_mul_pd(fscal,dy00);
902 tz = _mm256_mul_pd(fscal,dz00);
904 /* Update vectorial force */
905 fix0 = _mm256_add_pd(fix0,tx);
906 fiy0 = _mm256_add_pd(fiy0,ty);
907 fiz0 = _mm256_add_pd(fiz0,tz);
909 fjx0 = _mm256_add_pd(fjx0,tx);
910 fjy0 = _mm256_add_pd(fjy0,ty);
911 fjz0 = _mm256_add_pd(fjz0,tz);
915 /**************************
916 * CALCULATE INTERACTIONS *
917 **************************/
919 if (gmx_mm256_any_lt(rsq10,rcutoff2))
922 r10 = _mm256_mul_pd(rsq10,rinv10);
924 /* Compute parameters for interactions between i and j atoms */
925 qq10 = _mm256_mul_pd(iq1,jq0);
927 /* EWALD ELECTROSTATICS */
929 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
930 ewrt = _mm256_mul_pd(r10,ewtabscale);
931 ewitab = _mm256_cvttpd_epi32(ewrt);
932 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
933 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
934 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
936 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
937 felec = _mm256_mul_pd(_mm256_mul_pd(qq10,rinv10),_mm256_sub_pd(rinvsq10,felec));
939 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
943 fscal = _mm256_and_pd(fscal,cutoff_mask);
945 /* Calculate temporary vectorial force */
946 tx = _mm256_mul_pd(fscal,dx10);
947 ty = _mm256_mul_pd(fscal,dy10);
948 tz = _mm256_mul_pd(fscal,dz10);
950 /* Update vectorial force */
951 fix1 = _mm256_add_pd(fix1,tx);
952 fiy1 = _mm256_add_pd(fiy1,ty);
953 fiz1 = _mm256_add_pd(fiz1,tz);
955 fjx0 = _mm256_add_pd(fjx0,tx);
956 fjy0 = _mm256_add_pd(fjy0,ty);
957 fjz0 = _mm256_add_pd(fjz0,tz);
961 /**************************
962 * CALCULATE INTERACTIONS *
963 **************************/
965 if (gmx_mm256_any_lt(rsq20,rcutoff2))
968 r20 = _mm256_mul_pd(rsq20,rinv20);
970 /* Compute parameters for interactions between i and j atoms */
971 qq20 = _mm256_mul_pd(iq2,jq0);
973 /* EWALD ELECTROSTATICS */
975 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
976 ewrt = _mm256_mul_pd(r20,ewtabscale);
977 ewitab = _mm256_cvttpd_epi32(ewrt);
978 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
979 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
980 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
982 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
983 felec = _mm256_mul_pd(_mm256_mul_pd(qq20,rinv20),_mm256_sub_pd(rinvsq20,felec));
985 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
989 fscal = _mm256_and_pd(fscal,cutoff_mask);
991 /* Calculate temporary vectorial force */
992 tx = _mm256_mul_pd(fscal,dx20);
993 ty = _mm256_mul_pd(fscal,dy20);
994 tz = _mm256_mul_pd(fscal,dz20);
996 /* Update vectorial force */
997 fix2 = _mm256_add_pd(fix2,tx);
998 fiy2 = _mm256_add_pd(fiy2,ty);
999 fiz2 = _mm256_add_pd(fiz2,tz);
1001 fjx0 = _mm256_add_pd(fjx0,tx);
1002 fjy0 = _mm256_add_pd(fjy0,ty);
1003 fjz0 = _mm256_add_pd(fjz0,tz);
1007 fjptrA = f+j_coord_offsetA;
1008 fjptrB = f+j_coord_offsetB;
1009 fjptrC = f+j_coord_offsetC;
1010 fjptrD = f+j_coord_offsetD;
1012 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1014 /* Inner loop uses 120 flops */
1017 if(jidx<j_index_end)
1020 /* Get j neighbor index, and coordinate index */
1021 jnrlistA = jjnr[jidx];
1022 jnrlistB = jjnr[jidx+1];
1023 jnrlistC = jjnr[jidx+2];
1024 jnrlistD = jjnr[jidx+3];
1025 /* Sign of each element will be negative for non-real atoms.
1026 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1027 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
1029 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1031 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
1032 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
1033 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
1035 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1036 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1037 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1038 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1039 j_coord_offsetA = DIM*jnrA;
1040 j_coord_offsetB = DIM*jnrB;
1041 j_coord_offsetC = DIM*jnrC;
1042 j_coord_offsetD = DIM*jnrD;
1044 /* load j atom coordinates */
1045 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
1046 x+j_coord_offsetC,x+j_coord_offsetD,
1049 /* Calculate displacement vector */
1050 dx00 = _mm256_sub_pd(ix0,jx0);
1051 dy00 = _mm256_sub_pd(iy0,jy0);
1052 dz00 = _mm256_sub_pd(iz0,jz0);
1053 dx10 = _mm256_sub_pd(ix1,jx0);
1054 dy10 = _mm256_sub_pd(iy1,jy0);
1055 dz10 = _mm256_sub_pd(iz1,jz0);
1056 dx20 = _mm256_sub_pd(ix2,jx0);
1057 dy20 = _mm256_sub_pd(iy2,jy0);
1058 dz20 = _mm256_sub_pd(iz2,jz0);
1060 /* Calculate squared distance and things based on it */
1061 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
1062 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
1063 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
1065 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
1066 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
1067 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
1069 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
1070 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
1071 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
1073 /* Load parameters for j particles */
1074 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
1075 charge+jnrC+0,charge+jnrD+0);
1077 fjx0 = _mm256_setzero_pd();
1078 fjy0 = _mm256_setzero_pd();
1079 fjz0 = _mm256_setzero_pd();
1081 /**************************
1082 * CALCULATE INTERACTIONS *
1083 **************************/
1085 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1088 r00 = _mm256_mul_pd(rsq00,rinv00);
1089 r00 = _mm256_andnot_pd(dummy_mask,r00);
1091 /* Compute parameters for interactions between i and j atoms */
1092 qq00 = _mm256_mul_pd(iq0,jq0);
1094 /* EWALD ELECTROSTATICS */
1096 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1097 ewrt = _mm256_mul_pd(r00,ewtabscale);
1098 ewitab = _mm256_cvttpd_epi32(ewrt);
1099 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
1100 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
1101 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
1103 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
1104 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
1106 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
1110 fscal = _mm256_and_pd(fscal,cutoff_mask);
1112 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1114 /* Calculate temporary vectorial force */
1115 tx = _mm256_mul_pd(fscal,dx00);
1116 ty = _mm256_mul_pd(fscal,dy00);
1117 tz = _mm256_mul_pd(fscal,dz00);
1119 /* Update vectorial force */
1120 fix0 = _mm256_add_pd(fix0,tx);
1121 fiy0 = _mm256_add_pd(fiy0,ty);
1122 fiz0 = _mm256_add_pd(fiz0,tz);
1124 fjx0 = _mm256_add_pd(fjx0,tx);
1125 fjy0 = _mm256_add_pd(fjy0,ty);
1126 fjz0 = _mm256_add_pd(fjz0,tz);
1130 /**************************
1131 * CALCULATE INTERACTIONS *
1132 **************************/
1134 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1137 r10 = _mm256_mul_pd(rsq10,rinv10);
1138 r10 = _mm256_andnot_pd(dummy_mask,r10);
1140 /* Compute parameters for interactions between i and j atoms */
1141 qq10 = _mm256_mul_pd(iq1,jq0);
1143 /* EWALD ELECTROSTATICS */
1145 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1146 ewrt = _mm256_mul_pd(r10,ewtabscale);
1147 ewitab = _mm256_cvttpd_epi32(ewrt);
1148 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
1149 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
1150 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
1152 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
1153 felec = _mm256_mul_pd(_mm256_mul_pd(qq10,rinv10),_mm256_sub_pd(rinvsq10,felec));
1155 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
1159 fscal = _mm256_and_pd(fscal,cutoff_mask);
1161 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1163 /* Calculate temporary vectorial force */
1164 tx = _mm256_mul_pd(fscal,dx10);
1165 ty = _mm256_mul_pd(fscal,dy10);
1166 tz = _mm256_mul_pd(fscal,dz10);
1168 /* Update vectorial force */
1169 fix1 = _mm256_add_pd(fix1,tx);
1170 fiy1 = _mm256_add_pd(fiy1,ty);
1171 fiz1 = _mm256_add_pd(fiz1,tz);
1173 fjx0 = _mm256_add_pd(fjx0,tx);
1174 fjy0 = _mm256_add_pd(fjy0,ty);
1175 fjz0 = _mm256_add_pd(fjz0,tz);
1179 /**************************
1180 * CALCULATE INTERACTIONS *
1181 **************************/
1183 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1186 r20 = _mm256_mul_pd(rsq20,rinv20);
1187 r20 = _mm256_andnot_pd(dummy_mask,r20);
1189 /* Compute parameters for interactions between i and j atoms */
1190 qq20 = _mm256_mul_pd(iq2,jq0);
1192 /* EWALD ELECTROSTATICS */
1194 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1195 ewrt = _mm256_mul_pd(r20,ewtabscale);
1196 ewitab = _mm256_cvttpd_epi32(ewrt);
1197 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
1198 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
1199 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
1201 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
1202 felec = _mm256_mul_pd(_mm256_mul_pd(qq20,rinv20),_mm256_sub_pd(rinvsq20,felec));
1204 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
1208 fscal = _mm256_and_pd(fscal,cutoff_mask);
1210 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1212 /* Calculate temporary vectorial force */
1213 tx = _mm256_mul_pd(fscal,dx20);
1214 ty = _mm256_mul_pd(fscal,dy20);
1215 tz = _mm256_mul_pd(fscal,dz20);
1217 /* Update vectorial force */
1218 fix2 = _mm256_add_pd(fix2,tx);
1219 fiy2 = _mm256_add_pd(fiy2,ty);
1220 fiz2 = _mm256_add_pd(fiz2,tz);
1222 fjx0 = _mm256_add_pd(fjx0,tx);
1223 fjy0 = _mm256_add_pd(fjy0,ty);
1224 fjz0 = _mm256_add_pd(fjz0,tz);
1228 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1229 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1230 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1231 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1233 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1235 /* Inner loop uses 123 flops */
1238 /* End of innermost loop */
1240 gmx_mm256_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1241 f+i_coord_offset,fshift+i_shift_offset);
1243 /* Increment number of inner iterations */
1244 inneriter += j_index_end - j_index_start;
1246 /* Outer loop uses 18 flops */
1249 /* Increment number of outer iterations */
1252 /* Update outer/inner flops */
1254 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*123);