From 643ed9ead6251e729100ab640cba8e28f7759401 Mon Sep 17 00:00:00 2001 From: HanatoK Date: Wed, 16 Oct 2024 10:07:26 -0500 Subject: [PATCH] Use the same trick for __restrict as LAMMPS See https://github.com/lammps/lammps/blob/59bbc5bcc1104bdb4fb45107cd65b5d4d76dbc00/src/lmptype.h#L342-L348 --- src/colvar_rotation_derivative.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/colvar_rotation_derivative.h b/src/colvar_rotation_derivative.h index 52ad0a6b4..09752d521 100644 --- a/src/colvar_rotation_derivative.h +++ b/src/colvar_rotation_derivative.h @@ -5,11 +5,21 @@ #include #include +#ifndef _noalias +#if defined(__INTEL_COMPILER) || (defined(__PGI) && !defined(__NVCOMPILER)) +#define _noalias restrict +#elif defined(__GNUC__) || defined(__INTEL_LLVM_COMPILER) || defined(__NVCOMPILER) +#define _noalias __restrict +#else +#define _noalias +#endif +#endif + /// \brief Helper function for loading the ia-th atom in the vector pos to x, y and z (C++11 SFINAE is used) template ::value, bool>::type = true> inline void read_atom_coord( size_t ia, const std::vector& pos, - cvm::real* __restrict x, cvm::real* __restrict y, cvm::real* __restrict z) { + cvm::real* _noalias x, cvm::real* _noalias y, cvm::real* _noalias z) { *x = pos[ia].x; *y = pos[ia].y; *z = pos[ia].z; @@ -18,7 +28,7 @@ inline void read_atom_coord( template ::value, bool>::type = true> inline void read_atom_coord( size_t ia, const std::vector& pos, - cvm::real* __restrict x, cvm::real* __restrict y, cvm::real* __restrict z) { + cvm::real* _noalias x, cvm::real* _noalias y, cvm::real* _noalias z) { *x = pos[ia].pos.x; *y = pos[ia].pos.y; *z = pos[ia].pos.z; @@ -330,9 +340,9 @@ struct rotation_derivative { template void calc_derivative_impl( const cvm::rvector (&ds)[4][4], - cvm::rvector* __restrict const dl0_out, - cvm::vector1d* __restrict const dq0_out, - cvm::matrix2d* __restrict const ds_out) const { + cvm::rvector* _noalias const dl0_out, + cvm::vector1d* _noalias const dq0_out, + cvm::matrix2d* _noalias const ds_out) const { if (use_ds) { // this code path is for debug_gradients, so not necessary to unroll the loop *ds_out = cvm::matrix2d(4, 4); @@ -465,9 +475,9 @@ struct rotation_derivative { */ template void calc_derivative_wrt_group1( - size_t ia, cvm::rvector* __restrict const dl0_1_out = nullptr, - cvm::vector1d* __restrict const dq0_1_out = nullptr, - cvm::matrix2d* __restrict const ds_1_out = nullptr) const { + size_t ia, cvm::rvector* _noalias const dl0_1_out = nullptr, + cvm::vector1d* _noalias const dq0_1_out = nullptr, + cvm::matrix2d* _noalias const ds_1_out = nullptr) const { // if (dl0_1_out == nullptr && dq0_1_out == nullptr) return; cvm::real a2x, a2y, a2z; // we can get rid of the helper function read_atom_coord if C++17 (constexpr) is available @@ -491,9 +501,9 @@ struct rotation_derivative { */ template void calc_derivative_wrt_group2( - size_t ia, cvm::rvector* __restrict const dl0_2_out = nullptr, - cvm::vector1d* __restrict const dq0_2_out = nullptr, - cvm::matrix2d* __restrict const ds_2_out = nullptr) const { + size_t ia, cvm::rvector* _noalias const dl0_2_out = nullptr, + cvm::vector1d* _noalias const dq0_2_out = nullptr, + cvm::matrix2d* _noalias const ds_2_out = nullptr) const { // if (dl0_2_out == nullptr && dq0_2_out == nullptr) return; cvm::real a1x, a1y, a1z; // we can get rid of the helper function read_atom_coord if C++17 (constexpr) is available