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 "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.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_ElecEw_VdwNone_GeomP1P1_VF_avx_256_double
52 * Electrostatics interaction: Ewald
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEw_VdwNone_GeomP1P1_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 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
87 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
88 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
89 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
92 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
93 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
95 __m256d dummy_mask,cutoff_mask;
96 __m128 tmpmask0,tmpmask1;
97 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
98 __m256d one = _mm256_set1_pd(1.0);
99 __m256d two = _mm256_set1_pd(2.0);
105 jindex = nlist->jindex;
107 shiftidx = nlist->shift;
109 shiftvec = fr->shift_vec[0];
110 fshift = fr->fshift[0];
111 facel = _mm256_set1_pd(fr->epsfac);
112 charge = mdatoms->chargeA;
114 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
115 beta = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
116 beta2 = _mm256_mul_pd(beta,beta);
117 beta3 = _mm256_mul_pd(beta,beta2);
119 ewtab = fr->ic->tabq_coul_FDV0;
120 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
121 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
123 /* Avoid stupid compiler warnings */
124 jnrA = jnrB = jnrC = jnrD = 0;
133 for(iidx=0;iidx<4*DIM;iidx++)
138 /* Start outer loop over neighborlists */
139 for(iidx=0; iidx<nri; iidx++)
141 /* Load shift vector for this list */
142 i_shift_offset = DIM*shiftidx[iidx];
144 /* Load limits for loop over neighbors */
145 j_index_start = jindex[iidx];
146 j_index_end = jindex[iidx+1];
148 /* Get outer coordinate index */
150 i_coord_offset = DIM*inr;
152 /* Load i particle coords and add shift vector */
153 gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
155 fix0 = _mm256_setzero_pd();
156 fiy0 = _mm256_setzero_pd();
157 fiz0 = _mm256_setzero_pd();
159 /* Load parameters for i particles */
160 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
162 /* Reset potential sums */
163 velecsum = _mm256_setzero_pd();
165 /* Start inner kernel loop */
166 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
169 /* Get j neighbor index, and coordinate index */
174 j_coord_offsetA = DIM*jnrA;
175 j_coord_offsetB = DIM*jnrB;
176 j_coord_offsetC = DIM*jnrC;
177 j_coord_offsetD = DIM*jnrD;
179 /* load j atom coordinates */
180 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
181 x+j_coord_offsetC,x+j_coord_offsetD,
184 /* Calculate displacement vector */
185 dx00 = _mm256_sub_pd(ix0,jx0);
186 dy00 = _mm256_sub_pd(iy0,jy0);
187 dz00 = _mm256_sub_pd(iz0,jz0);
189 /* Calculate squared distance and things based on it */
190 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
192 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
194 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
196 /* Load parameters for j particles */
197 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
198 charge+jnrC+0,charge+jnrD+0);
200 /**************************
201 * CALCULATE INTERACTIONS *
202 **************************/
204 r00 = _mm256_mul_pd(rsq00,rinv00);
206 /* Compute parameters for interactions between i and j atoms */
207 qq00 = _mm256_mul_pd(iq0,jq0);
209 /* EWALD ELECTROSTATICS */
211 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
212 ewrt = _mm256_mul_pd(r00,ewtabscale);
213 ewitab = _mm256_cvttpd_epi32(ewrt);
214 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
215 ewitab = _mm_slli_epi32(ewitab,2);
216 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
217 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
218 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
219 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
220 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
221 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
222 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
223 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(rinv00,velec));
224 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
226 /* Update potential sum for this i atom from the interaction with this j atom. */
227 velecsum = _mm256_add_pd(velecsum,velec);
231 /* Calculate temporary vectorial force */
232 tx = _mm256_mul_pd(fscal,dx00);
233 ty = _mm256_mul_pd(fscal,dy00);
234 tz = _mm256_mul_pd(fscal,dz00);
236 /* Update vectorial force */
237 fix0 = _mm256_add_pd(fix0,tx);
238 fiy0 = _mm256_add_pd(fiy0,ty);
239 fiz0 = _mm256_add_pd(fiz0,tz);
241 fjptrA = f+j_coord_offsetA;
242 fjptrB = f+j_coord_offsetB;
243 fjptrC = f+j_coord_offsetC;
244 fjptrD = f+j_coord_offsetD;
245 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
247 /* Inner loop uses 41 flops */
253 /* Get j neighbor index, and coordinate index */
254 jnrlistA = jjnr[jidx];
255 jnrlistB = jjnr[jidx+1];
256 jnrlistC = jjnr[jidx+2];
257 jnrlistD = jjnr[jidx+3];
258 /* Sign of each element will be negative for non-real atoms.
259 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
260 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
262 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
264 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
265 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
266 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
268 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
269 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
270 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
271 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
272 j_coord_offsetA = DIM*jnrA;
273 j_coord_offsetB = DIM*jnrB;
274 j_coord_offsetC = DIM*jnrC;
275 j_coord_offsetD = DIM*jnrD;
277 /* load j atom coordinates */
278 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
279 x+j_coord_offsetC,x+j_coord_offsetD,
282 /* Calculate displacement vector */
283 dx00 = _mm256_sub_pd(ix0,jx0);
284 dy00 = _mm256_sub_pd(iy0,jy0);
285 dz00 = _mm256_sub_pd(iz0,jz0);
287 /* Calculate squared distance and things based on it */
288 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
290 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
292 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
294 /* Load parameters for j particles */
295 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
296 charge+jnrC+0,charge+jnrD+0);
298 /**************************
299 * CALCULATE INTERACTIONS *
300 **************************/
302 r00 = _mm256_mul_pd(rsq00,rinv00);
303 r00 = _mm256_andnot_pd(dummy_mask,r00);
305 /* Compute parameters for interactions between i and j atoms */
306 qq00 = _mm256_mul_pd(iq0,jq0);
308 /* EWALD ELECTROSTATICS */
310 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
311 ewrt = _mm256_mul_pd(r00,ewtabscale);
312 ewitab = _mm256_cvttpd_epi32(ewrt);
313 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
314 ewitab = _mm_slli_epi32(ewitab,2);
315 ewtabF = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
316 ewtabD = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
317 ewtabV = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
318 ewtabFn = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
319 GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
320 felec = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
321 velec = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
322 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(rinv00,velec));
323 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
325 /* Update potential sum for this i atom from the interaction with this j atom. */
326 velec = _mm256_andnot_pd(dummy_mask,velec);
327 velecsum = _mm256_add_pd(velecsum,velec);
331 fscal = _mm256_andnot_pd(dummy_mask,fscal);
333 /* Calculate temporary vectorial force */
334 tx = _mm256_mul_pd(fscal,dx00);
335 ty = _mm256_mul_pd(fscal,dy00);
336 tz = _mm256_mul_pd(fscal,dz00);
338 /* Update vectorial force */
339 fix0 = _mm256_add_pd(fix0,tx);
340 fiy0 = _mm256_add_pd(fiy0,ty);
341 fiz0 = _mm256_add_pd(fiz0,tz);
343 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
344 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
345 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
346 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
347 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
349 /* Inner loop uses 42 flops */
352 /* End of innermost loop */
354 gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
355 f+i_coord_offset,fshift+i_shift_offset);
358 /* Update potential energies */
359 gmx_mm256_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
361 /* Increment number of inner iterations */
362 inneriter += j_index_end - j_index_start;
364 /* Outer loop uses 8 flops */
367 /* Increment number of outer iterations */
370 /* Update outer/inner flops */
372 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*42);
375 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_256_double
376 * Electrostatics interaction: Ewald
377 * VdW interaction: None
378 * Geometry: Particle-Particle
379 * Calculate force/pot: Force
382 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_256_double
383 (t_nblist * gmx_restrict nlist,
384 rvec * gmx_restrict xx,
385 rvec * gmx_restrict ff,
386 t_forcerec * gmx_restrict fr,
387 t_mdatoms * gmx_restrict mdatoms,
388 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
389 t_nrnb * gmx_restrict nrnb)
391 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
392 * just 0 for non-waters.
393 * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
394 * jnr indices corresponding to data put in the four positions in the SIMD register.
396 int i_shift_offset,i_coord_offset,outeriter,inneriter;
397 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
398 int jnrA,jnrB,jnrC,jnrD;
399 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
400 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
401 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
402 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
404 real *shiftvec,*fshift,*x,*f;
405 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
407 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
408 real * vdwioffsetptr0;
409 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
410 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
411 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
412 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
413 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
416 __m256d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
417 __m256d beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
419 __m256d dummy_mask,cutoff_mask;
420 __m128 tmpmask0,tmpmask1;
421 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
422 __m256d one = _mm256_set1_pd(1.0);
423 __m256d two = _mm256_set1_pd(2.0);
429 jindex = nlist->jindex;
431 shiftidx = nlist->shift;
433 shiftvec = fr->shift_vec[0];
434 fshift = fr->fshift[0];
435 facel = _mm256_set1_pd(fr->epsfac);
436 charge = mdatoms->chargeA;
438 sh_ewald = _mm256_set1_pd(fr->ic->sh_ewald);
439 beta = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
440 beta2 = _mm256_mul_pd(beta,beta);
441 beta3 = _mm256_mul_pd(beta,beta2);
443 ewtab = fr->ic->tabq_coul_F;
444 ewtabscale = _mm256_set1_pd(fr->ic->tabq_scale);
445 ewtabhalfspace = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
447 /* Avoid stupid compiler warnings */
448 jnrA = jnrB = jnrC = jnrD = 0;
457 for(iidx=0;iidx<4*DIM;iidx++)
462 /* Start outer loop over neighborlists */
463 for(iidx=0; iidx<nri; iidx++)
465 /* Load shift vector for this list */
466 i_shift_offset = DIM*shiftidx[iidx];
468 /* Load limits for loop over neighbors */
469 j_index_start = jindex[iidx];
470 j_index_end = jindex[iidx+1];
472 /* Get outer coordinate index */
474 i_coord_offset = DIM*inr;
476 /* Load i particle coords and add shift vector */
477 gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
479 fix0 = _mm256_setzero_pd();
480 fiy0 = _mm256_setzero_pd();
481 fiz0 = _mm256_setzero_pd();
483 /* Load parameters for i particles */
484 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
486 /* Start inner kernel loop */
487 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
490 /* Get j neighbor index, and coordinate index */
495 j_coord_offsetA = DIM*jnrA;
496 j_coord_offsetB = DIM*jnrB;
497 j_coord_offsetC = DIM*jnrC;
498 j_coord_offsetD = DIM*jnrD;
500 /* load j atom coordinates */
501 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
502 x+j_coord_offsetC,x+j_coord_offsetD,
505 /* Calculate displacement vector */
506 dx00 = _mm256_sub_pd(ix0,jx0);
507 dy00 = _mm256_sub_pd(iy0,jy0);
508 dz00 = _mm256_sub_pd(iz0,jz0);
510 /* Calculate squared distance and things based on it */
511 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
513 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
515 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
517 /* Load parameters for j particles */
518 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
519 charge+jnrC+0,charge+jnrD+0);
521 /**************************
522 * CALCULATE INTERACTIONS *
523 **************************/
525 r00 = _mm256_mul_pd(rsq00,rinv00);
527 /* Compute parameters for interactions between i and j atoms */
528 qq00 = _mm256_mul_pd(iq0,jq0);
530 /* EWALD ELECTROSTATICS */
532 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
533 ewrt = _mm256_mul_pd(r00,ewtabscale);
534 ewitab = _mm256_cvttpd_epi32(ewrt);
535 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
536 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
537 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
539 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
540 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
544 /* Calculate temporary vectorial force */
545 tx = _mm256_mul_pd(fscal,dx00);
546 ty = _mm256_mul_pd(fscal,dy00);
547 tz = _mm256_mul_pd(fscal,dz00);
549 /* Update vectorial force */
550 fix0 = _mm256_add_pd(fix0,tx);
551 fiy0 = _mm256_add_pd(fiy0,ty);
552 fiz0 = _mm256_add_pd(fiz0,tz);
554 fjptrA = f+j_coord_offsetA;
555 fjptrB = f+j_coord_offsetB;
556 fjptrC = f+j_coord_offsetC;
557 fjptrD = f+j_coord_offsetD;
558 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
560 /* Inner loop uses 36 flops */
566 /* Get j neighbor index, and coordinate index */
567 jnrlistA = jjnr[jidx];
568 jnrlistB = jjnr[jidx+1];
569 jnrlistC = jjnr[jidx+2];
570 jnrlistD = jjnr[jidx+3];
571 /* Sign of each element will be negative for non-real atoms.
572 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
573 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
575 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
577 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
578 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
579 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
581 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
582 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
583 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
584 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
585 j_coord_offsetA = DIM*jnrA;
586 j_coord_offsetB = DIM*jnrB;
587 j_coord_offsetC = DIM*jnrC;
588 j_coord_offsetD = DIM*jnrD;
590 /* load j atom coordinates */
591 gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
592 x+j_coord_offsetC,x+j_coord_offsetD,
595 /* Calculate displacement vector */
596 dx00 = _mm256_sub_pd(ix0,jx0);
597 dy00 = _mm256_sub_pd(iy0,jy0);
598 dz00 = _mm256_sub_pd(iz0,jz0);
600 /* Calculate squared distance and things based on it */
601 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
603 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
605 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
607 /* Load parameters for j particles */
608 jq0 = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
609 charge+jnrC+0,charge+jnrD+0);
611 /**************************
612 * CALCULATE INTERACTIONS *
613 **************************/
615 r00 = _mm256_mul_pd(rsq00,rinv00);
616 r00 = _mm256_andnot_pd(dummy_mask,r00);
618 /* Compute parameters for interactions between i and j atoms */
619 qq00 = _mm256_mul_pd(iq0,jq0);
621 /* EWALD ELECTROSTATICS */
623 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
624 ewrt = _mm256_mul_pd(r00,ewtabscale);
625 ewitab = _mm256_cvttpd_epi32(ewrt);
626 eweps = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
627 gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
628 ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
630 felec = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
631 felec = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
635 fscal = _mm256_andnot_pd(dummy_mask,fscal);
637 /* Calculate temporary vectorial force */
638 tx = _mm256_mul_pd(fscal,dx00);
639 ty = _mm256_mul_pd(fscal,dy00);
640 tz = _mm256_mul_pd(fscal,dz00);
642 /* Update vectorial force */
643 fix0 = _mm256_add_pd(fix0,tx);
644 fiy0 = _mm256_add_pd(fiy0,ty);
645 fiz0 = _mm256_add_pd(fiz0,tz);
647 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
648 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
649 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
650 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
651 gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
653 /* Inner loop uses 37 flops */
656 /* End of innermost loop */
658 gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
659 f+i_coord_offset,fshift+i_shift_offset);
661 /* Increment number of inner iterations */
662 inneriter += j_index_end - j_index_start;
664 /* Outer loop uses 7 flops */
667 /* Increment number of outer iterations */
670 /* Update outer/inner flops */
672 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*37);