src/core/model/int64x64-128.h
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Fri, 16 Jan 2015 11:55:23 -0800
changeset 11140 35c2c969d0b2
parent 11092 6afcfe8a5447
child 11356 8589e611d657
permissions -rw-r--r--
[Doxygen] Various in src/core
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10979
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     2
/*
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     3
 * Copyright (c) 2010 INRIA
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     4
 *
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     7
 * published by the Free Software Foundation;
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     8
 *
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    12
 * GNU General Public License for more details.
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    13
 *
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    14
 * You should have received a copy of the GNU General Public License
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    15
 * along with this program; if not, write to the Free Software
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    17
 *
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    18
 */
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    19
7048
a6d78cb50f6e early work to make python bindings work again with ns-3-time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7045
diff changeset
    20
#include "ns3/core-config.h"
10979
dfda54e1d825 add missing GPLs
Tom Henderson <tomh@tomh.org>
parents: 10637
diff changeset
    21
7048
a6d78cb50f6e early work to make python bindings work again with ns-3-time
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7045
diff changeset
    22
#if !defined(INT64X64_128_H) && defined (INT64X64_USE_128) && !defined(PYTHON_SCAN)
7039
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7035
diff changeset
    23
#define INT64X64_128_H
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#include <stdint.h>
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    26
#include <cmath>  // pow
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
7494
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7169
diff changeset
    28
#if defined(HAVE___UINT128_T) && !defined(HAVE_UINT128_T)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
typedef __uint128_t uint128_t;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
typedef __int128_t int128_t;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
#endif
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
namespace ns3 {
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    35
/**
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    36
 * \internal
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    37
 * The implementation documented here is based on native 128-bit integers.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    38
 */
7039
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7035
diff changeset
    39
class int64x64_t
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
{
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    41
  /// uint128_t high bit (sign bit).
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    42
  static const uint128_t   HP128_MASK_HI_BIT = (((int128_t)1)<<127);
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    43
  /// Mask for fraction part.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    44
  static const uint64_t    HP_MASK_LO = 0xffffffffffffffffULL;
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    45
  /// Mask for sign + integer part.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    46
  static const uint64_t    HP_MASK_HI = ~HP_MASK_LO;
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    47
  /**
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    48
   * Floating point value of HP_MASK_LO + 1.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    49
   * We really want:
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    50
   * \code
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    51
   *   static const long double HP_MAX_64 = std:pow (2.0L, 64);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    52
   * \endcode
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    53
   * but we can't call functions in const definitions.
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    54
   *
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    55
   * We could make this a static and initialize in int64x64-128.cc or
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    56
   * int64x64.cc, but this requires handling static initialization order
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    57
   * when most of the implementation is inline.  Instead, we resort to
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    58
   * this define.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    59
   */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    60
#define HP_MAX_64    (std::pow (2.0L, 64))
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    61
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
public:
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    63
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    64
   * Type tag for the underlying implementation.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    65
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    66
   * A few testcases are are sensitive to implementation,
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    67
   * specifically the double implementation.  To handle this,
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    68
   * we expose the underlying implementation type here.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    69
   */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    70
  enum impl_type {
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    71
    int128_impl,  //!< Native \c int128_t implementation.
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    72
    cairo_impl,   //!< Cairo wideint implementation.
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    73
    ld_impl,      //!< `long double` implementation.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    74
  };
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    75
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    76
  /// Type tag for this implementation.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    77
  static const enum impl_type implementation = int128_impl;
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    78
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    79
  /// Default constructor.
7039
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7035
diff changeset
    80
  inline int64x64_t ()
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    81
    : _v (0)  {}
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    82
  /**
11140
35c2c969d0b2 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11092
diff changeset
    83
   * \name Construct from a floating point value.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    84
   *
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
    85
   * \param [in] value Floating value to represent.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    86
   */
11140
35c2c969d0b2 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11092
diff changeset
    87
  /**@{*/
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    88
  inline int64x64_t (const double value)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
  {
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    90
    const int64x64_t tmp ((long double)value);
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    91
    _v = tmp._v;
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
  }
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    93
  inline int64x64_t (const long double value)
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
    94
  {
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    95
    const bool negative = value < 0;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    96
    const long double v = negative ? -value : value;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    97
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    98
    long double fhi;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
    99
    long double flo = std::modf (v, &fhi);
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   100
    // Add 0.5 to round, which improves the last count
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   101
    // This breaks these tests:
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   102
    //   TestSuite devices-mesh-dot11s-regression
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   103
    //   TestSuite devices-mesh-flame-regression
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   104
    //   TestSuite routing-aodv-regression
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   105
    //   TestSuite routing-olsr-regression
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   106
    // Setting round = 0; breaks:
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   107
    //   TestSuite int64x64
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   108
    const long double round = 0.5;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   109
    flo = flo * HP_MAX_64 + round;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   110
    int128_t hi = fhi;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   111
    const uint64_t lo = flo;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   112
    if (flo >= HP_MAX_64)
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   113
      {
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   114
	// conversion to uint64 rolled over
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   115
	++hi;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   116
      }
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   117
    _v = hi << 64;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   118
    _v |= lo;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   119
    _v = negative ? -_v : _v;
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   120
  }
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   121
  /**@}*/
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   122
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   123
  /**
11140
35c2c969d0b2 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11092
diff changeset
   124
   * \name Construct from an integral type.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   125
   *
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   126
   * \param [in] v Integer value to represent.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   127
   */
11140
35c2c969d0b2 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11092
diff changeset
   128
  /**@{*/
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   129
  inline int64x64_t (const int v)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
    : _v (v)
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
  {
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
    _v <<= 64;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
  }
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   134
  inline int64x64_t (const long int v)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
    : _v (v) 
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
  {
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
    _v <<= 64;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
  }
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   139
  inline int64x64_t (const long long int v)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
    : _v (v) 
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
  {
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
    _v <<= 64;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
  }
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   144
  inline int64x64_t (const unsigned int v)
7035
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   145
    : _v (v)
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   146
  {
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   147
    _v <<= 64;
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   148
  }
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   149
  inline int64x64_t (const unsigned long int v)
7035
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   150
    : _v (v) 
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   151
  {
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   152
    _v <<= 64;
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   153
  }
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   154
  inline int64x64_t (const unsigned long long int v)
7035
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   155
    : _v (v) 
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   156
  {
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   157
    _v <<= 64;
8446ae042275 add missing constructors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7032
diff changeset
   158
  }
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   159
  /**@}*/
11140
35c2c969d0b2 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11092
diff changeset
   160
  
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   161
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   162
   * Construct from explicit high and low values.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   163
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   164
   * \param [in] hi Integer portion.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   165
   * \param [in] lo Fractional portion, already scaled to HP_MAX_64.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   166
   */
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   167
  explicit inline int64x64_t (const int64_t hi, const uint64_t lo)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
  {
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   169
    _v = (int128_t)hi << 64;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   170
    _v |= lo;
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
  }
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   173
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   174
   * Copy constructor.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   175
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   176
   * \param [in] o Value to copy.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   177
   */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   178
  inline int64x64_t (const int64x64_t & o)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
    : _v (o._v) {}
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   180
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   181
   * Assignment.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   182
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   183
   * \param [in] o Value to assign to this int64x64_t.
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   184
   * \returns This int64x64_t.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   185
   */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   186
  inline int64x64_t & operator = (const int64x64_t & o)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7048
diff changeset
   187
  {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7048
diff changeset
   188
    _v = o._v;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7048
diff changeset
   189
    return *this;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7048
diff changeset
   190
  }
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   192
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   193
   * Get this value as a double.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   194
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   195
   * \return This value in floating form.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   196
   */
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
  inline double GetDouble (void) const
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
  {
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   199
    const bool negative = _v < 0;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   200
    const uint128_t value = negative ? -_v : _v;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   201
    const long double fhi = value >> 64;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   202
    const long double flo = (value & HP_MASK_LO) / HP_MAX_64;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   203
    long double retval = fhi;
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
    retval += flo;
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   205
    retval = negative ? -retval : retval;
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
    return retval;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
  }
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   208
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   209
   * Get the integer portion.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   210
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   211
   * \return The integer portion of this value.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   212
   */
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
  inline int64_t GetHigh (void) const
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
  {
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   215
    const int128_t retval = _v >> 64;
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   216
    return retval;
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
  }
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   218
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   219
   * Get the fractional portion of this value, unscaled.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   220
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   221
   * \return The fractional portion, unscaled, as an integer.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   222
   */
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
  inline uint64_t GetLow (void) const
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
  {
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   225
    const uint128_t retval = _v & HP_MASK_LO;
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
    return retval;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
  }
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   228
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   229
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   230
   * Multiply this value by a Q0.128 value, presumably representing an inverse,
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   231
   * completing a division operation.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   232
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   233
   * \param [in] o The inverse operand.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   234
   *
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   235
   * \see Invert()
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   236
   */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   237
  void MulByInvert (const int64x64_t & o);
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   239
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   240
   * Compute the inverse of an integer value.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   241
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   242
   * Ordinary division by an integer would be limited to 64 bits of precsion.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   243
   * Instead, we multiply by the 128-bit inverse of the divisor.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   244
   * This function computes the inverse to 128-bit precision.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   245
   * MulByInvert() then completes the division.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   246
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   247
   * (Really this should be a separate type representing Q0.128.)
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   248
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   249
   * \param [in] v The value to compute the inverse of.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   250
   * \return A Q0.128 representation of the inverse.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   251
   */
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   252
  static int64x64_t Invert (const uint64_t v);
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
private:
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   255
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   256
  friend bool         operator == (const int64x64_t & lhs, const int64x64_t & rhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   257
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   258
  friend bool         operator <  (const int64x64_t & lhs, const int64x64_t & rhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   259
  friend bool         operator >  (const int64x64_t & lhs, const int64x64_t & rhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   260
  
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   261
  friend int64x64_t & operator += (      int64x64_t & lhs, const int64x64_t & rhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   262
  friend int64x64_t & operator -= (      int64x64_t & lhs, const int64x64_t & rhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   263
  friend int64x64_t & operator *= (      int64x64_t & lhs, const int64x64_t & rhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   264
  friend int64x64_t & operator /= (      int64x64_t & lhs, const int64x64_t & rhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   265
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   266
  friend int64x64_t   operator -  (const int64x64_t & lhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   267
  friend int64x64_t   operator !  (const int64x64_t & lhs);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   268
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   269
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   270
   * Implement `*=`.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   271
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   272
   * \param [in] o The other factor.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   273
   */   
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   274
  void Mul (const int64x64_t & o);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   275
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   276
   * Implement `/=`.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   277
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   278
   * \param [in] o The divisor.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   279
   */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   280
  void Div (const int64x64_t & o);
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   281
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   282
   * Unsigned multiplication of Q64.64 values.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   283
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   284
   * Mathematically this should produce a Q128.128 value;
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   285
   * we keep the central 128 bits, representing the Q64.64 result.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   286
   * We assert on integer overflow beyond the 64-bit integer portion.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   287
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   288
   * \param [in] a First factor.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   289
   * \param [in] b Second factor.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   290
   * \return The Q64.64 product.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   291
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   292
   * \internal
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   293
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   294
   * It might be tempting to just use \pname{a} `*` \pname{b}
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   295
   * and be done with it, but it's not that simple.  With \pname{a}
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   296
   * and \pname{b} as 128-bit integers, \pname{a} `*` \pname{b}
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   297
   * mathematically produces a 256-bit result, which the computer
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   298
   * truncates to the lowest 128 bits.  In our case, where \pname{a}
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   299
   * and \pname{b} are interpreted as Q64.64 fixed point numbers,
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   300
   * the multiplication mathematically produces a Q128.128 fixed point number.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   301
   * We want the middle 128 bits from the result, truncating both the
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   302
   * high and low 64 bits.  To achieve this, we carry out the multiplication
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   303
   * explicitly with 64-bit operands and 128-bit intermediate results.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   304
   */
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   305
  static uint128_t Umul         (const uint128_t a, const uint128_t b);
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   306
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   307
   * Unsigned division of Q64.64 values.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   308
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   309
   * \param [in] a Numerator.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   310
   * \param [in] b Denominator.
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   311
   * \return The Q64.64 representation of `a / b`.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   312
   */
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   313
  static uint128_t Udiv         (const uint128_t a, const uint128_t b);
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   314
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   315
   * Unsigned multiplication of Q64.64 and Q0.128 values.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   316
   *
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   317
   * \param [in] a The numerator, a Q64.64 value.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   318
   * \param [in] b The inverse of the denominator, a Q0.128 value
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   319
   * \return The product `a * b`, representing the ration `a / b^-1`.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   320
   *
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   321
   * \see Invert()
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   322
   */
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   323
  static uint128_t UmulByInvert (const uint128_t a, const uint128_t b);
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   324
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   325
  /**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   326
   * Construct from an integral type.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   327
   *
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   328
   * \param [in] v Integer value to represent.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   329
   */
10637
67601c471c22 [Bug 1856] int64x64_t double conversions
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10597
diff changeset
   330
  inline int64x64_t (const int128_t v)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
    : _v (v) {}
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   332
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   333
  int128_t _v;  //!< The Q64.64 value.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   334
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   335
};  // class int64x64_t
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   336
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   338
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   339
 * \ingroup highprec
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   340
 * Equality operator.
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   341
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   342
inline bool operator == (const int64x64_t & lhs, const int64x64_t & rhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   343
{
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   344
  return lhs._v == rhs._v;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   345
}
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   346
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   347
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   348
 * Less than operator.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   349
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   350
inline bool operator < (const int64x64_t & lhs, const int64x64_t & rhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   351
{
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   352
  return lhs._v < rhs._v;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   353
}
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   354
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   355
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   356
 * Greater operator.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   357
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   358
inline bool operator > (const int64x64_t & lhs, const int64x64_t & rhs)
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   359
{
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   360
  return lhs._v > rhs._v;
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   361
}
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   362
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   363
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   364
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   365
 * Compound addition operator.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   366
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   367
inline int64x64_t & operator += (int64x64_t & lhs, const int64x64_t & rhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   368
{
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   369
  lhs._v += rhs._v;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   370
  return lhs;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   371
}
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   372
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   373
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   374
 * Compound subtraction operator.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   375
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   376
inline int64x64_t & operator -= (int64x64_t & lhs, const int64x64_t & rhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   377
{
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   378
  lhs._v -= rhs._v;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   379
  return lhs;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   380
}
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   381
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   382
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   383
 * Compound multiplication operator.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   384
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   385
inline int64x64_t & operator *= (int64x64_t & lhs, const int64x64_t & rhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   386
{
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   387
  lhs.Mul (rhs);
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   388
  return lhs;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   389
}
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   390
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   391
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   392
 * Compound division operator.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   393
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   394
inline int64x64_t & operator /= (int64x64_t & lhs, const int64x64_t & rhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   395
{
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   396
  lhs.Div (rhs);
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   397
  return lhs;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   398
}
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   399
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   400
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   401
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   402
 * Unary plus operator.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   403
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   404
inline int64x64_t operator + (const int64x64_t & lhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   405
{
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   406
  return lhs;
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   407
}
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   408
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   409
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   410
 * Unary negation operator (change sign operator).
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   411
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   412
inline int64x64_t operator - (const int64x64_t & lhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   413
{
7039
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7035
diff changeset
   414
  return int64x64_t (-lhs._v);
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   415
}
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   416
/**
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   417
 * \ingroup highprec
11092
6afcfe8a5447 [Doxygen] specialized data types
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10979
diff changeset
   418
 * Logical not operator.
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   419
 */
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   420
inline int64x64_t operator ! (const int64x64_t & lhs)
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   421
{
7039
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7035
diff changeset
   422
  return int64x64_t (!lhs._v);
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   423
}
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   424
10597
6e1bd685bcaa [Bug 1786] Fix for os << (int64x64_t) and fractional arithmetic
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9063
diff changeset
   425
7032
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   426
} // namespace ns3
17d4c8f349d6 split out uint64x64 type, optimize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   427
7039
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7035
diff changeset
   428
#endif /* INT64X64_128_H */