2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_256_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomP1P1_VF_avx_256_double
51 * Electrostatics interaction: Ewald
52 * VdW interaction: None
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEw_VdwNone_GeomP1P1_VF_avx_256_double
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 real * vdwioffsetptr0;
84 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
91 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
92 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
94 __m256d dummy_mask,cutoff_mask;
95 __m128 tmpmask0,tmpmask1;
96 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
97 __m256d one = _mm256_set1_pd(1.0);
98 __m256d two = _mm256_set1_pd(2.0);
104 jindex = nlist->jindex;
106 shiftidx = nlist->shift;
108 shiftvec = fr->shift_vec[0];
109 fshift = fr->fshift[0];
110 facel = _mm256_set1_pd(fr->ic->epsfac);
111 charge = mdatoms->chargeA;
113 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
114 beta = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
115 beta2 = _mm256_mul_pd(beta,beta);
116 beta3 = _mm256_mul_pd(beta,beta2);
118 ewtab = fr->ic->tabq_coul_FDV0;
119 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
120 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
122 /* Avoid stupid compiler warnings */
123 jnrA = jnrB = jnrC = jnrD = 0;
132 for(iidx=0;iidx<4*DIM;iidx++)
137 /* Start outer loop over neighborlists */
138 for(iidx=0; iidx<nri; iidx++)
140 /* Load shift vector for this list */
141 i_shift_offset = DIM*shiftidx[iidx];
143 /* Load limits for loop over neighbors */
144 j_index_start = jindex[iidx];
145 j_index_end = jindex[iidx+1];
147 /* Get outer coordinate index */
149 i_coord_offset = DIM*inr;
151 /* Load i particle coords and add shift vector */
152 gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
154 fix0 = _mm256_setzero_pd();
155 fiy0 = _mm256_setzero_pd();
156 fiz0 = _mm256_setzero_pd();
158 /* Load parameters for i particles */
159 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
161 /* Reset potential sums */
162 velecsum = _mm256_setzero_pd();
164 /* Start inner kernel loop */
165 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
168 /* Get j neighbor index, and coordinate index */
173 j_coord_offsetA = DIM*jnrA;
174 j_coord_offsetB = DIM*jnrB;
175 j_coord_offsetC = DIM*jnrC;
176 j_coord_offsetD = DIM*jnrD;
178 /* load j atom coordinates */
179 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
180 x+j_coord_offsetC,x+j_coord_offsetD,
183 /* Calculate displacement vector */
184 dx00 = _mm256_sub_pd(ix0,jx0);
185 dy00 = _mm256_sub_pd(iy0,jy0);
186 dz00 = _mm256_sub_pd(iz0,jz0);
188 /* Calculate squared distance and things based on it */
189 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
191 rinv00 = avx256_invsqrt_d(rsq00);
193 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
195 /* Load parameters for j particles */
196 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
197 charge+jnrC+0,charge+jnrD+0);
199 /**************************
200 * CALCULATE INTERACTIONS *
201 **************************/
203 r00 = _mm256_mul_pd(rsq00,rinv00);
205 /* Compute parameters for interactions between i and j atoms */
206 qq00 = _mm256_mul_pd(iq0,jq0);
208 /* EWALD ELECTROSTATICS */
210 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
211 ewrt = _mm256_mul_pd(r00,ewtabscale);
212 ewitab = _mm256_cvttpd_epi32(ewrt);
213 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
214 ewitab = _mm_slli_epi32(ewitab,2);
215 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
216 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
217 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
218 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
219 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
220 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
221 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
222 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(rinv00,velec));
223 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
225 /* Update potential sum for this i atom from the interaction with this j atom. */
226 velecsum = _mm256_add_pd(velecsum,velec);
230 /* Calculate temporary vectorial force */
231 tx = _mm256_mul_pd(fscal,dx00);
232 ty = _mm256_mul_pd(fscal,dy00);
233 tz = _mm256_mul_pd(fscal,dz00);
235 /* Update vectorial force */
236 fix0 = _mm256_add_pd(fix0,tx);
237 fiy0 = _mm256_add_pd(fiy0,ty);
238 fiz0 = _mm256_add_pd(fiz0,tz);
240 fjptrA = f+j_coord_offsetA;
241 fjptrB = f+j_coord_offsetB;
242 fjptrC = f+j_coord_offsetC;
243 fjptrD = f+j_coord_offsetD;
244 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
246 /* Inner loop uses 41 flops */
252 /* Get j neighbor index, and coordinate index */
253 jnrlistA = jjnr[jidx];
254 jnrlistB = jjnr[jidx+1];
255 jnrlistC = jjnr[jidx+2];
256 jnrlistD = jjnr[jidx+3];
257 /* Sign of each element will be negative for non-real atoms.
258 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
259 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
261 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
263 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
264 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
265 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
267 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
268 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
269 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
270 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
271 j_coord_offsetA = DIM*jnrA;
272 j_coord_offsetB = DIM*jnrB;
273 j_coord_offsetC = DIM*jnrC;
274 j_coord_offsetD = DIM*jnrD;
276 /* load j atom coordinates */
277 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
278 x+j_coord_offsetC,x+j_coord_offsetD,
281 /* Calculate displacement vector */
282 dx00 = _mm256_sub_pd(ix0,jx0);
283 dy00 = _mm256_sub_pd(iy0,jy0);
284 dz00 = _mm256_sub_pd(iz0,jz0);
286 /* Calculate squared distance and things based on it */
287 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
289 rinv00 = avx256_invsqrt_d(rsq00);
291 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
293 /* Load parameters for j particles */
294 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
295 charge+jnrC+0,charge+jnrD+0);
297 /**************************
298 * CALCULATE INTERACTIONS *
299 **************************/
301 r00 = _mm256_mul_pd(rsq00,rinv00);
302 r00 = _mm256_andnot_pd(dummy_mask,r00);
304 /* Compute parameters for interactions between i and j atoms */
305 qq00 = _mm256_mul_pd(iq0,jq0);
307 /* EWALD ELECTROSTATICS */
309 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
310 ewrt = _mm256_mul_pd(r00,ewtabscale);
311 ewitab = _mm256_cvttpd_epi32(ewrt);
312 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
313 ewitab = _mm_slli_epi32(ewitab,2);
314 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
315 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
316 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
317 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
318 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
319 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
320 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
321 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(rinv00,velec));
322 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
324 /* Update potential sum for this i atom from the interaction with this j atom. */
325 velec = _mm256_andnot_pd(dummy_mask,velec);
326 velecsum = _mm256_add_pd(velecsum,velec);
330 fscal = _mm256_andnot_pd(dummy_mask,fscal);
332 /* Calculate temporary vectorial force */
333 tx = _mm256_mul_pd(fscal,dx00);
334 ty = _mm256_mul_pd(fscal,dy00);
335 tz = _mm256_mul_pd(fscal,dz00);
337 /* Update vectorial force */
338 fix0 = _mm256_add_pd(fix0,tx);
339 fiy0 = _mm256_add_pd(fiy0,ty);
340 fiz0 = _mm256_add_pd(fiz0,tz);
342 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
343 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
344 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
345 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
346 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
348 /* Inner loop uses 42 flops */
351 /* End of innermost loop */
353 gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
354 f+i_coord_offset,fshift+i_shift_offset);
357 /* Update potential energies */
358 gmx_mm256_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
360 /* Increment number of inner iterations */
361 inneriter += j_index_end - j_index_start;
363 /* Outer loop uses 8 flops */
366 /* Increment number of outer iterations */
369 /* Update outer/inner flops */
371 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*42);
374 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_256_double
375 * Electrostatics interaction: Ewald
376 * VdW interaction: None
377 * Geometry: Particle-Particle
378 * Calculate force/pot: Force
381 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_256_double
382 (t_nblist * gmx_restrict nlist,
383 rvec * gmx_restrict xx,
384 rvec * gmx_restrict ff,
385 struct t_forcerec * gmx_restrict fr,
386 t_mdatoms * gmx_restrict mdatoms,
387 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
388 t_nrnb * gmx_restrict nrnb)
390 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
391 * just 0 for non-waters.
392 * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
393 * jnr indices corresponding to data put in the four positions in the SIMD register.
395 int i_shift_offset,i_coord_offset,outeriter,inneriter;
396 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
397 int jnrA,jnrB,jnrC,jnrD;
398 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
399 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
400 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
401 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
403 real *shiftvec,*fshift,*x,*f;
404 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
406 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
407 real * vdwioffsetptr0;
408 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
409 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
410 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
411 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
412 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
415 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
416 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
418 __m256d dummy_mask,cutoff_mask;
419 __m128 tmpmask0,tmpmask1;
420 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
421 __m256d one = _mm256_set1_pd(1.0);
422 __m256d two = _mm256_set1_pd(2.0);
428 jindex = nlist->jindex;
430 shiftidx = nlist->shift;
432 shiftvec = fr->shift_vec[0];
433 fshift = fr->fshift[0];
434 facel = _mm256_set1_pd(fr->ic->epsfac);
435 charge = mdatoms->chargeA;
437 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
438 beta = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
439 beta2 = _mm256_mul_pd(beta,beta);
440 beta3 = _mm256_mul_pd(beta,beta2);
442 ewtab = fr->ic->tabq_coul_F;
443 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
444 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
446 /* Avoid stupid compiler warnings */
447 jnrA = jnrB = jnrC = jnrD = 0;
456 for(iidx=0;iidx<4*DIM;iidx++)
461 /* Start outer loop over neighborlists */
462 for(iidx=0; iidx<nri; iidx++)
464 /* Load shift vector for this list */
465 i_shift_offset = DIM*shiftidx[iidx];
467 /* Load limits for loop over neighbors */
468 j_index_start = jindex[iidx];
469 j_index_end = jindex[iidx+1];
471 /* Get outer coordinate index */
473 i_coord_offset = DIM*inr;
475 /* Load i particle coords and add shift vector */
476 gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
478 fix0 = _mm256_setzero_pd();
479 fiy0 = _mm256_setzero_pd();
480 fiz0 = _mm256_setzero_pd();
482 /* Load parameters for i particles */
483 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
485 /* Start inner kernel loop */
486 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
489 /* Get j neighbor index, and coordinate index */
494 j_coord_offsetA = DIM*jnrA;
495 j_coord_offsetB = DIM*jnrB;
496 j_coord_offsetC = DIM*jnrC;
497 j_coord_offsetD = DIM*jnrD;
499 /* load j atom coordinates */
500 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
501 x+j_coord_offsetC,x+j_coord_offsetD,
504 /* Calculate displacement vector */
505 dx00 = _mm256_sub_pd(ix0,jx0);
506 dy00 = _mm256_sub_pd(iy0,jy0);
507 dz00 = _mm256_sub_pd(iz0,jz0);
509 /* Calculate squared distance and things based on it */
510 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
512 rinv00 = avx256_invsqrt_d(rsq00);
514 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
516 /* Load parameters for j particles */
517 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
518 charge+jnrC+0,charge+jnrD+0);
520 /**************************
521 * CALCULATE INTERACTIONS *
522 **************************/
524 r00 = _mm256_mul_pd(rsq00,rinv00);
526 /* Compute parameters for interactions between i and j atoms */
527 qq00 = _mm256_mul_pd(iq0,jq0);
529 /* EWALD ELECTROSTATICS */
531 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
532 ewrt = _mm256_mul_pd(r00,ewtabscale);
533 ewitab = _mm256_cvttpd_epi32(ewrt);
534 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
535 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
536 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
538 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
539 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
543 /* Calculate temporary vectorial force */
544 tx = _mm256_mul_pd(fscal,dx00);
545 ty = _mm256_mul_pd(fscal,dy00);
546 tz = _mm256_mul_pd(fscal,dz00);
548 /* Update vectorial force */
549 fix0 = _mm256_add_pd(fix0,tx);
550 fiy0 = _mm256_add_pd(fiy0,ty);
551 fiz0 = _mm256_add_pd(fiz0,tz);
553 fjptrA = f+j_coord_offsetA;
554 fjptrB = f+j_coord_offsetB;
555 fjptrC = f+j_coord_offsetC;
556 fjptrD = f+j_coord_offsetD;
557 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
559 /* Inner loop uses 36 flops */
565 /* Get j neighbor index, and coordinate index */
566 jnrlistA = jjnr[jidx];
567 jnrlistB = jjnr[jidx+1];
568 jnrlistC = jjnr[jidx+2];
569 jnrlistD = jjnr[jidx+3];
570 /* Sign of each element will be negative for non-real atoms.
571 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
572 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
574 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
576 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
577 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
578 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
580 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
581 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
582 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
583 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
584 j_coord_offsetA = DIM*jnrA;
585 j_coord_offsetB = DIM*jnrB;
586 j_coord_offsetC = DIM*jnrC;
587 j_coord_offsetD = DIM*jnrD;
589 /* load j atom coordinates */
590 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
591 x+j_coord_offsetC,x+j_coord_offsetD,
594 /* Calculate displacement vector */
595 dx00 = _mm256_sub_pd(ix0,jx0);
596 dy00 = _mm256_sub_pd(iy0,jy0);
597 dz00 = _mm256_sub_pd(iz0,jz0);
599 /* Calculate squared distance and things based on it */
600 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
602 rinv00 = avx256_invsqrt_d(rsq00);
604 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
606 /* Load parameters for j particles */
607 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
608 charge+jnrC+0,charge+jnrD+0);
610 /**************************
611 * CALCULATE INTERACTIONS *
612 **************************/
614 r00 = _mm256_mul_pd(rsq00,rinv00);
615 r00 = _mm256_andnot_pd(dummy_mask,r00);
617 /* Compute parameters for interactions between i and j atoms */
618 qq00 = _mm256_mul_pd(iq0,jq0);
620 /* EWALD ELECTROSTATICS */
622 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
623 ewrt = _mm256_mul_pd(r00,ewtabscale);
624 ewitab = _mm256_cvttpd_epi32(ewrt);
625 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
626 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
627 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
629 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
630 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
634 fscal = _mm256_andnot_pd(dummy_mask,fscal);
636 /* Calculate temporary vectorial force */
637 tx = _mm256_mul_pd(fscal,dx00);
638 ty = _mm256_mul_pd(fscal,dy00);
639 tz = _mm256_mul_pd(fscal,dz00);
641 /* Update vectorial force */
642 fix0 = _mm256_add_pd(fix0,tx);
643 fiy0 = _mm256_add_pd(fiy0,ty);
644 fiz0 = _mm256_add_pd(fiz0,tz);
646 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
647 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
648 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
649 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
650 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
652 /* Inner loop uses 37 flops */
655 /* End of innermost loop */
657 gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
658 f+i_coord_offset,fshift+i_shift_offset);
660 /* Increment number of inner iterations */
661 inneriter += j_index_end - j_index_start;
663 /* Outer loop uses 7 flops */
666 /* Increment number of outer iterations */
669 /* Update outer/inner flops */
671 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*37);