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_ElecNone_VdwLJSw_GeomP1P1_VF_avx_128_fma_single
54 * Electrostatics interaction: None
55 * VdW interaction: LennardJones
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecNone_VdwLJSw_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;
91 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
94 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
95 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
96 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
97 real rswitch_scalar,d_scalar;
98 __m128 dummy_mask,cutoff_mask;
99 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
100 __m128 one = _mm_set1_ps(1.0);
101 __m128 two = _mm_set1_ps(2.0);
107 jindex = nlist->jindex;
109 shiftidx = nlist->shift;
111 shiftvec = fr->shift_vec[0];
112 fshift = fr->fshift[0];
113 nvdwtype = fr->ntype;
115 vdwtype = mdatoms->typeA;
117 rcutoff_scalar = fr->rvdw;
118 rcutoff = _mm_set1_ps(rcutoff_scalar);
119 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
121 rswitch_scalar = fr->rvdw_switch;
122 rswitch = _mm_set1_ps(rswitch_scalar);
123 /* Setup switch parameters */
124 d_scalar = rcutoff_scalar-rswitch_scalar;
125 d = _mm_set1_ps(d_scalar);
126 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
127 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
128 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
129 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
130 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
131 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
133 /* Avoid stupid compiler warnings */
134 jnrA = jnrB = jnrC = jnrD = 0;
143 for(iidx=0;iidx<4*DIM;iidx++)
148 /* Start outer loop over neighborlists */
149 for(iidx=0; iidx<nri; iidx++)
151 /* Load shift vector for this list */
152 i_shift_offset = DIM*shiftidx[iidx];
154 /* Load limits for loop over neighbors */
155 j_index_start = jindex[iidx];
156 j_index_end = jindex[iidx+1];
158 /* Get outer coordinate index */
160 i_coord_offset = DIM*inr;
162 /* Load i particle coords and add shift vector */
163 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
165 fix0 = _mm_setzero_ps();
166 fiy0 = _mm_setzero_ps();
167 fiz0 = _mm_setzero_ps();
169 /* Load parameters for i particles */
170 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
172 /* Reset potential sums */
173 vvdwsum = _mm_setzero_ps();
175 /* Start inner kernel loop */
176 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
179 /* Get j neighbor index, and coordinate index */
184 j_coord_offsetA = DIM*jnrA;
185 j_coord_offsetB = DIM*jnrB;
186 j_coord_offsetC = DIM*jnrC;
187 j_coord_offsetD = DIM*jnrD;
189 /* load j atom coordinates */
190 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
191 x+j_coord_offsetC,x+j_coord_offsetD,
194 /* Calculate displacement vector */
195 dx00 = _mm_sub_ps(ix0,jx0);
196 dy00 = _mm_sub_ps(iy0,jy0);
197 dz00 = _mm_sub_ps(iz0,jz0);
199 /* Calculate squared distance and things based on it */
200 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
202 rinv00 = gmx_mm_invsqrt_ps(rsq00);
204 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
206 /* Load parameters for j particles */
207 vdwjidx0A = 2*vdwtype[jnrA+0];
208 vdwjidx0B = 2*vdwtype[jnrB+0];
209 vdwjidx0C = 2*vdwtype[jnrC+0];
210 vdwjidx0D = 2*vdwtype[jnrD+0];
212 /**************************
213 * CALCULATE INTERACTIONS *
214 **************************/
216 if (gmx_mm_any_lt(rsq00,rcutoff2))
219 r00 = _mm_mul_ps(rsq00,rinv00);
221 /* Compute parameters for interactions between i and j atoms */
222 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
223 vdwparam+vdwioffset0+vdwjidx0B,
224 vdwparam+vdwioffset0+vdwjidx0C,
225 vdwparam+vdwioffset0+vdwjidx0D,
228 /* LENNARD-JONES DISPERSION/REPULSION */
230 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
231 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
232 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
233 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
234 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
236 d = _mm_sub_ps(r00,rswitch);
237 d = _mm_max_ps(d,_mm_setzero_ps());
238 d2 = _mm_mul_ps(d,d);
239 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
241 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
243 /* Evaluate switch function */
244 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
245 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
246 vvdw = _mm_mul_ps(vvdw,sw);
247 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
249 /* Update potential sum for this i atom from the interaction with this j atom. */
250 vvdw = _mm_and_ps(vvdw,cutoff_mask);
251 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
255 fscal = _mm_and_ps(fscal,cutoff_mask);
257 /* Update vectorial force */
258 fix0 = _mm_macc_ps(dx00,fscal,fix0);
259 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
260 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
262 fjptrA = f+j_coord_offsetA;
263 fjptrB = f+j_coord_offsetB;
264 fjptrC = f+j_coord_offsetC;
265 fjptrD = f+j_coord_offsetD;
266 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
267 _mm_mul_ps(dx00,fscal),
268 _mm_mul_ps(dy00,fscal),
269 _mm_mul_ps(dz00,fscal));
273 /* Inner loop uses 62 flops */
279 /* Get j neighbor index, and coordinate index */
280 jnrlistA = jjnr[jidx];
281 jnrlistB = jjnr[jidx+1];
282 jnrlistC = jjnr[jidx+2];
283 jnrlistD = jjnr[jidx+3];
284 /* Sign of each element will be negative for non-real atoms.
285 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
286 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
288 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
289 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
290 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
291 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
292 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
293 j_coord_offsetA = DIM*jnrA;
294 j_coord_offsetB = DIM*jnrB;
295 j_coord_offsetC = DIM*jnrC;
296 j_coord_offsetD = DIM*jnrD;
298 /* load j atom coordinates */
299 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
300 x+j_coord_offsetC,x+j_coord_offsetD,
303 /* Calculate displacement vector */
304 dx00 = _mm_sub_ps(ix0,jx0);
305 dy00 = _mm_sub_ps(iy0,jy0);
306 dz00 = _mm_sub_ps(iz0,jz0);
308 /* Calculate squared distance and things based on it */
309 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
311 rinv00 = gmx_mm_invsqrt_ps(rsq00);
313 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
315 /* Load parameters for j particles */
316 vdwjidx0A = 2*vdwtype[jnrA+0];
317 vdwjidx0B = 2*vdwtype[jnrB+0];
318 vdwjidx0C = 2*vdwtype[jnrC+0];
319 vdwjidx0D = 2*vdwtype[jnrD+0];
321 /**************************
322 * CALCULATE INTERACTIONS *
323 **************************/
325 if (gmx_mm_any_lt(rsq00,rcutoff2))
328 r00 = _mm_mul_ps(rsq00,rinv00);
329 r00 = _mm_andnot_ps(dummy_mask,r00);
331 /* Compute parameters for interactions between i and j atoms */
332 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
333 vdwparam+vdwioffset0+vdwjidx0B,
334 vdwparam+vdwioffset0+vdwjidx0C,
335 vdwparam+vdwioffset0+vdwjidx0D,
338 /* LENNARD-JONES DISPERSION/REPULSION */
340 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
341 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
342 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
343 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
344 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
346 d = _mm_sub_ps(r00,rswitch);
347 d = _mm_max_ps(d,_mm_setzero_ps());
348 d2 = _mm_mul_ps(d,d);
349 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
351 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
353 /* Evaluate switch function */
354 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
355 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
356 vvdw = _mm_mul_ps(vvdw,sw);
357 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
359 /* Update potential sum for this i atom from the interaction with this j atom. */
360 vvdw = _mm_and_ps(vvdw,cutoff_mask);
361 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
362 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
366 fscal = _mm_and_ps(fscal,cutoff_mask);
368 fscal = _mm_andnot_ps(dummy_mask,fscal);
370 /* Update vectorial force */
371 fix0 = _mm_macc_ps(dx00,fscal,fix0);
372 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
373 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
375 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
376 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
377 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
378 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
379 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
380 _mm_mul_ps(dx00,fscal),
381 _mm_mul_ps(dy00,fscal),
382 _mm_mul_ps(dz00,fscal));
386 /* Inner loop uses 63 flops */
389 /* End of innermost loop */
391 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
392 f+i_coord_offset,fshift+i_shift_offset);
395 /* Update potential energies */
396 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
398 /* Increment number of inner iterations */
399 inneriter += j_index_end - j_index_start;
401 /* Outer loop uses 7 flops */
404 /* Increment number of outer iterations */
407 /* Update outer/inner flops */
409 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*63);
412 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_avx_128_fma_single
413 * Electrostatics interaction: None
414 * VdW interaction: LennardJones
415 * Geometry: Particle-Particle
416 * Calculate force/pot: Force
419 nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_avx_128_fma_single
420 (t_nblist * gmx_restrict nlist,
421 rvec * gmx_restrict xx,
422 rvec * gmx_restrict ff,
423 t_forcerec * gmx_restrict fr,
424 t_mdatoms * gmx_restrict mdatoms,
425 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
426 t_nrnb * gmx_restrict nrnb)
428 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
429 * just 0 for non-waters.
430 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
431 * jnr indices corresponding to data put in the four positions in the SIMD register.
433 int i_shift_offset,i_coord_offset,outeriter,inneriter;
434 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
435 int jnrA,jnrB,jnrC,jnrD;
436 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
437 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
438 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
440 real *shiftvec,*fshift,*x,*f;
441 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
443 __m128 fscal,rcutoff,rcutoff2,jidxall;
445 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
446 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
447 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
448 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
450 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
453 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
454 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
455 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
456 real rswitch_scalar,d_scalar;
457 __m128 dummy_mask,cutoff_mask;
458 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
459 __m128 one = _mm_set1_ps(1.0);
460 __m128 two = _mm_set1_ps(2.0);
466 jindex = nlist->jindex;
468 shiftidx = nlist->shift;
470 shiftvec = fr->shift_vec[0];
471 fshift = fr->fshift[0];
472 nvdwtype = fr->ntype;
474 vdwtype = mdatoms->typeA;
476 rcutoff_scalar = fr->rvdw;
477 rcutoff = _mm_set1_ps(rcutoff_scalar);
478 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
480 rswitch_scalar = fr->rvdw_switch;
481 rswitch = _mm_set1_ps(rswitch_scalar);
482 /* Setup switch parameters */
483 d_scalar = rcutoff_scalar-rswitch_scalar;
484 d = _mm_set1_ps(d_scalar);
485 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
486 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
487 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
488 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
489 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
490 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
492 /* Avoid stupid compiler warnings */
493 jnrA = jnrB = jnrC = jnrD = 0;
502 for(iidx=0;iidx<4*DIM;iidx++)
507 /* Start outer loop over neighborlists */
508 for(iidx=0; iidx<nri; iidx++)
510 /* Load shift vector for this list */
511 i_shift_offset = DIM*shiftidx[iidx];
513 /* Load limits for loop over neighbors */
514 j_index_start = jindex[iidx];
515 j_index_end = jindex[iidx+1];
517 /* Get outer coordinate index */
519 i_coord_offset = DIM*inr;
521 /* Load i particle coords and add shift vector */
522 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
524 fix0 = _mm_setzero_ps();
525 fiy0 = _mm_setzero_ps();
526 fiz0 = _mm_setzero_ps();
528 /* Load parameters for i particles */
529 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
531 /* Start inner kernel loop */
532 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
535 /* Get j neighbor index, and coordinate index */
540 j_coord_offsetA = DIM*jnrA;
541 j_coord_offsetB = DIM*jnrB;
542 j_coord_offsetC = DIM*jnrC;
543 j_coord_offsetD = DIM*jnrD;
545 /* load j atom coordinates */
546 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
547 x+j_coord_offsetC,x+j_coord_offsetD,
550 /* Calculate displacement vector */
551 dx00 = _mm_sub_ps(ix0,jx0);
552 dy00 = _mm_sub_ps(iy0,jy0);
553 dz00 = _mm_sub_ps(iz0,jz0);
555 /* Calculate squared distance and things based on it */
556 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
558 rinv00 = gmx_mm_invsqrt_ps(rsq00);
560 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
562 /* Load parameters for j particles */
563 vdwjidx0A = 2*vdwtype[jnrA+0];
564 vdwjidx0B = 2*vdwtype[jnrB+0];
565 vdwjidx0C = 2*vdwtype[jnrC+0];
566 vdwjidx0D = 2*vdwtype[jnrD+0];
568 /**************************
569 * CALCULATE INTERACTIONS *
570 **************************/
572 if (gmx_mm_any_lt(rsq00,rcutoff2))
575 r00 = _mm_mul_ps(rsq00,rinv00);
577 /* Compute parameters for interactions between i and j atoms */
578 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
579 vdwparam+vdwioffset0+vdwjidx0B,
580 vdwparam+vdwioffset0+vdwjidx0C,
581 vdwparam+vdwioffset0+vdwjidx0D,
584 /* LENNARD-JONES DISPERSION/REPULSION */
586 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
587 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
588 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
589 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
590 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
592 d = _mm_sub_ps(r00,rswitch);
593 d = _mm_max_ps(d,_mm_setzero_ps());
594 d2 = _mm_mul_ps(d,d);
595 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
597 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
599 /* Evaluate switch function */
600 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
601 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
602 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
606 fscal = _mm_and_ps(fscal,cutoff_mask);
608 /* Update vectorial force */
609 fix0 = _mm_macc_ps(dx00,fscal,fix0);
610 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
611 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
613 fjptrA = f+j_coord_offsetA;
614 fjptrB = f+j_coord_offsetB;
615 fjptrC = f+j_coord_offsetC;
616 fjptrD = f+j_coord_offsetD;
617 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
618 _mm_mul_ps(dx00,fscal),
619 _mm_mul_ps(dy00,fscal),
620 _mm_mul_ps(dz00,fscal));
624 /* Inner loop uses 59 flops */
630 /* Get j neighbor index, and coordinate index */
631 jnrlistA = jjnr[jidx];
632 jnrlistB = jjnr[jidx+1];
633 jnrlistC = jjnr[jidx+2];
634 jnrlistD = jjnr[jidx+3];
635 /* Sign of each element will be negative for non-real atoms.
636 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
637 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
639 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
640 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
641 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
642 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
643 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
644 j_coord_offsetA = DIM*jnrA;
645 j_coord_offsetB = DIM*jnrB;
646 j_coord_offsetC = DIM*jnrC;
647 j_coord_offsetD = DIM*jnrD;
649 /* load j atom coordinates */
650 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
651 x+j_coord_offsetC,x+j_coord_offsetD,
654 /* Calculate displacement vector */
655 dx00 = _mm_sub_ps(ix0,jx0);
656 dy00 = _mm_sub_ps(iy0,jy0);
657 dz00 = _mm_sub_ps(iz0,jz0);
659 /* Calculate squared distance and things based on it */
660 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
662 rinv00 = gmx_mm_invsqrt_ps(rsq00);
664 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
666 /* Load parameters for j particles */
667 vdwjidx0A = 2*vdwtype[jnrA+0];
668 vdwjidx0B = 2*vdwtype[jnrB+0];
669 vdwjidx0C = 2*vdwtype[jnrC+0];
670 vdwjidx0D = 2*vdwtype[jnrD+0];
672 /**************************
673 * CALCULATE INTERACTIONS *
674 **************************/
676 if (gmx_mm_any_lt(rsq00,rcutoff2))
679 r00 = _mm_mul_ps(rsq00,rinv00);
680 r00 = _mm_andnot_ps(dummy_mask,r00);
682 /* Compute parameters for interactions between i and j atoms */
683 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
684 vdwparam+vdwioffset0+vdwjidx0B,
685 vdwparam+vdwioffset0+vdwjidx0C,
686 vdwparam+vdwioffset0+vdwjidx0D,
689 /* LENNARD-JONES DISPERSION/REPULSION */
691 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
692 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
693 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
694 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
695 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
697 d = _mm_sub_ps(r00,rswitch);
698 d = _mm_max_ps(d,_mm_setzero_ps());
699 d2 = _mm_mul_ps(d,d);
700 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
702 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
704 /* Evaluate switch function */
705 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
706 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
707 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
711 fscal = _mm_and_ps(fscal,cutoff_mask);
713 fscal = _mm_andnot_ps(dummy_mask,fscal);
715 /* Update vectorial force */
716 fix0 = _mm_macc_ps(dx00,fscal,fix0);
717 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
718 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
720 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
721 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
722 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
723 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
724 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
725 _mm_mul_ps(dx00,fscal),
726 _mm_mul_ps(dy00,fscal),
727 _mm_mul_ps(dz00,fscal));
731 /* Inner loop uses 60 flops */
734 /* End of innermost loop */
736 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
737 f+i_coord_offset,fshift+i_shift_offset);
739 /* Increment number of inner iterations */
740 inneriter += j_index_end - j_index_start;
742 /* Outer loop uses 6 flops */
745 /* Increment number of outer iterations */
748 /* Update outer/inner flops */
750 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*60);