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 sse4_1_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gromacs/simd/math_x86_sse4_1_double.h"
50 #include "kernelutil_x86_sse4_1_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomP1P1_VF_sse4_1_double
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRF_VdwLJ_GeomP1P1_VF_sse4_1_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
77 int j_coord_offsetA,j_coord_offsetB;
78 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
80 real *shiftvec,*fshift,*x,*f;
81 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84 int vdwjidx0A,vdwjidx0B;
85 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
93 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
94 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
95 __m128d dummy_mask,cutoff_mask;
96 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
97 __m128d one = _mm_set1_pd(1.0);
98 __m128d two = _mm_set1_pd(2.0);
104 jindex = nlist->jindex;
106 shiftidx = nlist->shift;
108 shiftvec = fr->shift_vec[0];
109 fshift = fr->fshift[0];
110 facel = _mm_set1_pd(fr->epsfac);
111 charge = mdatoms->chargeA;
112 krf = _mm_set1_pd(fr->ic->k_rf);
113 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
114 crf = _mm_set1_pd(fr->ic->c_rf);
115 nvdwtype = fr->ntype;
117 vdwtype = mdatoms->typeA;
119 /* Avoid stupid compiler warnings */
127 /* Start outer loop over neighborlists */
128 for(iidx=0; iidx<nri; iidx++)
130 /* Load shift vector for this list */
131 i_shift_offset = DIM*shiftidx[iidx];
133 /* Load limits for loop over neighbors */
134 j_index_start = jindex[iidx];
135 j_index_end = jindex[iidx+1];
137 /* Get outer coordinate index */
139 i_coord_offset = DIM*inr;
141 /* Load i particle coords and add shift vector */
142 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
144 fix0 = _mm_setzero_pd();
145 fiy0 = _mm_setzero_pd();
146 fiz0 = _mm_setzero_pd();
148 /* Load parameters for i particles */
149 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
150 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
152 /* Reset potential sums */
153 velecsum = _mm_setzero_pd();
154 vvdwsum = _mm_setzero_pd();
156 /* Start inner kernel loop */
157 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
160 /* Get j neighbor index, and coordinate index */
163 j_coord_offsetA = DIM*jnrA;
164 j_coord_offsetB = DIM*jnrB;
166 /* load j atom coordinates */
167 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
170 /* Calculate displacement vector */
171 dx00 = _mm_sub_pd(ix0,jx0);
172 dy00 = _mm_sub_pd(iy0,jy0);
173 dz00 = _mm_sub_pd(iz0,jz0);
175 /* Calculate squared distance and things based on it */
176 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
178 rinv00 = gmx_mm_invsqrt_pd(rsq00);
180 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
182 /* Load parameters for j particles */
183 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
184 vdwjidx0A = 2*vdwtype[jnrA+0];
185 vdwjidx0B = 2*vdwtype[jnrB+0];
187 /**************************
188 * CALCULATE INTERACTIONS *
189 **************************/
191 /* Compute parameters for interactions between i and j atoms */
192 qq00 = _mm_mul_pd(iq0,jq0);
193 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
194 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
196 /* REACTION-FIELD ELECTROSTATICS */
197 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_add_pd(rinv00,_mm_mul_pd(krf,rsq00)),crf));
198 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
200 /* LENNARD-JONES DISPERSION/REPULSION */
202 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
203 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
204 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
205 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
206 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
208 /* Update potential sum for this i atom from the interaction with this j atom. */
209 velecsum = _mm_add_pd(velecsum,velec);
210 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
212 fscal = _mm_add_pd(felec,fvdw);
214 /* Calculate temporary vectorial force */
215 tx = _mm_mul_pd(fscal,dx00);
216 ty = _mm_mul_pd(fscal,dy00);
217 tz = _mm_mul_pd(fscal,dz00);
219 /* Update vectorial force */
220 fix0 = _mm_add_pd(fix0,tx);
221 fiy0 = _mm_add_pd(fiy0,ty);
222 fiz0 = _mm_add_pd(fiz0,tz);
224 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
226 /* Inner loop uses 44 flops */
233 j_coord_offsetA = DIM*jnrA;
235 /* load j atom coordinates */
236 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
239 /* Calculate displacement vector */
240 dx00 = _mm_sub_pd(ix0,jx0);
241 dy00 = _mm_sub_pd(iy0,jy0);
242 dz00 = _mm_sub_pd(iz0,jz0);
244 /* Calculate squared distance and things based on it */
245 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
247 rinv00 = gmx_mm_invsqrt_pd(rsq00);
249 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
251 /* Load parameters for j particles */
252 jq0 = _mm_load_sd(charge+jnrA+0);
253 vdwjidx0A = 2*vdwtype[jnrA+0];
255 /**************************
256 * CALCULATE INTERACTIONS *
257 **************************/
259 /* Compute parameters for interactions between i and j atoms */
260 qq00 = _mm_mul_pd(iq0,jq0);
261 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
263 /* REACTION-FIELD ELECTROSTATICS */
264 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_add_pd(rinv00,_mm_mul_pd(krf,rsq00)),crf));
265 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
267 /* LENNARD-JONES DISPERSION/REPULSION */
269 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
270 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
271 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
272 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
273 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
275 /* Update potential sum for this i atom from the interaction with this j atom. */
276 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
277 velecsum = _mm_add_pd(velecsum,velec);
278 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
279 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
281 fscal = _mm_add_pd(felec,fvdw);
283 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
285 /* Calculate temporary vectorial force */
286 tx = _mm_mul_pd(fscal,dx00);
287 ty = _mm_mul_pd(fscal,dy00);
288 tz = _mm_mul_pd(fscal,dz00);
290 /* Update vectorial force */
291 fix0 = _mm_add_pd(fix0,tx);
292 fiy0 = _mm_add_pd(fiy0,ty);
293 fiz0 = _mm_add_pd(fiz0,tz);
295 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
297 /* Inner loop uses 44 flops */
300 /* End of innermost loop */
302 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
303 f+i_coord_offset,fshift+i_shift_offset);
306 /* Update potential energies */
307 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
308 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
310 /* Increment number of inner iterations */
311 inneriter += j_index_end - j_index_start;
313 /* Outer loop uses 9 flops */
316 /* Increment number of outer iterations */
319 /* Update outer/inner flops */
321 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*44);
324 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomP1P1_F_sse4_1_double
325 * Electrostatics interaction: ReactionField
326 * VdW interaction: LennardJones
327 * Geometry: Particle-Particle
328 * Calculate force/pot: Force
331 nb_kernel_ElecRF_VdwLJ_GeomP1P1_F_sse4_1_double
332 (t_nblist * gmx_restrict nlist,
333 rvec * gmx_restrict xx,
334 rvec * gmx_restrict ff,
335 t_forcerec * gmx_restrict fr,
336 t_mdatoms * gmx_restrict mdatoms,
337 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
338 t_nrnb * gmx_restrict nrnb)
340 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
341 * just 0 for non-waters.
342 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
343 * jnr indices corresponding to data put in the four positions in the SIMD register.
345 int i_shift_offset,i_coord_offset,outeriter,inneriter;
346 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
348 int j_coord_offsetA,j_coord_offsetB;
349 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
351 real *shiftvec,*fshift,*x,*f;
352 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
354 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
355 int vdwjidx0A,vdwjidx0B;
356 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
357 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
358 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
361 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
364 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
365 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
366 __m128d dummy_mask,cutoff_mask;
367 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
368 __m128d one = _mm_set1_pd(1.0);
369 __m128d two = _mm_set1_pd(2.0);
375 jindex = nlist->jindex;
377 shiftidx = nlist->shift;
379 shiftvec = fr->shift_vec[0];
380 fshift = fr->fshift[0];
381 facel = _mm_set1_pd(fr->epsfac);
382 charge = mdatoms->chargeA;
383 krf = _mm_set1_pd(fr->ic->k_rf);
384 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
385 crf = _mm_set1_pd(fr->ic->c_rf);
386 nvdwtype = fr->ntype;
388 vdwtype = mdatoms->typeA;
390 /* Avoid stupid compiler warnings */
398 /* Start outer loop over neighborlists */
399 for(iidx=0; iidx<nri; iidx++)
401 /* Load shift vector for this list */
402 i_shift_offset = DIM*shiftidx[iidx];
404 /* Load limits for loop over neighbors */
405 j_index_start = jindex[iidx];
406 j_index_end = jindex[iidx+1];
408 /* Get outer coordinate index */
410 i_coord_offset = DIM*inr;
412 /* Load i particle coords and add shift vector */
413 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
415 fix0 = _mm_setzero_pd();
416 fiy0 = _mm_setzero_pd();
417 fiz0 = _mm_setzero_pd();
419 /* Load parameters for i particles */
420 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
421 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
423 /* Start inner kernel loop */
424 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
427 /* Get j neighbor index, and coordinate index */
430 j_coord_offsetA = DIM*jnrA;
431 j_coord_offsetB = DIM*jnrB;
433 /* load j atom coordinates */
434 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
437 /* Calculate displacement vector */
438 dx00 = _mm_sub_pd(ix0,jx0);
439 dy00 = _mm_sub_pd(iy0,jy0);
440 dz00 = _mm_sub_pd(iz0,jz0);
442 /* Calculate squared distance and things based on it */
443 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
445 rinv00 = gmx_mm_invsqrt_pd(rsq00);
447 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
449 /* Load parameters for j particles */
450 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
451 vdwjidx0A = 2*vdwtype[jnrA+0];
452 vdwjidx0B = 2*vdwtype[jnrB+0];
454 /**************************
455 * CALCULATE INTERACTIONS *
456 **************************/
458 /* Compute parameters for interactions between i and j atoms */
459 qq00 = _mm_mul_pd(iq0,jq0);
460 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
461 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
463 /* REACTION-FIELD ELECTROSTATICS */
464 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
466 /* LENNARD-JONES DISPERSION/REPULSION */
468 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
469 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
471 fscal = _mm_add_pd(felec,fvdw);
473 /* Calculate temporary vectorial force */
474 tx = _mm_mul_pd(fscal,dx00);
475 ty = _mm_mul_pd(fscal,dy00);
476 tz = _mm_mul_pd(fscal,dz00);
478 /* Update vectorial force */
479 fix0 = _mm_add_pd(fix0,tx);
480 fiy0 = _mm_add_pd(fiy0,ty);
481 fiz0 = _mm_add_pd(fiz0,tz);
483 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
485 /* Inner loop uses 34 flops */
492 j_coord_offsetA = DIM*jnrA;
494 /* load j atom coordinates */
495 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
498 /* Calculate displacement vector */
499 dx00 = _mm_sub_pd(ix0,jx0);
500 dy00 = _mm_sub_pd(iy0,jy0);
501 dz00 = _mm_sub_pd(iz0,jz0);
503 /* Calculate squared distance and things based on it */
504 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
506 rinv00 = gmx_mm_invsqrt_pd(rsq00);
508 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
510 /* Load parameters for j particles */
511 jq0 = _mm_load_sd(charge+jnrA+0);
512 vdwjidx0A = 2*vdwtype[jnrA+0];
514 /**************************
515 * CALCULATE INTERACTIONS *
516 **************************/
518 /* Compute parameters for interactions between i and j atoms */
519 qq00 = _mm_mul_pd(iq0,jq0);
520 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
522 /* REACTION-FIELD ELECTROSTATICS */
523 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
525 /* LENNARD-JONES DISPERSION/REPULSION */
527 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
528 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
530 fscal = _mm_add_pd(felec,fvdw);
532 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
534 /* Calculate temporary vectorial force */
535 tx = _mm_mul_pd(fscal,dx00);
536 ty = _mm_mul_pd(fscal,dy00);
537 tz = _mm_mul_pd(fscal,dz00);
539 /* Update vectorial force */
540 fix0 = _mm_add_pd(fix0,tx);
541 fiy0 = _mm_add_pd(fiy0,ty);
542 fiz0 = _mm_add_pd(fiz0,tz);
544 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
546 /* Inner loop uses 34 flops */
549 /* End of innermost loop */
551 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
552 f+i_coord_offset,fshift+i_shift_offset);
554 /* Increment number of inner iterations */
555 inneriter += j_index_end - j_index_start;
557 /* Outer loop uses 7 flops */
560 /* Increment number of outer iterations */
563 /* Update outer/inner flops */
565 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*34);