2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2015,2016,2017,2018,2019, 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.
35 /*! \libinternal \file
37 * \brief This file contains a definition, declaration and inline function
38 * for SIMD accelerated PBC calculations.
40 * \author Berk Hess <hess@kth.se>
42 * \ingroup module_pbcutil
45 #ifndef GMX_PBCUTIL_PBC_SIMD_H
46 #define GMX_PBCUTIL_PBC_SIMD_H
50 #include "gromacs/pbcutil/pbc.h"
51 #include "gromacs/simd/simd.h"
55 /*! \brief Set the SIMD PBC data from a normal t_pbc struct.
57 * \param pbc Type of periodic boundary,
58 * NULL can be passed for then no PBC will be used.
59 * \param pbc_simd Pointer to aligned memory with (DIM + DIM*(DIM+1)/2)
60 * GMX_SIMD_REAL_WIDTH reals describing the box vectors
61 * unrolled by GMX_SIMD_REAL_WIDTH.
62 * These are sorted in a slightly non-standard
63 * order so that we always issue the memory loads in order
64 * (to improve prefetching) in pbc_correct_dx_simd().
65 * The order is inv_bzz, bzx, bzy, bzz, inv_byy, byx, byy,
68 void set_pbc_simd(const t_pbc
*pbc
,
71 #if GMX_SIMD_HAVE_REAL
73 /*! \brief Correct SIMD distance vector *dx,*dy,*dz for PBC using SIMD.
75 * For rectangular boxes all returned distance vectors are the shortest.
76 * For triclinic boxes only distances up to half the smallest box diagonal
77 * element are guaranteed to be the shortest. This means that distances from
78 * 0.5/sqrt(2) times a box vector length (e.g. for a rhombic dodecahedron)
79 * can use a more distant periodic image.
80 * Note that this routine always does PBC arithmetic, even for dimensions
81 * without PBC. But on modern processors the overhead of this, often called,
82 * routine should be low. On e.g. Intel Haswell/Broadwell it takes 8 cycles.
84 static inline void gmx_simdcall
85 pbc_correct_dx_simd(gmx::SimdReal
*dx
,
91 SimdReal shz
, shy
, shx
;
93 shz
= round(*dz
* load
<SimdReal
>(pbc_simd
+0*GMX_SIMD_REAL_WIDTH
)); // load inv_bzz
94 *dx
= *dx
- shz
* load
<SimdReal
>(pbc_simd
+1*GMX_SIMD_REAL_WIDTH
); // load bzx
95 *dy
= *dy
- shz
* load
<SimdReal
>(pbc_simd
+2*GMX_SIMD_REAL_WIDTH
); // load bzy
96 *dz
= *dz
- shz
* load
<SimdReal
>(pbc_simd
+3*GMX_SIMD_REAL_WIDTH
); // load bzz
98 shy
= round(*dy
* load
<SimdReal
>(pbc_simd
+4*GMX_SIMD_REAL_WIDTH
)); // load inv_byy
99 *dx
= *dx
- shy
* load
<SimdReal
>(pbc_simd
+5*GMX_SIMD_REAL_WIDTH
); // load byx
100 *dy
= *dy
- shy
* load
<SimdReal
>(pbc_simd
+6*GMX_SIMD_REAL_WIDTH
); // load byy
102 shx
= round(*dx
* load
<SimdReal
>(pbc_simd
+7*GMX_SIMD_REAL_WIDTH
)); // load inv_bxx
103 *dx
= *dx
- shx
* load
<SimdReal
>(pbc_simd
+8*GMX_SIMD_REAL_WIDTH
); // load bxx
107 /*! \brief Calculates the PBC corrected distance between SIMD coordinates.
109 * \param pbc_simd SIMD formatted PBC information
110 * \param x1 Packed coordinates of atom1, size 3*GMX_SIMD_REAL_WIDTH
111 * \param x2 Packed coordinates of atom2, size 3*GMX_SIMD_REAL_WIDTH
112 * \param dx The PBC corrected distance x1 - x2
114 * This routine only returns the shortest distance correctd for PBC
115 * when all atoms are in the unit-cell (aiuc).
116 * This is the SIMD equivalent of the scalar version declared in pbc.h.
118 static inline void gmx_simdcall
119 pbc_dx_aiuc(const real
*pbc_simd
,
120 const gmx::SimdReal
*x1
,
121 const gmx::SimdReal
*x2
,
124 for (int d
= 0; d
< DIM
; d
++)
126 dx
[d
] = x1
[d
] - x2
[d
];
128 pbc_correct_dx_simd(&dx
[XX
], &dx
[YY
], &dx
[ZZ
], pbc_simd
);
131 #endif /* GMX_SIMD_HAVE_REAL */