2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_256_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.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_GeomP1P1_VF_avx_256_double
54 * Electrostatics interaction: Ewald
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_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 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
94 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
95 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
97 __m256d dummy_mask,cutoff_mask;
98 __m128 tmpmask0,tmpmask1;
99 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
100 __m256d one = _mm256_set1_pd(1.0);
101 __m256d two = _mm256_set1_pd(2.0);
107 jindex = nlist->jindex;
109 shiftidx = nlist->shift;
111 shiftvec = fr->shift_vec[0];
112 fshift = fr->fshift[0];
113 facel = _mm256_set1_pd(fr->epsfac);
114 charge = mdatoms->chargeA;
116 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
117 beta = _mm256_set1_pd(fr->ic->ewaldcoeff);
118 beta2 = _mm256_mul_pd(beta,beta);
119 beta3 = _mm256_mul_pd(beta,beta2);
121 ewtab = fr->ic->tabq_coul_FDV0;
122 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
123 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
125 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
126 rcutoff_scalar = fr->rcoulomb;
127 rcutoff = _mm256_set1_pd(rcutoff_scalar);
128 rcutoff2 = _mm256_mul_pd(rcutoff,rcutoff);
130 /* Avoid stupid compiler warnings */
131 jnrA = jnrB = jnrC = jnrD = 0;
140 for(iidx=0;iidx<4*DIM;iidx++)
145 /* Start outer loop over neighborlists */
146 for(iidx=0; iidx<nri; iidx++)
148 /* Load shift vector for this list */
149 i_shift_offset = DIM*shiftidx[iidx];
151 /* Load limits for loop over neighbors */
152 j_index_start = jindex[iidx];
153 j_index_end = jindex[iidx+1];
155 /* Get outer coordinate index */
157 i_coord_offset = DIM*inr;
159 /* Load i particle coords and add shift vector */
160 gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
162 fix0 = _mm256_setzero_pd();
163 fiy0 = _mm256_setzero_pd();
164 fiz0 = _mm256_setzero_pd();
166 /* Load parameters for i particles */
167 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
169 /* Reset potential sums */
170 velecsum = _mm256_setzero_pd();
172 /* Start inner kernel loop */
173 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
176 /* Get j neighbor index, and coordinate index */
181 j_coord_offsetA = DIM*jnrA;
182 j_coord_offsetB = DIM*jnrB;
183 j_coord_offsetC = DIM*jnrC;
184 j_coord_offsetD = DIM*jnrD;
186 /* load j atom coordinates */
187 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
188 x+j_coord_offsetC,x+j_coord_offsetD,
191 /* Calculate displacement vector */
192 dx00 = _mm256_sub_pd(ix0,jx0);
193 dy00 = _mm256_sub_pd(iy0,jy0);
194 dz00 = _mm256_sub_pd(iz0,jz0);
196 /* Calculate squared distance and things based on it */
197 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
199 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
201 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
203 /* Load parameters for j particles */
204 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
205 charge+jnrC+0,charge+jnrD+0);
207 /**************************
208 * CALCULATE INTERACTIONS *
209 **************************/
211 if (gmx_mm256_any_lt(rsq00,rcutoff2))
214 r00 = _mm256_mul_pd(rsq00,rinv00);
216 /* Compute parameters for interactions between i and j atoms */
217 qq00 = _mm256_mul_pd(iq0,jq0);
219 /* EWALD ELECTROSTATICS */
221 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
222 ewrt = _mm256_mul_pd(r00,ewtabscale);
223 ewitab = _mm256_cvttpd_epi32(ewrt);
224 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
225 ewitab = _mm_slli_epi32(ewitab,2);
226 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
227 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
228 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
229 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
230 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
231 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
232 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
233 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_sub_pd(rinv00,sh_ewald),velec));
234 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
236 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
238 /* Update potential sum for this i atom from the interaction with this j atom. */
239 velec = _mm256_and_pd(velec,cutoff_mask);
240 velecsum = _mm256_add_pd(velecsum,velec);
244 fscal = _mm256_and_pd(fscal,cutoff_mask);
246 /* Calculate temporary vectorial force */
247 tx = _mm256_mul_pd(fscal,dx00);
248 ty = _mm256_mul_pd(fscal,dy00);
249 tz = _mm256_mul_pd(fscal,dz00);
251 /* Update vectorial force */
252 fix0 = _mm256_add_pd(fix0,tx);
253 fiy0 = _mm256_add_pd(fiy0,ty);
254 fiz0 = _mm256_add_pd(fiz0,tz);
256 fjptrA = f+j_coord_offsetA;
257 fjptrB = f+j_coord_offsetB;
258 fjptrC = f+j_coord_offsetC;
259 fjptrD = f+j_coord_offsetD;
260 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
264 /* Inner loop uses 46 flops */
270 /* Get j neighbor index, and coordinate index */
271 jnrlistA = jjnr[jidx];
272 jnrlistB = jjnr[jidx+1];
273 jnrlistC = jjnr[jidx+2];
274 jnrlistD = jjnr[jidx+3];
275 /* Sign of each element will be negative for non-real atoms.
276 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
277 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
279 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
281 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
282 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
283 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
285 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
286 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
287 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
288 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
289 j_coord_offsetA = DIM*jnrA;
290 j_coord_offsetB = DIM*jnrB;
291 j_coord_offsetC = DIM*jnrC;
292 j_coord_offsetD = DIM*jnrD;
294 /* load j atom coordinates */
295 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
296 x+j_coord_offsetC,x+j_coord_offsetD,
299 /* Calculate displacement vector */
300 dx00 = _mm256_sub_pd(ix0,jx0);
301 dy00 = _mm256_sub_pd(iy0,jy0);
302 dz00 = _mm256_sub_pd(iz0,jz0);
304 /* Calculate squared distance and things based on it */
305 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
307 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
309 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
311 /* Load parameters for j particles */
312 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
313 charge+jnrC+0,charge+jnrD+0);
315 /**************************
316 * CALCULATE INTERACTIONS *
317 **************************/
319 if (gmx_mm256_any_lt(rsq00,rcutoff2))
322 r00 = _mm256_mul_pd(rsq00,rinv00);
323 r00 = _mm256_andnot_pd(dummy_mask,r00);
325 /* Compute parameters for interactions between i and j atoms */
326 qq00 = _mm256_mul_pd(iq0,jq0);
328 /* EWALD ELECTROSTATICS */
330 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
331 ewrt = _mm256_mul_pd(r00,ewtabscale);
332 ewitab = _mm256_cvttpd_epi32(ewrt);
333 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
334 ewitab = _mm_slli_epi32(ewitab,2);
335 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
336 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
337 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
338 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
339 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
340 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
341 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
342 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_sub_pd(rinv00,sh_ewald),velec));
343 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
345 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
347 /* Update potential sum for this i atom from the interaction with this j atom. */
348 velec = _mm256_and_pd(velec,cutoff_mask);
349 velec = _mm256_andnot_pd(dummy_mask,velec);
350 velecsum = _mm256_add_pd(velecsum,velec);
354 fscal = _mm256_and_pd(fscal,cutoff_mask);
356 fscal = _mm256_andnot_pd(dummy_mask,fscal);
358 /* Calculate temporary vectorial force */
359 tx = _mm256_mul_pd(fscal,dx00);
360 ty = _mm256_mul_pd(fscal,dy00);
361 tz = _mm256_mul_pd(fscal,dz00);
363 /* Update vectorial force */
364 fix0 = _mm256_add_pd(fix0,tx);
365 fiy0 = _mm256_add_pd(fiy0,ty);
366 fiz0 = _mm256_add_pd(fiz0,tz);
368 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
369 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
370 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
371 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
372 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
376 /* Inner loop uses 47 flops */
379 /* End of innermost loop */
381 gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
382 f+i_coord_offset,fshift+i_shift_offset);
385 /* Update potential energies */
386 gmx_mm256_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
388 /* Increment number of inner iterations */
389 inneriter += j_index_end - j_index_start;
391 /* Outer loop uses 8 flops */
394 /* Increment number of outer iterations */
397 /* Update outer/inner flops */
399 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*47);
402 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_avx_256_double
403 * Electrostatics interaction: Ewald
404 * VdW interaction: None
405 * Geometry: Particle-Particle
406 * Calculate force/pot: Force
409 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_avx_256_double
410 (t_nblist * gmx_restrict nlist,
411 rvec * gmx_restrict xx,
412 rvec * gmx_restrict ff,
413 t_forcerec * gmx_restrict fr,
414 t_mdatoms * gmx_restrict mdatoms,
415 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
416 t_nrnb * gmx_restrict nrnb)
418 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
419 * just 0 for non-waters.
420 * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
421 * jnr indices corresponding to data put in the four positions in the SIMD register.
423 int i_shift_offset,i_coord_offset,outeriter,inneriter;
424 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
425 int jnrA,jnrB,jnrC,jnrD;
426 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
427 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
428 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
429 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
431 real *shiftvec,*fshift,*x,*f;
432 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
434 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
435 real * vdwioffsetptr0;
436 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
437 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
438 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
439 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
440 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
443 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
444 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
446 __m256d dummy_mask,cutoff_mask;
447 __m128 tmpmask0,tmpmask1;
448 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
449 __m256d one = _mm256_set1_pd(1.0);
450 __m256d two = _mm256_set1_pd(2.0);
456 jindex = nlist->jindex;
458 shiftidx = nlist->shift;
460 shiftvec = fr->shift_vec[0];
461 fshift = fr->fshift[0];
462 facel = _mm256_set1_pd(fr->epsfac);
463 charge = mdatoms->chargeA;
465 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
466 beta = _mm256_set1_pd(fr->ic->ewaldcoeff);
467 beta2 = _mm256_mul_pd(beta,beta);
468 beta3 = _mm256_mul_pd(beta,beta2);
470 ewtab = fr->ic->tabq_coul_F;
471 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
472 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
474 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
475 rcutoff_scalar = fr->rcoulomb;
476 rcutoff = _mm256_set1_pd(rcutoff_scalar);
477 rcutoff2 = _mm256_mul_pd(rcutoff,rcutoff);
479 /* Avoid stupid compiler warnings */
480 jnrA = jnrB = jnrC = jnrD = 0;
489 for(iidx=0;iidx<4*DIM;iidx++)
494 /* Start outer loop over neighborlists */
495 for(iidx=0; iidx<nri; iidx++)
497 /* Load shift vector for this list */
498 i_shift_offset = DIM*shiftidx[iidx];
500 /* Load limits for loop over neighbors */
501 j_index_start = jindex[iidx];
502 j_index_end = jindex[iidx+1];
504 /* Get outer coordinate index */
506 i_coord_offset = DIM*inr;
508 /* Load i particle coords and add shift vector */
509 gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
511 fix0 = _mm256_setzero_pd();
512 fiy0 = _mm256_setzero_pd();
513 fiz0 = _mm256_setzero_pd();
515 /* Load parameters for i particles */
516 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
518 /* Start inner kernel loop */
519 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
522 /* Get j neighbor index, and coordinate index */
527 j_coord_offsetA = DIM*jnrA;
528 j_coord_offsetB = DIM*jnrB;
529 j_coord_offsetC = DIM*jnrC;
530 j_coord_offsetD = DIM*jnrD;
532 /* load j atom coordinates */
533 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
534 x+j_coord_offsetC,x+j_coord_offsetD,
537 /* Calculate displacement vector */
538 dx00 = _mm256_sub_pd(ix0,jx0);
539 dy00 = _mm256_sub_pd(iy0,jy0);
540 dz00 = _mm256_sub_pd(iz0,jz0);
542 /* Calculate squared distance and things based on it */
543 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
545 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
547 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
549 /* Load parameters for j particles */
550 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
551 charge+jnrC+0,charge+jnrD+0);
553 /**************************
554 * CALCULATE INTERACTIONS *
555 **************************/
557 if (gmx_mm256_any_lt(rsq00,rcutoff2))
560 r00 = _mm256_mul_pd(rsq00,rinv00);
562 /* Compute parameters for interactions between i and j atoms */
563 qq00 = _mm256_mul_pd(iq0,jq0);
565 /* EWALD ELECTROSTATICS */
567 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
568 ewrt = _mm256_mul_pd(r00,ewtabscale);
569 ewitab = _mm256_cvttpd_epi32(ewrt);
570 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
571 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
572 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
574 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
575 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
577 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
581 fscal = _mm256_and_pd(fscal,cutoff_mask);
583 /* Calculate temporary vectorial force */
584 tx = _mm256_mul_pd(fscal,dx00);
585 ty = _mm256_mul_pd(fscal,dy00);
586 tz = _mm256_mul_pd(fscal,dz00);
588 /* Update vectorial force */
589 fix0 = _mm256_add_pd(fix0,tx);
590 fiy0 = _mm256_add_pd(fiy0,ty);
591 fiz0 = _mm256_add_pd(fiz0,tz);
593 fjptrA = f+j_coord_offsetA;
594 fjptrB = f+j_coord_offsetB;
595 fjptrC = f+j_coord_offsetC;
596 fjptrD = f+j_coord_offsetD;
597 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
601 /* Inner loop uses 39 flops */
607 /* Get j neighbor index, and coordinate index */
608 jnrlistA = jjnr[jidx];
609 jnrlistB = jjnr[jidx+1];
610 jnrlistC = jjnr[jidx+2];
611 jnrlistD = jjnr[jidx+3];
612 /* Sign of each element will be negative for non-real atoms.
613 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
614 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
616 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
618 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
619 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
620 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
622 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
623 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
624 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
625 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
626 j_coord_offsetA = DIM*jnrA;
627 j_coord_offsetB = DIM*jnrB;
628 j_coord_offsetC = DIM*jnrC;
629 j_coord_offsetD = DIM*jnrD;
631 /* load j atom coordinates */
632 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
633 x+j_coord_offsetC,x+j_coord_offsetD,
636 /* Calculate displacement vector */
637 dx00 = _mm256_sub_pd(ix0,jx0);
638 dy00 = _mm256_sub_pd(iy0,jy0);
639 dz00 = _mm256_sub_pd(iz0,jz0);
641 /* Calculate squared distance and things based on it */
642 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
644 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
646 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
648 /* Load parameters for j particles */
649 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
650 charge+jnrC+0,charge+jnrD+0);
652 /**************************
653 * CALCULATE INTERACTIONS *
654 **************************/
656 if (gmx_mm256_any_lt(rsq00,rcutoff2))
659 r00 = _mm256_mul_pd(rsq00,rinv00);
660 r00 = _mm256_andnot_pd(dummy_mask,r00);
662 /* Compute parameters for interactions between i and j atoms */
663 qq00 = _mm256_mul_pd(iq0,jq0);
665 /* EWALD ELECTROSTATICS */
667 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
668 ewrt = _mm256_mul_pd(r00,ewtabscale);
669 ewitab = _mm256_cvttpd_epi32(ewrt);
670 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
671 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
672 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
674 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
675 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
677 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
681 fscal = _mm256_and_pd(fscal,cutoff_mask);
683 fscal = _mm256_andnot_pd(dummy_mask,fscal);
685 /* Calculate temporary vectorial force */
686 tx = _mm256_mul_pd(fscal,dx00);
687 ty = _mm256_mul_pd(fscal,dy00);
688 tz = _mm256_mul_pd(fscal,dz00);
690 /* Update vectorial force */
691 fix0 = _mm256_add_pd(fix0,tx);
692 fiy0 = _mm256_add_pd(fiy0,ty);
693 fiz0 = _mm256_add_pd(fiz0,tz);
695 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
696 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
697 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
698 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
699 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
703 /* Inner loop uses 40 flops */
706 /* End of innermost loop */
708 gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
709 f+i_coord_offset,fshift+i_shift_offset);
711 /* Increment number of inner iterations */
712 inneriter += j_index_end - j_index_start;
714 /* Outer loop uses 7 flops */
717 /* Increment number of outer iterations */
720 /* Update outer/inner flops */
722 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*40);