2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse4_1_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomP1P1_VF_sse4_1_double
51 * Electrostatics interaction: Coulomb
52 * VdW interaction: LennardJones
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecCoul_VdwLJ_GeomP1P1_VF_sse4_1_double
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int j_coord_offsetA,j_coord_offsetB;
75 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
77 real *shiftvec,*fshift,*x,*f;
78 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
81 int vdwjidx0A,vdwjidx0B;
82 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
83 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
84 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
87 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
90 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
91 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
92 __m128d dummy_mask,cutoff_mask;
93 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
94 __m128d one = _mm_set1_pd(1.0);
95 __m128d two = _mm_set1_pd(2.0);
101 jindex = nlist->jindex;
103 shiftidx = nlist->shift;
105 shiftvec = fr->shift_vec[0];
106 fshift = fr->fshift[0];
107 facel = _mm_set1_pd(fr->ic->epsfac);
108 charge = mdatoms->chargeA;
109 nvdwtype = fr->ntype;
111 vdwtype = mdatoms->typeA;
113 /* Avoid stupid compiler warnings */
121 /* Start outer loop over neighborlists */
122 for(iidx=0; iidx<nri; iidx++)
124 /* Load shift vector for this list */
125 i_shift_offset = DIM*shiftidx[iidx];
127 /* Load limits for loop over neighbors */
128 j_index_start = jindex[iidx];
129 j_index_end = jindex[iidx+1];
131 /* Get outer coordinate index */
133 i_coord_offset = DIM*inr;
135 /* Load i particle coords and add shift vector */
136 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
138 fix0 = _mm_setzero_pd();
139 fiy0 = _mm_setzero_pd();
140 fiz0 = _mm_setzero_pd();
142 /* Load parameters for i particles */
143 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
144 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
146 /* Reset potential sums */
147 velecsum = _mm_setzero_pd();
148 vvdwsum = _mm_setzero_pd();
150 /* Start inner kernel loop */
151 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
154 /* Get j neighbor index, and coordinate index */
157 j_coord_offsetA = DIM*jnrA;
158 j_coord_offsetB = DIM*jnrB;
160 /* load j atom coordinates */
161 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
164 /* Calculate displacement vector */
165 dx00 = _mm_sub_pd(ix0,jx0);
166 dy00 = _mm_sub_pd(iy0,jy0);
167 dz00 = _mm_sub_pd(iz0,jz0);
169 /* Calculate squared distance and things based on it */
170 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
172 rinv00 = sse41_invsqrt_d(rsq00);
174 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
176 /* Load parameters for j particles */
177 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
178 vdwjidx0A = 2*vdwtype[jnrA+0];
179 vdwjidx0B = 2*vdwtype[jnrB+0];
181 /**************************
182 * CALCULATE INTERACTIONS *
183 **************************/
185 /* Compute parameters for interactions between i and j atoms */
186 qq00 = _mm_mul_pd(iq0,jq0);
187 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
188 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
190 /* COULOMB ELECTROSTATICS */
191 velec = _mm_mul_pd(qq00,rinv00);
192 felec = _mm_mul_pd(velec,rinvsq00);
194 /* LENNARD-JONES DISPERSION/REPULSION */
196 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
197 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
198 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
199 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
200 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
202 /* Update potential sum for this i atom from the interaction with this j atom. */
203 velecsum = _mm_add_pd(velecsum,velec);
204 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
206 fscal = _mm_add_pd(felec,fvdw);
208 /* Calculate temporary vectorial force */
209 tx = _mm_mul_pd(fscal,dx00);
210 ty = _mm_mul_pd(fscal,dy00);
211 tz = _mm_mul_pd(fscal,dz00);
213 /* Update vectorial force */
214 fix0 = _mm_add_pd(fix0,tx);
215 fiy0 = _mm_add_pd(fiy0,ty);
216 fiz0 = _mm_add_pd(fiz0,tz);
218 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
220 /* Inner loop uses 40 flops */
227 j_coord_offsetA = DIM*jnrA;
229 /* load j atom coordinates */
230 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
233 /* Calculate displacement vector */
234 dx00 = _mm_sub_pd(ix0,jx0);
235 dy00 = _mm_sub_pd(iy0,jy0);
236 dz00 = _mm_sub_pd(iz0,jz0);
238 /* Calculate squared distance and things based on it */
239 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
241 rinv00 = sse41_invsqrt_d(rsq00);
243 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
245 /* Load parameters for j particles */
246 jq0 = _mm_load_sd(charge+jnrA+0);
247 vdwjidx0A = 2*vdwtype[jnrA+0];
249 /**************************
250 * CALCULATE INTERACTIONS *
251 **************************/
253 /* Compute parameters for interactions between i and j atoms */
254 qq00 = _mm_mul_pd(iq0,jq0);
255 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
257 /* COULOMB ELECTROSTATICS */
258 velec = _mm_mul_pd(qq00,rinv00);
259 felec = _mm_mul_pd(velec,rinvsq00);
261 /* LENNARD-JONES DISPERSION/REPULSION */
263 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
264 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
265 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
266 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
267 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
269 /* Update potential sum for this i atom from the interaction with this j atom. */
270 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
271 velecsum = _mm_add_pd(velecsum,velec);
272 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
273 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
275 fscal = _mm_add_pd(felec,fvdw);
277 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
279 /* Calculate temporary vectorial force */
280 tx = _mm_mul_pd(fscal,dx00);
281 ty = _mm_mul_pd(fscal,dy00);
282 tz = _mm_mul_pd(fscal,dz00);
284 /* Update vectorial force */
285 fix0 = _mm_add_pd(fix0,tx);
286 fiy0 = _mm_add_pd(fiy0,ty);
287 fiz0 = _mm_add_pd(fiz0,tz);
289 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
291 /* Inner loop uses 40 flops */
294 /* End of innermost loop */
296 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
297 f+i_coord_offset,fshift+i_shift_offset);
300 /* Update potential energies */
301 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
302 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
304 /* Increment number of inner iterations */
305 inneriter += j_index_end - j_index_start;
307 /* Outer loop uses 9 flops */
310 /* Increment number of outer iterations */
313 /* Update outer/inner flops */
315 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*40);
318 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomP1P1_F_sse4_1_double
319 * Electrostatics interaction: Coulomb
320 * VdW interaction: LennardJones
321 * Geometry: Particle-Particle
322 * Calculate force/pot: Force
325 nb_kernel_ElecCoul_VdwLJ_GeomP1P1_F_sse4_1_double
326 (t_nblist * gmx_restrict nlist,
327 rvec * gmx_restrict xx,
328 rvec * gmx_restrict ff,
329 struct t_forcerec * gmx_restrict fr,
330 t_mdatoms * gmx_restrict mdatoms,
331 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
332 t_nrnb * gmx_restrict nrnb)
334 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
335 * just 0 for non-waters.
336 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
337 * jnr indices corresponding to data put in the four positions in the SIMD register.
339 int i_shift_offset,i_coord_offset,outeriter,inneriter;
340 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
342 int j_coord_offsetA,j_coord_offsetB;
343 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
345 real *shiftvec,*fshift,*x,*f;
346 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
348 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
349 int vdwjidx0A,vdwjidx0B;
350 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
351 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
352 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
355 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
358 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
359 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
360 __m128d dummy_mask,cutoff_mask;
361 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
362 __m128d one = _mm_set1_pd(1.0);
363 __m128d two = _mm_set1_pd(2.0);
369 jindex = nlist->jindex;
371 shiftidx = nlist->shift;
373 shiftvec = fr->shift_vec[0];
374 fshift = fr->fshift[0];
375 facel = _mm_set1_pd(fr->ic->epsfac);
376 charge = mdatoms->chargeA;
377 nvdwtype = fr->ntype;
379 vdwtype = mdatoms->typeA;
381 /* Avoid stupid compiler warnings */
389 /* Start outer loop over neighborlists */
390 for(iidx=0; iidx<nri; iidx++)
392 /* Load shift vector for this list */
393 i_shift_offset = DIM*shiftidx[iidx];
395 /* Load limits for loop over neighbors */
396 j_index_start = jindex[iidx];
397 j_index_end = jindex[iidx+1];
399 /* Get outer coordinate index */
401 i_coord_offset = DIM*inr;
403 /* Load i particle coords and add shift vector */
404 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
406 fix0 = _mm_setzero_pd();
407 fiy0 = _mm_setzero_pd();
408 fiz0 = _mm_setzero_pd();
410 /* Load parameters for i particles */
411 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
412 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
414 /* Start inner kernel loop */
415 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
418 /* Get j neighbor index, and coordinate index */
421 j_coord_offsetA = DIM*jnrA;
422 j_coord_offsetB = DIM*jnrB;
424 /* load j atom coordinates */
425 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
428 /* Calculate displacement vector */
429 dx00 = _mm_sub_pd(ix0,jx0);
430 dy00 = _mm_sub_pd(iy0,jy0);
431 dz00 = _mm_sub_pd(iz0,jz0);
433 /* Calculate squared distance and things based on it */
434 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
436 rinv00 = sse41_invsqrt_d(rsq00);
438 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
440 /* Load parameters for j particles */
441 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
442 vdwjidx0A = 2*vdwtype[jnrA+0];
443 vdwjidx0B = 2*vdwtype[jnrB+0];
445 /**************************
446 * CALCULATE INTERACTIONS *
447 **************************/
449 /* Compute parameters for interactions between i and j atoms */
450 qq00 = _mm_mul_pd(iq0,jq0);
451 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
452 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
454 /* COULOMB ELECTROSTATICS */
455 velec = _mm_mul_pd(qq00,rinv00);
456 felec = _mm_mul_pd(velec,rinvsq00);
458 /* LENNARD-JONES DISPERSION/REPULSION */
460 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
461 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
463 fscal = _mm_add_pd(felec,fvdw);
465 /* Calculate temporary vectorial force */
466 tx = _mm_mul_pd(fscal,dx00);
467 ty = _mm_mul_pd(fscal,dy00);
468 tz = _mm_mul_pd(fscal,dz00);
470 /* Update vectorial force */
471 fix0 = _mm_add_pd(fix0,tx);
472 fiy0 = _mm_add_pd(fiy0,ty);
473 fiz0 = _mm_add_pd(fiz0,tz);
475 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
477 /* Inner loop uses 34 flops */
484 j_coord_offsetA = DIM*jnrA;
486 /* load j atom coordinates */
487 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
490 /* Calculate displacement vector */
491 dx00 = _mm_sub_pd(ix0,jx0);
492 dy00 = _mm_sub_pd(iy0,jy0);
493 dz00 = _mm_sub_pd(iz0,jz0);
495 /* Calculate squared distance and things based on it */
496 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
498 rinv00 = sse41_invsqrt_d(rsq00);
500 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
502 /* Load parameters for j particles */
503 jq0 = _mm_load_sd(charge+jnrA+0);
504 vdwjidx0A = 2*vdwtype[jnrA+0];
506 /**************************
507 * CALCULATE INTERACTIONS *
508 **************************/
510 /* Compute parameters for interactions between i and j atoms */
511 qq00 = _mm_mul_pd(iq0,jq0);
512 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
514 /* COULOMB ELECTROSTATICS */
515 velec = _mm_mul_pd(qq00,rinv00);
516 felec = _mm_mul_pd(velec,rinvsq00);
518 /* LENNARD-JONES DISPERSION/REPULSION */
520 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
521 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
523 fscal = _mm_add_pd(felec,fvdw);
525 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
527 /* Calculate temporary vectorial force */
528 tx = _mm_mul_pd(fscal,dx00);
529 ty = _mm_mul_pd(fscal,dy00);
530 tz = _mm_mul_pd(fscal,dz00);
532 /* Update vectorial force */
533 fix0 = _mm_add_pd(fix0,tx);
534 fiy0 = _mm_add_pd(fiy0,ty);
535 fiz0 = _mm_add_pd(fiz0,tz);
537 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
539 /* Inner loop uses 34 flops */
542 /* End of innermost loop */
544 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
545 f+i_coord_offset,fshift+i_shift_offset);
547 /* Increment number of inner iterations */
548 inneriter += j_index_end - j_index_start;
550 /* Outer loop uses 7 flops */
553 /* Increment number of outer iterations */
556 /* Update outer/inner flops */
558 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*34);