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.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSw_GeomP1P1_VF_avx_128_fma_single
52 * Electrostatics interaction: None
53 * VdW interaction: LennardJones
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecNone_VdwLJSw_GeomP1P1_VF_avx_128_fma_single
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_128, 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 j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
89 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
92 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
93 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
94 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
95 real rswitch_scalar,d_scalar;
96 __m128 dummy_mask,cutoff_mask;
97 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
98 __m128 one = _mm_set1_ps(1.0);
99 __m128 two = _mm_set1_ps(2.0);
105 jindex = nlist->jindex;
107 shiftidx = nlist->shift;
109 shiftvec = fr->shift_vec[0];
110 fshift = fr->fshift[0];
111 nvdwtype = fr->ntype;
113 vdwtype = mdatoms->typeA;
115 rcutoff_scalar = fr->rvdw;
116 rcutoff = _mm_set1_ps(rcutoff_scalar);
117 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
119 rswitch_scalar = fr->rvdw_switch;
120 rswitch = _mm_set1_ps(rswitch_scalar);
121 /* Setup switch parameters */
122 d_scalar = rcutoff_scalar-rswitch_scalar;
123 d = _mm_set1_ps(d_scalar);
124 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
125 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
126 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
127 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
128 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
129 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
131 /* Avoid stupid compiler warnings */
132 jnrA = jnrB = jnrC = jnrD = 0;
141 for(iidx=0;iidx<4*DIM;iidx++)
146 /* Start outer loop over neighborlists */
147 for(iidx=0; iidx<nri; iidx++)
149 /* Load shift vector for this list */
150 i_shift_offset = DIM*shiftidx[iidx];
152 /* Load limits for loop over neighbors */
153 j_index_start = jindex[iidx];
154 j_index_end = jindex[iidx+1];
156 /* Get outer coordinate index */
158 i_coord_offset = DIM*inr;
160 /* Load i particle coords and add shift vector */
161 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
163 fix0 = _mm_setzero_ps();
164 fiy0 = _mm_setzero_ps();
165 fiz0 = _mm_setzero_ps();
167 /* Load parameters for i particles */
168 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
170 /* Reset potential sums */
171 vvdwsum = _mm_setzero_ps();
173 /* Start inner kernel loop */
174 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
177 /* Get j neighbor index, and coordinate index */
182 j_coord_offsetA = DIM*jnrA;
183 j_coord_offsetB = DIM*jnrB;
184 j_coord_offsetC = DIM*jnrC;
185 j_coord_offsetD = DIM*jnrD;
187 /* load j atom coordinates */
188 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
189 x+j_coord_offsetC,x+j_coord_offsetD,
192 /* Calculate displacement vector */
193 dx00 = _mm_sub_ps(ix0,jx0);
194 dy00 = _mm_sub_ps(iy0,jy0);
195 dz00 = _mm_sub_ps(iz0,jz0);
197 /* Calculate squared distance and things based on it */
198 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
200 rinv00 = gmx_mm_invsqrt_ps(rsq00);
202 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
204 /* Load parameters for j particles */
205 vdwjidx0A = 2*vdwtype[jnrA+0];
206 vdwjidx0B = 2*vdwtype[jnrB+0];
207 vdwjidx0C = 2*vdwtype[jnrC+0];
208 vdwjidx0D = 2*vdwtype[jnrD+0];
210 /**************************
211 * CALCULATE INTERACTIONS *
212 **************************/
214 if (gmx_mm_any_lt(rsq00,rcutoff2))
217 r00 = _mm_mul_ps(rsq00,rinv00);
219 /* Compute parameters for interactions between i and j atoms */
220 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
221 vdwparam+vdwioffset0+vdwjidx0B,
222 vdwparam+vdwioffset0+vdwjidx0C,
223 vdwparam+vdwioffset0+vdwjidx0D,
226 /* LENNARD-JONES DISPERSION/REPULSION */
228 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
229 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
230 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
231 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
232 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
234 d = _mm_sub_ps(r00,rswitch);
235 d = _mm_max_ps(d,_mm_setzero_ps());
236 d2 = _mm_mul_ps(d,d);
237 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
239 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
241 /* Evaluate switch function */
242 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
243 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
244 vvdw = _mm_mul_ps(vvdw,sw);
245 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
247 /* Update potential sum for this i atom from the interaction with this j atom. */
248 vvdw = _mm_and_ps(vvdw,cutoff_mask);
249 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
253 fscal = _mm_and_ps(fscal,cutoff_mask);
255 /* Update vectorial force */
256 fix0 = _mm_macc_ps(dx00,fscal,fix0);
257 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
258 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
260 fjptrA = f+j_coord_offsetA;
261 fjptrB = f+j_coord_offsetB;
262 fjptrC = f+j_coord_offsetC;
263 fjptrD = f+j_coord_offsetD;
264 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
265 _mm_mul_ps(dx00,fscal),
266 _mm_mul_ps(dy00,fscal),
267 _mm_mul_ps(dz00,fscal));
271 /* Inner loop uses 62 flops */
277 /* Get j neighbor index, and coordinate index */
278 jnrlistA = jjnr[jidx];
279 jnrlistB = jjnr[jidx+1];
280 jnrlistC = jjnr[jidx+2];
281 jnrlistD = jjnr[jidx+3];
282 /* Sign of each element will be negative for non-real atoms.
283 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
284 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
286 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
287 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
288 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
289 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
290 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
291 j_coord_offsetA = DIM*jnrA;
292 j_coord_offsetB = DIM*jnrB;
293 j_coord_offsetC = DIM*jnrC;
294 j_coord_offsetD = DIM*jnrD;
296 /* load j atom coordinates */
297 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
298 x+j_coord_offsetC,x+j_coord_offsetD,
301 /* Calculate displacement vector */
302 dx00 = _mm_sub_ps(ix0,jx0);
303 dy00 = _mm_sub_ps(iy0,jy0);
304 dz00 = _mm_sub_ps(iz0,jz0);
306 /* Calculate squared distance and things based on it */
307 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
309 rinv00 = gmx_mm_invsqrt_ps(rsq00);
311 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
313 /* Load parameters for j particles */
314 vdwjidx0A = 2*vdwtype[jnrA+0];
315 vdwjidx0B = 2*vdwtype[jnrB+0];
316 vdwjidx0C = 2*vdwtype[jnrC+0];
317 vdwjidx0D = 2*vdwtype[jnrD+0];
319 /**************************
320 * CALCULATE INTERACTIONS *
321 **************************/
323 if (gmx_mm_any_lt(rsq00,rcutoff2))
326 r00 = _mm_mul_ps(rsq00,rinv00);
327 r00 = _mm_andnot_ps(dummy_mask,r00);
329 /* Compute parameters for interactions between i and j atoms */
330 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
331 vdwparam+vdwioffset0+vdwjidx0B,
332 vdwparam+vdwioffset0+vdwjidx0C,
333 vdwparam+vdwioffset0+vdwjidx0D,
336 /* LENNARD-JONES DISPERSION/REPULSION */
338 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
339 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
340 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
341 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
342 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
344 d = _mm_sub_ps(r00,rswitch);
345 d = _mm_max_ps(d,_mm_setzero_ps());
346 d2 = _mm_mul_ps(d,d);
347 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
349 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
351 /* Evaluate switch function */
352 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
353 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
354 vvdw = _mm_mul_ps(vvdw,sw);
355 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
357 /* Update potential sum for this i atom from the interaction with this j atom. */
358 vvdw = _mm_and_ps(vvdw,cutoff_mask);
359 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
360 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
364 fscal = _mm_and_ps(fscal,cutoff_mask);
366 fscal = _mm_andnot_ps(dummy_mask,fscal);
368 /* Update vectorial force */
369 fix0 = _mm_macc_ps(dx00,fscal,fix0);
370 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
371 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
373 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
374 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
375 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
376 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
377 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
378 _mm_mul_ps(dx00,fscal),
379 _mm_mul_ps(dy00,fscal),
380 _mm_mul_ps(dz00,fscal));
384 /* Inner loop uses 63 flops */
387 /* End of innermost loop */
389 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
390 f+i_coord_offset,fshift+i_shift_offset);
393 /* Update potential energies */
394 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
396 /* Increment number of inner iterations */
397 inneriter += j_index_end - j_index_start;
399 /* Outer loop uses 7 flops */
402 /* Increment number of outer iterations */
405 /* Update outer/inner flops */
407 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*63);
410 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_avx_128_fma_single
411 * Electrostatics interaction: None
412 * VdW interaction: LennardJones
413 * Geometry: Particle-Particle
414 * Calculate force/pot: Force
417 nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_avx_128_fma_single
418 (t_nblist * gmx_restrict nlist,
419 rvec * gmx_restrict xx,
420 rvec * gmx_restrict ff,
421 t_forcerec * gmx_restrict fr,
422 t_mdatoms * gmx_restrict mdatoms,
423 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
424 t_nrnb * gmx_restrict nrnb)
426 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
427 * just 0 for non-waters.
428 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
429 * jnr indices corresponding to data put in the four positions in the SIMD register.
431 int i_shift_offset,i_coord_offset,outeriter,inneriter;
432 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
433 int jnrA,jnrB,jnrC,jnrD;
434 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
435 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
436 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
438 real *shiftvec,*fshift,*x,*f;
439 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
441 __m128 fscal,rcutoff,rcutoff2,jidxall;
443 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
444 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
445 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
446 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
448 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
451 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
452 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
453 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
454 real rswitch_scalar,d_scalar;
455 __m128 dummy_mask,cutoff_mask;
456 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
457 __m128 one = _mm_set1_ps(1.0);
458 __m128 two = _mm_set1_ps(2.0);
464 jindex = nlist->jindex;
466 shiftidx = nlist->shift;
468 shiftvec = fr->shift_vec[0];
469 fshift = fr->fshift[0];
470 nvdwtype = fr->ntype;
472 vdwtype = mdatoms->typeA;
474 rcutoff_scalar = fr->rvdw;
475 rcutoff = _mm_set1_ps(rcutoff_scalar);
476 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
478 rswitch_scalar = fr->rvdw_switch;
479 rswitch = _mm_set1_ps(rswitch_scalar);
480 /* Setup switch parameters */
481 d_scalar = rcutoff_scalar-rswitch_scalar;
482 d = _mm_set1_ps(d_scalar);
483 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
484 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
485 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
486 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
487 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
488 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
490 /* Avoid stupid compiler warnings */
491 jnrA = jnrB = jnrC = jnrD = 0;
500 for(iidx=0;iidx<4*DIM;iidx++)
505 /* Start outer loop over neighborlists */
506 for(iidx=0; iidx<nri; iidx++)
508 /* Load shift vector for this list */
509 i_shift_offset = DIM*shiftidx[iidx];
511 /* Load limits for loop over neighbors */
512 j_index_start = jindex[iidx];
513 j_index_end = jindex[iidx+1];
515 /* Get outer coordinate index */
517 i_coord_offset = DIM*inr;
519 /* Load i particle coords and add shift vector */
520 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
522 fix0 = _mm_setzero_ps();
523 fiy0 = _mm_setzero_ps();
524 fiz0 = _mm_setzero_ps();
526 /* Load parameters for i particles */
527 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
529 /* Start inner kernel loop */
530 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
533 /* Get j neighbor index, and coordinate index */
538 j_coord_offsetA = DIM*jnrA;
539 j_coord_offsetB = DIM*jnrB;
540 j_coord_offsetC = DIM*jnrC;
541 j_coord_offsetD = DIM*jnrD;
543 /* load j atom coordinates */
544 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
545 x+j_coord_offsetC,x+j_coord_offsetD,
548 /* Calculate displacement vector */
549 dx00 = _mm_sub_ps(ix0,jx0);
550 dy00 = _mm_sub_ps(iy0,jy0);
551 dz00 = _mm_sub_ps(iz0,jz0);
553 /* Calculate squared distance and things based on it */
554 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
556 rinv00 = gmx_mm_invsqrt_ps(rsq00);
558 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
560 /* Load parameters for j particles */
561 vdwjidx0A = 2*vdwtype[jnrA+0];
562 vdwjidx0B = 2*vdwtype[jnrB+0];
563 vdwjidx0C = 2*vdwtype[jnrC+0];
564 vdwjidx0D = 2*vdwtype[jnrD+0];
566 /**************************
567 * CALCULATE INTERACTIONS *
568 **************************/
570 if (gmx_mm_any_lt(rsq00,rcutoff2))
573 r00 = _mm_mul_ps(rsq00,rinv00);
575 /* Compute parameters for interactions between i and j atoms */
576 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
577 vdwparam+vdwioffset0+vdwjidx0B,
578 vdwparam+vdwioffset0+vdwjidx0C,
579 vdwparam+vdwioffset0+vdwjidx0D,
582 /* LENNARD-JONES DISPERSION/REPULSION */
584 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
585 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
586 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
587 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
588 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
590 d = _mm_sub_ps(r00,rswitch);
591 d = _mm_max_ps(d,_mm_setzero_ps());
592 d2 = _mm_mul_ps(d,d);
593 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
595 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
597 /* Evaluate switch function */
598 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
599 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
600 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
604 fscal = _mm_and_ps(fscal,cutoff_mask);
606 /* Update vectorial force */
607 fix0 = _mm_macc_ps(dx00,fscal,fix0);
608 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
609 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
611 fjptrA = f+j_coord_offsetA;
612 fjptrB = f+j_coord_offsetB;
613 fjptrC = f+j_coord_offsetC;
614 fjptrD = f+j_coord_offsetD;
615 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
616 _mm_mul_ps(dx00,fscal),
617 _mm_mul_ps(dy00,fscal),
618 _mm_mul_ps(dz00,fscal));
622 /* Inner loop uses 59 flops */
628 /* Get j neighbor index, and coordinate index */
629 jnrlistA = jjnr[jidx];
630 jnrlistB = jjnr[jidx+1];
631 jnrlistC = jjnr[jidx+2];
632 jnrlistD = jjnr[jidx+3];
633 /* Sign of each element will be negative for non-real atoms.
634 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
635 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
637 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
638 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
639 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
640 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
641 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
642 j_coord_offsetA = DIM*jnrA;
643 j_coord_offsetB = DIM*jnrB;
644 j_coord_offsetC = DIM*jnrC;
645 j_coord_offsetD = DIM*jnrD;
647 /* load j atom coordinates */
648 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
649 x+j_coord_offsetC,x+j_coord_offsetD,
652 /* Calculate displacement vector */
653 dx00 = _mm_sub_ps(ix0,jx0);
654 dy00 = _mm_sub_ps(iy0,jy0);
655 dz00 = _mm_sub_ps(iz0,jz0);
657 /* Calculate squared distance and things based on it */
658 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
660 rinv00 = gmx_mm_invsqrt_ps(rsq00);
662 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
664 /* Load parameters for j particles */
665 vdwjidx0A = 2*vdwtype[jnrA+0];
666 vdwjidx0B = 2*vdwtype[jnrB+0];
667 vdwjidx0C = 2*vdwtype[jnrC+0];
668 vdwjidx0D = 2*vdwtype[jnrD+0];
670 /**************************
671 * CALCULATE INTERACTIONS *
672 **************************/
674 if (gmx_mm_any_lt(rsq00,rcutoff2))
677 r00 = _mm_mul_ps(rsq00,rinv00);
678 r00 = _mm_andnot_ps(dummy_mask,r00);
680 /* Compute parameters for interactions between i and j atoms */
681 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
682 vdwparam+vdwioffset0+vdwjidx0B,
683 vdwparam+vdwioffset0+vdwjidx0C,
684 vdwparam+vdwioffset0+vdwjidx0D,
687 /* LENNARD-JONES DISPERSION/REPULSION */
689 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
690 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
691 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
692 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
693 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
695 d = _mm_sub_ps(r00,rswitch);
696 d = _mm_max_ps(d,_mm_setzero_ps());
697 d2 = _mm_mul_ps(d,d);
698 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_macc_ps(d,_mm_macc_ps(d,swV5,swV4),swV3))));
700 dsw = _mm_mul_ps(d2,_mm_macc_ps(d,_mm_macc_ps(d,swF4,swF3),swF2));
702 /* Evaluate switch function */
703 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
704 fvdw = _mm_msub_ps( fvdw,sw , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
705 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
709 fscal = _mm_and_ps(fscal,cutoff_mask);
711 fscal = _mm_andnot_ps(dummy_mask,fscal);
713 /* Update vectorial force */
714 fix0 = _mm_macc_ps(dx00,fscal,fix0);
715 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
716 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
718 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
719 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
720 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
721 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
722 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
723 _mm_mul_ps(dx00,fscal),
724 _mm_mul_ps(dy00,fscal),
725 _mm_mul_ps(dz00,fscal));
729 /* Inner loop uses 60 flops */
732 /* End of innermost loop */
734 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
735 f+i_coord_offset,fshift+i_shift_offset);
737 /* Increment number of inner iterations */
738 inneriter += j_index_end - j_index_start;
740 /* Outer loop uses 6 flops */
743 /* Increment number of outer iterations */
746 /* Update outer/inner flops */
748 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*60);