2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2009, The GROMACS Development Team
6 * Copyright (c) 2012,2013, by the GROMACS development team, led by
7 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
8 * others, as listed in the AUTHORS file in the top-level source
9 * directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
39 /* Half-width SIMD operations are required here.
40 * As the 4xn kernels are the "standard" kernels and some special operations
41 * are required only here, we define those in nbnxn_kernel_simd_utils_...
43 * Half-width SIMD real type:
46 * Half-width SIMD operations
47 * Load reals at half-width aligned pointer b into half-width SIMD register a:
49 * Set all entries in half-width SIMD register *a to b:
51 * Load one real at b and one real at b+1 into halves of a, respectively:
52 * gmx_load1p1_pr(a, b)
53 * Load reals at half-width aligned pointer b into two halves of a:
55 * Store half-width SIMD register b into half width aligned memory a:
59 * Sum over 4 half SIMD registers:
61 * Sum the elements of halfs of each input register and store sums in out:
62 * gmx_mm_transpose_sum4h_pr(a, b)
63 * Extract two half-width registers *b, *c from a full width register a:
64 * gmx_pr_to_2hpr(a, b, c)
69 const nbnxn_ci_t *nbln;
70 const nbnxn_cj_t *l_cj;
75 const real *nbfp0, *nbfp1, *nbfp2 = NULL, *nbfp3 = NULL;
80 gmx_bool do_LJ, half_LJ, do_coul;
81 int sci, scix, sciy, sciz, sci2;
82 int cjind0, cjind1, cjind;
87 int egps_ishift, egps_imask;
88 int egps_jshift, egps_jmask, egps_jstride;
90 real *vvdwtp[UNROLLI];
97 gmx_mm_pr ix_S0, iy_S0, iz_S0;
98 gmx_mm_pr ix_S2, iy_S2, iz_S2;
99 gmx_mm_pr fix_S0, fiy_S0, fiz_S0;
100 gmx_mm_pr fix_S2, fiy_S2, fiz_S2;
101 /* We use an i-force SIMD register width of 4 */
102 /* The pr4 stuff is defined in nbnxn_kernel_simd_utils.h */
103 gmx_mm_pr4 fix_S, fiy_S, fiz_S;
105 gmx_mm_pr diagonal_jmi_S;
106 #if UNROLLI == UNROLLJ
107 gmx_mm_pb diagonal_mask_S0, diagonal_mask_S2;
109 gmx_mm_pb diagonal_mask0_S0, diagonal_mask0_S2;
110 gmx_mm_pb diagonal_mask1_S0, diagonal_mask1_S2;
113 unsigned *exclusion_filter;
114 gmx_exclfilter filter_S0, filter_S2;
116 gmx_mm_pr zero_S = gmx_set1_pr(0);
118 gmx_mm_pr one_S = gmx_set1_pr(1.0);
119 gmx_mm_pr iq_S0 = gmx_setzero_pr();
120 gmx_mm_pr iq_S2 = gmx_setzero_pr();
123 gmx_mm_pr hrc_3_S, moh_rc_S;
127 /* Coulomb table variables */
129 const real *tab_coul_F;
131 const real *tab_coul_V;
133 int ti0_array[2*GMX_SIMD_WIDTH_HERE], *ti0;
134 int ti2_array[2*GMX_SIMD_WIDTH_HERE], *ti2;
140 #ifdef CALC_COUL_EWALD
141 gmx_mm_pr beta2_S, beta_S;
144 #if defined CALC_ENERGIES && (defined CALC_COUL_EWALD || defined CALC_COUL_TAB)
145 gmx_mm_pr sh_ewald_S;
151 gmx_mm_pr hsig_i_S0, seps_i_S0;
152 gmx_mm_pr hsig_i_S2, seps_i_S2;
155 real pvdw_array[2*UNROLLI*UNROLLJ+GMX_SIMD_WIDTH_HERE];
156 real *pvdw_c6, *pvdw_c12;
157 gmx_mm_pr c6_S0, c12_S0;
158 gmx_mm_pr c6_S2, c12_S2;
164 gmx_mm_pr c6s_S0, c12s_S0;
165 gmx_mm_pr c6s_S1, c12s_S1;
166 gmx_mm_pr c6s_S2 = gmx_setzero_pr(), c12s_S2 = gmx_setzero_pr();
167 gmx_mm_pr c6s_S3 = gmx_setzero_pr(), c12s_S3 = gmx_setzero_pr();
169 #endif /* LJ_COMB_LB */
171 gmx_mm_pr vctot_S, Vvdwtot_S;
172 gmx_mm_pr sixth_S, twelveth_S;
174 gmx_mm_pr avoid_sing_S;
176 #ifdef VDW_CUTOFF_CHECK
181 gmx_mm_pr sh_invrc6_S, sh_invrc12_S;
183 /* cppcheck-suppress unassignedVariable */
184 real tmpsum_array[2*GMX_SIMD_WIDTH_HERE], *tmpsum;
186 #ifdef CALC_SHIFTFORCES
187 /* cppcheck-suppress unassignedVariable */
188 real shf_array[2*GMX_SIMD_WIDTH_HERE], *shf;
197 #if defined LJ_COMB_GEOM || defined LJ_COMB_LB
200 /* No combination rule used */
201 nbfp_ptr = (4 == nbfp_stride) ? nbat->nbfp_s4 : nbat->nbfp;
204 /* Load j-i for the first i */
205 diagonal_jmi_S = gmx_load_pr(nbat->simd_2xnn_diagonal_j_minus_i);
206 /* Generate all the diagonal masks as comparison results */
207 #if UNROLLI == UNROLLJ
208 diagonal_mask_S0 = gmx_cmplt_pr(zero_S, diagonal_jmi_S);
209 diagonal_jmi_S = gmx_sub_pr(diagonal_jmi_S, one_S);
210 diagonal_jmi_S = gmx_sub_pr(diagonal_jmi_S, one_S);
211 diagonal_mask_S2 = gmx_cmplt_pr(zero_S, diagonal_jmi_S);
213 #if 2*UNROLLI == UNROLLJ
214 diagonal_mask0_S0 = gmx_cmplt_pr(zero_S, diagonal_jmi_S);
215 diagonal_jmi_S = gmx_sub_pr(diagonal_jmi_S, one_S);
216 diagonal_jmi_S = gmx_sub_pr(diagonal_jmi_S, one_S);
217 diagonal_mask0_S2 = gmx_cmplt_pr(zero_S, diagonal_jmi_S);
218 diagonal_jmi_S = gmx_sub_pr(diagonal_jmi_S, one_S);
219 diagonal_jmi_S = gmx_sub_pr(diagonal_jmi_S, one_S);
220 diagonal_mask1_S0 = gmx_cmplt_pr(zero_S, diagonal_jmi_S);
221 diagonal_jmi_S = gmx_sub_pr(diagonal_jmi_S, one_S);
222 diagonal_jmi_S = gmx_sub_pr(diagonal_jmi_S, one_S);
223 diagonal_mask1_S2 = gmx_cmplt_pr(zero_S, diagonal_jmi_S);
227 /* Load masks for topology exclusion masking. filter_stride is
228 static const, so the conditional will be optimized away. */
229 if (1 == filter_stride)
231 exclusion_filter = nbat->simd_exclusion_filter1;
233 else /* (2 == filter_stride) */
235 exclusion_filter = nbat->simd_exclusion_filter2;
238 /* Here we cast the exclusion masks from unsigned * to int * or
239 * real *. Since we only check bits, the actual value they
240 * represent does not matter, as long as both mask and exclusion
241 * info are treated the same way.
243 filter_S0 = gmx_load_exclusion_filter(exclusion_filter + 0*2*UNROLLJ*filter_stride);
244 filter_S2 = gmx_load_exclusion_filter(exclusion_filter + 1*2*UNROLLJ*filter_stride);
247 /* Generate aligned table index pointers */
248 ti0 = prepare_table_load_buffer(ti0_array);
249 ti2 = prepare_table_load_buffer(ti2_array);
251 invtsp_S = gmx_set1_pr(ic->tabq_scale);
253 mhalfsp_S = gmx_set1_pr(-0.5/ic->tabq_scale);
257 tab_coul_F = ic->tabq_coul_FDV0;
259 tab_coul_F = ic->tabq_coul_F;
260 tab_coul_V = ic->tabq_coul_V;
262 #endif /* CALC_COUL_TAB */
264 #ifdef CALC_COUL_EWALD
265 beta2_S = gmx_set1_pr(ic->ewaldcoeff*ic->ewaldcoeff);
266 beta_S = gmx_set1_pr(ic->ewaldcoeff);
269 #if (defined CALC_COUL_TAB || defined CALC_COUL_EWALD) && defined CALC_ENERGIES
270 sh_ewald_S = gmx_set1_pr(ic->sh_ewald);
276 shiftvec = shift_vec[0];
279 avoid_sing_S = gmx_set1_pr(NBNXN_AVOID_SING_R2_INC);
281 /* The kernel either supports rcoulomb = rvdw or rcoulomb >= rvdw */
282 rc2_S = gmx_set1_pr(ic->rcoulomb*ic->rcoulomb);
283 #ifdef VDW_CUTOFF_CHECK
284 rcvdw2_S = gmx_set1_pr(ic->rvdw*ic->rvdw);
288 sixth_S = gmx_set1_pr(1.0/6.0);
289 twelveth_S = gmx_set1_pr(1.0/12.0);
291 sh_invrc6_S = gmx_set1_pr(ic->sh_invrc6);
292 sh_invrc12_S = gmx_set1_pr(ic->sh_invrc6*ic->sh_invrc6);
295 mrc_3_S = gmx_set1_pr(-2*ic->k_rf);
298 hrc_3_S = gmx_set1_pr(ic->k_rf);
300 moh_rc_S = gmx_set1_pr(-ic->c_rf);
304 tmpsum = gmx_simd_align_real(tmpsum_array);
306 #ifdef CALC_SHIFTFORCES
307 shf = gmx_simd_align_real(shf_array);
311 pvdw_c6 = gmx_simd_align_real(pvdw_array);
312 pvdw_c12 = pvdw_c6 + UNROLLI*UNROLLJ;
314 for (jp = 0; jp < UNROLLJ; jp++)
316 pvdw_c6 [0*UNROLLJ+jp] = nbat->nbfp[0*2];
317 pvdw_c6 [1*UNROLLJ+jp] = nbat->nbfp[0*2];
318 pvdw_c6 [2*UNROLLJ+jp] = nbat->nbfp[0*2];
319 pvdw_c6 [3*UNROLLJ+jp] = nbat->nbfp[0*2];
321 pvdw_c12[0*UNROLLJ+jp] = nbat->nbfp[0*2+1];
322 pvdw_c12[1*UNROLLJ+jp] = nbat->nbfp[0*2+1];
323 pvdw_c12[2*UNROLLJ+jp] = nbat->nbfp[0*2+1];
324 pvdw_c12[3*UNROLLJ+jp] = nbat->nbfp[0*2+1];
326 c6_S0 = gmx_load_pr(pvdw_c6 +0*UNROLLJ);
327 c6_S1 = gmx_load_pr(pvdw_c6 +1*UNROLLJ);
328 c6_S2 = gmx_load_pr(pvdw_c6 +2*UNROLLJ);
329 c6_S3 = gmx_load_pr(pvdw_c6 +3*UNROLLJ);
331 c12_S0 = gmx_load_pr(pvdw_c12+0*UNROLLJ);
332 c12_S1 = gmx_load_pr(pvdw_c12+1*UNROLLJ);
333 c12_S2 = gmx_load_pr(pvdw_c12+2*UNROLLJ);
334 c12_S3 = gmx_load_pr(pvdw_c12+3*UNROLLJ);
335 #endif /* FIX_LJ_C */
338 egps_ishift = nbat->neg_2log;
339 egps_imask = (1<<egps_ishift) - 1;
340 egps_jshift = 2*nbat->neg_2log;
341 egps_jmask = (1<<egps_jshift) - 1;
342 egps_jstride = (UNROLLJ>>1)*UNROLLJ;
343 /* Major division is over i-particle energy groups, determine the stride */
344 Vstride_i = nbat->nenergrp*(1<<nbat->neg_2log)*egps_jstride;
350 for (n = 0; n < nbl->nci; n++)
354 ish = (nbln->shift & NBNXN_CI_SHIFT);
356 cjind0 = nbln->cj_ind_start;
357 cjind1 = nbln->cj_ind_end;
359 ci_sh = (ish == CENTRAL ? ci : -1);
361 shX_S = gmx_load1_pr(shiftvec+ish3);
362 shY_S = gmx_load1_pr(shiftvec+ish3+1);
363 shZ_S = gmx_load1_pr(shiftvec+ish3+2);
370 sci = (ci>>1)*STRIDE;
371 scix = sci*DIM + (ci & 1)*(STRIDE>>1);
372 sci2 = sci*2 + (ci & 1)*(STRIDE>>1);
373 sci += (ci & 1)*(STRIDE>>1);
376 /* We have 5 LJ/C combinations, but use only three inner loops,
377 * as the other combinations are unlikely and/or not much faster:
378 * inner half-LJ + C for half-LJ + C / no-LJ + C
379 * inner LJ + C for full-LJ + C
380 * inner LJ for full-LJ + no-C / half-LJ + no-C
382 do_LJ = (nbln->shift & NBNXN_CI_DO_LJ(0));
383 do_coul = (nbln->shift & NBNXN_CI_DO_COUL(0));
384 half_LJ = ((nbln->shift & NBNXN_CI_HALF_LJ(0)) || !do_LJ) && do_coul;
387 egps_i = nbat->energrp[ci];
391 for (ia = 0; ia < UNROLLI; ia++)
393 egp_ia = (egps_i >> (ia*egps_ishift)) & egps_imask;
394 vvdwtp[ia] = Vvdw + egp_ia*Vstride_i;
395 vctp[ia] = Vc + egp_ia*Vstride_i;
399 #if defined CALC_ENERGIES
401 if (do_coul && l_cj[nbln->cj_ind_start].cj == ci_sh)
404 if (do_coul && l_cj[nbln->cj_ind_start].cj == (ci_sh>>1))
411 Vc_sub_self = 0.5*ic->c_rf;
415 Vc_sub_self = 0.5*tab_coul_F[2];
417 Vc_sub_self = 0.5*tab_coul_V[0];
420 #ifdef CALC_COUL_EWALD
422 Vc_sub_self = 0.5*ic->ewaldcoeff*M_2_SQRTPI;
425 for (ia = 0; ia < UNROLLI; ia++)
431 vctp[ia][((egps_i>>(ia*egps_ishift)) & egps_imask)*egps_jstride]
435 -= facel*qi*qi*Vc_sub_self;
440 /* Load i atom data */
441 sciy = scix + STRIDE;
442 sciz = sciy + STRIDE;
443 gmx_load1p1_pr(&ix_S0, x+scix);
444 gmx_load1p1_pr(&ix_S2, x+scix+2);
445 gmx_load1p1_pr(&iy_S0, x+sciy);
446 gmx_load1p1_pr(&iy_S2, x+sciy+2);
447 gmx_load1p1_pr(&iz_S0, x+sciz);
448 gmx_load1p1_pr(&iz_S2, x+sciz+2);
449 ix_S0 = gmx_add_pr(ix_S0, shX_S);
450 ix_S2 = gmx_add_pr(ix_S2, shX_S);
451 iy_S0 = gmx_add_pr(iy_S0, shY_S);
452 iy_S2 = gmx_add_pr(iy_S2, shY_S);
453 iz_S0 = gmx_add_pr(iz_S0, shZ_S);
454 iz_S2 = gmx_add_pr(iz_S2, shZ_S);
460 facel_S = gmx_set1_pr(facel);
462 gmx_load1p1_pr(&iq_S0, q+sci);
463 gmx_load1p1_pr(&iq_S2, q+sci+2);
464 iq_S0 = gmx_mul_pr(facel_S, iq_S0);
465 iq_S2 = gmx_mul_pr(facel_S, iq_S2);
469 gmx_load1p1_pr(&hsig_i_S0, ljc+sci2+0);
470 gmx_load1p1_pr(&hsig_i_S2, ljc+sci2+2);
471 gmx_load1p1_pr(&seps_i_S0, ljc+sci2+STRIDE+0);
472 gmx_load1p1_pr(&seps_i_S2, ljc+sci2+STRIDE+2);
475 gmx_load1p1_pr(&c6s_S0, ljc+sci2+0);
478 gmx_load1p1_pr(&c6s_S2, ljc+sci2+2);
480 gmx_load1p1_pr(&c12s_S0, ljc+sci2+STRIDE+0);
483 gmx_load1p1_pr(&c12s_S2, ljc+sci2+STRIDE+2);
486 nbfp0 = nbfp_ptr + type[sci ]*nbat->ntype*nbfp_stride;
487 nbfp1 = nbfp_ptr + type[sci+1]*nbat->ntype*nbfp_stride;
490 nbfp2 = nbfp_ptr + type[sci+2]*nbat->ntype*nbfp_stride;
491 nbfp3 = nbfp_ptr + type[sci+3]*nbat->ntype*nbfp_stride;
496 /* Zero the potential energy for this list */
497 Vvdwtot_S = gmx_setzero_pr();
498 vctot_S = gmx_setzero_pr();
500 /* Clear i atom forces */
501 fix_S0 = gmx_setzero_pr();
502 fix_S2 = gmx_setzero_pr();
503 fiy_S0 = gmx_setzero_pr();
504 fiy_S2 = gmx_setzero_pr();
505 fiz_S0 = gmx_setzero_pr();
506 fiz_S2 = gmx_setzero_pr();
510 /* Currently all kernels use (at least half) LJ */
517 while (cjind < cjind1 && nbl->cj[cjind].excl != NBNXN_INTERACTION_MASK_ALL)
519 #include "nbnxn_kernel_simd_2xnn_inner.h"
523 for (; (cjind < cjind1); cjind++)
525 #include "nbnxn_kernel_simd_2xnn_inner.h"
534 while (cjind < cjind1 && nbl->cj[cjind].excl != NBNXN_INTERACTION_MASK_ALL)
536 #include "nbnxn_kernel_simd_2xnn_inner.h"
540 for (; (cjind < cjind1); cjind++)
542 #include "nbnxn_kernel_simd_2xnn_inner.h"
549 while (cjind < cjind1 && nbl->cj[cjind].excl != NBNXN_INTERACTION_MASK_ALL)
551 #include "nbnxn_kernel_simd_2xnn_inner.h"
555 for (; (cjind < cjind1); cjind++)
557 #include "nbnxn_kernel_simd_2xnn_inner.h"
561 ninner += cjind1 - cjind0;
563 /* Add accumulated i-forces to the force array */
564 fix_S = gmx_mm_transpose_sum4h_pr(fix_S0, fix_S2);
565 gmx_store_pr4(f+scix, gmx_add_pr4(fix_S, gmx_load_pr4(f+scix)));
567 fiy_S = gmx_mm_transpose_sum4h_pr(fiy_S0, fiy_S2);
568 gmx_store_pr4(f+sciy, gmx_add_pr4(fiy_S, gmx_load_pr4(f+sciy)));
570 fiz_S = gmx_mm_transpose_sum4h_pr(fiz_S0, fiz_S2);
571 gmx_store_pr4(f+sciz, gmx_add_pr4(fiz_S, gmx_load_pr4(f+sciz)));
573 #ifdef CALC_SHIFTFORCES
574 gmx_store_pr4(shf, fix_S);
575 fshift[ish3+0] += SUM_SIMD4(shf);
576 gmx_store_pr4(shf, fiy_S);
577 fshift[ish3+1] += SUM_SIMD4(shf);
578 gmx_store_pr4(shf, fiz_S);
579 fshift[ish3+2] += SUM_SIMD4(shf);
585 gmx_store_pr(tmpsum, vctot_S);
586 *Vc += SUM_SIMD(tmpsum);
589 gmx_store_pr(tmpsum, Vvdwtot_S);
590 *Vvdw += SUM_SIMD(tmpsum);
593 /* Outer loop uses 6 flops/iteration */
597 printf("atom pairs %d\n", npair);