2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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_ElecRFCut_VdwNone_GeomP1P1_VF_sse4_1_double
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: None
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwNone_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
;
86 __m128d dummy_mask
,cutoff_mask
;
87 __m128d signbit
= gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
88 __m128d one
= _mm_set1_pd(1.0);
89 __m128d two
= _mm_set1_pd(2.0);
95 jindex
= nlist
->jindex
;
97 shiftidx
= nlist
->shift
;
99 shiftvec
= fr
->shift_vec
[0];
100 fshift
= fr
->fshift
[0];
101 facel
= _mm_set1_pd(fr
->ic
->epsfac
);
102 charge
= mdatoms
->chargeA
;
103 krf
= _mm_set1_pd(fr
->ic
->k_rf
);
104 krf2
= _mm_set1_pd(fr
->ic
->k_rf
*2.0);
105 crf
= _mm_set1_pd(fr
->ic
->c_rf
);
107 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
108 rcutoff_scalar
= fr
->ic
->rcoulomb
;
109 rcutoff
= _mm_set1_pd(rcutoff_scalar
);
110 rcutoff2
= _mm_mul_pd(rcutoff
,rcutoff
);
112 /* Avoid stupid compiler warnings */
120 /* Start outer loop over neighborlists */
121 for(iidx
=0; iidx
<nri
; iidx
++)
123 /* Load shift vector for this list */
124 i_shift_offset
= DIM
*shiftidx
[iidx
];
126 /* Load limits for loop over neighbors */
127 j_index_start
= jindex
[iidx
];
128 j_index_end
= jindex
[iidx
+1];
130 /* Get outer coordinate index */
132 i_coord_offset
= DIM
*inr
;
134 /* Load i particle coords and add shift vector */
135 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec
+i_shift_offset
,x
+i_coord_offset
,&ix0
,&iy0
,&iz0
);
137 fix0
= _mm_setzero_pd();
138 fiy0
= _mm_setzero_pd();
139 fiz0
= _mm_setzero_pd();
141 /* Load parameters for i particles */
142 iq0
= _mm_mul_pd(facel
,_mm_load1_pd(charge
+inr
+0));
144 /* Reset potential sums */
145 velecsum
= _mm_setzero_pd();
147 /* Start inner kernel loop */
148 for(jidx
=j_index_start
; jidx
<j_index_end
-1; jidx
+=2)
151 /* Get j neighbor index, and coordinate index */
154 j_coord_offsetA
= DIM
*jnrA
;
155 j_coord_offsetB
= DIM
*jnrB
;
157 /* load j atom coordinates */
158 gmx_mm_load_1rvec_2ptr_swizzle_pd(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
161 /* Calculate displacement vector */
162 dx00
= _mm_sub_pd(ix0
,jx0
);
163 dy00
= _mm_sub_pd(iy0
,jy0
);
164 dz00
= _mm_sub_pd(iz0
,jz0
);
166 /* Calculate squared distance and things based on it */
167 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
169 rinv00
= sse41_invsqrt_d(rsq00
);
171 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
173 /* Load parameters for j particles */
174 jq0
= gmx_mm_load_2real_swizzle_pd(charge
+jnrA
+0,charge
+jnrB
+0);
176 /**************************
177 * CALCULATE INTERACTIONS *
178 **************************/
180 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
183 /* Compute parameters for interactions between i and j atoms */
184 qq00
= _mm_mul_pd(iq0
,jq0
);
186 /* REACTION-FIELD ELECTROSTATICS */
187 velec
= _mm_mul_pd(qq00
,_mm_sub_pd(_mm_add_pd(rinv00
,_mm_mul_pd(krf
,rsq00
)),crf
));
188 felec
= _mm_mul_pd(qq00
,_mm_sub_pd(_mm_mul_pd(rinv00
,rinvsq00
),krf2
));
190 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
192 /* Update potential sum for this i atom from the interaction with this j atom. */
193 velec
= _mm_and_pd(velec
,cutoff_mask
);
194 velecsum
= _mm_add_pd(velecsum
,velec
);
198 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
200 /* Calculate temporary vectorial force */
201 tx
= _mm_mul_pd(fscal
,dx00
);
202 ty
= _mm_mul_pd(fscal
,dy00
);
203 tz
= _mm_mul_pd(fscal
,dz00
);
205 /* Update vectorial force */
206 fix0
= _mm_add_pd(fix0
,tx
);
207 fiy0
= _mm_add_pd(fiy0
,ty
);
208 fiz0
= _mm_add_pd(fiz0
,tz
);
210 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f
+j_coord_offsetA
,f
+j_coord_offsetB
,tx
,ty
,tz
);
214 /* Inner loop uses 36 flops */
221 j_coord_offsetA
= DIM
*jnrA
;
223 /* load j atom coordinates */
224 gmx_mm_load_1rvec_1ptr_swizzle_pd(x
+j_coord_offsetA
,
227 /* Calculate displacement vector */
228 dx00
= _mm_sub_pd(ix0
,jx0
);
229 dy00
= _mm_sub_pd(iy0
,jy0
);
230 dz00
= _mm_sub_pd(iz0
,jz0
);
232 /* Calculate squared distance and things based on it */
233 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
235 rinv00
= sse41_invsqrt_d(rsq00
);
237 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
239 /* Load parameters for j particles */
240 jq0
= _mm_load_sd(charge
+jnrA
+0);
242 /**************************
243 * CALCULATE INTERACTIONS *
244 **************************/
246 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
249 /* Compute parameters for interactions between i and j atoms */
250 qq00
= _mm_mul_pd(iq0
,jq0
);
252 /* REACTION-FIELD ELECTROSTATICS */
253 velec
= _mm_mul_pd(qq00
,_mm_sub_pd(_mm_add_pd(rinv00
,_mm_mul_pd(krf
,rsq00
)),crf
));
254 felec
= _mm_mul_pd(qq00
,_mm_sub_pd(_mm_mul_pd(rinv00
,rinvsq00
),krf2
));
256 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
258 /* Update potential sum for this i atom from the interaction with this j atom. */
259 velec
= _mm_and_pd(velec
,cutoff_mask
);
260 velec
= _mm_unpacklo_pd(velec
,_mm_setzero_pd());
261 velecsum
= _mm_add_pd(velecsum
,velec
);
265 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
267 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
269 /* Calculate temporary vectorial force */
270 tx
= _mm_mul_pd(fscal
,dx00
);
271 ty
= _mm_mul_pd(fscal
,dy00
);
272 tz
= _mm_mul_pd(fscal
,dz00
);
274 /* Update vectorial force */
275 fix0
= _mm_add_pd(fix0
,tx
);
276 fiy0
= _mm_add_pd(fiy0
,ty
);
277 fiz0
= _mm_add_pd(fiz0
,tz
);
279 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f
+j_coord_offsetA
,tx
,ty
,tz
);
283 /* Inner loop uses 36 flops */
286 /* End of innermost loop */
288 gmx_mm_update_iforce_1atom_swizzle_pd(fix0
,fiy0
,fiz0
,
289 f
+i_coord_offset
,fshift
+i_shift_offset
);
292 /* Update potential energies */
293 gmx_mm_update_1pot_pd(velecsum
,kernel_data
->energygrp_elec
+ggid
);
295 /* Increment number of inner iterations */
296 inneriter
+= j_index_end
- j_index_start
;
298 /* Outer loop uses 8 flops */
301 /* Increment number of outer iterations */
304 /* Update outer/inner flops */
306 inc_nrnb(nrnb
,eNR_NBKERNEL_ELEC_VF
,outeriter
*8 + inneriter
*36);
309 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_sse4_1_double
310 * Electrostatics interaction: ReactionField
311 * VdW interaction: None
312 * Geometry: Particle-Particle
313 * Calculate force/pot: Force
316 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_sse4_1_double
317 (t_nblist
* gmx_restrict nlist
,
318 rvec
* gmx_restrict xx
,
319 rvec
* gmx_restrict ff
,
320 struct t_forcerec
* gmx_restrict fr
,
321 t_mdatoms
* gmx_restrict mdatoms
,
322 nb_kernel_data_t gmx_unused
* gmx_restrict kernel_data
,
323 t_nrnb
* gmx_restrict nrnb
)
325 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
326 * just 0 for non-waters.
327 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
328 * jnr indices corresponding to data put in the four positions in the SIMD register.
330 int i_shift_offset
,i_coord_offset
,outeriter
,inneriter
;
331 int j_index_start
,j_index_end
,jidx
,nri
,inr
,ggid
,iidx
;
333 int j_coord_offsetA
,j_coord_offsetB
;
334 int *iinr
,*jindex
,*jjnr
,*shiftidx
,*gid
;
336 real
*shiftvec
,*fshift
,*x
,*f
;
337 __m128d tx
,ty
,tz
,fscal
,rcutoff
,rcutoff2
,jidxall
;
339 __m128d ix0
,iy0
,iz0
,fix0
,fiy0
,fiz0
,iq0
,isai0
;
340 int vdwjidx0A
,vdwjidx0B
;
341 __m128d jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
342 __m128d dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
343 __m128d velec
,felec
,velecsum
,facel
,crf
,krf
,krf2
;
345 __m128d dummy_mask
,cutoff_mask
;
346 __m128d signbit
= gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
347 __m128d one
= _mm_set1_pd(1.0);
348 __m128d two
= _mm_set1_pd(2.0);
354 jindex
= nlist
->jindex
;
356 shiftidx
= nlist
->shift
;
358 shiftvec
= fr
->shift_vec
[0];
359 fshift
= fr
->fshift
[0];
360 facel
= _mm_set1_pd(fr
->ic
->epsfac
);
361 charge
= mdatoms
->chargeA
;
362 krf
= _mm_set1_pd(fr
->ic
->k_rf
);
363 krf2
= _mm_set1_pd(fr
->ic
->k_rf
*2.0);
364 crf
= _mm_set1_pd(fr
->ic
->c_rf
);
366 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
367 rcutoff_scalar
= fr
->ic
->rcoulomb
;
368 rcutoff
= _mm_set1_pd(rcutoff_scalar
);
369 rcutoff2
= _mm_mul_pd(rcutoff
,rcutoff
);
371 /* Avoid stupid compiler warnings */
379 /* Start outer loop over neighborlists */
380 for(iidx
=0; iidx
<nri
; iidx
++)
382 /* Load shift vector for this list */
383 i_shift_offset
= DIM
*shiftidx
[iidx
];
385 /* Load limits for loop over neighbors */
386 j_index_start
= jindex
[iidx
];
387 j_index_end
= jindex
[iidx
+1];
389 /* Get outer coordinate index */
391 i_coord_offset
= DIM
*inr
;
393 /* Load i particle coords and add shift vector */
394 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec
+i_shift_offset
,x
+i_coord_offset
,&ix0
,&iy0
,&iz0
);
396 fix0
= _mm_setzero_pd();
397 fiy0
= _mm_setzero_pd();
398 fiz0
= _mm_setzero_pd();
400 /* Load parameters for i particles */
401 iq0
= _mm_mul_pd(facel
,_mm_load1_pd(charge
+inr
+0));
403 /* Start inner kernel loop */
404 for(jidx
=j_index_start
; jidx
<j_index_end
-1; jidx
+=2)
407 /* Get j neighbor index, and coordinate index */
410 j_coord_offsetA
= DIM
*jnrA
;
411 j_coord_offsetB
= DIM
*jnrB
;
413 /* load j atom coordinates */
414 gmx_mm_load_1rvec_2ptr_swizzle_pd(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
417 /* Calculate displacement vector */
418 dx00
= _mm_sub_pd(ix0
,jx0
);
419 dy00
= _mm_sub_pd(iy0
,jy0
);
420 dz00
= _mm_sub_pd(iz0
,jz0
);
422 /* Calculate squared distance and things based on it */
423 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
425 rinv00
= sse41_invsqrt_d(rsq00
);
427 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
429 /* Load parameters for j particles */
430 jq0
= gmx_mm_load_2real_swizzle_pd(charge
+jnrA
+0,charge
+jnrB
+0);
432 /**************************
433 * CALCULATE INTERACTIONS *
434 **************************/
436 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
439 /* Compute parameters for interactions between i and j atoms */
440 qq00
= _mm_mul_pd(iq0
,jq0
);
442 /* REACTION-FIELD ELECTROSTATICS */
443 felec
= _mm_mul_pd(qq00
,_mm_sub_pd(_mm_mul_pd(rinv00
,rinvsq00
),krf2
));
445 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
449 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
451 /* Calculate temporary vectorial force */
452 tx
= _mm_mul_pd(fscal
,dx00
);
453 ty
= _mm_mul_pd(fscal
,dy00
);
454 tz
= _mm_mul_pd(fscal
,dz00
);
456 /* Update vectorial force */
457 fix0
= _mm_add_pd(fix0
,tx
);
458 fiy0
= _mm_add_pd(fiy0
,ty
);
459 fiz0
= _mm_add_pd(fiz0
,tz
);
461 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f
+j_coord_offsetA
,f
+j_coord_offsetB
,tx
,ty
,tz
);
465 /* Inner loop uses 30 flops */
472 j_coord_offsetA
= DIM
*jnrA
;
474 /* load j atom coordinates */
475 gmx_mm_load_1rvec_1ptr_swizzle_pd(x
+j_coord_offsetA
,
478 /* Calculate displacement vector */
479 dx00
= _mm_sub_pd(ix0
,jx0
);
480 dy00
= _mm_sub_pd(iy0
,jy0
);
481 dz00
= _mm_sub_pd(iz0
,jz0
);
483 /* Calculate squared distance and things based on it */
484 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
486 rinv00
= sse41_invsqrt_d(rsq00
);
488 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
490 /* Load parameters for j particles */
491 jq0
= _mm_load_sd(charge
+jnrA
+0);
493 /**************************
494 * CALCULATE INTERACTIONS *
495 **************************/
497 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
500 /* Compute parameters for interactions between i and j atoms */
501 qq00
= _mm_mul_pd(iq0
,jq0
);
503 /* REACTION-FIELD ELECTROSTATICS */
504 felec
= _mm_mul_pd(qq00
,_mm_sub_pd(_mm_mul_pd(rinv00
,rinvsq00
),krf2
));
506 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
510 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
512 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
514 /* Calculate temporary vectorial force */
515 tx
= _mm_mul_pd(fscal
,dx00
);
516 ty
= _mm_mul_pd(fscal
,dy00
);
517 tz
= _mm_mul_pd(fscal
,dz00
);
519 /* Update vectorial force */
520 fix0
= _mm_add_pd(fix0
,tx
);
521 fiy0
= _mm_add_pd(fiy0
,ty
);
522 fiz0
= _mm_add_pd(fiz0
,tz
);
524 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f
+j_coord_offsetA
,tx
,ty
,tz
);
528 /* Inner loop uses 30 flops */
531 /* End of innermost loop */
533 gmx_mm_update_iforce_1atom_swizzle_pd(fix0
,fiy0
,fiz0
,
534 f
+i_coord_offset
,fshift
+i_shift_offset
);
536 /* Increment number of inner iterations */
537 inneriter
+= j_index_end
- j_index_start
;
539 /* Outer loop uses 7 flops */
542 /* Increment number of outer iterations */
545 /* Update outer/inner flops */
547 inc_nrnb(nrnb
,eNR_NBKERNEL_ELEC_F
,outeriter
*7 + inneriter
*30);