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_128_fma_single 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_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_VF_avx_128_fma_single
54 * Electrostatics interaction: Ewald
55 * VdW interaction: LennardJones
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_VF_avx_128_fma_single
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_128, 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 j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
88 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
93 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
96 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
97 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
99 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
100 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
102 __m128 dummy_mask,cutoff_mask;
103 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
104 __m128 one = _mm_set1_ps(1.0);
105 __m128 two = _mm_set1_ps(2.0);
111 jindex = nlist->jindex;
113 shiftidx = nlist->shift;
115 shiftvec = fr->shift_vec[0];
116 fshift = fr->fshift[0];
117 facel = _mm_set1_ps(fr->epsfac);
118 charge = mdatoms->chargeA;
119 nvdwtype = fr->ntype;
121 vdwtype = mdatoms->typeA;
123 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
124 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
125 beta2 = _mm_mul_ps(beta,beta);
126 beta3 = _mm_mul_ps(beta,beta2);
127 ewtab = fr->ic->tabq_coul_FDV0;
128 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
129 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
131 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
132 rcutoff_scalar = fr->rcoulomb;
133 rcutoff = _mm_set1_ps(rcutoff_scalar);
134 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
136 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
137 rvdw = _mm_set1_ps(fr->rvdw);
139 /* Avoid stupid compiler warnings */
140 jnrA = jnrB = jnrC = jnrD = 0;
149 for(iidx=0;iidx<4*DIM;iidx++)
154 /* Start outer loop over neighborlists */
155 for(iidx=0; iidx<nri; iidx++)
157 /* Load shift vector for this list */
158 i_shift_offset = DIM*shiftidx[iidx];
160 /* Load limits for loop over neighbors */
161 j_index_start = jindex[iidx];
162 j_index_end = jindex[iidx+1];
164 /* Get outer coordinate index */
166 i_coord_offset = DIM*inr;
168 /* Load i particle coords and add shift vector */
169 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
171 fix0 = _mm_setzero_ps();
172 fiy0 = _mm_setzero_ps();
173 fiz0 = _mm_setzero_ps();
175 /* Load parameters for i particles */
176 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
177 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
179 /* Reset potential sums */
180 velecsum = _mm_setzero_ps();
181 vvdwsum = _mm_setzero_ps();
183 /* Start inner kernel loop */
184 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
187 /* Get j neighbor index, and coordinate index */
192 j_coord_offsetA = DIM*jnrA;
193 j_coord_offsetB = DIM*jnrB;
194 j_coord_offsetC = DIM*jnrC;
195 j_coord_offsetD = DIM*jnrD;
197 /* load j atom coordinates */
198 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
199 x+j_coord_offsetC,x+j_coord_offsetD,
202 /* Calculate displacement vector */
203 dx00 = _mm_sub_ps(ix0,jx0);
204 dy00 = _mm_sub_ps(iy0,jy0);
205 dz00 = _mm_sub_ps(iz0,jz0);
207 /* Calculate squared distance and things based on it */
208 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
210 rinv00 = gmx_mm_invsqrt_ps(rsq00);
212 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
214 /* Load parameters for j particles */
215 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
216 charge+jnrC+0,charge+jnrD+0);
217 vdwjidx0A = 2*vdwtype[jnrA+0];
218 vdwjidx0B = 2*vdwtype[jnrB+0];
219 vdwjidx0C = 2*vdwtype[jnrC+0];
220 vdwjidx0D = 2*vdwtype[jnrD+0];
222 /**************************
223 * CALCULATE INTERACTIONS *
224 **************************/
226 if (gmx_mm_any_lt(rsq00,rcutoff2))
229 r00 = _mm_mul_ps(rsq00,rinv00);
231 /* Compute parameters for interactions between i and j atoms */
232 qq00 = _mm_mul_ps(iq0,jq0);
233 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
234 vdwparam+vdwioffset0+vdwjidx0B,
235 vdwparam+vdwioffset0+vdwjidx0C,
236 vdwparam+vdwioffset0+vdwjidx0D,
239 /* EWALD ELECTROSTATICS */
241 /* Analytical PME correction */
242 zeta2 = _mm_mul_ps(beta2,rsq00);
243 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
244 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
245 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
246 felec = _mm_mul_ps(qq00,felec);
247 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
248 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
249 velec = _mm_mul_ps(qq00,velec);
251 /* LENNARD-JONES DISPERSION/REPULSION */
253 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
254 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
255 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
256 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
257 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
258 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
260 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
262 /* Update potential sum for this i atom from the interaction with this j atom. */
263 velec = _mm_and_ps(velec,cutoff_mask);
264 velecsum = _mm_add_ps(velecsum,velec);
265 vvdw = _mm_and_ps(vvdw,cutoff_mask);
266 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
268 fscal = _mm_add_ps(felec,fvdw);
270 fscal = _mm_and_ps(fscal,cutoff_mask);
272 /* Update vectorial force */
273 fix0 = _mm_macc_ps(dx00,fscal,fix0);
274 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
275 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
277 fjptrA = f+j_coord_offsetA;
278 fjptrB = f+j_coord_offsetB;
279 fjptrC = f+j_coord_offsetC;
280 fjptrD = f+j_coord_offsetD;
281 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
282 _mm_mul_ps(dx00,fscal),
283 _mm_mul_ps(dy00,fscal),
284 _mm_mul_ps(dz00,fscal));
288 /* Inner loop uses 51 flops */
294 /* Get j neighbor index, and coordinate index */
295 jnrlistA = jjnr[jidx];
296 jnrlistB = jjnr[jidx+1];
297 jnrlistC = jjnr[jidx+2];
298 jnrlistD = jjnr[jidx+3];
299 /* Sign of each element will be negative for non-real atoms.
300 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
301 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
303 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
304 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
305 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
306 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
307 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
308 j_coord_offsetA = DIM*jnrA;
309 j_coord_offsetB = DIM*jnrB;
310 j_coord_offsetC = DIM*jnrC;
311 j_coord_offsetD = DIM*jnrD;
313 /* load j atom coordinates */
314 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
315 x+j_coord_offsetC,x+j_coord_offsetD,
318 /* Calculate displacement vector */
319 dx00 = _mm_sub_ps(ix0,jx0);
320 dy00 = _mm_sub_ps(iy0,jy0);
321 dz00 = _mm_sub_ps(iz0,jz0);
323 /* Calculate squared distance and things based on it */
324 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
326 rinv00 = gmx_mm_invsqrt_ps(rsq00);
328 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
330 /* Load parameters for j particles */
331 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
332 charge+jnrC+0,charge+jnrD+0);
333 vdwjidx0A = 2*vdwtype[jnrA+0];
334 vdwjidx0B = 2*vdwtype[jnrB+0];
335 vdwjidx0C = 2*vdwtype[jnrC+0];
336 vdwjidx0D = 2*vdwtype[jnrD+0];
338 /**************************
339 * CALCULATE INTERACTIONS *
340 **************************/
342 if (gmx_mm_any_lt(rsq00,rcutoff2))
345 r00 = _mm_mul_ps(rsq00,rinv00);
346 r00 = _mm_andnot_ps(dummy_mask,r00);
348 /* Compute parameters for interactions between i and j atoms */
349 qq00 = _mm_mul_ps(iq0,jq0);
350 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
351 vdwparam+vdwioffset0+vdwjidx0B,
352 vdwparam+vdwioffset0+vdwjidx0C,
353 vdwparam+vdwioffset0+vdwjidx0D,
356 /* EWALD ELECTROSTATICS */
358 /* Analytical PME correction */
359 zeta2 = _mm_mul_ps(beta2,rsq00);
360 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
361 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
362 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
363 felec = _mm_mul_ps(qq00,felec);
364 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
365 velec = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
366 velec = _mm_mul_ps(qq00,velec);
368 /* LENNARD-JONES DISPERSION/REPULSION */
370 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
371 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
372 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
373 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
374 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
375 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
377 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
379 /* Update potential sum for this i atom from the interaction with this j atom. */
380 velec = _mm_and_ps(velec,cutoff_mask);
381 velec = _mm_andnot_ps(dummy_mask,velec);
382 velecsum = _mm_add_ps(velecsum,velec);
383 vvdw = _mm_and_ps(vvdw,cutoff_mask);
384 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
385 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
387 fscal = _mm_add_ps(felec,fvdw);
389 fscal = _mm_and_ps(fscal,cutoff_mask);
391 fscal = _mm_andnot_ps(dummy_mask,fscal);
393 /* Update vectorial force */
394 fix0 = _mm_macc_ps(dx00,fscal,fix0);
395 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
396 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
398 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
399 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
400 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
401 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
402 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
403 _mm_mul_ps(dx00,fscal),
404 _mm_mul_ps(dy00,fscal),
405 _mm_mul_ps(dz00,fscal));
409 /* Inner loop uses 52 flops */
412 /* End of innermost loop */
414 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
415 f+i_coord_offset,fshift+i_shift_offset);
418 /* Update potential energies */
419 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
420 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
422 /* Increment number of inner iterations */
423 inneriter += j_index_end - j_index_start;
425 /* Outer loop uses 9 flops */
428 /* Increment number of outer iterations */
431 /* Update outer/inner flops */
433 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*52);
436 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_single
437 * Electrostatics interaction: Ewald
438 * VdW interaction: LennardJones
439 * Geometry: Particle-Particle
440 * Calculate force/pot: Force
443 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_avx_128_fma_single
444 (t_nblist * gmx_restrict nlist,
445 rvec * gmx_restrict xx,
446 rvec * gmx_restrict ff,
447 t_forcerec * gmx_restrict fr,
448 t_mdatoms * gmx_restrict mdatoms,
449 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
450 t_nrnb * gmx_restrict nrnb)
452 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
453 * just 0 for non-waters.
454 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
455 * jnr indices corresponding to data put in the four positions in the SIMD register.
457 int i_shift_offset,i_coord_offset,outeriter,inneriter;
458 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
459 int jnrA,jnrB,jnrC,jnrD;
460 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
461 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
462 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
464 real *shiftvec,*fshift,*x,*f;
465 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
467 __m128 fscal,rcutoff,rcutoff2,jidxall;
469 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
470 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
471 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
472 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
473 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
476 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
479 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
480 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
482 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
483 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
485 __m128 dummy_mask,cutoff_mask;
486 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
487 __m128 one = _mm_set1_ps(1.0);
488 __m128 two = _mm_set1_ps(2.0);
494 jindex = nlist->jindex;
496 shiftidx = nlist->shift;
498 shiftvec = fr->shift_vec[0];
499 fshift = fr->fshift[0];
500 facel = _mm_set1_ps(fr->epsfac);
501 charge = mdatoms->chargeA;
502 nvdwtype = fr->ntype;
504 vdwtype = mdatoms->typeA;
506 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
507 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
508 beta2 = _mm_mul_ps(beta,beta);
509 beta3 = _mm_mul_ps(beta,beta2);
510 ewtab = fr->ic->tabq_coul_F;
511 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
512 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
514 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
515 rcutoff_scalar = fr->rcoulomb;
516 rcutoff = _mm_set1_ps(rcutoff_scalar);
517 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
519 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
520 rvdw = _mm_set1_ps(fr->rvdw);
522 /* Avoid stupid compiler warnings */
523 jnrA = jnrB = jnrC = jnrD = 0;
532 for(iidx=0;iidx<4*DIM;iidx++)
537 /* Start outer loop over neighborlists */
538 for(iidx=0; iidx<nri; iidx++)
540 /* Load shift vector for this list */
541 i_shift_offset = DIM*shiftidx[iidx];
543 /* Load limits for loop over neighbors */
544 j_index_start = jindex[iidx];
545 j_index_end = jindex[iidx+1];
547 /* Get outer coordinate index */
549 i_coord_offset = DIM*inr;
551 /* Load i particle coords and add shift vector */
552 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
554 fix0 = _mm_setzero_ps();
555 fiy0 = _mm_setzero_ps();
556 fiz0 = _mm_setzero_ps();
558 /* Load parameters for i particles */
559 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
560 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
562 /* Start inner kernel loop */
563 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
566 /* Get j neighbor index, and coordinate index */
571 j_coord_offsetA = DIM*jnrA;
572 j_coord_offsetB = DIM*jnrB;
573 j_coord_offsetC = DIM*jnrC;
574 j_coord_offsetD = DIM*jnrD;
576 /* load j atom coordinates */
577 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
578 x+j_coord_offsetC,x+j_coord_offsetD,
581 /* Calculate displacement vector */
582 dx00 = _mm_sub_ps(ix0,jx0);
583 dy00 = _mm_sub_ps(iy0,jy0);
584 dz00 = _mm_sub_ps(iz0,jz0);
586 /* Calculate squared distance and things based on it */
587 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
589 rinv00 = gmx_mm_invsqrt_ps(rsq00);
591 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
593 /* Load parameters for j particles */
594 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
595 charge+jnrC+0,charge+jnrD+0);
596 vdwjidx0A = 2*vdwtype[jnrA+0];
597 vdwjidx0B = 2*vdwtype[jnrB+0];
598 vdwjidx0C = 2*vdwtype[jnrC+0];
599 vdwjidx0D = 2*vdwtype[jnrD+0];
601 /**************************
602 * CALCULATE INTERACTIONS *
603 **************************/
605 if (gmx_mm_any_lt(rsq00,rcutoff2))
608 r00 = _mm_mul_ps(rsq00,rinv00);
610 /* Compute parameters for interactions between i and j atoms */
611 qq00 = _mm_mul_ps(iq0,jq0);
612 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
613 vdwparam+vdwioffset0+vdwjidx0B,
614 vdwparam+vdwioffset0+vdwjidx0C,
615 vdwparam+vdwioffset0+vdwjidx0D,
618 /* EWALD ELECTROSTATICS */
620 /* Analytical PME correction */
621 zeta2 = _mm_mul_ps(beta2,rsq00);
622 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
623 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
624 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
625 felec = _mm_mul_ps(qq00,felec);
627 /* LENNARD-JONES DISPERSION/REPULSION */
629 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
630 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
632 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
634 fscal = _mm_add_ps(felec,fvdw);
636 fscal = _mm_and_ps(fscal,cutoff_mask);
638 /* Update vectorial force */
639 fix0 = _mm_macc_ps(dx00,fscal,fix0);
640 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
641 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
643 fjptrA = f+j_coord_offsetA;
644 fjptrB = f+j_coord_offsetB;
645 fjptrC = f+j_coord_offsetC;
646 fjptrD = f+j_coord_offsetD;
647 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
648 _mm_mul_ps(dx00,fscal),
649 _mm_mul_ps(dy00,fscal),
650 _mm_mul_ps(dz00,fscal));
654 /* Inner loop uses 38 flops */
660 /* Get j neighbor index, and coordinate index */
661 jnrlistA = jjnr[jidx];
662 jnrlistB = jjnr[jidx+1];
663 jnrlistC = jjnr[jidx+2];
664 jnrlistD = jjnr[jidx+3];
665 /* Sign of each element will be negative for non-real atoms.
666 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
667 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
669 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
670 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
671 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
672 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
673 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
674 j_coord_offsetA = DIM*jnrA;
675 j_coord_offsetB = DIM*jnrB;
676 j_coord_offsetC = DIM*jnrC;
677 j_coord_offsetD = DIM*jnrD;
679 /* load j atom coordinates */
680 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
681 x+j_coord_offsetC,x+j_coord_offsetD,
684 /* Calculate displacement vector */
685 dx00 = _mm_sub_ps(ix0,jx0);
686 dy00 = _mm_sub_ps(iy0,jy0);
687 dz00 = _mm_sub_ps(iz0,jz0);
689 /* Calculate squared distance and things based on it */
690 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
692 rinv00 = gmx_mm_invsqrt_ps(rsq00);
694 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
696 /* Load parameters for j particles */
697 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
698 charge+jnrC+0,charge+jnrD+0);
699 vdwjidx0A = 2*vdwtype[jnrA+0];
700 vdwjidx0B = 2*vdwtype[jnrB+0];
701 vdwjidx0C = 2*vdwtype[jnrC+0];
702 vdwjidx0D = 2*vdwtype[jnrD+0];
704 /**************************
705 * CALCULATE INTERACTIONS *
706 **************************/
708 if (gmx_mm_any_lt(rsq00,rcutoff2))
711 r00 = _mm_mul_ps(rsq00,rinv00);
712 r00 = _mm_andnot_ps(dummy_mask,r00);
714 /* Compute parameters for interactions between i and j atoms */
715 qq00 = _mm_mul_ps(iq0,jq0);
716 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
717 vdwparam+vdwioffset0+vdwjidx0B,
718 vdwparam+vdwioffset0+vdwjidx0C,
719 vdwparam+vdwioffset0+vdwjidx0D,
722 /* EWALD ELECTROSTATICS */
724 /* Analytical PME correction */
725 zeta2 = _mm_mul_ps(beta2,rsq00);
726 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
727 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
728 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
729 felec = _mm_mul_ps(qq00,felec);
731 /* LENNARD-JONES DISPERSION/REPULSION */
733 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
734 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
736 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
738 fscal = _mm_add_ps(felec,fvdw);
740 fscal = _mm_and_ps(fscal,cutoff_mask);
742 fscal = _mm_andnot_ps(dummy_mask,fscal);
744 /* Update vectorial force */
745 fix0 = _mm_macc_ps(dx00,fscal,fix0);
746 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
747 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
749 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
750 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
751 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
752 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
753 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
754 _mm_mul_ps(dx00,fscal),
755 _mm_mul_ps(dy00,fscal),
756 _mm_mul_ps(dz00,fscal));
760 /* Inner loop uses 39 flops */
763 /* End of innermost loop */
765 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
766 f+i_coord_offset,fshift+i_shift_offset);
768 /* Increment number of inner iterations */
769 inneriter += j_index_end - j_index_start;
771 /* Outer loop uses 7 flops */
774 /* Increment number of outer iterations */
777 /* Update outer/inner flops */
779 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*39);