2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015, 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.
44 #include "../nb_kernel.h"
45 #include "gromacs/math/vec.h"
46 #include "gromacs/legacyheaders/nrnb.h"
48 #include "gromacs/simd/math_x86_sse2_double.h"
49 #include "kernelutil_x86_sse2_double.h"
52 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSh_GeomP1P1_VF_sse2_double
53 * Electrostatics interaction: None
54 * VdW interaction: LennardJones
55 * Geometry: Particle-Particle
56 * Calculate force/pot: PotentialAndForce
59 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_VF_sse2_double
60 (t_nblist
* gmx_restrict nlist
,
61 rvec
* gmx_restrict xx
,
62 rvec
* gmx_restrict ff
,
63 t_forcerec
* gmx_restrict fr
,
64 t_mdatoms
* gmx_restrict mdatoms
,
65 nb_kernel_data_t gmx_unused
* gmx_restrict kernel_data
,
66 t_nrnb
* gmx_restrict nrnb
)
68 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
69 * just 0 for non-waters.
70 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
71 * jnr indices corresponding to data put in the four positions in the SIMD register.
73 int i_shift_offset
,i_coord_offset
,outeriter
,inneriter
;
74 int j_index_start
,j_index_end
,jidx
,nri
,inr
,ggid
,iidx
;
76 int j_coord_offsetA
,j_coord_offsetB
;
77 int *iinr
,*jindex
,*jjnr
,*shiftidx
,*gid
;
79 real
*shiftvec
,*fshift
,*x
,*f
;
80 __m128d tx
,ty
,tz
,fscal
,rcutoff
,rcutoff2
,jidxall
;
82 __m128d ix0
,iy0
,iz0
,fix0
,fiy0
,fiz0
,iq0
,isai0
;
83 int vdwjidx0A
,vdwjidx0B
;
84 __m128d jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
85 __m128d dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
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 nvdwtype
= fr
->ntype
;
109 vdwtype
= mdatoms
->typeA
;
111 rcutoff_scalar
= fr
->rvdw
;
112 rcutoff
= _mm_set1_pd(rcutoff_scalar
);
113 rcutoff2
= _mm_mul_pd(rcutoff
,rcutoff
);
115 sh_vdw_invrcut6
= _mm_set1_pd(fr
->ic
->sh_invrc6
);
116 rvdw
= _mm_set1_pd(fr
->rvdw
);
118 /* Avoid stupid compiler warnings */
126 /* Start outer loop over neighborlists */
127 for(iidx
=0; iidx
<nri
; iidx
++)
129 /* Load shift vector for this list */
130 i_shift_offset
= DIM
*shiftidx
[iidx
];
132 /* Load limits for loop over neighbors */
133 j_index_start
= jindex
[iidx
];
134 j_index_end
= jindex
[iidx
+1];
136 /* Get outer coordinate index */
138 i_coord_offset
= DIM
*inr
;
140 /* Load i particle coords and add shift vector */
141 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec
+i_shift_offset
,x
+i_coord_offset
,&ix0
,&iy0
,&iz0
);
143 fix0
= _mm_setzero_pd();
144 fiy0
= _mm_setzero_pd();
145 fiz0
= _mm_setzero_pd();
147 /* Load parameters for i particles */
148 vdwioffset0
= 2*nvdwtype
*vdwtype
[inr
+0];
150 /* Reset potential sums */
151 vvdwsum
= _mm_setzero_pd();
153 /* Start inner kernel loop */
154 for(jidx
=j_index_start
; jidx
<j_index_end
-1; jidx
+=2)
157 /* Get j neighbor index, and coordinate index */
160 j_coord_offsetA
= DIM
*jnrA
;
161 j_coord_offsetB
= DIM
*jnrB
;
163 /* load j atom coordinates */
164 gmx_mm_load_1rvec_2ptr_swizzle_pd(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
167 /* Calculate displacement vector */
168 dx00
= _mm_sub_pd(ix0
,jx0
);
169 dy00
= _mm_sub_pd(iy0
,jy0
);
170 dz00
= _mm_sub_pd(iz0
,jz0
);
172 /* Calculate squared distance and things based on it */
173 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
175 rinvsq00
= gmx_mm_inv_pd(rsq00
);
177 /* Load parameters for j particles */
178 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
179 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
181 /**************************
182 * CALCULATE INTERACTIONS *
183 **************************/
185 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
188 /* Compute parameters for interactions between i and j atoms */
189 gmx_mm_load_2pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,
190 vdwparam
+vdwioffset0
+vdwjidx0B
,&c6_00
,&c12_00
);
192 /* LENNARD-JONES DISPERSION/REPULSION */
194 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
195 vvdw6
= _mm_mul_pd(c6_00
,rinvsix
);
196 vvdw12
= _mm_mul_pd(c12_00
,_mm_mul_pd(rinvsix
,rinvsix
));
197 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
) ,
198 _mm_mul_pd( _mm_sub_pd(vvdw6
,_mm_mul_pd(c6_00
,sh_vdw_invrcut6
)),one_sixth
));
199 fvdw
= _mm_mul_pd(_mm_sub_pd(vvdw12
,vvdw6
),rinvsq00
);
201 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
203 /* Update potential sum for this i atom from the interaction with this j atom. */
204 vvdw
= _mm_and_pd(vvdw
,cutoff_mask
);
205 vvdwsum
= _mm_add_pd(vvdwsum
,vvdw
);
209 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
211 /* Calculate temporary vectorial force */
212 tx
= _mm_mul_pd(fscal
,dx00
);
213 ty
= _mm_mul_pd(fscal
,dy00
);
214 tz
= _mm_mul_pd(fscal
,dz00
);
216 /* Update vectorial force */
217 fix0
= _mm_add_pd(fix0
,tx
);
218 fiy0
= _mm_add_pd(fiy0
,ty
);
219 fiz0
= _mm_add_pd(fiz0
,tz
);
221 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f
+j_coord_offsetA
,f
+j_coord_offsetB
,tx
,ty
,tz
);
225 /* Inner loop uses 41 flops */
232 j_coord_offsetA
= DIM
*jnrA
;
234 /* load j atom coordinates */
235 gmx_mm_load_1rvec_1ptr_swizzle_pd(x
+j_coord_offsetA
,
238 /* Calculate displacement vector */
239 dx00
= _mm_sub_pd(ix0
,jx0
);
240 dy00
= _mm_sub_pd(iy0
,jy0
);
241 dz00
= _mm_sub_pd(iz0
,jz0
);
243 /* Calculate squared distance and things based on it */
244 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
246 rinvsq00
= gmx_mm_inv_pd(rsq00
);
248 /* Load parameters for j particles */
249 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
251 /**************************
252 * CALCULATE INTERACTIONS *
253 **************************/
255 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
258 /* Compute parameters for interactions between i and j atoms */
259 gmx_mm_load_1pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,&c6_00
,&c12_00
);
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( _mm_sub_pd(vvdw12
, _mm_mul_pd(c12_00
,_mm_mul_pd(sh_vdw_invrcut6
,sh_vdw_invrcut6
))), one_twelfth
) ,
267 _mm_mul_pd( _mm_sub_pd(vvdw6
,_mm_mul_pd(c6_00
,sh_vdw_invrcut6
)),one_sixth
));
268 fvdw
= _mm_mul_pd(_mm_sub_pd(vvdw12
,vvdw6
),rinvsq00
);
270 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
272 /* Update potential sum for this i atom from the interaction with this j atom. */
273 vvdw
= _mm_and_pd(vvdw
,cutoff_mask
);
274 vvdw
= _mm_unpacklo_pd(vvdw
,_mm_setzero_pd());
275 vvdwsum
= _mm_add_pd(vvdwsum
,vvdw
);
279 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
281 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
283 /* Calculate temporary vectorial force */
284 tx
= _mm_mul_pd(fscal
,dx00
);
285 ty
= _mm_mul_pd(fscal
,dy00
);
286 tz
= _mm_mul_pd(fscal
,dz00
);
288 /* Update vectorial force */
289 fix0
= _mm_add_pd(fix0
,tx
);
290 fiy0
= _mm_add_pd(fiy0
,ty
);
291 fiz0
= _mm_add_pd(fiz0
,tz
);
293 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f
+j_coord_offsetA
,tx
,ty
,tz
);
297 /* Inner loop uses 41 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(vvdwsum
,kernel_data
->energygrp_vdw
+ggid
);
309 /* Increment number of inner iterations */
310 inneriter
+= j_index_end
- j_index_start
;
312 /* Outer loop uses 7 flops */
315 /* Increment number of outer iterations */
318 /* Update outer/inner flops */
320 inc_nrnb(nrnb
,eNR_NBKERNEL_VDW_VF
,outeriter
*7 + inneriter
*41);
323 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_sse2_double
324 * Electrostatics interaction: None
325 * VdW interaction: LennardJones
326 * Geometry: Particle-Particle
327 * Calculate force/pot: Force
330 nb_kernel_ElecNone_VdwLJSh_GeomP1P1_F_sse2_double
331 (t_nblist
* gmx_restrict nlist
,
332 rvec
* gmx_restrict xx
,
333 rvec
* gmx_restrict ff
,
334 t_forcerec
* gmx_restrict fr
,
335 t_mdatoms
* gmx_restrict mdatoms
,
336 nb_kernel_data_t gmx_unused
* gmx_restrict kernel_data
,
337 t_nrnb
* gmx_restrict nrnb
)
339 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
340 * just 0 for non-waters.
341 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
342 * jnr indices corresponding to data put in the four positions in the SIMD register.
344 int i_shift_offset
,i_coord_offset
,outeriter
,inneriter
;
345 int j_index_start
,j_index_end
,jidx
,nri
,inr
,ggid
,iidx
;
347 int j_coord_offsetA
,j_coord_offsetB
;
348 int *iinr
,*jindex
,*jjnr
,*shiftidx
,*gid
;
350 real
*shiftvec
,*fshift
,*x
,*f
;
351 __m128d tx
,ty
,tz
,fscal
,rcutoff
,rcutoff2
,jidxall
;
353 __m128d ix0
,iy0
,iz0
,fix0
,fiy0
,fiz0
,iq0
,isai0
;
354 int vdwjidx0A
,vdwjidx0B
;
355 __m128d jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
356 __m128d dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
358 __m128d rinvsix
,rvdw
,vvdw
,vvdw6
,vvdw12
,fvdw
,fvdw6
,fvdw12
,vvdwsum
,sh_vdw_invrcut6
;
361 __m128d one_sixth
= _mm_set1_pd(1.0/6.0);
362 __m128d one_twelfth
= _mm_set1_pd(1.0/12.0);
363 __m128d dummy_mask
,cutoff_mask
;
364 __m128d signbit
= gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
365 __m128d one
= _mm_set1_pd(1.0);
366 __m128d two
= _mm_set1_pd(2.0);
372 jindex
= nlist
->jindex
;
374 shiftidx
= nlist
->shift
;
376 shiftvec
= fr
->shift_vec
[0];
377 fshift
= fr
->fshift
[0];
378 nvdwtype
= fr
->ntype
;
380 vdwtype
= mdatoms
->typeA
;
382 rcutoff_scalar
= fr
->rvdw
;
383 rcutoff
= _mm_set1_pd(rcutoff_scalar
);
384 rcutoff2
= _mm_mul_pd(rcutoff
,rcutoff
);
386 sh_vdw_invrcut6
= _mm_set1_pd(fr
->ic
->sh_invrc6
);
387 rvdw
= _mm_set1_pd(fr
->rvdw
);
389 /* Avoid stupid compiler warnings */
397 /* Start outer loop over neighborlists */
398 for(iidx
=0; iidx
<nri
; iidx
++)
400 /* Load shift vector for this list */
401 i_shift_offset
= DIM
*shiftidx
[iidx
];
403 /* Load limits for loop over neighbors */
404 j_index_start
= jindex
[iidx
];
405 j_index_end
= jindex
[iidx
+1];
407 /* Get outer coordinate index */
409 i_coord_offset
= DIM
*inr
;
411 /* Load i particle coords and add shift vector */
412 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec
+i_shift_offset
,x
+i_coord_offset
,&ix0
,&iy0
,&iz0
);
414 fix0
= _mm_setzero_pd();
415 fiy0
= _mm_setzero_pd();
416 fiz0
= _mm_setzero_pd();
418 /* Load parameters for i particles */
419 vdwioffset0
= 2*nvdwtype
*vdwtype
[inr
+0];
421 /* Start inner kernel loop */
422 for(jidx
=j_index_start
; jidx
<j_index_end
-1; jidx
+=2)
425 /* Get j neighbor index, and coordinate index */
428 j_coord_offsetA
= DIM
*jnrA
;
429 j_coord_offsetB
= DIM
*jnrB
;
431 /* load j atom coordinates */
432 gmx_mm_load_1rvec_2ptr_swizzle_pd(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
435 /* Calculate displacement vector */
436 dx00
= _mm_sub_pd(ix0
,jx0
);
437 dy00
= _mm_sub_pd(iy0
,jy0
);
438 dz00
= _mm_sub_pd(iz0
,jz0
);
440 /* Calculate squared distance and things based on it */
441 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
443 rinvsq00
= gmx_mm_inv_pd(rsq00
);
445 /* Load parameters for j particles */
446 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
447 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
449 /**************************
450 * CALCULATE INTERACTIONS *
451 **************************/
453 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
456 /* Compute parameters for interactions between i and j atoms */
457 gmx_mm_load_2pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,
458 vdwparam
+vdwioffset0
+vdwjidx0B
,&c6_00
,&c12_00
);
460 /* LENNARD-JONES DISPERSION/REPULSION */
462 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
463 fvdw
= _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00
,rinvsix
),c6_00
),_mm_mul_pd(rinvsix
,rinvsq00
));
465 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
469 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
471 /* Calculate temporary vectorial force */
472 tx
= _mm_mul_pd(fscal
,dx00
);
473 ty
= _mm_mul_pd(fscal
,dy00
);
474 tz
= _mm_mul_pd(fscal
,dz00
);
476 /* Update vectorial force */
477 fix0
= _mm_add_pd(fix0
,tx
);
478 fiy0
= _mm_add_pd(fiy0
,ty
);
479 fiz0
= _mm_add_pd(fiz0
,tz
);
481 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f
+j_coord_offsetA
,f
+j_coord_offsetB
,tx
,ty
,tz
);
485 /* Inner loop uses 30 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 rinvsq00
= gmx_mm_inv_pd(rsq00
);
508 /* Load parameters for j particles */
509 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
511 /**************************
512 * CALCULATE INTERACTIONS *
513 **************************/
515 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
518 /* Compute parameters for interactions between i and j atoms */
519 gmx_mm_load_1pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,&c6_00
,&c12_00
);
521 /* LENNARD-JONES DISPERSION/REPULSION */
523 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
524 fvdw
= _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00
,rinvsix
),c6_00
),_mm_mul_pd(rinvsix
,rinvsq00
));
526 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
530 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
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
);
548 /* Inner loop uses 30 flops */
551 /* End of innermost loop */
553 gmx_mm_update_iforce_1atom_swizzle_pd(fix0
,fiy0
,fiz0
,
554 f
+i_coord_offset
,fshift
+i_shift_offset
);
556 /* Increment number of inner iterations */
557 inneriter
+= j_index_end
- j_index_start
;
559 /* Outer loop uses 6 flops */
562 /* Increment number of outer iterations */
565 /* Update outer/inner flops */
567 inc_nrnb(nrnb
,eNR_NBKERNEL_VDW_F
,outeriter
*6 + inneriter
*30);