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 sse4_1_double kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_sse4_1_double.h"
48 #include "kernelutil_x86_sse4_1_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSh_GeomP1P1_VF_sse4_1_double
52 * Electrostatics interaction: None
53 * VdW interaction: LennardJones
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_VF_sse4_1_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82 int vdwjidx0A,vdwjidx0B;
83 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
84 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
86 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
89 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
90 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
91 __m128d dummy_mask,cutoff_mask;
92 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
93 __m128d one = _mm_set1_pd(1.0);
94 __m128d two = _mm_set1_pd(2.0);
100 jindex = nlist->jindex;
102 shiftidx = nlist->shift;
104 shiftvec = fr->shift_vec[0];
105 fshift = fr->fshift[0];
106 nvdwtype = fr->ntype;
108 vdwtype = mdatoms->typeA;
110 rcutoff_scalar = fr->rvdw;
111 rcutoff = _mm_set1_pd(rcutoff_scalar);
112 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
114 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
115 rvdw = _mm_set1_pd(fr->rvdw);
117 /* Avoid stupid compiler warnings */
125 /* Start outer loop over neighborlists */
126 for(iidx=0; iidx<nri; iidx++)
128 /* Load shift vector for this list */
129 i_shift_offset = DIM*shiftidx[iidx];
131 /* Load limits for loop over neighbors */
132 j_index_start = jindex[iidx];
133 j_index_end = jindex[iidx+1];
135 /* Get outer coordinate index */
137 i_coord_offset = DIM*inr;
139 /* Load i particle coords and add shift vector */
140 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
142 fix0 = _mm_setzero_pd();
143 fiy0 = _mm_setzero_pd();
144 fiz0 = _mm_setzero_pd();
146 /* Load parameters for i particles */
147 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
149 /* Reset potential sums */
150 vvdwsum = _mm_setzero_pd();
152 /* Start inner kernel loop */
153 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
156 /* Get j neighbor index, and coordinate index */
159 j_coord_offsetA = DIM*jnrA;
160 j_coord_offsetB = DIM*jnrB;
162 /* load j atom coordinates */
163 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
166 /* Calculate displacement vector */
167 dx00 = _mm_sub_pd(ix0,jx0);
168 dy00 = _mm_sub_pd(iy0,jy0);
169 dz00 = _mm_sub_pd(iz0,jz0);
171 /* Calculate squared distance and things based on it */
172 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
174 rinvsq00 = gmx_mm_inv_pd(rsq00);
176 /* Load parameters for j particles */
177 vdwjidx0A = 2*vdwtype[jnrA+0];
178 vdwjidx0B = 2*vdwtype[jnrB+0];
180 /**************************
181 * CALCULATE INTERACTIONS *
182 **************************/
184 if (gmx_mm_any_lt(rsq00,rcutoff2))
187 /* Compute parameters for interactions between i and j atoms */
188 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
189 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
191 /* LENNARD-JONES DISPERSION/REPULSION */
193 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
194 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
195 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
196 vvdw = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
197 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
198 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
200 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
202 /* Update potential sum for this i atom from the interaction with this j atom. */
203 vvdw = _mm_and_pd(vvdw,cutoff_mask);
204 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
208 fscal = _mm_and_pd(fscal,cutoff_mask);
210 /* Calculate temporary vectorial force */
211 tx = _mm_mul_pd(fscal,dx00);
212 ty = _mm_mul_pd(fscal,dy00);
213 tz = _mm_mul_pd(fscal,dz00);
215 /* Update vectorial force */
216 fix0 = _mm_add_pd(fix0,tx);
217 fiy0 = _mm_add_pd(fiy0,ty);
218 fiz0 = _mm_add_pd(fiz0,tz);
220 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
224 /* Inner loop uses 41 flops */
231 j_coord_offsetA = DIM*jnrA;
233 /* load j atom coordinates */
234 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
237 /* Calculate displacement vector */
238 dx00 = _mm_sub_pd(ix0,jx0);
239 dy00 = _mm_sub_pd(iy0,jy0);
240 dz00 = _mm_sub_pd(iz0,jz0);
242 /* Calculate squared distance and things based on it */
243 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
245 rinvsq00 = gmx_mm_inv_pd(rsq00);
247 /* Load parameters for j particles */
248 vdwjidx0A = 2*vdwtype[jnrA+0];
250 /**************************
251 * CALCULATE INTERACTIONS *
252 **************************/
254 if (gmx_mm_any_lt(rsq00,rcutoff2))
257 /* Compute parameters for interactions between i and j atoms */
258 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
260 /* LENNARD-JONES DISPERSION/REPULSION */
262 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
263 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
264 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
265 vvdw = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
266 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
267 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
269 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
271 /* Update potential sum for this i atom from the interaction with this j atom. */
272 vvdw = _mm_and_pd(vvdw,cutoff_mask);
273 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
274 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
278 fscal = _mm_and_pd(fscal,cutoff_mask);
280 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
282 /* Calculate temporary vectorial force */
283 tx = _mm_mul_pd(fscal,dx00);
284 ty = _mm_mul_pd(fscal,dy00);
285 tz = _mm_mul_pd(fscal,dz00);
287 /* Update vectorial force */
288 fix0 = _mm_add_pd(fix0,tx);
289 fiy0 = _mm_add_pd(fiy0,ty);
290 fiz0 = _mm_add_pd(fiz0,tz);
292 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
296 /* Inner loop uses 41 flops */
299 /* End of innermost loop */
301 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
302 f+i_coord_offset,fshift+i_shift_offset);
305 /* Update potential energies */
306 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
308 /* Increment number of inner iterations */
309 inneriter += j_index_end - j_index_start;
311 /* Outer loop uses 7 flops */
314 /* Increment number of outer iterations */
317 /* Update outer/inner flops */
319 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*41);
322 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_sse4_1_double
323 * Electrostatics interaction: None
324 * VdW interaction: LennardJones
325 * Geometry: Particle-Particle
326 * Calculate force/pot: Force
329 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_sse4_1_double
330 (t_nblist * gmx_restrict nlist,
331 rvec * gmx_restrict xx,
332 rvec * gmx_restrict ff,
333 t_forcerec * gmx_restrict fr,
334 t_mdatoms * gmx_restrict mdatoms,
335 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
336 t_nrnb * gmx_restrict nrnb)
338 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
339 * just 0 for non-waters.
340 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
341 * jnr indices corresponding to data put in the four positions in the SIMD register.
343 int i_shift_offset,i_coord_offset,outeriter,inneriter;
344 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
346 int j_coord_offsetA,j_coord_offsetB;
347 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
349 real *shiftvec,*fshift,*x,*f;
350 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
352 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
353 int vdwjidx0A,vdwjidx0B;
354 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
355 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
357 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
360 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
361 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
362 __m128d dummy_mask,cutoff_mask;
363 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
364 __m128d one = _mm_set1_pd(1.0);
365 __m128d two = _mm_set1_pd(2.0);
371 jindex = nlist->jindex;
373 shiftidx = nlist->shift;
375 shiftvec = fr->shift_vec[0];
376 fshift = fr->fshift[0];
377 nvdwtype = fr->ntype;
379 vdwtype = mdatoms->typeA;
381 rcutoff_scalar = fr->rvdw;
382 rcutoff = _mm_set1_pd(rcutoff_scalar);
383 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
385 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
386 rvdw = _mm_set1_pd(fr->rvdw);
388 /* Avoid stupid compiler warnings */
396 /* Start outer loop over neighborlists */
397 for(iidx=0; iidx<nri; iidx++)
399 /* Load shift vector for this list */
400 i_shift_offset = DIM*shiftidx[iidx];
402 /* Load limits for loop over neighbors */
403 j_index_start = jindex[iidx];
404 j_index_end = jindex[iidx+1];
406 /* Get outer coordinate index */
408 i_coord_offset = DIM*inr;
410 /* Load i particle coords and add shift vector */
411 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
413 fix0 = _mm_setzero_pd();
414 fiy0 = _mm_setzero_pd();
415 fiz0 = _mm_setzero_pd();
417 /* Load parameters for i particles */
418 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
420 /* Start inner kernel loop */
421 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
424 /* Get j neighbor index, and coordinate index */
427 j_coord_offsetA = DIM*jnrA;
428 j_coord_offsetB = DIM*jnrB;
430 /* load j atom coordinates */
431 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
434 /* Calculate displacement vector */
435 dx00 = _mm_sub_pd(ix0,jx0);
436 dy00 = _mm_sub_pd(iy0,jy0);
437 dz00 = _mm_sub_pd(iz0,jz0);
439 /* Calculate squared distance and things based on it */
440 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
442 rinvsq00 = gmx_mm_inv_pd(rsq00);
444 /* Load parameters for j particles */
445 vdwjidx0A = 2*vdwtype[jnrA+0];
446 vdwjidx0B = 2*vdwtype[jnrB+0];
448 /**************************
449 * CALCULATE INTERACTIONS *
450 **************************/
452 if (gmx_mm_any_lt(rsq00,rcutoff2))
455 /* Compute parameters for interactions between i and j atoms */
456 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
457 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
459 /* LENNARD-JONES DISPERSION/REPULSION */
461 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
462 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
464 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
468 fscal = _mm_and_pd(fscal,cutoff_mask);
470 /* Calculate temporary vectorial force */
471 tx = _mm_mul_pd(fscal,dx00);
472 ty = _mm_mul_pd(fscal,dy00);
473 tz = _mm_mul_pd(fscal,dz00);
475 /* Update vectorial force */
476 fix0 = _mm_add_pd(fix0,tx);
477 fiy0 = _mm_add_pd(fiy0,ty);
478 fiz0 = _mm_add_pd(fiz0,tz);
480 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
484 /* Inner loop uses 30 flops */
491 j_coord_offsetA = DIM*jnrA;
493 /* load j atom coordinates */
494 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
497 /* Calculate displacement vector */
498 dx00 = _mm_sub_pd(ix0,jx0);
499 dy00 = _mm_sub_pd(iy0,jy0);
500 dz00 = _mm_sub_pd(iz0,jz0);
502 /* Calculate squared distance and things based on it */
503 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
505 rinvsq00 = gmx_mm_inv_pd(rsq00);
507 /* Load parameters for j particles */
508 vdwjidx0A = 2*vdwtype[jnrA+0];
510 /**************************
511 * CALCULATE INTERACTIONS *
512 **************************/
514 if (gmx_mm_any_lt(rsq00,rcutoff2))
517 /* Compute parameters for interactions between i and j atoms */
518 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
520 /* LENNARD-JONES DISPERSION/REPULSION */
522 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
523 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
525 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
529 fscal = _mm_and_pd(fscal,cutoff_mask);
531 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
533 /* Calculate temporary vectorial force */
534 tx = _mm_mul_pd(fscal,dx00);
535 ty = _mm_mul_pd(fscal,dy00);
536 tz = _mm_mul_pd(fscal,dz00);
538 /* Update vectorial force */
539 fix0 = _mm_add_pd(fix0,tx);
540 fiy0 = _mm_add_pd(fiy0,ty);
541 fiz0 = _mm_add_pd(fiz0,tz);
543 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
547 /* Inner loop uses 30 flops */
550 /* End of innermost loop */
552 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
553 f+i_coord_offset,fshift+i_shift_offset);
555 /* Increment number of inner iterations */
556 inneriter += j_index_end - j_index_start;
558 /* Outer loop uses 6 flops */
561 /* Increment number of outer iterations */
564 /* Update outer/inner flops */
566 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*30);