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.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_avx_256_double.h"
50 #include "kernelutil_x86_avx_256_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomW3P1_VF_avx_256_double
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_256_double
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, 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 jnrlistE,jnrlistF,jnrlistG,jnrlistH;
79 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
80 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
82 real *shiftvec,*fshift,*x,*f;
83 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
85 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86 real * vdwioffsetptr0;
87 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 real * vdwioffsetptr1;
89 __m256d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 real * vdwioffsetptr2;
91 __m256d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
92 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
93 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
94 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
95 __m256d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
96 __m256d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
97 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
100 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
101 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
103 __m256d dummy_mask,cutoff_mask;
104 __m128 tmpmask0,tmpmask1;
105 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
106 __m256d one = _mm256_set1_pd(1.0);
107 __m256d two = _mm256_set1_pd(2.0);
113 jindex = nlist->jindex;
115 shiftidx = nlist->shift;
117 shiftvec = fr->shift_vec[0];
118 fshift = fr->fshift[0];
119 facel = _mm256_set1_pd(fr->epsfac);
120 charge = mdatoms->chargeA;
122 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
123 beta = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
124 beta2 = _mm256_mul_pd(beta,beta);
125 beta3 = _mm256_mul_pd(beta,beta2);
127 ewtab = fr->ic->tabq_coul_FDV0;
128 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
129 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
131 /* Setup water-specific parameters */
132 inr = nlist->iinr[0];
133 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
134 iq1 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+1]));
135 iq2 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+2]));
137 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
138 rcutoff_scalar = fr->rcoulomb;
139 rcutoff = _mm256_set1_pd(rcutoff_scalar);
140 rcutoff2 = _mm256_mul_pd(rcutoff,rcutoff);
142 /* Avoid stupid compiler warnings */
143 jnrA = jnrB = jnrC = jnrD = 0;
152 for(iidx=0;iidx<4*DIM;iidx++)
157 /* Start outer loop over neighborlists */
158 for(iidx=0; iidx<nri; iidx++)
160 /* Load shift vector for this list */
161 i_shift_offset = DIM*shiftidx[iidx];
163 /* Load limits for loop over neighbors */
164 j_index_start = jindex[iidx];
165 j_index_end = jindex[iidx+1];
167 /* Get outer coordinate index */
169 i_coord_offset = DIM*inr;
171 /* Load i particle coords and add shift vector */
172 gmx_mm256_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
173 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
175 fix0 = _mm256_setzero_pd();
176 fiy0 = _mm256_setzero_pd();
177 fiz0 = _mm256_setzero_pd();
178 fix1 = _mm256_setzero_pd();
179 fiy1 = _mm256_setzero_pd();
180 fiz1 = _mm256_setzero_pd();
181 fix2 = _mm256_setzero_pd();
182 fiy2 = _mm256_setzero_pd();
183 fiz2 = _mm256_setzero_pd();
185 /* Reset potential sums */
186 velecsum = _mm256_setzero_pd();
188 /* Start inner kernel loop */
189 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
192 /* Get j neighbor index, and coordinate index */
197 j_coord_offsetA = DIM*jnrA;
198 j_coord_offsetB = DIM*jnrB;
199 j_coord_offsetC = DIM*jnrC;
200 j_coord_offsetD = DIM*jnrD;
202 /* load j atom coordinates */
203 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
204 x+j_coord_offsetC,x+j_coord_offsetD,
207 /* Calculate displacement vector */
208 dx00 = _mm256_sub_pd(ix0,jx0);
209 dy00 = _mm256_sub_pd(iy0,jy0);
210 dz00 = _mm256_sub_pd(iz0,jz0);
211 dx10 = _mm256_sub_pd(ix1,jx0);
212 dy10 = _mm256_sub_pd(iy1,jy0);
213 dz10 = _mm256_sub_pd(iz1,jz0);
214 dx20 = _mm256_sub_pd(ix2,jx0);
215 dy20 = _mm256_sub_pd(iy2,jy0);
216 dz20 = _mm256_sub_pd(iz2,jz0);
218 /* Calculate squared distance and things based on it */
219 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
220 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
221 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
223 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
224 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
225 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
227 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
228 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
229 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
231 /* Load parameters for j particles */
232 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
233 charge+jnrC+0,charge+jnrD+0);
235 fjx0 = _mm256_setzero_pd();
236 fjy0 = _mm256_setzero_pd();
237 fjz0 = _mm256_setzero_pd();
239 /**************************
240 * CALCULATE INTERACTIONS *
241 **************************/
243 if (gmx_mm256_any_lt(rsq00,rcutoff2))
246 r00 = _mm256_mul_pd(rsq00,rinv00);
248 /* Compute parameters for interactions between i and j atoms */
249 qq00 = _mm256_mul_pd(iq0,jq0);
251 /* EWALD ELECTROSTATICS */
253 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
254 ewrt = _mm256_mul_pd(r00,ewtabscale);
255 ewitab = _mm256_cvttpd_epi32(ewrt);
256 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
257 ewitab = _mm_slli_epi32(ewitab,2);
258 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
259 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
260 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
261 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
262 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
263 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
264 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
265 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_sub_pd(rinv00,sh_ewald),velec));
266 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
268 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
270 /* Update potential sum for this i atom from the interaction with this j atom. */
271 velec = _mm256_and_pd(velec,cutoff_mask);
272 velecsum = _mm256_add_pd(velecsum,velec);
276 fscal = _mm256_and_pd(fscal,cutoff_mask);
278 /* Calculate temporary vectorial force */
279 tx = _mm256_mul_pd(fscal,dx00);
280 ty = _mm256_mul_pd(fscal,dy00);
281 tz = _mm256_mul_pd(fscal,dz00);
283 /* Update vectorial force */
284 fix0 = _mm256_add_pd(fix0,tx);
285 fiy0 = _mm256_add_pd(fiy0,ty);
286 fiz0 = _mm256_add_pd(fiz0,tz);
288 fjx0 = _mm256_add_pd(fjx0,tx);
289 fjy0 = _mm256_add_pd(fjy0,ty);
290 fjz0 = _mm256_add_pd(fjz0,tz);
294 /**************************
295 * CALCULATE INTERACTIONS *
296 **************************/
298 if (gmx_mm256_any_lt(rsq10,rcutoff2))
301 r10 = _mm256_mul_pd(rsq10,rinv10);
303 /* Compute parameters for interactions between i and j atoms */
304 qq10 = _mm256_mul_pd(iq1,jq0);
306 /* EWALD ELECTROSTATICS */
308 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
309 ewrt = _mm256_mul_pd(r10,ewtabscale);
310 ewitab = _mm256_cvttpd_epi32(ewrt);
311 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
312 ewitab = _mm_slli_epi32(ewitab,2);
313 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
314 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
315 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
316 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
317 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
318 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
319 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
320 velec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_sub_pd(rinv10,sh_ewald),velec));
321 felec = _mm256_mul_pd(_mm256_mul_pd(qq10,rinv10),_mm256_sub_pd(rinvsq10,felec));
323 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
325 /* Update potential sum for this i atom from the interaction with this j atom. */
326 velec = _mm256_and_pd(velec,cutoff_mask);
327 velecsum = _mm256_add_pd(velecsum,velec);
331 fscal = _mm256_and_pd(fscal,cutoff_mask);
333 /* Calculate temporary vectorial force */
334 tx = _mm256_mul_pd(fscal,dx10);
335 ty = _mm256_mul_pd(fscal,dy10);
336 tz = _mm256_mul_pd(fscal,dz10);
338 /* Update vectorial force */
339 fix1 = _mm256_add_pd(fix1,tx);
340 fiy1 = _mm256_add_pd(fiy1,ty);
341 fiz1 = _mm256_add_pd(fiz1,tz);
343 fjx0 = _mm256_add_pd(fjx0,tx);
344 fjy0 = _mm256_add_pd(fjy0,ty);
345 fjz0 = _mm256_add_pd(fjz0,tz);
349 /**************************
350 * CALCULATE INTERACTIONS *
351 **************************/
353 if (gmx_mm256_any_lt(rsq20,rcutoff2))
356 r20 = _mm256_mul_pd(rsq20,rinv20);
358 /* Compute parameters for interactions between i and j atoms */
359 qq20 = _mm256_mul_pd(iq2,jq0);
361 /* EWALD ELECTROSTATICS */
363 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
364 ewrt = _mm256_mul_pd(r20,ewtabscale);
365 ewitab = _mm256_cvttpd_epi32(ewrt);
366 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
367 ewitab = _mm_slli_epi32(ewitab,2);
368 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
369 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
370 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
371 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
372 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
373 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
374 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
375 velec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_sub_pd(rinv20,sh_ewald),velec));
376 felec = _mm256_mul_pd(_mm256_mul_pd(qq20,rinv20),_mm256_sub_pd(rinvsq20,felec));
378 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
380 /* Update potential sum for this i atom from the interaction with this j atom. */
381 velec = _mm256_and_pd(velec,cutoff_mask);
382 velecsum = _mm256_add_pd(velecsum,velec);
386 fscal = _mm256_and_pd(fscal,cutoff_mask);
388 /* Calculate temporary vectorial force */
389 tx = _mm256_mul_pd(fscal,dx20);
390 ty = _mm256_mul_pd(fscal,dy20);
391 tz = _mm256_mul_pd(fscal,dz20);
393 /* Update vectorial force */
394 fix2 = _mm256_add_pd(fix2,tx);
395 fiy2 = _mm256_add_pd(fiy2,ty);
396 fiz2 = _mm256_add_pd(fiz2,tz);
398 fjx0 = _mm256_add_pd(fjx0,tx);
399 fjy0 = _mm256_add_pd(fjy0,ty);
400 fjz0 = _mm256_add_pd(fjz0,tz);
404 fjptrA = f+j_coord_offsetA;
405 fjptrB = f+j_coord_offsetB;
406 fjptrC = f+j_coord_offsetC;
407 fjptrD = f+j_coord_offsetD;
409 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
411 /* Inner loop uses 141 flops */
417 /* Get j neighbor index, and coordinate index */
418 jnrlistA = jjnr[jidx];
419 jnrlistB = jjnr[jidx+1];
420 jnrlistC = jjnr[jidx+2];
421 jnrlistD = jjnr[jidx+3];
422 /* Sign of each element will be negative for non-real atoms.
423 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
424 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
426 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
428 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
429 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
430 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
432 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
433 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
434 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
435 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
436 j_coord_offsetA = DIM*jnrA;
437 j_coord_offsetB = DIM*jnrB;
438 j_coord_offsetC = DIM*jnrC;
439 j_coord_offsetD = DIM*jnrD;
441 /* load j atom coordinates */
442 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
443 x+j_coord_offsetC,x+j_coord_offsetD,
446 /* Calculate displacement vector */
447 dx00 = _mm256_sub_pd(ix0,jx0);
448 dy00 = _mm256_sub_pd(iy0,jy0);
449 dz00 = _mm256_sub_pd(iz0,jz0);
450 dx10 = _mm256_sub_pd(ix1,jx0);
451 dy10 = _mm256_sub_pd(iy1,jy0);
452 dz10 = _mm256_sub_pd(iz1,jz0);
453 dx20 = _mm256_sub_pd(ix2,jx0);
454 dy20 = _mm256_sub_pd(iy2,jy0);
455 dz20 = _mm256_sub_pd(iz2,jz0);
457 /* Calculate squared distance and things based on it */
458 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
459 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
460 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
462 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
463 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
464 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
466 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
467 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
468 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
470 /* Load parameters for j particles */
471 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
472 charge+jnrC+0,charge+jnrD+0);
474 fjx0 = _mm256_setzero_pd();
475 fjy0 = _mm256_setzero_pd();
476 fjz0 = _mm256_setzero_pd();
478 /**************************
479 * CALCULATE INTERACTIONS *
480 **************************/
482 if (gmx_mm256_any_lt(rsq00,rcutoff2))
485 r00 = _mm256_mul_pd(rsq00,rinv00);
486 r00 = _mm256_andnot_pd(dummy_mask,r00);
488 /* Compute parameters for interactions between i and j atoms */
489 qq00 = _mm256_mul_pd(iq0,jq0);
491 /* EWALD ELECTROSTATICS */
493 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
494 ewrt = _mm256_mul_pd(r00,ewtabscale);
495 ewitab = _mm256_cvttpd_epi32(ewrt);
496 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
497 ewitab = _mm_slli_epi32(ewitab,2);
498 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
499 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
500 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
501 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
502 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
503 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
504 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
505 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_sub_pd(rinv00,sh_ewald),velec));
506 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
508 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
510 /* Update potential sum for this i atom from the interaction with this j atom. */
511 velec = _mm256_and_pd(velec,cutoff_mask);
512 velec = _mm256_andnot_pd(dummy_mask,velec);
513 velecsum = _mm256_add_pd(velecsum,velec);
517 fscal = _mm256_and_pd(fscal,cutoff_mask);
519 fscal = _mm256_andnot_pd(dummy_mask,fscal);
521 /* Calculate temporary vectorial force */
522 tx = _mm256_mul_pd(fscal,dx00);
523 ty = _mm256_mul_pd(fscal,dy00);
524 tz = _mm256_mul_pd(fscal,dz00);
526 /* Update vectorial force */
527 fix0 = _mm256_add_pd(fix0,tx);
528 fiy0 = _mm256_add_pd(fiy0,ty);
529 fiz0 = _mm256_add_pd(fiz0,tz);
531 fjx0 = _mm256_add_pd(fjx0,tx);
532 fjy0 = _mm256_add_pd(fjy0,ty);
533 fjz0 = _mm256_add_pd(fjz0,tz);
537 /**************************
538 * CALCULATE INTERACTIONS *
539 **************************/
541 if (gmx_mm256_any_lt(rsq10,rcutoff2))
544 r10 = _mm256_mul_pd(rsq10,rinv10);
545 r10 = _mm256_andnot_pd(dummy_mask,r10);
547 /* Compute parameters for interactions between i and j atoms */
548 qq10 = _mm256_mul_pd(iq1,jq0);
550 /* EWALD ELECTROSTATICS */
552 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
553 ewrt = _mm256_mul_pd(r10,ewtabscale);
554 ewitab = _mm256_cvttpd_epi32(ewrt);
555 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
556 ewitab = _mm_slli_epi32(ewitab,2);
557 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
558 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
559 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
560 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
561 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
562 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
563 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
564 velec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_sub_pd(rinv10,sh_ewald),velec));
565 felec = _mm256_mul_pd(_mm256_mul_pd(qq10,rinv10),_mm256_sub_pd(rinvsq10,felec));
567 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
569 /* Update potential sum for this i atom from the interaction with this j atom. */
570 velec = _mm256_and_pd(velec,cutoff_mask);
571 velec = _mm256_andnot_pd(dummy_mask,velec);
572 velecsum = _mm256_add_pd(velecsum,velec);
576 fscal = _mm256_and_pd(fscal,cutoff_mask);
578 fscal = _mm256_andnot_pd(dummy_mask,fscal);
580 /* Calculate temporary vectorial force */
581 tx = _mm256_mul_pd(fscal,dx10);
582 ty = _mm256_mul_pd(fscal,dy10);
583 tz = _mm256_mul_pd(fscal,dz10);
585 /* Update vectorial force */
586 fix1 = _mm256_add_pd(fix1,tx);
587 fiy1 = _mm256_add_pd(fiy1,ty);
588 fiz1 = _mm256_add_pd(fiz1,tz);
590 fjx0 = _mm256_add_pd(fjx0,tx);
591 fjy0 = _mm256_add_pd(fjy0,ty);
592 fjz0 = _mm256_add_pd(fjz0,tz);
596 /**************************
597 * CALCULATE INTERACTIONS *
598 **************************/
600 if (gmx_mm256_any_lt(rsq20,rcutoff2))
603 r20 = _mm256_mul_pd(rsq20,rinv20);
604 r20 = _mm256_andnot_pd(dummy_mask,r20);
606 /* Compute parameters for interactions between i and j atoms */
607 qq20 = _mm256_mul_pd(iq2,jq0);
609 /* EWALD ELECTROSTATICS */
611 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
612 ewrt = _mm256_mul_pd(r20,ewtabscale);
613 ewitab = _mm256_cvttpd_epi32(ewrt);
614 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
615 ewitab = _mm_slli_epi32(ewitab,2);
616 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
617 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
618 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
619 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
620 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
621 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
622 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
623 velec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_sub_pd(rinv20,sh_ewald),velec));
624 felec = _mm256_mul_pd(_mm256_mul_pd(qq20,rinv20),_mm256_sub_pd(rinvsq20,felec));
626 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
628 /* Update potential sum for this i atom from the interaction with this j atom. */
629 velec = _mm256_and_pd(velec,cutoff_mask);
630 velec = _mm256_andnot_pd(dummy_mask,velec);
631 velecsum = _mm256_add_pd(velecsum,velec);
635 fscal = _mm256_and_pd(fscal,cutoff_mask);
637 fscal = _mm256_andnot_pd(dummy_mask,fscal);
639 /* Calculate temporary vectorial force */
640 tx = _mm256_mul_pd(fscal,dx20);
641 ty = _mm256_mul_pd(fscal,dy20);
642 tz = _mm256_mul_pd(fscal,dz20);
644 /* Update vectorial force */
645 fix2 = _mm256_add_pd(fix2,tx);
646 fiy2 = _mm256_add_pd(fiy2,ty);
647 fiz2 = _mm256_add_pd(fiz2,tz);
649 fjx0 = _mm256_add_pd(fjx0,tx);
650 fjy0 = _mm256_add_pd(fjy0,ty);
651 fjz0 = _mm256_add_pd(fjz0,tz);
655 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
656 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
657 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
658 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
660 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
662 /* Inner loop uses 144 flops */
665 /* End of innermost loop */
667 gmx_mm256_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
668 f+i_coord_offset,fshift+i_shift_offset);
671 /* Update potential energies */
672 gmx_mm256_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
674 /* Increment number of inner iterations */
675 inneriter += j_index_end - j_index_start;
677 /* Outer loop uses 19 flops */
680 /* Increment number of outer iterations */
683 /* Update outer/inner flops */
685 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*144);
688 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomW3P1_F_avx_256_double
689 * Electrostatics interaction: Ewald
690 * VdW interaction: None
691 * Geometry: Water3-Particle
692 * Calculate force/pot: Force
695 nb_kernel_ElecEwSh_VdwNone_GeomW3P1_F_avx_256_double
696 (t_nblist * gmx_restrict nlist,
697 rvec * gmx_restrict xx,
698 rvec * gmx_restrict ff,
699 t_forcerec * gmx_restrict fr,
700 t_mdatoms * gmx_restrict mdatoms,
701 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
702 t_nrnb * gmx_restrict nrnb)
704 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
705 * just 0 for non-waters.
706 * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
707 * jnr indices corresponding to data put in the four positions in the SIMD register.
709 int i_shift_offset,i_coord_offset,outeriter,inneriter;
710 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
711 int jnrA,jnrB,jnrC,jnrD;
712 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
713 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
714 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
715 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
717 real *shiftvec,*fshift,*x,*f;
718 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
720 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
721 real * vdwioffsetptr0;
722 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
723 real * vdwioffsetptr1;
724 __m256d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
725 real * vdwioffsetptr2;
726 __m256d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
727 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
728 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
729 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
730 __m256d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
731 __m256d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
732 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
735 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
736 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
738 __m256d dummy_mask,cutoff_mask;
739 __m128 tmpmask0,tmpmask1;
740 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
741 __m256d one = _mm256_set1_pd(1.0);
742 __m256d two = _mm256_set1_pd(2.0);
748 jindex = nlist->jindex;
750 shiftidx = nlist->shift;
752 shiftvec = fr->shift_vec[0];
753 fshift = fr->fshift[0];
754 facel = _mm256_set1_pd(fr->epsfac);
755 charge = mdatoms->chargeA;
757 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
758 beta = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
759 beta2 = _mm256_mul_pd(beta,beta);
760 beta3 = _mm256_mul_pd(beta,beta2);
762 ewtab = fr->ic->tabq_coul_F;
763 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
764 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
766 /* Setup water-specific parameters */
767 inr = nlist->iinr[0];
768 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
769 iq1 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+1]));
770 iq2 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+2]));
772 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
773 rcutoff_scalar = fr->rcoulomb;
774 rcutoff = _mm256_set1_pd(rcutoff_scalar);
775 rcutoff2 = _mm256_mul_pd(rcutoff,rcutoff);
777 /* Avoid stupid compiler warnings */
778 jnrA = jnrB = jnrC = jnrD = 0;
787 for(iidx=0;iidx<4*DIM;iidx++)
792 /* Start outer loop over neighborlists */
793 for(iidx=0; iidx<nri; iidx++)
795 /* Load shift vector for this list */
796 i_shift_offset = DIM*shiftidx[iidx];
798 /* Load limits for loop over neighbors */
799 j_index_start = jindex[iidx];
800 j_index_end = jindex[iidx+1];
802 /* Get outer coordinate index */
804 i_coord_offset = DIM*inr;
806 /* Load i particle coords and add shift vector */
807 gmx_mm256_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
808 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
810 fix0 = _mm256_setzero_pd();
811 fiy0 = _mm256_setzero_pd();
812 fiz0 = _mm256_setzero_pd();
813 fix1 = _mm256_setzero_pd();
814 fiy1 = _mm256_setzero_pd();
815 fiz1 = _mm256_setzero_pd();
816 fix2 = _mm256_setzero_pd();
817 fiy2 = _mm256_setzero_pd();
818 fiz2 = _mm256_setzero_pd();
820 /* Start inner kernel loop */
821 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
824 /* Get j neighbor index, and coordinate index */
829 j_coord_offsetA = DIM*jnrA;
830 j_coord_offsetB = DIM*jnrB;
831 j_coord_offsetC = DIM*jnrC;
832 j_coord_offsetD = DIM*jnrD;
834 /* load j atom coordinates */
835 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
836 x+j_coord_offsetC,x+j_coord_offsetD,
839 /* Calculate displacement vector */
840 dx00 = _mm256_sub_pd(ix0,jx0);
841 dy00 = _mm256_sub_pd(iy0,jy0);
842 dz00 = _mm256_sub_pd(iz0,jz0);
843 dx10 = _mm256_sub_pd(ix1,jx0);
844 dy10 = _mm256_sub_pd(iy1,jy0);
845 dz10 = _mm256_sub_pd(iz1,jz0);
846 dx20 = _mm256_sub_pd(ix2,jx0);
847 dy20 = _mm256_sub_pd(iy2,jy0);
848 dz20 = _mm256_sub_pd(iz2,jz0);
850 /* Calculate squared distance and things based on it */
851 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
852 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
853 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
855 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
856 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
857 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
859 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
860 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
861 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
863 /* Load parameters for j particles */
864 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
865 charge+jnrC+0,charge+jnrD+0);
867 fjx0 = _mm256_setzero_pd();
868 fjy0 = _mm256_setzero_pd();
869 fjz0 = _mm256_setzero_pd();
871 /**************************
872 * CALCULATE INTERACTIONS *
873 **************************/
875 if (gmx_mm256_any_lt(rsq00,rcutoff2))
878 r00 = _mm256_mul_pd(rsq00,rinv00);
880 /* Compute parameters for interactions between i and j atoms */
881 qq00 = _mm256_mul_pd(iq0,jq0);
883 /* EWALD ELECTROSTATICS */
885 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
886 ewrt = _mm256_mul_pd(r00,ewtabscale);
887 ewitab = _mm256_cvttpd_epi32(ewrt);
888 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
889 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
890 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
892 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
893 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
895 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
899 fscal = _mm256_and_pd(fscal,cutoff_mask);
901 /* Calculate temporary vectorial force */
902 tx = _mm256_mul_pd(fscal,dx00);
903 ty = _mm256_mul_pd(fscal,dy00);
904 tz = _mm256_mul_pd(fscal,dz00);
906 /* Update vectorial force */
907 fix0 = _mm256_add_pd(fix0,tx);
908 fiy0 = _mm256_add_pd(fiy0,ty);
909 fiz0 = _mm256_add_pd(fiz0,tz);
911 fjx0 = _mm256_add_pd(fjx0,tx);
912 fjy0 = _mm256_add_pd(fjy0,ty);
913 fjz0 = _mm256_add_pd(fjz0,tz);
917 /**************************
918 * CALCULATE INTERACTIONS *
919 **************************/
921 if (gmx_mm256_any_lt(rsq10,rcutoff2))
924 r10 = _mm256_mul_pd(rsq10,rinv10);
926 /* Compute parameters for interactions between i and j atoms */
927 qq10 = _mm256_mul_pd(iq1,jq0);
929 /* EWALD ELECTROSTATICS */
931 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
932 ewrt = _mm256_mul_pd(r10,ewtabscale);
933 ewitab = _mm256_cvttpd_epi32(ewrt);
934 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
935 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
936 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
938 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
939 felec = _mm256_mul_pd(_mm256_mul_pd(qq10,rinv10),_mm256_sub_pd(rinvsq10,felec));
941 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
945 fscal = _mm256_and_pd(fscal,cutoff_mask);
947 /* Calculate temporary vectorial force */
948 tx = _mm256_mul_pd(fscal,dx10);
949 ty = _mm256_mul_pd(fscal,dy10);
950 tz = _mm256_mul_pd(fscal,dz10);
952 /* Update vectorial force */
953 fix1 = _mm256_add_pd(fix1,tx);
954 fiy1 = _mm256_add_pd(fiy1,ty);
955 fiz1 = _mm256_add_pd(fiz1,tz);
957 fjx0 = _mm256_add_pd(fjx0,tx);
958 fjy0 = _mm256_add_pd(fjy0,ty);
959 fjz0 = _mm256_add_pd(fjz0,tz);
963 /**************************
964 * CALCULATE INTERACTIONS *
965 **************************/
967 if (gmx_mm256_any_lt(rsq20,rcutoff2))
970 r20 = _mm256_mul_pd(rsq20,rinv20);
972 /* Compute parameters for interactions between i and j atoms */
973 qq20 = _mm256_mul_pd(iq2,jq0);
975 /* EWALD ELECTROSTATICS */
977 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
978 ewrt = _mm256_mul_pd(r20,ewtabscale);
979 ewitab = _mm256_cvttpd_epi32(ewrt);
980 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
981 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
982 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
984 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
985 felec = _mm256_mul_pd(_mm256_mul_pd(qq20,rinv20),_mm256_sub_pd(rinvsq20,felec));
987 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
991 fscal = _mm256_and_pd(fscal,cutoff_mask);
993 /* Calculate temporary vectorial force */
994 tx = _mm256_mul_pd(fscal,dx20);
995 ty = _mm256_mul_pd(fscal,dy20);
996 tz = _mm256_mul_pd(fscal,dz20);
998 /* Update vectorial force */
999 fix2 = _mm256_add_pd(fix2,tx);
1000 fiy2 = _mm256_add_pd(fiy2,ty);
1001 fiz2 = _mm256_add_pd(fiz2,tz);
1003 fjx0 = _mm256_add_pd(fjx0,tx);
1004 fjy0 = _mm256_add_pd(fjy0,ty);
1005 fjz0 = _mm256_add_pd(fjz0,tz);
1009 fjptrA = f+j_coord_offsetA;
1010 fjptrB = f+j_coord_offsetB;
1011 fjptrC = f+j_coord_offsetC;
1012 fjptrD = f+j_coord_offsetD;
1014 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1016 /* Inner loop uses 120 flops */
1019 if(jidx<j_index_end)
1022 /* Get j neighbor index, and coordinate index */
1023 jnrlistA = jjnr[jidx];
1024 jnrlistB = jjnr[jidx+1];
1025 jnrlistC = jjnr[jidx+2];
1026 jnrlistD = jjnr[jidx+3];
1027 /* Sign of each element will be negative for non-real atoms.
1028 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1029 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
1031 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1033 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
1034 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
1035 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
1037 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1038 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1039 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1040 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1041 j_coord_offsetA = DIM*jnrA;
1042 j_coord_offsetB = DIM*jnrB;
1043 j_coord_offsetC = DIM*jnrC;
1044 j_coord_offsetD = DIM*jnrD;
1046 /* load j atom coordinates */
1047 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
1048 x+j_coord_offsetC,x+j_coord_offsetD,
1051 /* Calculate displacement vector */
1052 dx00 = _mm256_sub_pd(ix0,jx0);
1053 dy00 = _mm256_sub_pd(iy0,jy0);
1054 dz00 = _mm256_sub_pd(iz0,jz0);
1055 dx10 = _mm256_sub_pd(ix1,jx0);
1056 dy10 = _mm256_sub_pd(iy1,jy0);
1057 dz10 = _mm256_sub_pd(iz1,jz0);
1058 dx20 = _mm256_sub_pd(ix2,jx0);
1059 dy20 = _mm256_sub_pd(iy2,jy0);
1060 dz20 = _mm256_sub_pd(iz2,jz0);
1062 /* Calculate squared distance and things based on it */
1063 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
1064 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
1065 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
1067 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
1068 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
1069 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
1071 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
1072 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
1073 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
1075 /* Load parameters for j particles */
1076 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
1077 charge+jnrC+0,charge+jnrD+0);
1079 fjx0 = _mm256_setzero_pd();
1080 fjy0 = _mm256_setzero_pd();
1081 fjz0 = _mm256_setzero_pd();
1083 /**************************
1084 * CALCULATE INTERACTIONS *
1085 **************************/
1087 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1090 r00 = _mm256_mul_pd(rsq00,rinv00);
1091 r00 = _mm256_andnot_pd(dummy_mask,r00);
1093 /* Compute parameters for interactions between i and j atoms */
1094 qq00 = _mm256_mul_pd(iq0,jq0);
1096 /* EWALD ELECTROSTATICS */
1098 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1099 ewrt = _mm256_mul_pd(r00,ewtabscale);
1100 ewitab = _mm256_cvttpd_epi32(ewrt);
1101 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
1102 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
1103 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
1105 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
1106 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
1108 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
1112 fscal = _mm256_and_pd(fscal,cutoff_mask);
1114 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1116 /* Calculate temporary vectorial force */
1117 tx = _mm256_mul_pd(fscal,dx00);
1118 ty = _mm256_mul_pd(fscal,dy00);
1119 tz = _mm256_mul_pd(fscal,dz00);
1121 /* Update vectorial force */
1122 fix0 = _mm256_add_pd(fix0,tx);
1123 fiy0 = _mm256_add_pd(fiy0,ty);
1124 fiz0 = _mm256_add_pd(fiz0,tz);
1126 fjx0 = _mm256_add_pd(fjx0,tx);
1127 fjy0 = _mm256_add_pd(fjy0,ty);
1128 fjz0 = _mm256_add_pd(fjz0,tz);
1132 /**************************
1133 * CALCULATE INTERACTIONS *
1134 **************************/
1136 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1139 r10 = _mm256_mul_pd(rsq10,rinv10);
1140 r10 = _mm256_andnot_pd(dummy_mask,r10);
1142 /* Compute parameters for interactions between i and j atoms */
1143 qq10 = _mm256_mul_pd(iq1,jq0);
1145 /* EWALD ELECTROSTATICS */
1147 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1148 ewrt = _mm256_mul_pd(r10,ewtabscale);
1149 ewitab = _mm256_cvttpd_epi32(ewrt);
1150 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
1151 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
1152 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
1154 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
1155 felec = _mm256_mul_pd(_mm256_mul_pd(qq10,rinv10),_mm256_sub_pd(rinvsq10,felec));
1157 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
1161 fscal = _mm256_and_pd(fscal,cutoff_mask);
1163 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1165 /* Calculate temporary vectorial force */
1166 tx = _mm256_mul_pd(fscal,dx10);
1167 ty = _mm256_mul_pd(fscal,dy10);
1168 tz = _mm256_mul_pd(fscal,dz10);
1170 /* Update vectorial force */
1171 fix1 = _mm256_add_pd(fix1,tx);
1172 fiy1 = _mm256_add_pd(fiy1,ty);
1173 fiz1 = _mm256_add_pd(fiz1,tz);
1175 fjx0 = _mm256_add_pd(fjx0,tx);
1176 fjy0 = _mm256_add_pd(fjy0,ty);
1177 fjz0 = _mm256_add_pd(fjz0,tz);
1181 /**************************
1182 * CALCULATE INTERACTIONS *
1183 **************************/
1185 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1188 r20 = _mm256_mul_pd(rsq20,rinv20);
1189 r20 = _mm256_andnot_pd(dummy_mask,r20);
1191 /* Compute parameters for interactions between i and j atoms */
1192 qq20 = _mm256_mul_pd(iq2,jq0);
1194 /* EWALD ELECTROSTATICS */
1196 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1197 ewrt = _mm256_mul_pd(r20,ewtabscale);
1198 ewitab = _mm256_cvttpd_epi32(ewrt);
1199 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
1200 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
1201 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
1203 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
1204 felec = _mm256_mul_pd(_mm256_mul_pd(qq20,rinv20),_mm256_sub_pd(rinvsq20,felec));
1206 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
1210 fscal = _mm256_and_pd(fscal,cutoff_mask);
1212 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1214 /* Calculate temporary vectorial force */
1215 tx = _mm256_mul_pd(fscal,dx20);
1216 ty = _mm256_mul_pd(fscal,dy20);
1217 tz = _mm256_mul_pd(fscal,dz20);
1219 /* Update vectorial force */
1220 fix2 = _mm256_add_pd(fix2,tx);
1221 fiy2 = _mm256_add_pd(fiy2,ty);
1222 fiz2 = _mm256_add_pd(fiz2,tz);
1224 fjx0 = _mm256_add_pd(fjx0,tx);
1225 fjy0 = _mm256_add_pd(fjy0,ty);
1226 fjz0 = _mm256_add_pd(fjz0,tz);
1230 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1231 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1232 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1233 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1235 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1237 /* Inner loop uses 123 flops */
1240 /* End of innermost loop */
1242 gmx_mm256_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1243 f+i_coord_offset,fshift+i_shift_offset);
1245 /* Increment number of inner iterations */
1246 inneriter += j_index_end - j_index_start;
1248 /* Outer loop uses 18 flops */
1251 /* Increment number of outer iterations */
1254 /* Update outer/inner flops */
1256 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*123);