Minor vec.h cleanup
authorTeemu Murtola <teemu.murtola@gmail.com>
Sat, 21 Dec 2013 05:03:52 +0000 (07:03 +0200)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sun, 29 Dec 2013 11:53:01 +0000 (13:53 +0200)
- Remove unused and not defined vecinvsqrt() and vecrecip().
- Remove PR_VEC() macro and replace the few remaining uses with the
  expansion.
- Move all C++ overloads to the same place in the file.
- Add a few missing gmx_inline attributes.
- Combine all #ifdef GMX_SOFTWARE_INVSQRT blocks, and move macros
  required only for it inside the #ifdef.
- Remove tabs in comments.

Change-Id: I59b8129a813d70b4887f9e6d00e72d2b256acfe4

src/gromacs/gmxana/gmx_anaeig.c
src/gromacs/gmxana/gmx_trjconv.c
src/gromacs/legacyheaders/vec.h

index 691dc2ad4d89177063e7520d6f7e5f073268ed1c..3788f3528f37dc98eacf5a934235cb2aeaec2ae9 100644 (file)
@@ -761,7 +761,7 @@ static void project(const char *trajfile, t_topology *top, int ePBC, matrix topb
                     j = 0;
                 }
                 fprintf(out, pdbform, "ATOM", i+1, "C", "PRJ", ' ', j+1,
-                        PR_VEC(10*x[i]), 1.0, 10*b[i]);
+                        10*x[i][XX], 10*x[i][YY], 10*x[i][ZZ], 1.0, 10*b[i]);
                 if (j > 0)
                 {
                     fprintf(out, "CONECT%5d%5d\n", i, i+1);
index 3950060f6061a03c24571f27b498ae64400a7a6f..e78459b1a8e744d6b9c709d027c276fb248cd46f 100644 (file)
@@ -317,8 +317,9 @@ static void put_molecule_com_in_box(int unitcell_enum, int ecenter,
         {
             if (debug)
             {
-                fprintf (debug, "\nShifting position of molecule %d "
-                         "by %8.3f  %8.3f  %8.3f\n", i+1, PR_VEC(shift));
+                fprintf(debug, "\nShifting position of molecule %d "
+                        "by %8.3f  %8.3f  %8.3f\n", i+1,
+                        shift[XX], shift[YY], shift[ZZ]);
             }
             for (j = mols->index[i]; (j < mols->index[i+1] && j < natoms); j++)
             {
@@ -372,9 +373,9 @@ static void put_residue_com_in_box(int unitcell_enum, int ecenter,
             {
                 if (debug)
                 {
-                    fprintf (debug, "\nShifting position of residue %d (atoms %u-%u) "
-                             "by %g,%g,%g\n", atom[res_start].resind+1,
-                             res_start+1, res_end+1, PR_VEC(shift));
+                    fprintf(debug, "\nShifting position of residue %d (atoms %u-%u) "
+                            "by %g,%g,%g\n", atom[res_start].resind+1,
+                            res_start+1, res_end+1, shift[XX], shift[YY], shift[ZZ]);
                 }
                 for (j = res_start; j < res_end; j++)
                 {
index c4e2e44e6f5423fd287126ce6482f48c87b15b1f..5951209f3a62bddeda8628f5b1b1ee8181c4856a 100644 (file)
@@ -40,8 +40,6 @@
 
    lookup-table optimized scalar operations:
    real gmx_invsqrt(real x)
-   void vecinvsqrt(real in[],real out[],int n)
-   void vecrecip(real in[],real out[],int n)
    real sqr(real x)
    double dsqr(double x)
 
     could produce less rounding errors, not due to the operations themselves,
     but because the compiler can easier recombine the operations
    void copy_mat(matrix a,matrix b)                 b = a
-   void clear_mat(matrix a)                       a = 0
-   void mmul(matrix a,matrix b,matrix dest)    !  dest = a . b
+   void clear_mat(matrix a)                         a = 0
+   void mmul(matrix a,matrix b,matrix dest)      !  dest = a . b
    void mmul_ur0(matrix a,matrix b,matrix dest)     dest = a . b
-   void transpose(matrix src,matrix dest)      !  dest = src*
-   void tmmul(matrix a,matrix b,matrix dest)   !  dest = a* . b
-   void mtmul(matrix a,matrix b,matrix dest)   !  dest = a . b*
-   real det(matrix a)                             = det(a)
-   void m_add(matrix a,matrix b,matrix dest)      dest = a + b
-   void m_sub(matrix a,matrix b,matrix dest)      dest = a - b
-   void msmul(matrix m1,real r1,matrix dest)      dest = r1 * m1
+   void transpose(matrix src,matrix dest)        !  dest = src*
+   void tmmul(matrix a,matrix b,matrix dest)     !  dest = a* . b
+   void mtmul(matrix a,matrix b,matrix dest)     !  dest = a . b*
+   real det(matrix a)                               = det(a)
+   void m_add(matrix a,matrix b,matrix dest)        dest = a + b
+   void m_sub(matrix a,matrix b,matrix dest)        dest = a - b
+   void msmul(matrix m1,real r1,matrix dest)        dest = r1 * m1
    void m_inv_ur0(matrix src,matrix dest)           dest = src^-1
-   void m_inv(matrix src,matrix dest)          !  dest = src^-1
-   void mvmul(matrix a,rvec src,rvec dest)     !  dest = a . src
+   void m_inv(matrix src,matrix dest)            !  dest = src^-1
+   void mvmul(matrix a,rvec src,rvec dest)       !  dest = a . src
    void mvmul_ur0(matrix a,rvec src,rvec dest)      dest = a . src
    void tmvmul_ur0(matrix a,rvec src,rvec dest)     dest = a* . src
    real trace(matrix m)                             = trace(m)
 #include "physics.h"
 
 #ifdef __cplusplus
-
-static gmx_inline real det(const matrix a)
-{
-    return ( a[XX][XX]*(a[YY][YY]*a[ZZ][ZZ]-a[ZZ][YY]*a[YY][ZZ])
-             -a[YY][XX]*(a[XX][YY]*a[ZZ][ZZ]-a[ZZ][YY]*a[XX][ZZ])
-             +a[ZZ][XX]*(a[XX][YY]*a[YY][ZZ]-a[YY][YY]*a[XX][ZZ]));
-}
-
-static gmx_inline void mvmul(const matrix a, const rvec src, rvec dest)
-{
-    dest[XX] = a[XX][XX]*src[XX]+a[XX][YY]*src[YY]+a[XX][ZZ]*src[ZZ];
-    dest[YY] = a[YY][XX]*src[XX]+a[YY][YY]*src[YY]+a[YY][ZZ]*src[ZZ];
-    dest[ZZ] = a[ZZ][XX]*src[XX]+a[ZZ][YY]*src[YY]+a[ZZ][ZZ]*src[ZZ];
-}
-
 extern "C" {
 #elif 0
 } /* avoid screwing up indentation */
 #endif
 
-
+#ifdef GMX_SOFTWARE_INVSQRT
 #define EXP_LSB         0x00800000
 #define EXP_MASK        0x7f800000
 #define EXP_SHIFT       23
@@ -144,13 +127,8 @@ extern "C" {
 #define EXP_ADDR(val)   (((val)&EXP_MASK)>>EXP_SHIFT)
 #define FRACT_ADDR(val) (((val)&(FRACT_MASK|EXP_LSB))>>FRACT_SHIFT)
 
-#define PR_VEC(a)       a[XX], a[YY], a[ZZ]
-
-#ifdef GMX_SOFTWARE_INVSQRT
-extern const unsigned int *  gmx_invsqrt_exptab;
-extern const unsigned int *  gmx_invsqrt_fracttab;
-#endif
-
+extern const unsigned int *gmx_invsqrt_exptab;
+extern const unsigned int *gmx_invsqrt_fracttab;
 
 typedef union
 {
@@ -158,9 +136,7 @@ typedef union
     float        fval;
 } t_convert;
 
-
-#ifdef GMX_SOFTWARE_INVSQRT
-static real gmx_software_invsqrt(real x)
+static gmx_inline real gmx_software_invsqrt(real x)
 {
     const real   half  = 0.5;
     const real   three = 3.0;
@@ -212,7 +188,7 @@ static real gmx_software_invsqrt(real x)
 #endif
 
 
-static real sqr(real x)
+static gmx_inline real sqr(real x)
 {
     return (x*x);
 }
@@ -232,22 +208,6 @@ static gmx_inline real series_sinhx(real x)
     return (1 + (x2/6.0)*(1 + (x2/20.0)*(1 + (x2/42.0)*(1 + (x2/72.0)*(1 + (x2/110.0))))));
 }
 
-void vecinvsqrt(real in[], real out[], int n);
-/* Perform out[i]=1.0/sqrt(in[i]) for n elements */
-
-
-void vecrecip(real in[], real out[], int n);
-/* Perform out[i]=1.0/(in[i]) for n elements */
-
-/* Note: If you need a fast version of vecinvsqrt
- * and/or vecrecip, call detectcpu() and run the SSE/3DNow/SSE2/Altivec
- * versions if your hardware supports it.
- *
- * To use those routines, your memory HAS TO BE CACHE-ALIGNED.
- * Use snew_aligned(ptr,size,32) to allocate and sfree_aligned to free.
- */
-
-
 static gmx_inline void rvec_add(const rvec a, const rvec b, rvec c)
 {
     real x, y, z;
@@ -452,7 +412,6 @@ static gmx_inline void clear_ivec(ivec a)
 
 static gmx_inline void clear_rvecs(int n, rvec v[])
 {
-/*  memset(v[0],0,DIM*n*sizeof(v[0][0])); */
     int i;
 
     for (i = 0; (i < n); i++)
@@ -463,8 +422,6 @@ static gmx_inline void clear_rvecs(int n, rvec v[])
 
 static gmx_inline void clear_mat(matrix a)
 {
-/*  memset(a[0],0,DIM*DIM*sizeof(a[0][0])); */
-
     const real nul = 0.0;
 
     a[XX][XX] = a[XX][YY] = a[XX][ZZ] = nul;
@@ -550,7 +507,7 @@ cos_angle(const rvec a, const rvec b)
     double aa, bb, ip, ipa, ipb, ipab; /* For accuracy these must be double! */
 
     ip = ipa = ipb = 0.0;
-    for (m = 0; (m < DIM); m++) /* 18          */
+    for (m = 0; (m < DIM); m++) /* 18 */
     {
         aa   = a[m];
         bb   = b[m];
@@ -561,13 +518,13 @@ cos_angle(const rvec a, const rvec b)
     ipab = ipa*ipb;
     if (ipab > 0)
     {
-        cosval = ip*gmx_invsqrt(ipab);  /*  7          */
+        cosval = ip*gmx_invsqrt(ipab);  /*  7 */
     }
     else
     {
         cosval = 1;
     }
-    /* 25 TOTAL        */
+    /* 25 TOTAL */
     if (cosval > 1.0)
     {
         return 1.0;
@@ -595,7 +552,7 @@ cos_angle_no_table(const rvec a, const rvec b)
     double aa, bb, ip, ipa, ipb; /* For accuracy these must be double! */
 
     ip = ipa = ipb = 0.0;
-    for (m = 0; (m < DIM); m++) /* 18          */
+    for (m = 0; (m < DIM); m++) /* 18 */
     {
         aa   = a[m];
         bb   = b[m];
@@ -603,8 +560,8 @@ cos_angle_no_table(const rvec a, const rvec b)
         ipa += aa*aa;
         ipb += bb*bb;
     }
-    cosval = ip/sqrt(ipa*ipb);  /* 12          */
-    /* 30 TOTAL        */
+    cosval = ip/sqrt(ipa*ipb);  /* 12 */
+    /* 30 TOTAL */
     if (cosval > 1.0)
     {
         return 1.0;
@@ -883,7 +840,7 @@ static gmx_inline int _mod(int a, int b, char *file, int line)
 }
 
 /* Operations on multidimensional rvecs, used e.g. in edsam.c */
-static void m_rveccopy(int dim, rvec *a, rvec *b)
+static gmx_inline void m_rveccopy(int dim, rvec *a, rvec *b)
 {
     /* b = a */
     int i;
@@ -895,7 +852,7 @@ static void m_rveccopy(int dim, rvec *a, rvec *b)
 }
 
 /*computer matrix vectors from base vectors and angles */
-static void matrix_convert(matrix box, rvec vec, rvec angle)
+static gmx_inline void matrix_convert(matrix box, rvec vec, rvec angle)
 {
     svmul(DEG2RAD, angle, angle);
     box[XX][XX] = vec[XX];
@@ -914,6 +871,20 @@ static void matrix_convert(matrix box, rvec vec, rvec angle)
 #ifdef __cplusplus
 }
 
+static gmx_inline real det(const matrix a)
+{
+    return ( a[XX][XX]*(a[YY][YY]*a[ZZ][ZZ]-a[ZZ][YY]*a[YY][ZZ])
+             -a[YY][XX]*(a[XX][YY]*a[ZZ][ZZ]-a[ZZ][YY]*a[XX][ZZ])
+             +a[ZZ][XX]*(a[XX][YY]*a[YY][ZZ]-a[YY][YY]*a[XX][ZZ]));
+}
+
+static gmx_inline void mvmul(const matrix a, const rvec src, rvec dest)
+{
+    dest[XX] = a[XX][XX]*src[XX]+a[XX][YY]*src[YY]+a[XX][ZZ]*src[ZZ];
+    dest[YY] = a[YY][XX]*src[XX]+a[YY][YY]*src[YY]+a[YY][ZZ]*src[ZZ];
+    dest[ZZ] = a[ZZ][XX]*src[XX]+a[ZZ][YY]*src[YY]+a[ZZ][ZZ]*src[ZZ];
+}
+
 static gmx_inline void tmvmul_ur0(const matrix a, const rvec src, rvec dest)
 {
     dest[XX] = a[XX][XX]*src[XX]+a[YY][XX]*src[YY]+a[ZZ][XX]*src[ZZ];