2 * Note: this file was generated by the Gromacs sse2_double kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_sse2_double.h"
34 #include "kernelutil_x86_sse2_double.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSh_GeomP1P1_VF_sse2_double
38 * Electrostatics interaction: None
39 * VdW interaction: LennardJones
40 * Geometry: Particle-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_VF_sse2_double
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
61 int j_coord_offsetA,j_coord_offsetB;
62 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
64 real *shiftvec,*fshift,*x,*f;
65 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
67 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
68 int vdwjidx0A,vdwjidx0B;
69 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
70 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
72 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
75 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
76 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
77 __m128d dummy_mask,cutoff_mask;
78 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
79 __m128d one = _mm_set1_pd(1.0);
80 __m128d two = _mm_set1_pd(2.0);
86 jindex = nlist->jindex;
88 shiftidx = nlist->shift;
90 shiftvec = fr->shift_vec[0];
91 fshift = fr->fshift[0];
94 vdwtype = mdatoms->typeA;
96 rcutoff_scalar = fr->rvdw;
97 rcutoff = _mm_set1_pd(rcutoff_scalar);
98 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
100 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
101 rvdw = _mm_set1_pd(fr->rvdw);
103 /* Avoid stupid compiler warnings */
111 /* Start outer loop over neighborlists */
112 for(iidx=0; iidx<nri; iidx++)
114 /* Load shift vector for this list */
115 i_shift_offset = DIM*shiftidx[iidx];
117 /* Load limits for loop over neighbors */
118 j_index_start = jindex[iidx];
119 j_index_end = jindex[iidx+1];
121 /* Get outer coordinate index */
123 i_coord_offset = DIM*inr;
125 /* Load i particle coords and add shift vector */
126 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
128 fix0 = _mm_setzero_pd();
129 fiy0 = _mm_setzero_pd();
130 fiz0 = _mm_setzero_pd();
132 /* Load parameters for i particles */
133 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
135 /* Reset potential sums */
136 vvdwsum = _mm_setzero_pd();
138 /* Start inner kernel loop */
139 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
142 /* Get j neighbor index, and coordinate index */
145 j_coord_offsetA = DIM*jnrA;
146 j_coord_offsetB = DIM*jnrB;
148 /* load j atom coordinates */
149 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
152 /* Calculate displacement vector */
153 dx00 = _mm_sub_pd(ix0,jx0);
154 dy00 = _mm_sub_pd(iy0,jy0);
155 dz00 = _mm_sub_pd(iz0,jz0);
157 /* Calculate squared distance and things based on it */
158 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
160 rinvsq00 = gmx_mm_inv_pd(rsq00);
162 /* Load parameters for j particles */
163 vdwjidx0A = 2*vdwtype[jnrA+0];
164 vdwjidx0B = 2*vdwtype[jnrB+0];
166 /**************************
167 * CALCULATE INTERACTIONS *
168 **************************/
170 if (gmx_mm_any_lt(rsq00,rcutoff2))
173 /* Compute parameters for interactions between i and j atoms */
174 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
175 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
177 /* LENNARD-JONES DISPERSION/REPULSION */
179 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
180 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
181 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
182 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) ,
183 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
184 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
186 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
188 /* Update potential sum for this i atom from the interaction with this j atom. */
189 vvdw = _mm_and_pd(vvdw,cutoff_mask);
190 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
194 fscal = _mm_and_pd(fscal,cutoff_mask);
196 /* Calculate temporary vectorial force */
197 tx = _mm_mul_pd(fscal,dx00);
198 ty = _mm_mul_pd(fscal,dy00);
199 tz = _mm_mul_pd(fscal,dz00);
201 /* Update vectorial force */
202 fix0 = _mm_add_pd(fix0,tx);
203 fiy0 = _mm_add_pd(fiy0,ty);
204 fiz0 = _mm_add_pd(fiz0,tz);
206 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
210 /* Inner loop uses 41 flops */
217 j_coord_offsetA = DIM*jnrA;
219 /* load j atom coordinates */
220 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
223 /* Calculate displacement vector */
224 dx00 = _mm_sub_pd(ix0,jx0);
225 dy00 = _mm_sub_pd(iy0,jy0);
226 dz00 = _mm_sub_pd(iz0,jz0);
228 /* Calculate squared distance and things based on it */
229 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
231 rinvsq00 = gmx_mm_inv_pd(rsq00);
233 /* Load parameters for j particles */
234 vdwjidx0A = 2*vdwtype[jnrA+0];
236 /**************************
237 * CALCULATE INTERACTIONS *
238 **************************/
240 if (gmx_mm_any_lt(rsq00,rcutoff2))
243 /* Compute parameters for interactions between i and j atoms */
244 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
246 /* LENNARD-JONES DISPERSION/REPULSION */
248 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
249 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
250 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
251 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) ,
252 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
253 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
255 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
257 /* Update potential sum for this i atom from the interaction with this j atom. */
258 vvdw = _mm_and_pd(vvdw,cutoff_mask);
259 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
260 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
264 fscal = _mm_and_pd(fscal,cutoff_mask);
266 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
268 /* Calculate temporary vectorial force */
269 tx = _mm_mul_pd(fscal,dx00);
270 ty = _mm_mul_pd(fscal,dy00);
271 tz = _mm_mul_pd(fscal,dz00);
273 /* Update vectorial force */
274 fix0 = _mm_add_pd(fix0,tx);
275 fiy0 = _mm_add_pd(fiy0,ty);
276 fiz0 = _mm_add_pd(fiz0,tz);
278 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
282 /* Inner loop uses 41 flops */
285 /* End of innermost loop */
287 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
288 f+i_coord_offset,fshift+i_shift_offset);
291 /* Update potential energies */
292 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
294 /* Increment number of inner iterations */
295 inneriter += j_index_end - j_index_start;
297 /* Outer loop uses 7 flops */
300 /* Increment number of outer iterations */
303 /* Update outer/inner flops */
305 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*41);
308 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_sse2_double
309 * Electrostatics interaction: None
310 * VdW interaction: LennardJones
311 * Geometry: Particle-Particle
312 * Calculate force/pot: Force
315 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_sse2_double
316 (t_nblist * gmx_restrict nlist,
317 rvec * gmx_restrict xx,
318 rvec * gmx_restrict ff,
319 t_forcerec * gmx_restrict fr,
320 t_mdatoms * gmx_restrict mdatoms,
321 nb_kernel_data_t * gmx_restrict kernel_data,
322 t_nrnb * gmx_restrict nrnb)
324 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
325 * just 0 for non-waters.
326 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
327 * jnr indices corresponding to data put in the four positions in the SIMD register.
329 int i_shift_offset,i_coord_offset,outeriter,inneriter;
330 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
332 int j_coord_offsetA,j_coord_offsetB;
333 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
335 real *shiftvec,*fshift,*x,*f;
336 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
338 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
339 int vdwjidx0A,vdwjidx0B;
340 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
341 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
343 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
346 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
347 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
348 __m128d dummy_mask,cutoff_mask;
349 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
350 __m128d one = _mm_set1_pd(1.0);
351 __m128d two = _mm_set1_pd(2.0);
357 jindex = nlist->jindex;
359 shiftidx = nlist->shift;
361 shiftvec = fr->shift_vec[0];
362 fshift = fr->fshift[0];
363 nvdwtype = fr->ntype;
365 vdwtype = mdatoms->typeA;
367 rcutoff_scalar = fr->rvdw;
368 rcutoff = _mm_set1_pd(rcutoff_scalar);
369 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
371 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
372 rvdw = _mm_set1_pd(fr->rvdw);
374 /* Avoid stupid compiler warnings */
382 /* Start outer loop over neighborlists */
383 for(iidx=0; iidx<nri; iidx++)
385 /* Load shift vector for this list */
386 i_shift_offset = DIM*shiftidx[iidx];
388 /* Load limits for loop over neighbors */
389 j_index_start = jindex[iidx];
390 j_index_end = jindex[iidx+1];
392 /* Get outer coordinate index */
394 i_coord_offset = DIM*inr;
396 /* Load i particle coords and add shift vector */
397 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
399 fix0 = _mm_setzero_pd();
400 fiy0 = _mm_setzero_pd();
401 fiz0 = _mm_setzero_pd();
403 /* Load parameters for i particles */
404 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
406 /* Start inner kernel loop */
407 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
410 /* Get j neighbor index, and coordinate index */
413 j_coord_offsetA = DIM*jnrA;
414 j_coord_offsetB = DIM*jnrB;
416 /* load j atom coordinates */
417 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
420 /* Calculate displacement vector */
421 dx00 = _mm_sub_pd(ix0,jx0);
422 dy00 = _mm_sub_pd(iy0,jy0);
423 dz00 = _mm_sub_pd(iz0,jz0);
425 /* Calculate squared distance and things based on it */
426 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
428 rinvsq00 = gmx_mm_inv_pd(rsq00);
430 /* Load parameters for j particles */
431 vdwjidx0A = 2*vdwtype[jnrA+0];
432 vdwjidx0B = 2*vdwtype[jnrB+0];
434 /**************************
435 * CALCULATE INTERACTIONS *
436 **************************/
438 if (gmx_mm_any_lt(rsq00,rcutoff2))
441 /* Compute parameters for interactions between i and j atoms */
442 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
443 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
445 /* LENNARD-JONES DISPERSION/REPULSION */
447 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
448 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
450 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
454 fscal = _mm_and_pd(fscal,cutoff_mask);
456 /* Calculate temporary vectorial force */
457 tx = _mm_mul_pd(fscal,dx00);
458 ty = _mm_mul_pd(fscal,dy00);
459 tz = _mm_mul_pd(fscal,dz00);
461 /* Update vectorial force */
462 fix0 = _mm_add_pd(fix0,tx);
463 fiy0 = _mm_add_pd(fiy0,ty);
464 fiz0 = _mm_add_pd(fiz0,tz);
466 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
470 /* Inner loop uses 30 flops */
477 j_coord_offsetA = DIM*jnrA;
479 /* load j atom coordinates */
480 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
483 /* Calculate displacement vector */
484 dx00 = _mm_sub_pd(ix0,jx0);
485 dy00 = _mm_sub_pd(iy0,jy0);
486 dz00 = _mm_sub_pd(iz0,jz0);
488 /* Calculate squared distance and things based on it */
489 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
491 rinvsq00 = gmx_mm_inv_pd(rsq00);
493 /* Load parameters for j particles */
494 vdwjidx0A = 2*vdwtype[jnrA+0];
496 /**************************
497 * CALCULATE INTERACTIONS *
498 **************************/
500 if (gmx_mm_any_lt(rsq00,rcutoff2))
503 /* Compute parameters for interactions between i and j atoms */
504 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
506 /* LENNARD-JONES DISPERSION/REPULSION */
508 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
509 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
511 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
515 fscal = _mm_and_pd(fscal,cutoff_mask);
517 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
519 /* Calculate temporary vectorial force */
520 tx = _mm_mul_pd(fscal,dx00);
521 ty = _mm_mul_pd(fscal,dy00);
522 tz = _mm_mul_pd(fscal,dz00);
524 /* Update vectorial force */
525 fix0 = _mm_add_pd(fix0,tx);
526 fiy0 = _mm_add_pd(fiy0,ty);
527 fiz0 = _mm_add_pd(fiz0,tz);
529 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
533 /* Inner loop uses 30 flops */
536 /* End of innermost loop */
538 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
539 f+i_coord_offset,fshift+i_shift_offset);
541 /* Increment number of inner iterations */
542 inneriter += j_index_end - j_index_start;
544 /* Outer loop uses 6 flops */
547 /* Increment number of outer iterations */
550 /* Update outer/inner flops */
552 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*30);