Skip to content

Commit

Permalink
refactor: use __restrict instead of __restrict__
Browse files Browse the repository at this point in the history
Wikipedia says "__restrict" is recognized by all three compilers. Let me
try it.
  • Loading branch information
HanatoK committed Oct 15, 2024
1 parent ea0d6ae commit 09def4b
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/colvar_rotation_derivative.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef COLVAR_ROTATION_DERIVATIVE
#define COLVAR_ROTATION_DERIVATIVE

#ifdef _MSC_VER
#define __restrict__
#endif

#include "colvartypes.h"
#include <type_traits>
#include <cstring>
Expand All @@ -13,7 +9,7 @@
template <typename T, typename std::enable_if<std::is_same<T, cvm::atom_pos>::value, bool>::type = true>
inline void read_atom_coord(
size_t ia, const std::vector<T>& pos,
cvm::real* __restrict__ x, cvm::real* __restrict__ y, cvm::real* __restrict__ z) {
cvm::real* __restrict x, cvm::real* __restrict y, cvm::real* __restrict z) {
*x = pos[ia].x;
*y = pos[ia].y;
*z = pos[ia].z;
Expand All @@ -22,7 +18,7 @@ inline void read_atom_coord(
template <typename T, typename std::enable_if<std::is_same<T, cvm::atom>::value, bool>::type = true>
inline void read_atom_coord(
size_t ia, const std::vector<T>& pos,
cvm::real* __restrict__ x, cvm::real* __restrict__ y, cvm::real* __restrict__ z) {
cvm::real* __restrict x, cvm::real* __restrict y, cvm::real* __restrict z) {
*x = pos[ia].pos.x;
*y = pos[ia].pos.y;
*z = pos[ia].pos.z;
Expand Down Expand Up @@ -334,9 +330,9 @@ struct rotation_derivative {
template <bool use_dl, bool use_dq, bool use_ds>
void calc_derivative_impl(
const cvm::rvector (&ds)[4][4],
cvm::rvector* __restrict__ const dl0_out,
cvm::vector1d<cvm::rvector>* __restrict__ const dq0_out,
cvm::matrix2d<cvm::rvector>* __restrict__ const ds_out) const {
cvm::rvector* __restrict const dl0_out,
cvm::vector1d<cvm::rvector>* __restrict const dq0_out,
cvm::matrix2d<cvm::rvector>* __restrict 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<cvm::rvector>(4, 4);
Expand Down Expand Up @@ -469,9 +465,9 @@ struct rotation_derivative {
*/
template <bool use_dl, bool use_dq, bool use_ds>
void calc_derivative_wrt_group1(
size_t ia, cvm::rvector* __restrict__ const dl0_1_out = nullptr,
cvm::vector1d<cvm::rvector>* __restrict__ const dq0_1_out = nullptr,
cvm::matrix2d<cvm::rvector>* __restrict__ const ds_1_out = nullptr) const {
size_t ia, cvm::rvector* __restrict const dl0_1_out = nullptr,
cvm::vector1d<cvm::rvector>* __restrict const dq0_1_out = nullptr,
cvm::matrix2d<cvm::rvector>* __restrict 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
Expand All @@ -495,9 +491,9 @@ struct rotation_derivative {
*/
template <bool use_dl, bool use_dq, bool use_ds>
void calc_derivative_wrt_group2(
size_t ia, cvm::rvector* __restrict__ const dl0_2_out = nullptr,
cvm::vector1d<cvm::rvector>* __restrict__ const dq0_2_out = nullptr,
cvm::matrix2d<cvm::rvector>* __restrict__ const ds_2_out = nullptr) const {
size_t ia, cvm::rvector* __restrict const dl0_2_out = nullptr,
cvm::vector1d<cvm::rvector>* __restrict const dq0_2_out = nullptr,
cvm::matrix2d<cvm::rvector>* __restrict 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
Expand Down

0 comments on commit 09def4b

Please sign in to comment.