Unverified Commit 62742343 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

have a single union ubuf definition in lmptype.h and remove others

parent 006f7956
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
@@ -209,25 +209,6 @@ class AtomVec : protected Pointers {

  bool *threads;

  // union data struct for packing 32-bit and 64-bit ints into double bufs
  // this avoids aliasing issues by having 2 pointers (double,int)
  //   to same buf memory
  // constructor for 32-bit int prevents compiler
  //   from possibly calling the double constructor when passed an int
  // copy to a double *buf:
  //   buf[m++] = ubuf(foo).d, where foo is a 32-bit or 64-bit int
  // copy from a double *buf:
  //   foo = (int) ubuf(buf[m++]).i;, where (int) or (tagint) match foo
  //   the cast prevents compiler warnings about possible truncation

  union ubuf {
    double d;
    int64_t i;
    ubuf(double arg) : d(arg) {}
    ubuf(int64_t arg) : i(arg) {}
    ubuf(int arg) : i(arg) {}
  };

  // local methods

  void grow_nmax();
+0 −11
Original line number Diff line number Diff line
@@ -161,17 +161,6 @@ class Compute : protected Pointers {
    return j >> SBBITS & 3;
  }

  // union data struct for packing 32-bit and 64-bit ints into double bufs
  // see atom_vec.h for documentation

  union ubuf {
    double d;
    int64_t i;
    ubuf(double arg) : d(arg) {}
    ubuf(int64_t arg) : i(arg) {}
    ubuf(int arg) : i(arg) {}
  };

  // private methods

  void adjust_dof_fix();
+0 −11
Original line number Diff line number Diff line
@@ -242,17 +242,6 @@ class Fix : protected Pointers {
  void v_tally(int, int *, double, double *);
  void v_tally(int, double *);
  void v_tally(int, int, double);

  // union data struct for packing 32-bit and 64-bit ints into double bufs
  // see atom_vec.h for documentation

  union ubuf {
    double d;
    int64_t i;
    ubuf(double arg) : d(arg) {}
    ubuf(int64_t arg) : i(arg) {}
    ubuf(int arg) : i(arg) {}
  };
};

namespace FixConst {
+40 −0
Original line number Diff line number Diff line
@@ -171,6 +171,46 @@ typedef int bigint;

#endif

  /// Data structe for packing 32-bit and 64-bit integers
  /// into double (communication) buffers
  ///
  /// Using this union avoids aliasing issues by having member types
  /// (double, int) referencing the same buffer memory location.
  ///
  /// The explicit constructor for 32-bit integers prevents compilers
  /// from (incorrectly) calling the double constructor when storing
  ///  an int into a double buffer.
  /*
\verbatim embed:rst
**Usage:**

To copy an integer into a double buffer:

.. code-block: c++

   double buf[2];
   int    foo =   1;
   tagint bar = 2<<40;
   buf[1] = ubuf(foo).d;
   buf[2] = ubuf(bar).d;

To copy from a double buffer back to an int:

.. code-block: c++

   foo = (int)    ubuf(buf[1]).i;
   bar = (tagint) ubuf(buf[2]).i;

The typecast prevents compiler warnings about possible truncations.
\endverbatim
  */
  union ubuf {
    double  d;
    int64_t i;
    ubuf(const double  &arg) : d(arg) {}
    ubuf(const int64_t &arg) : i(arg) {}
    ubuf(const int     &arg) : i(arg) {}
  };
}

// preprocessor macros for compiler specific settings
+0 −11
Original line number Diff line number Diff line
@@ -258,17 +258,6 @@ class Pair : protected Pointers {
                      double, double, double, double, double, double);
  void virial_fdotr_compute();

  // union data struct for packing 32-bit and 64-bit ints into double bufs
  // see atom_vec.h for documentation

  union ubuf {
    double d;
    int64_t i;
    ubuf(double arg) : d(arg) {}
    ubuf(int64_t arg) : i(arg) {}
    ubuf(int arg) : i(arg) {}
  };

  inline int sbmask(int j) const {
    return j >> SBBITS & 3;
  }
Loading