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_128_fma_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEwSw_VdwNone_GeomP1P1_VF_avx_128_fma_single
51 * Electrostatics interaction: Ewald
52 * VdW interaction: None
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSw_VdwNone_GeomP1P1_VF_avx_128_fma_single
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_128, 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 j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
85 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
91 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
93 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
94 real rswitch_scalar,d_scalar;
95 __m128 dummy_mask,cutoff_mask;
96 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
97 __m128 one = _mm_set1_ps(1.0);
98 __m128 two = _mm_set1_ps(2.0);
104 jindex = nlist->jindex;
106 shiftidx = nlist->shift;
108 shiftvec = fr->shift_vec[0];
109 fshift = fr->fshift[0];
110 facel = _mm_set1_ps(fr->ic->epsfac);
111 charge = mdatoms->chargeA;
113 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
114 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
115 beta2 = _mm_mul_ps(beta,beta);
116 beta3 = _mm_mul_ps(beta,beta2);
117 ewtab = fr->ic->tabq_coul_FDV0;
118 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
119 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
121 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
122 rcutoff_scalar = fr->ic->rcoulomb;
123 rcutoff = _mm_set1_ps(rcutoff_scalar);
124 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
126 rswitch_scalar = fr->ic->rcoulomb_switch;
127 rswitch = _mm_set1_ps(rswitch_scalar);
128 /* Setup switch parameters */
129 d_scalar = rcutoff_scalar-rswitch_scalar;
130 d = _mm_set1_ps(d_scalar);
131 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
132 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
133 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
134 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
135 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
136 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
138 /* Avoid stupid compiler warnings */
139 jnrA = jnrB = jnrC = jnrD = 0;
148 for(iidx=0;iidx<4*DIM;iidx++)
153 /* Start outer loop over neighborlists */
154 for(iidx=0; iidx<nri; iidx++)
156 /* Load shift vector for this list */
157 i_shift_offset = DIM*shiftidx[iidx];
159 /* Load limits for loop over neighbors */
160 j_index_start = jindex[iidx];
161 j_index_end = jindex[iidx+1];
163 /* Get outer coordinate index */
165 i_coord_offset = DIM*inr;
167 /* Load i particle coords and add shift vector */
168 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
170 fix0 = _mm_setzero_ps();
171 fiy0 = _mm_setzero_ps();
172 fiz0 = _mm_setzero_ps();
174 /* Load parameters for i particles */
175 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
177 /* Reset potential sums */
178 velecsum = _mm_setzero_ps();
180 /* Start inner kernel loop */
181 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
184 /* Get j neighbor index, and coordinate index */
189 j_coord_offsetA = DIM*jnrA;
190 j_coord_offsetB = DIM*jnrB;
191 j_coord_offsetC = DIM*jnrC;
192 j_coord_offsetD = DIM*jnrD;
194 /* load j atom coordinates */
195 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
196 x+j_coord_offsetC,x+j_coord_offsetD,
199 /* Calculate displacement vector */
200 dx00 = _mm_sub_ps(ix0,jx0);
201 dy00 = _mm_sub_ps(iy0,jy0);
202 dz00 = _mm_sub_ps(iz0,jz0);
204 /* Calculate squared distance and things based on it */
205 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
207 rinv00 = avx128fma_invsqrt_f(rsq00);
209 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
211 /* Load parameters for j particles */
212 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
213 charge+jnrC+0,charge+jnrD+0);
215 /**************************
216 * CALCULATE INTERACTIONS *
217 **************************/
219 if (gmx_mm_any_lt(rsq00,rcutoff2))
222 r00 = _mm_mul_ps(rsq00,rinv00);
224 /* Compute parameters for interactions between i and j atoms */
225 qq00 = _mm_mul_ps(iq0,jq0);
227 /* EWALD ELECTROSTATICS */
229 /* Analytical PME correction */
230 zeta2 = _mm_mul_ps(beta2,rsq00);
231 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
232 pmecorrF = avx128fma_pmecorrF_f(zeta2);
233 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
234 felec = _mm_mul_ps(qq00,felec);
235 pmecorrV = avx128fma_pmecorrV_f(zeta2);
236 velec = _mm_nmacc_ps(pmecorrV,beta,rinv00);
237 velec = _mm_mul_ps(qq00,velec);
239 d = _mm_sub_ps(r00,rswitch);
240 d = _mm_max_ps(d,_mm_setzero_ps());
241 d2 = _mm_mul_ps(d,d);
242 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
244 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
246 /* Evaluate switch function */
247 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
248 felec = _mm_msub_ps( felec,sw , _mm_mul_ps(rinv00,_mm_mul_ps(velec,dsw)) );
249 velec = _mm_mul_ps(velec,sw);
250 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
252 /* Update potential sum for this i atom from the interaction with this j atom. */
253 velec = _mm_and_ps(velec,cutoff_mask);
254 velecsum = _mm_add_ps(velecsum,velec);
258 fscal = _mm_and_ps(fscal,cutoff_mask);
260 /* Update vectorial force */
261 fix0 = _mm_macc_ps(dx00,fscal,fix0);
262 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
263 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
265 fjptrA = f+j_coord_offsetA;
266 fjptrB = f+j_coord_offsetB;
267 fjptrC = f+j_coord_offsetC;
268 fjptrD = f+j_coord_offsetD;
269 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
270 _mm_mul_ps(dx00,fscal),
271 _mm_mul_ps(dy00,fscal),
272 _mm_mul_ps(dz00,fscal));
276 /* Inner loop uses 53 flops */
282 /* Get j neighbor index, and coordinate index */
283 jnrlistA = jjnr[jidx];
284 jnrlistB = jjnr[jidx+1];
285 jnrlistC = jjnr[jidx+2];
286 jnrlistD = jjnr[jidx+3];
287 /* Sign of each element will be negative for non-real atoms.
288 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
289 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
291 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
292 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
293 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
294 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
295 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
296 j_coord_offsetA = DIM*jnrA;
297 j_coord_offsetB = DIM*jnrB;
298 j_coord_offsetC = DIM*jnrC;
299 j_coord_offsetD = DIM*jnrD;
301 /* load j atom coordinates */
302 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
303 x+j_coord_offsetC,x+j_coord_offsetD,
306 /* Calculate displacement vector */
307 dx00 = _mm_sub_ps(ix0,jx0);
308 dy00 = _mm_sub_ps(iy0,jy0);
309 dz00 = _mm_sub_ps(iz0,jz0);
311 /* Calculate squared distance and things based on it */
312 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
314 rinv00 = avx128fma_invsqrt_f(rsq00);
316 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
318 /* Load parameters for j particles */
319 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
320 charge+jnrC+0,charge+jnrD+0);
322 /**************************
323 * CALCULATE INTERACTIONS *
324 **************************/
326 if (gmx_mm_any_lt(rsq00,rcutoff2))
329 r00 = _mm_mul_ps(rsq00,rinv00);
330 r00 = _mm_andnot_ps(dummy_mask,r00);
332 /* Compute parameters for interactions between i and j atoms */
333 qq00 = _mm_mul_ps(iq0,jq0);
335 /* EWALD ELECTROSTATICS */
337 /* Analytical PME correction */
338 zeta2 = _mm_mul_ps(beta2,rsq00);
339 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
340 pmecorrF = avx128fma_pmecorrF_f(zeta2);
341 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
342 felec = _mm_mul_ps(qq00,felec);
343 pmecorrV = avx128fma_pmecorrV_f(zeta2);
344 velec = _mm_nmacc_ps(pmecorrV,beta,rinv00);
345 velec = _mm_mul_ps(qq00,velec);
347 d = _mm_sub_ps(r00,rswitch);
348 d = _mm_max_ps(d,_mm_setzero_ps());
349 d2 = _mm_mul_ps(d,d);
350 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
352 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
354 /* Evaluate switch function */
355 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
356 felec = _mm_msub_ps( felec,sw , _mm_mul_ps(rinv00,_mm_mul_ps(velec,dsw)) );
357 velec = _mm_mul_ps(velec,sw);
358 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
360 /* Update potential sum for this i atom from the interaction with this j atom. */
361 velec = _mm_and_ps(velec,cutoff_mask);
362 velec = _mm_andnot_ps(dummy_mask,velec);
363 velecsum = _mm_add_ps(velecsum,velec);
367 fscal = _mm_and_ps(fscal,cutoff_mask);
369 fscal = _mm_andnot_ps(dummy_mask,fscal);
371 /* Update vectorial force */
372 fix0 = _mm_macc_ps(dx00,fscal,fix0);
373 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
374 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
376 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
377 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
378 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
379 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
380 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
381 _mm_mul_ps(dx00,fscal),
382 _mm_mul_ps(dy00,fscal),
383 _mm_mul_ps(dz00,fscal));
387 /* Inner loop uses 54 flops */
390 /* End of innermost loop */
392 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
393 f+i_coord_offset,fshift+i_shift_offset);
396 /* Update potential energies */
397 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
399 /* Increment number of inner iterations */
400 inneriter += j_index_end - j_index_start;
402 /* Outer loop uses 8 flops */
405 /* Increment number of outer iterations */
408 /* Update outer/inner flops */
410 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*54);
413 * Gromacs nonbonded kernel: nb_kernel_ElecEwSw_VdwNone_GeomP1P1_F_avx_128_fma_single
414 * Electrostatics interaction: Ewald
415 * VdW interaction: None
416 * Geometry: Particle-Particle
417 * Calculate force/pot: Force
420 nb_kernel_ElecEwSw_VdwNone_GeomP1P1_F_avx_128_fma_single
421 (t_nblist * gmx_restrict nlist,
422 rvec * gmx_restrict xx,
423 rvec * gmx_restrict ff,
424 struct t_forcerec * gmx_restrict fr,
425 t_mdatoms * gmx_restrict mdatoms,
426 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
427 t_nrnb * gmx_restrict nrnb)
429 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
430 * just 0 for non-waters.
431 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
432 * jnr indices corresponding to data put in the four positions in the SIMD register.
434 int i_shift_offset,i_coord_offset,outeriter,inneriter;
435 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
436 int jnrA,jnrB,jnrC,jnrD;
437 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
438 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
439 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
441 real *shiftvec,*fshift,*x,*f;
442 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
444 __m128 fscal,rcutoff,rcutoff2,jidxall;
446 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
447 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
448 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
449 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
450 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
453 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
454 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
456 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
457 real rswitch_scalar,d_scalar;
458 __m128 dummy_mask,cutoff_mask;
459 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
460 __m128 one = _mm_set1_ps(1.0);
461 __m128 two = _mm_set1_ps(2.0);
467 jindex = nlist->jindex;
469 shiftidx = nlist->shift;
471 shiftvec = fr->shift_vec[0];
472 fshift = fr->fshift[0];
473 facel = _mm_set1_ps(fr->ic->epsfac);
474 charge = mdatoms->chargeA;
476 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
477 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
478 beta2 = _mm_mul_ps(beta,beta);
479 beta3 = _mm_mul_ps(beta,beta2);
480 ewtab = fr->ic->tabq_coul_FDV0;
481 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
482 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
484 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
485 rcutoff_scalar = fr->ic->rcoulomb;
486 rcutoff = _mm_set1_ps(rcutoff_scalar);
487 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
489 rswitch_scalar = fr->ic->rcoulomb_switch;
490 rswitch = _mm_set1_ps(rswitch_scalar);
491 /* Setup switch parameters */
492 d_scalar = rcutoff_scalar-rswitch_scalar;
493 d = _mm_set1_ps(d_scalar);
494 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
495 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
496 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
497 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
498 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
499 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
501 /* Avoid stupid compiler warnings */
502 jnrA = jnrB = jnrC = jnrD = 0;
511 for(iidx=0;iidx<4*DIM;iidx++)
516 /* Start outer loop over neighborlists */
517 for(iidx=0; iidx<nri; iidx++)
519 /* Load shift vector for this list */
520 i_shift_offset = DIM*shiftidx[iidx];
522 /* Load limits for loop over neighbors */
523 j_index_start = jindex[iidx];
524 j_index_end = jindex[iidx+1];
526 /* Get outer coordinate index */
528 i_coord_offset = DIM*inr;
530 /* Load i particle coords and add shift vector */
531 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
533 fix0 = _mm_setzero_ps();
534 fiy0 = _mm_setzero_ps();
535 fiz0 = _mm_setzero_ps();
537 /* Load parameters for i particles */
538 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
540 /* Start inner kernel loop */
541 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
544 /* Get j neighbor index, and coordinate index */
549 j_coord_offsetA = DIM*jnrA;
550 j_coord_offsetB = DIM*jnrB;
551 j_coord_offsetC = DIM*jnrC;
552 j_coord_offsetD = DIM*jnrD;
554 /* load j atom coordinates */
555 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
556 x+j_coord_offsetC,x+j_coord_offsetD,
559 /* Calculate displacement vector */
560 dx00 = _mm_sub_ps(ix0,jx0);
561 dy00 = _mm_sub_ps(iy0,jy0);
562 dz00 = _mm_sub_ps(iz0,jz0);
564 /* Calculate squared distance and things based on it */
565 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
567 rinv00 = avx128fma_invsqrt_f(rsq00);
569 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
571 /* Load parameters for j particles */
572 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
573 charge+jnrC+0,charge+jnrD+0);
575 /**************************
576 * CALCULATE INTERACTIONS *
577 **************************/
579 if (gmx_mm_any_lt(rsq00,rcutoff2))
582 r00 = _mm_mul_ps(rsq00,rinv00);
584 /* Compute parameters for interactions between i and j atoms */
585 qq00 = _mm_mul_ps(iq0,jq0);
587 /* EWALD ELECTROSTATICS */
589 /* Analytical PME correction */
590 zeta2 = _mm_mul_ps(beta2,rsq00);
591 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
592 pmecorrF = avx128fma_pmecorrF_f(zeta2);
593 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
594 felec = _mm_mul_ps(qq00,felec);
595 pmecorrV = avx128fma_pmecorrV_f(zeta2);
596 velec = _mm_nmacc_ps(pmecorrV,beta,rinv00);
597 velec = _mm_mul_ps(qq00,velec);
599 d = _mm_sub_ps(r00,rswitch);
600 d = _mm_max_ps(d,_mm_setzero_ps());
601 d2 = _mm_mul_ps(d,d);
602 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
604 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
606 /* Evaluate switch function */
607 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
608 felec = _mm_msub_ps( felec,sw , _mm_mul_ps(rinv00,_mm_mul_ps(velec,dsw)) );
609 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
613 fscal = _mm_and_ps(fscal,cutoff_mask);
615 /* Update vectorial force */
616 fix0 = _mm_macc_ps(dx00,fscal,fix0);
617 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
618 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
620 fjptrA = f+j_coord_offsetA;
621 fjptrB = f+j_coord_offsetB;
622 fjptrC = f+j_coord_offsetC;
623 fjptrD = f+j_coord_offsetD;
624 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
625 _mm_mul_ps(dx00,fscal),
626 _mm_mul_ps(dy00,fscal),
627 _mm_mul_ps(dz00,fscal));
631 /* Inner loop uses 50 flops */
637 /* Get j neighbor index, and coordinate index */
638 jnrlistA = jjnr[jidx];
639 jnrlistB = jjnr[jidx+1];
640 jnrlistC = jjnr[jidx+2];
641 jnrlistD = jjnr[jidx+3];
642 /* Sign of each element will be negative for non-real atoms.
643 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
644 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
646 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
647 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
648 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
649 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
650 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
651 j_coord_offsetA = DIM*jnrA;
652 j_coord_offsetB = DIM*jnrB;
653 j_coord_offsetC = DIM*jnrC;
654 j_coord_offsetD = DIM*jnrD;
656 /* load j atom coordinates */
657 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
658 x+j_coord_offsetC,x+j_coord_offsetD,
661 /* Calculate displacement vector */
662 dx00 = _mm_sub_ps(ix0,jx0);
663 dy00 = _mm_sub_ps(iy0,jy0);
664 dz00 = _mm_sub_ps(iz0,jz0);
666 /* Calculate squared distance and things based on it */
667 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
669 rinv00 = avx128fma_invsqrt_f(rsq00);
671 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
673 /* Load parameters for j particles */
674 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
675 charge+jnrC+0,charge+jnrD+0);
677 /**************************
678 * CALCULATE INTERACTIONS *
679 **************************/
681 if (gmx_mm_any_lt(rsq00,rcutoff2))
684 r00 = _mm_mul_ps(rsq00,rinv00);
685 r00 = _mm_andnot_ps(dummy_mask,r00);
687 /* Compute parameters for interactions between i and j atoms */
688 qq00 = _mm_mul_ps(iq0,jq0);
690 /* EWALD ELECTROSTATICS */
692 /* Analytical PME correction */
693 zeta2 = _mm_mul_ps(beta2,rsq00);
694 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
695 pmecorrF = avx128fma_pmecorrF_f(zeta2);
696 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
697 felec = _mm_mul_ps(qq00,felec);
698 pmecorrV = avx128fma_pmecorrV_f(zeta2);
699 velec = _mm_nmacc_ps(pmecorrV,beta,rinv00);
700 velec = _mm_mul_ps(qq00,velec);
702 d = _mm_sub_ps(r00,rswitch);
703 d = _mm_max_ps(d,_mm_setzero_ps());
704 d2 = _mm_mul_ps(d,d);
705 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
707 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
709 /* Evaluate switch function */
710 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
711 felec = _mm_msub_ps( felec,sw , _mm_mul_ps(rinv00,_mm_mul_ps(velec,dsw)) );
712 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
716 fscal = _mm_and_ps(fscal,cutoff_mask);
718 fscal = _mm_andnot_ps(dummy_mask,fscal);
720 /* Update vectorial force */
721 fix0 = _mm_macc_ps(dx00,fscal,fix0);
722 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
723 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
725 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
726 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
727 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
728 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
729 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
730 _mm_mul_ps(dx00,fscal),
731 _mm_mul_ps(dy00,fscal),
732 _mm_mul_ps(dz00,fscal));
736 /* Inner loop uses 51 flops */
739 /* End of innermost loop */
741 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
742 f+i_coord_offset,fshift+i_shift_offset);
744 /* Increment number of inner iterations */
745 inneriter += j_index_end - j_index_start;
747 /* Outer loop uses 7 flops */
750 /* Increment number of outer iterations */
753 /* Update outer/inner flops */
755 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*51);