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 sse2_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_sse2_single.h"
48 #include "kernelutil_x86_sse2_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSw_GeomP1P1_VF_sse2_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_sse2_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 SSE, 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 tx,ty,tz,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_sub_ps( _mm_mul_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_add_ps(swV3,_mm_mul_ps(d,_mm_add_ps(swV4,_mm_mul_ps(d,swV5)))))));
239 dsw = _mm_mul_ps(d2,_mm_add_ps(swF2,_mm_mul_ps(d,_mm_add_ps(swF3,_mm_mul_ps(d,swF4)))));
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_sub_ps( _mm_mul_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 /* Calculate temporary vectorial force */
256 tx = _mm_mul_ps(fscal,dx00);
257 ty = _mm_mul_ps(fscal,dy00);
258 tz = _mm_mul_ps(fscal,dz00);
260 /* Update vectorial force */
261 fix0 = _mm_add_ps(fix0,tx);
262 fiy0 = _mm_add_ps(fiy0,ty);
263 fiz0 = _mm_add_ps(fiz0,tz);
265 fjptrA = f+j_coord_offsetA;
266 fjptrB = f+j_coord_offsetB;
267 fjptrC = f+j_coord_offsetC;
268 fjptrD = f+j_coord_offsetD;
269 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
273 /* Inner loop uses 59 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_sub_ps( _mm_mul_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_add_ps(swV3,_mm_mul_ps(d,_mm_add_ps(swV4,_mm_mul_ps(d,swV5)))))));
351 dsw = _mm_mul_ps(d2,_mm_add_ps(swF2,_mm_mul_ps(d,_mm_add_ps(swF3,_mm_mul_ps(d,swF4)))));
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_sub_ps( _mm_mul_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 /* Calculate temporary vectorial force */
371 tx = _mm_mul_ps(fscal,dx00);
372 ty = _mm_mul_ps(fscal,dy00);
373 tz = _mm_mul_ps(fscal,dz00);
375 /* Update vectorial force */
376 fix0 = _mm_add_ps(fix0,tx);
377 fiy0 = _mm_add_ps(fiy0,ty);
378 fiz0 = _mm_add_ps(fiz0,tz);
380 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
381 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
382 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
383 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
384 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
388 /* Inner loop uses 60 flops */
391 /* End of innermost loop */
393 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
394 f+i_coord_offset,fshift+i_shift_offset);
397 /* Update potential energies */
398 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
400 /* Increment number of inner iterations */
401 inneriter += j_index_end - j_index_start;
403 /* Outer loop uses 7 flops */
406 /* Increment number of outer iterations */
409 /* Update outer/inner flops */
411 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*60);
414 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_sse2_single
415 * Electrostatics interaction: None
416 * VdW interaction: LennardJones
417 * Geometry: Particle-Particle
418 * Calculate force/pot: Force
421 nb_kernel_ElecNone_VdwLJSw_GeomP1P1_F_sse2_single
422 (t_nblist * gmx_restrict nlist,
423 rvec * gmx_restrict xx,
424 rvec * gmx_restrict ff,
425 t_forcerec * gmx_restrict fr,
426 t_mdatoms * gmx_restrict mdatoms,
427 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
428 t_nrnb * gmx_restrict nrnb)
430 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
431 * just 0 for non-waters.
432 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
433 * jnr indices corresponding to data put in the four positions in the SIMD register.
435 int i_shift_offset,i_coord_offset,outeriter,inneriter;
436 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
437 int jnrA,jnrB,jnrC,jnrD;
438 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
439 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
440 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
442 real *shiftvec,*fshift,*x,*f;
443 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
445 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
447 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
448 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
449 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
450 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
452 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
455 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
456 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
457 __m128 rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
458 real rswitch_scalar,d_scalar;
459 __m128 dummy_mask,cutoff_mask;
460 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
461 __m128 one = _mm_set1_ps(1.0);
462 __m128 two = _mm_set1_ps(2.0);
468 jindex = nlist->jindex;
470 shiftidx = nlist->shift;
472 shiftvec = fr->shift_vec[0];
473 fshift = fr->fshift[0];
474 nvdwtype = fr->ntype;
476 vdwtype = mdatoms->typeA;
478 rcutoff_scalar = fr->rvdw;
479 rcutoff = _mm_set1_ps(rcutoff_scalar);
480 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
482 rswitch_scalar = fr->rvdw_switch;
483 rswitch = _mm_set1_ps(rswitch_scalar);
484 /* Setup switch parameters */
485 d_scalar = rcutoff_scalar-rswitch_scalar;
486 d = _mm_set1_ps(d_scalar);
487 swV3 = _mm_set1_ps(-10.0/(d_scalar*d_scalar*d_scalar));
488 swV4 = _mm_set1_ps( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
489 swV5 = _mm_set1_ps( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
490 swF2 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar));
491 swF3 = _mm_set1_ps( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
492 swF4 = _mm_set1_ps(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
494 /* Avoid stupid compiler warnings */
495 jnrA = jnrB = jnrC = jnrD = 0;
504 for(iidx=0;iidx<4*DIM;iidx++)
509 /* Start outer loop over neighborlists */
510 for(iidx=0; iidx<nri; iidx++)
512 /* Load shift vector for this list */
513 i_shift_offset = DIM*shiftidx[iidx];
515 /* Load limits for loop over neighbors */
516 j_index_start = jindex[iidx];
517 j_index_end = jindex[iidx+1];
519 /* Get outer coordinate index */
521 i_coord_offset = DIM*inr;
523 /* Load i particle coords and add shift vector */
524 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
526 fix0 = _mm_setzero_ps();
527 fiy0 = _mm_setzero_ps();
528 fiz0 = _mm_setzero_ps();
530 /* Load parameters for i particles */
531 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
533 /* Start inner kernel loop */
534 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
537 /* Get j neighbor index, and coordinate index */
542 j_coord_offsetA = DIM*jnrA;
543 j_coord_offsetB = DIM*jnrB;
544 j_coord_offsetC = DIM*jnrC;
545 j_coord_offsetD = DIM*jnrD;
547 /* load j atom coordinates */
548 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
549 x+j_coord_offsetC,x+j_coord_offsetD,
552 /* Calculate displacement vector */
553 dx00 = _mm_sub_ps(ix0,jx0);
554 dy00 = _mm_sub_ps(iy0,jy0);
555 dz00 = _mm_sub_ps(iz0,jz0);
557 /* Calculate squared distance and things based on it */
558 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
560 rinv00 = gmx_mm_invsqrt_ps(rsq00);
562 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
564 /* Load parameters for j particles */
565 vdwjidx0A = 2*vdwtype[jnrA+0];
566 vdwjidx0B = 2*vdwtype[jnrB+0];
567 vdwjidx0C = 2*vdwtype[jnrC+0];
568 vdwjidx0D = 2*vdwtype[jnrD+0];
570 /**************************
571 * CALCULATE INTERACTIONS *
572 **************************/
574 if (gmx_mm_any_lt(rsq00,rcutoff2))
577 r00 = _mm_mul_ps(rsq00,rinv00);
579 /* Compute parameters for interactions between i and j atoms */
580 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
581 vdwparam+vdwioffset0+vdwjidx0B,
582 vdwparam+vdwioffset0+vdwjidx0C,
583 vdwparam+vdwioffset0+vdwjidx0D,
586 /* LENNARD-JONES DISPERSION/REPULSION */
588 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
589 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
590 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
591 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
592 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
594 d = _mm_sub_ps(r00,rswitch);
595 d = _mm_max_ps(d,_mm_setzero_ps());
596 d2 = _mm_mul_ps(d,d);
597 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)))))));
599 dsw = _mm_mul_ps(d2,_mm_add_ps(swF2,_mm_mul_ps(d,_mm_add_ps(swF3,_mm_mul_ps(d,swF4)))));
601 /* Evaluate switch function */
602 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
603 fvdw = _mm_sub_ps( _mm_mul_ps(fvdw,sw) , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
604 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
608 fscal = _mm_and_ps(fscal,cutoff_mask);
610 /* Calculate temporary vectorial force */
611 tx = _mm_mul_ps(fscal,dx00);
612 ty = _mm_mul_ps(fscal,dy00);
613 tz = _mm_mul_ps(fscal,dz00);
615 /* Update vectorial force */
616 fix0 = _mm_add_ps(fix0,tx);
617 fiy0 = _mm_add_ps(fiy0,ty);
618 fiz0 = _mm_add_ps(fiz0,tz);
620 fjptrA = f+j_coord_offsetA;
621 fjptrB = f+j_coord_offsetB;
622 fjptrC = f+j_coord_offsetC;
623 fjptrD = f+j_coord_offsetD;
624 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
628 /* Inner loop uses 56 flops */
634 /* Get j neighbor index, and coordinate index */
635 jnrlistA = jjnr[jidx];
636 jnrlistB = jjnr[jidx+1];
637 jnrlistC = jjnr[jidx+2];
638 jnrlistD = jjnr[jidx+3];
639 /* Sign of each element will be negative for non-real atoms.
640 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
641 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
643 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
644 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
645 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
646 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
647 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
648 j_coord_offsetA = DIM*jnrA;
649 j_coord_offsetB = DIM*jnrB;
650 j_coord_offsetC = DIM*jnrC;
651 j_coord_offsetD = DIM*jnrD;
653 /* load j atom coordinates */
654 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
655 x+j_coord_offsetC,x+j_coord_offsetD,
658 /* Calculate displacement vector */
659 dx00 = _mm_sub_ps(ix0,jx0);
660 dy00 = _mm_sub_ps(iy0,jy0);
661 dz00 = _mm_sub_ps(iz0,jz0);
663 /* Calculate squared distance and things based on it */
664 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
666 rinv00 = gmx_mm_invsqrt_ps(rsq00);
668 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
670 /* Load parameters for j particles */
671 vdwjidx0A = 2*vdwtype[jnrA+0];
672 vdwjidx0B = 2*vdwtype[jnrB+0];
673 vdwjidx0C = 2*vdwtype[jnrC+0];
674 vdwjidx0D = 2*vdwtype[jnrD+0];
676 /**************************
677 * CALCULATE INTERACTIONS *
678 **************************/
680 if (gmx_mm_any_lt(rsq00,rcutoff2))
683 r00 = _mm_mul_ps(rsq00,rinv00);
684 r00 = _mm_andnot_ps(dummy_mask,r00);
686 /* Compute parameters for interactions between i and j atoms */
687 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
688 vdwparam+vdwioffset0+vdwjidx0B,
689 vdwparam+vdwioffset0+vdwjidx0C,
690 vdwparam+vdwioffset0+vdwjidx0D,
693 /* LENNARD-JONES DISPERSION/REPULSION */
695 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
696 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
697 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
698 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
699 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
701 d = _mm_sub_ps(r00,rswitch);
702 d = _mm_max_ps(d,_mm_setzero_ps());
703 d2 = _mm_mul_ps(d,d);
704 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)))))));
706 dsw = _mm_mul_ps(d2,_mm_add_ps(swF2,_mm_mul_ps(d,_mm_add_ps(swF3,_mm_mul_ps(d,swF4)))));
708 /* Evaluate switch function */
709 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
710 fvdw = _mm_sub_ps( _mm_mul_ps(fvdw,sw) , _mm_mul_ps(rinv00,_mm_mul_ps(vvdw,dsw)) );
711 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
715 fscal = _mm_and_ps(fscal,cutoff_mask);
717 fscal = _mm_andnot_ps(dummy_mask,fscal);
719 /* Calculate temporary vectorial force */
720 tx = _mm_mul_ps(fscal,dx00);
721 ty = _mm_mul_ps(fscal,dy00);
722 tz = _mm_mul_ps(fscal,dz00);
724 /* Update vectorial force */
725 fix0 = _mm_add_ps(fix0,tx);
726 fiy0 = _mm_add_ps(fiy0,ty);
727 fiz0 = _mm_add_ps(fiz0,tz);
729 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
730 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
731 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
732 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
733 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
737 /* Inner loop uses 57 flops */
740 /* End of innermost loop */
742 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
743 f+i_coord_offset,fshift+i_shift_offset);
745 /* Increment number of inner iterations */
746 inneriter += j_index_end - j_index_start;
748 /* Outer loop uses 6 flops */
751 /* Increment number of outer iterations */
754 /* Update outer/inner flops */
756 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*57);