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_double kernel generator.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
47 #include "gromacs/simd/math_x86_sse2_double.h"
48 #include "kernelutil_x86_sse2_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomP1P1_VF_sse2_double
52 * Electrostatics interaction: Coulomb
53 * VdW interaction: LennardJones
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCoul_VdwLJ_GeomP1P1_VF_sse2_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;
85 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
88 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
91 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
92 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
93 __m128d dummy_mask,cutoff_mask;
94 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
95 __m128d one = _mm_set1_pd(1.0);
96 __m128d two = _mm_set1_pd(2.0);
102 jindex = nlist->jindex;
104 shiftidx = nlist->shift;
106 shiftvec = fr->shift_vec[0];
107 fshift = fr->fshift[0];
108 facel = _mm_set1_pd(fr->epsfac);
109 charge = mdatoms->chargeA;
110 nvdwtype = fr->ntype;
112 vdwtype = mdatoms->typeA;
114 /* Avoid stupid compiler warnings */
122 /* Start outer loop over neighborlists */
123 for(iidx=0; iidx<nri; iidx++)
125 /* Load shift vector for this list */
126 i_shift_offset = DIM*shiftidx[iidx];
128 /* Load limits for loop over neighbors */
129 j_index_start = jindex[iidx];
130 j_index_end = jindex[iidx+1];
132 /* Get outer coordinate index */
134 i_coord_offset = DIM*inr;
136 /* Load i particle coords and add shift vector */
137 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
139 fix0 = _mm_setzero_pd();
140 fiy0 = _mm_setzero_pd();
141 fiz0 = _mm_setzero_pd();
143 /* Load parameters for i particles */
144 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
145 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
147 /* Reset potential sums */
148 velecsum = _mm_setzero_pd();
149 vvdwsum = _mm_setzero_pd();
151 /* Start inner kernel loop */
152 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
155 /* Get j neighbor index, and coordinate index */
158 j_coord_offsetA = DIM*jnrA;
159 j_coord_offsetB = DIM*jnrB;
161 /* load j atom coordinates */
162 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
165 /* Calculate displacement vector */
166 dx00 = _mm_sub_pd(ix0,jx0);
167 dy00 = _mm_sub_pd(iy0,jy0);
168 dz00 = _mm_sub_pd(iz0,jz0);
170 /* Calculate squared distance and things based on it */
171 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
173 rinv00 = gmx_mm_invsqrt_pd(rsq00);
175 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
177 /* Load parameters for j particles */
178 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
179 vdwjidx0A = 2*vdwtype[jnrA+0];
180 vdwjidx0B = 2*vdwtype[jnrB+0];
182 /**************************
183 * CALCULATE INTERACTIONS *
184 **************************/
186 /* Compute parameters for interactions between i and j atoms */
187 qq00 = _mm_mul_pd(iq0,jq0);
188 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
189 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
191 /* COULOMB ELECTROSTATICS */
192 velec = _mm_mul_pd(qq00,rinv00);
193 felec = _mm_mul_pd(velec,rinvsq00);
195 /* LENNARD-JONES DISPERSION/REPULSION */
197 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
198 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
199 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
200 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
201 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
203 /* Update potential sum for this i atom from the interaction with this j atom. */
204 velecsum = _mm_add_pd(velecsum,velec);
205 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
207 fscal = _mm_add_pd(felec,fvdw);
209 /* Calculate temporary vectorial force */
210 tx = _mm_mul_pd(fscal,dx00);
211 ty = _mm_mul_pd(fscal,dy00);
212 tz = _mm_mul_pd(fscal,dz00);
214 /* Update vectorial force */
215 fix0 = _mm_add_pd(fix0,tx);
216 fiy0 = _mm_add_pd(fiy0,ty);
217 fiz0 = _mm_add_pd(fiz0,tz);
219 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
221 /* Inner loop uses 40 flops */
228 j_coord_offsetA = DIM*jnrA;
230 /* load j atom coordinates */
231 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
234 /* Calculate displacement vector */
235 dx00 = _mm_sub_pd(ix0,jx0);
236 dy00 = _mm_sub_pd(iy0,jy0);
237 dz00 = _mm_sub_pd(iz0,jz0);
239 /* Calculate squared distance and things based on it */
240 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
242 rinv00 = gmx_mm_invsqrt_pd(rsq00);
244 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
246 /* Load parameters for j particles */
247 jq0 = _mm_load_sd(charge+jnrA+0);
248 vdwjidx0A = 2*vdwtype[jnrA+0];
250 /**************************
251 * CALCULATE INTERACTIONS *
252 **************************/
254 /* Compute parameters for interactions between i and j atoms */
255 qq00 = _mm_mul_pd(iq0,jq0);
256 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
258 /* COULOMB ELECTROSTATICS */
259 velec = _mm_mul_pd(qq00,rinv00);
260 felec = _mm_mul_pd(velec,rinvsq00);
262 /* LENNARD-JONES DISPERSION/REPULSION */
264 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
265 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
266 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
267 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
268 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
270 /* Update potential sum for this i atom from the interaction with this j atom. */
271 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
272 velecsum = _mm_add_pd(velecsum,velec);
273 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
274 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
276 fscal = _mm_add_pd(felec,fvdw);
278 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
280 /* Calculate temporary vectorial force */
281 tx = _mm_mul_pd(fscal,dx00);
282 ty = _mm_mul_pd(fscal,dy00);
283 tz = _mm_mul_pd(fscal,dz00);
285 /* Update vectorial force */
286 fix0 = _mm_add_pd(fix0,tx);
287 fiy0 = _mm_add_pd(fiy0,ty);
288 fiz0 = _mm_add_pd(fiz0,tz);
290 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
292 /* Inner loop uses 40 flops */
295 /* End of innermost loop */
297 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
298 f+i_coord_offset,fshift+i_shift_offset);
301 /* Update potential energies */
302 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
303 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
305 /* Increment number of inner iterations */
306 inneriter += j_index_end - j_index_start;
308 /* Outer loop uses 9 flops */
311 /* Increment number of outer iterations */
314 /* Update outer/inner flops */
316 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*40);
319 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomP1P1_F_sse2_double
320 * Electrostatics interaction: Coulomb
321 * VdW interaction: LennardJones
322 * Geometry: Particle-Particle
323 * Calculate force/pot: Force
326 nb_kernel_ElecCoul_VdwLJ_GeomP1P1_F_sse2_double
327 (t_nblist * gmx_restrict nlist,
328 rvec * gmx_restrict xx,
329 rvec * gmx_restrict ff,
330 t_forcerec * gmx_restrict fr,
331 t_mdatoms * gmx_restrict mdatoms,
332 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
333 t_nrnb * gmx_restrict nrnb)
335 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
336 * just 0 for non-waters.
337 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
338 * jnr indices corresponding to data put in the four positions in the SIMD register.
340 int i_shift_offset,i_coord_offset,outeriter,inneriter;
341 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
343 int j_coord_offsetA,j_coord_offsetB;
344 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
346 real *shiftvec,*fshift,*x,*f;
347 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
349 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
350 int vdwjidx0A,vdwjidx0B;
351 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
352 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
353 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
356 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
359 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
360 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
361 __m128d dummy_mask,cutoff_mask;
362 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
363 __m128d one = _mm_set1_pd(1.0);
364 __m128d two = _mm_set1_pd(2.0);
370 jindex = nlist->jindex;
372 shiftidx = nlist->shift;
374 shiftvec = fr->shift_vec[0];
375 fshift = fr->fshift[0];
376 facel = _mm_set1_pd(fr->epsfac);
377 charge = mdatoms->chargeA;
378 nvdwtype = fr->ntype;
380 vdwtype = mdatoms->typeA;
382 /* Avoid stupid compiler warnings */
390 /* Start outer loop over neighborlists */
391 for(iidx=0; iidx<nri; iidx++)
393 /* Load shift vector for this list */
394 i_shift_offset = DIM*shiftidx[iidx];
396 /* Load limits for loop over neighbors */
397 j_index_start = jindex[iidx];
398 j_index_end = jindex[iidx+1];
400 /* Get outer coordinate index */
402 i_coord_offset = DIM*inr;
404 /* Load i particle coords and add shift vector */
405 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
407 fix0 = _mm_setzero_pd();
408 fiy0 = _mm_setzero_pd();
409 fiz0 = _mm_setzero_pd();
411 /* Load parameters for i particles */
412 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
413 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
415 /* Start inner kernel loop */
416 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
419 /* Get j neighbor index, and coordinate index */
422 j_coord_offsetA = DIM*jnrA;
423 j_coord_offsetB = DIM*jnrB;
425 /* load j atom coordinates */
426 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
429 /* Calculate displacement vector */
430 dx00 = _mm_sub_pd(ix0,jx0);
431 dy00 = _mm_sub_pd(iy0,jy0);
432 dz00 = _mm_sub_pd(iz0,jz0);
434 /* Calculate squared distance and things based on it */
435 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
437 rinv00 = gmx_mm_invsqrt_pd(rsq00);
439 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
441 /* Load parameters for j particles */
442 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
443 vdwjidx0A = 2*vdwtype[jnrA+0];
444 vdwjidx0B = 2*vdwtype[jnrB+0];
446 /**************************
447 * CALCULATE INTERACTIONS *
448 **************************/
450 /* Compute parameters for interactions between i and j atoms */
451 qq00 = _mm_mul_pd(iq0,jq0);
452 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
453 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
455 /* COULOMB ELECTROSTATICS */
456 velec = _mm_mul_pd(qq00,rinv00);
457 felec = _mm_mul_pd(velec,rinvsq00);
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 fscal = _mm_add_pd(felec,fvdw);
466 /* Calculate temporary vectorial force */
467 tx = _mm_mul_pd(fscal,dx00);
468 ty = _mm_mul_pd(fscal,dy00);
469 tz = _mm_mul_pd(fscal,dz00);
471 /* Update vectorial force */
472 fix0 = _mm_add_pd(fix0,tx);
473 fiy0 = _mm_add_pd(fiy0,ty);
474 fiz0 = _mm_add_pd(fiz0,tz);
476 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
478 /* Inner loop uses 34 flops */
485 j_coord_offsetA = DIM*jnrA;
487 /* load j atom coordinates */
488 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
491 /* Calculate displacement vector */
492 dx00 = _mm_sub_pd(ix0,jx0);
493 dy00 = _mm_sub_pd(iy0,jy0);
494 dz00 = _mm_sub_pd(iz0,jz0);
496 /* Calculate squared distance and things based on it */
497 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
499 rinv00 = gmx_mm_invsqrt_pd(rsq00);
501 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
503 /* Load parameters for j particles */
504 jq0 = _mm_load_sd(charge+jnrA+0);
505 vdwjidx0A = 2*vdwtype[jnrA+0];
507 /**************************
508 * CALCULATE INTERACTIONS *
509 **************************/
511 /* Compute parameters for interactions between i and j atoms */
512 qq00 = _mm_mul_pd(iq0,jq0);
513 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
515 /* COULOMB ELECTROSTATICS */
516 velec = _mm_mul_pd(qq00,rinv00);
517 felec = _mm_mul_pd(velec,rinvsq00);
519 /* LENNARD-JONES DISPERSION/REPULSION */
521 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
522 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
524 fscal = _mm_add_pd(felec,fvdw);
526 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
528 /* Calculate temporary vectorial force */
529 tx = _mm_mul_pd(fscal,dx00);
530 ty = _mm_mul_pd(fscal,dy00);
531 tz = _mm_mul_pd(fscal,dz00);
533 /* Update vectorial force */
534 fix0 = _mm_add_pd(fix0,tx);
535 fiy0 = _mm_add_pd(fiy0,ty);
536 fiz0 = _mm_add_pd(fiz0,tz);
538 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
540 /* Inner loop uses 34 flops */
543 /* End of innermost loop */
545 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
546 f+i_coord_offset,fshift+i_shift_offset);
548 /* Increment number of inner iterations */
549 inneriter += j_index_end - j_index_start;
551 /* Outer loop uses 7 flops */
554 /* Increment number of outer iterations */
557 /* Update outer/inner flops */
559 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*34);