2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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 sse2_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gromacs/simd/math_x86_sse2_single.h"
50 #include "kernelutil_x86_sse2_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSw_GeomP1P1_VF_sse2_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_sse2_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 SSE, 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 tx,ty,tz,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_sub_ps( _mm_mul_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_add_ps(swV3,_mm_mul_ps(d,_mm_add_ps(swV4,_mm_mul_ps(d,swV5)))))));
241 dsw = _mm_mul_ps(d2,_mm_add_ps(swF2,_mm_mul_ps(d,_mm_add_ps(swF3,_mm_mul_ps(d,swF4)))));
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_sub_ps( _mm_mul_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 /* Calculate temporary vectorial force */
258 tx = _mm_mul_ps(fscal,dx00);
259 ty = _mm_mul_ps(fscal,dy00);
260 tz = _mm_mul_ps(fscal,dz00);
262 /* Update vectorial force */
263 fix0 = _mm_add_ps(fix0,tx);
264 fiy0 = _mm_add_ps(fiy0,ty);
265 fiz0 = _mm_add_ps(fiz0,tz);
267 fjptrA = f+j_coord_offsetA;
268 fjptrB = f+j_coord_offsetB;
269 fjptrC = f+j_coord_offsetC;
270 fjptrD = f+j_coord_offsetD;
271 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
275 /* Inner loop uses 59 flops */
281 /* Get j neighbor index, and coordinate index */
282 jnrlistA = jjnr[jidx];
283 jnrlistB = jjnr[jidx+1];
284 jnrlistC = jjnr[jidx+2];
285 jnrlistD = jjnr[jidx+3];
286 /* Sign of each element will be negative for non-real atoms.
287 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
288 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
290 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
291 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
292 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
293 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
294 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
295 j_coord_offsetA = DIM*jnrA;
296 j_coord_offsetB = DIM*jnrB;
297 j_coord_offsetC = DIM*jnrC;
298 j_coord_offsetD = DIM*jnrD;
300 /* load j atom coordinates */
301 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
302 x+j_coord_offsetC,x+j_coord_offsetD,
305 /* Calculate displacement vector */
306 dx00 = _mm_sub_ps(ix0,jx0);
307 dy00 = _mm_sub_ps(iy0,jy0);
308 dz00 = _mm_sub_ps(iz0,jz0);
310 /* Calculate squared distance and things based on it */
311 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
313 rinv00 = gmx_mm_invsqrt_ps(rsq00);
315 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
317 /* Load parameters for j particles */
318 vdwjidx0A = 2*vdwtype[jnrA+0];
319 vdwjidx0B = 2*vdwtype[jnrB+0];
320 vdwjidx0C = 2*vdwtype[jnrC+0];
321 vdwjidx0D = 2*vdwtype[jnrD+0];
323 /**************************
324 * CALCULATE INTERACTIONS *
325 **************************/
327 if (gmx_mm_any_lt(rsq00,rcutoff2))
330 r00 = _mm_mul_ps(rsq00,rinv00);
331 r00 = _mm_andnot_ps(dummy_mask,r00);
333 /* Compute parameters for interactions between i and j atoms */
334 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
335 vdwparam+vdwioffset0+vdwjidx0B,
336 vdwparam+vdwioffset0+vdwjidx0C,
337 vdwparam+vdwioffset0+vdwjidx0D,
340 /* LENNARD-JONES DISPERSION/REPULSION */
342 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
343 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
344 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
345 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
346 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
348 d = _mm_sub_ps(r00,rswitch);
349 d = _mm_max_ps(d,_mm_setzero_ps());
350 d2 = _mm_mul_ps(d,d);
351 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_add_ps(swV3,_mm_mul_ps(d,_mm_add_ps(swV4,_mm_mul_ps(d,swV5)))))));
353 dsw = _mm_mul_ps(d2,_mm_add_ps(swF2,_mm_mul_ps(d,_mm_add_ps(swF3,_mm_mul_ps(d,swF4)))));
355 /* Evaluate switch function */
356 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
357 fvdw = _mm_sub_ps( _mm_mul_ps(fvdw,sw) , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
358 vvdw = _mm_mul_ps(vvdw,sw);
359 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
361 /* Update potential sum for this i atom from the interaction with this j atom. */
362 vvdw = _mm_and_ps(vvdw,cutoff_mask);
363 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
364 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
368 fscal = _mm_and_ps(fscal,cutoff_mask);
370 fscal = _mm_andnot_ps(dummy_mask,fscal);
372 /* Calculate temporary vectorial force */
373 tx = _mm_mul_ps(fscal,dx00);
374 ty = _mm_mul_ps(fscal,dy00);
375 tz = _mm_mul_ps(fscal,dz00);
377 /* Update vectorial force */
378 fix0 = _mm_add_ps(fix0,tx);
379 fiy0 = _mm_add_ps(fiy0,ty);
380 fiz0 = _mm_add_ps(fiz0,tz);
382 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
383 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
384 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
385 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
386 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
390 /* Inner loop uses 60 flops */
393 /* End of innermost loop */
395 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
396 f+i_coord_offset,fshift+i_shift_offset);
399 /* Update potential energies */
400 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
402 /* Increment number of inner iterations */
403 inneriter += j_index_end - j_index_start;
405 /* Outer loop uses 7 flops */
408 /* Increment number of outer iterations */
411 /* Update outer/inner flops */
413 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*60);
416 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_sse2_single
417 * Electrostatics interaction: None
418 * VdW interaction: LennardJones
419 * Geometry: Particle-Particle
420 * Calculate force/pot: Force
423 nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_sse2_single
424 (t_nblist * gmx_restrict nlist,
425 rvec * gmx_restrict xx,
426 rvec * gmx_restrict ff,
427 t_forcerec * gmx_restrict fr,
428 t_mdatoms * gmx_restrict mdatoms,
429 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
430 t_nrnb * gmx_restrict nrnb)
432 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
433 * just 0 for non-waters.
434 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
435 * jnr indices corresponding to data put in the four positions in the SIMD register.
437 int i_shift_offset,i_coord_offset,outeriter,inneriter;
438 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
439 int jnrA,jnrB,jnrC,jnrD;
440 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
441 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
442 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
444 real *shiftvec,*fshift,*x,*f;
445 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
447 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
449 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
450 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
451 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
452 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
454 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
457 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
458 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
459 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
460 real rswitch_scalar,d_scalar;
461 __m128 dummy_mask,cutoff_mask;
462 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
463 __m128 one = _mm_set1_ps(1.0);
464 __m128 two = _mm_set1_ps(2.0);
470 jindex = nlist->jindex;
472 shiftidx = nlist->shift;
474 shiftvec = fr->shift_vec[0];
475 fshift = fr->fshift[0];
476 nvdwtype = fr->ntype;
478 vdwtype = mdatoms->typeA;
480 rcutoff_scalar = fr->rvdw;
481 rcutoff = _mm_set1_ps(rcutoff_scalar);
482 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
484 rswitch_scalar = fr->rvdw_switch;
485 rswitch = _mm_set1_ps(rswitch_scalar);
486 /* Setup switch parameters */
487 d_scalar = rcutoff_scalar-rswitch_scalar;
488 d = _mm_set1_ps(d_scalar);
489 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
490 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
491 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
492 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
493 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
494 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
496 /* Avoid stupid compiler warnings */
497 jnrA = jnrB = jnrC = jnrD = 0;
506 for(iidx=0;iidx<4*DIM;iidx++)
511 /* Start outer loop over neighborlists */
512 for(iidx=0; iidx<nri; iidx++)
514 /* Load shift vector for this list */
515 i_shift_offset = DIM*shiftidx[iidx];
517 /* Load limits for loop over neighbors */
518 j_index_start = jindex[iidx];
519 j_index_end = jindex[iidx+1];
521 /* Get outer coordinate index */
523 i_coord_offset = DIM*inr;
525 /* Load i particle coords and add shift vector */
526 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
528 fix0 = _mm_setzero_ps();
529 fiy0 = _mm_setzero_ps();
530 fiz0 = _mm_setzero_ps();
532 /* Load parameters for i particles */
533 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
535 /* Start inner kernel loop */
536 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
539 /* Get j neighbor index, and coordinate index */
544 j_coord_offsetA = DIM*jnrA;
545 j_coord_offsetB = DIM*jnrB;
546 j_coord_offsetC = DIM*jnrC;
547 j_coord_offsetD = DIM*jnrD;
549 /* load j atom coordinates */
550 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
551 x+j_coord_offsetC,x+j_coord_offsetD,
554 /* Calculate displacement vector */
555 dx00 = _mm_sub_ps(ix0,jx0);
556 dy00 = _mm_sub_ps(iy0,jy0);
557 dz00 = _mm_sub_ps(iz0,jz0);
559 /* Calculate squared distance and things based on it */
560 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
562 rinv00 = gmx_mm_invsqrt_ps(rsq00);
564 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
566 /* Load parameters for j particles */
567 vdwjidx0A = 2*vdwtype[jnrA+0];
568 vdwjidx0B = 2*vdwtype[jnrB+0];
569 vdwjidx0C = 2*vdwtype[jnrC+0];
570 vdwjidx0D = 2*vdwtype[jnrD+0];
572 /**************************
573 * CALCULATE INTERACTIONS *
574 **************************/
576 if (gmx_mm_any_lt(rsq00,rcutoff2))
579 r00 = _mm_mul_ps(rsq00,rinv00);
581 /* Compute parameters for interactions between i and j atoms */
582 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
583 vdwparam+vdwioffset0+vdwjidx0B,
584 vdwparam+vdwioffset0+vdwjidx0C,
585 vdwparam+vdwioffset0+vdwjidx0D,
588 /* LENNARD-JONES DISPERSION/REPULSION */
590 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
591 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
592 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
593 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
594 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
596 d = _mm_sub_ps(r00,rswitch);
597 d = _mm_max_ps(d,_mm_setzero_ps());
598 d2 = _mm_mul_ps(d,d);
599 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_add_ps(swV3,_mm_mul_ps(d,_mm_add_ps(swV4,_mm_mul_ps(d,swV5)))))));
601 dsw = _mm_mul_ps(d2,_mm_add_ps(swF2,_mm_mul_ps(d,_mm_add_ps(swF3,_mm_mul_ps(d,swF4)))));
603 /* Evaluate switch function */
604 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
605 fvdw = _mm_sub_ps( _mm_mul_ps(fvdw,sw) , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
606 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
610 fscal = _mm_and_ps(fscal,cutoff_mask);
612 /* Calculate temporary vectorial force */
613 tx = _mm_mul_ps(fscal,dx00);
614 ty = _mm_mul_ps(fscal,dy00);
615 tz = _mm_mul_ps(fscal,dz00);
617 /* Update vectorial force */
618 fix0 = _mm_add_ps(fix0,tx);
619 fiy0 = _mm_add_ps(fiy0,ty);
620 fiz0 = _mm_add_ps(fiz0,tz);
622 fjptrA = f+j_coord_offsetA;
623 fjptrB = f+j_coord_offsetB;
624 fjptrC = f+j_coord_offsetC;
625 fjptrD = f+j_coord_offsetD;
626 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
630 /* Inner loop uses 56 flops */
636 /* Get j neighbor index, and coordinate index */
637 jnrlistA = jjnr[jidx];
638 jnrlistB = jjnr[jidx+1];
639 jnrlistC = jjnr[jidx+2];
640 jnrlistD = jjnr[jidx+3];
641 /* Sign of each element will be negative for non-real atoms.
642 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
643 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
645 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
646 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
647 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
648 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
649 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
650 j_coord_offsetA = DIM*jnrA;
651 j_coord_offsetB = DIM*jnrB;
652 j_coord_offsetC = DIM*jnrC;
653 j_coord_offsetD = DIM*jnrD;
655 /* load j atom coordinates */
656 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
657 x+j_coord_offsetC,x+j_coord_offsetD,
660 /* Calculate displacement vector */
661 dx00 = _mm_sub_ps(ix0,jx0);
662 dy00 = _mm_sub_ps(iy0,jy0);
663 dz00 = _mm_sub_ps(iz0,jz0);
665 /* Calculate squared distance and things based on it */
666 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
668 rinv00 = gmx_mm_invsqrt_ps(rsq00);
670 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
672 /* Load parameters for j particles */
673 vdwjidx0A = 2*vdwtype[jnrA+0];
674 vdwjidx0B = 2*vdwtype[jnrB+0];
675 vdwjidx0C = 2*vdwtype[jnrC+0];
676 vdwjidx0D = 2*vdwtype[jnrD+0];
678 /**************************
679 * CALCULATE INTERACTIONS *
680 **************************/
682 if (gmx_mm_any_lt(rsq00,rcutoff2))
685 r00 = _mm_mul_ps(rsq00,rinv00);
686 r00 = _mm_andnot_ps(dummy_mask,r00);
688 /* Compute parameters for interactions between i and j atoms */
689 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
690 vdwparam+vdwioffset0+vdwjidx0B,
691 vdwparam+vdwioffset0+vdwjidx0C,
692 vdwparam+vdwioffset0+vdwjidx0D,
695 /* LENNARD-JONES DISPERSION/REPULSION */
697 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
698 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
699 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
700 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
701 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
703 d = _mm_sub_ps(r00,rswitch);
704 d = _mm_max_ps(d,_mm_setzero_ps());
705 d2 = _mm_mul_ps(d,d);
706 sw = _mm_add_ps(one,_mm_mul_ps(d2,_mm_mul_ps(d,_mm_add_ps(swV3,_mm_mul_ps(d,_mm_add_ps(swV4,_mm_mul_ps(d,swV5)))))));
708 dsw = _mm_mul_ps(d2,_mm_add_ps(swF2,_mm_mul_ps(d,_mm_add_ps(swF3,_mm_mul_ps(d,swF4)))));
710 /* Evaluate switch function */
711 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
712 fvdw = _mm_sub_ps( _mm_mul_ps(fvdw,sw) , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
713 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
717 fscal = _mm_and_ps(fscal,cutoff_mask);
719 fscal = _mm_andnot_ps(dummy_mask,fscal);
721 /* Calculate temporary vectorial force */
722 tx = _mm_mul_ps(fscal,dx00);
723 ty = _mm_mul_ps(fscal,dy00);
724 tz = _mm_mul_ps(fscal,dz00);
726 /* Update vectorial force */
727 fix0 = _mm_add_ps(fix0,tx);
728 fiy0 = _mm_add_ps(fiy0,ty);
729 fiz0 = _mm_add_ps(fiz0,tz);
731 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
732 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
733 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
734 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
735 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
739 /* Inner loop uses 57 flops */
742 /* End of innermost loop */
744 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
745 f+i_coord_offset,fshift+i_shift_offset);
747 /* Increment number of inner iterations */
748 inneriter += j_index_end - j_index_start;
750 /* Outer loop uses 6 flops */
753 /* Increment number of outer iterations */
756 /* Update outer/inner flops */
758 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*57);