Public Member Functions | Public Attributes | Static Public Attributes | List of all members
internal::DiyFp Struct Reference

#include <diyfp.h>

Public Member Functions

 DiyFp ()
 
 DiyFp (uint64_t fp, int exp)
 
 DiyFp (double d)
 
DiyFp operator- (const DiyFp &rhs) const
 
DiyFp operator* (const DiyFp &rhs) const
 
DiyFp Normalize () const
 
DiyFp NormalizeBoundary () const
 
void NormalizedBoundaries (DiyFp *minus, DiyFp *plus) const
 
double ToDouble () const
 

Public Attributes

uint64_t f
 
int e
 

Static Public Attributes

static const int kDiySignificandSize = 64
 
static const int kDpSignificandSize = 52
 
static const int kDpExponentBias = 0x3FF + kDpSignificandSize
 
static const int kDpMaxExponent = 0x7FF - kDpExponentBias
 
static const int kDpMinExponent = -kDpExponentBias
 
static const int kDpDenormalExponent = -kDpExponentBias + 1
 
static const uint64_t kDpExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000)
 
static const uint64_t kDpSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF)
 
static const uint64_t kDpHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000)
 

Detailed Description

Definition at line 44 of file diyfp.h.

Constructor & Destructor Documentation

internal::DiyFp::DiyFp ( )
inline

Definition at line 45 of file diyfp.h.

45 : f(), e() {}
uint64_t f
Definition: diyfp.h:171
internal::DiyFp::DiyFp ( uint64_t  fp,
int  exp 
)
inline

Definition at line 47 of file diyfp.h.

internal::DiyFp::DiyFp ( double  d)
inlineexplicit

Definition at line 49 of file diyfp.h.

49  {
50  union {
51  double d;
52  uint64_t u64;
53  } u = { d };
54 
55  int biased_e = static_cast<int>((u.u64 & kDpExponentMask) >> kDpSignificandSize);
56  uint64_t significand = (u.u64 & kDpSignificandMask);
57  if (biased_e != 0) {
58  f = significand + kDpHiddenBit;
59  e = biased_e - kDpExponentBias;
60  }
61  else {
62  f = significand;
63  e = kDpMinExponent + 1;
64  }
65  }
static const int kDpExponentBias
Definition: diyfp.h:163
static const uint64_t kDpSignificandMask
Definition: diyfp.h:168
unsigned __int64 uint64_t
Definition: stdint.h:136
uint64_t f
Definition: diyfp.h:171
static const uint64_t kDpExponentMask
Definition: diyfp.h:167
static const int kDpMinExponent
Definition: diyfp.h:165
static const uint64_t kDpHiddenBit
Definition: diyfp.h:169
static const int kDpSignificandSize
Definition: diyfp.h:162

Member Function Documentation

DiyFp internal::DiyFp::Normalize ( ) const
inline

Definition at line 102 of file diyfp.h.

102  {
103  RAPIDJSON_ASSERT(f != 0); // https://stackoverflow.com/a/26809183/291737
104 #if defined(_MSC_VER) && defined(_M_AMD64)
105  unsigned long index;
106  _BitScanReverse64(&index, f);
107  return DiyFp(f << (63 - index), e - (63 - index));
108 #elif defined(__GNUC__) && __GNUC__ >= 4
109  int s = __builtin_clzll(f);
110  return DiyFp(f << s, e - s);
111 #else
112  DiyFp res = *this;
113  while (!(res.f & (static_cast<uint64_t>(1) << 63))) {
114  res.f <<= 1;
115  res.e--;
116  }
117  return res;
118 #endif
119  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
uint64_t f
Definition: diyfp.h:171
static QCString * s
Definition: config.cpp:1042
DiyFp internal::DiyFp::NormalizeBoundary ( ) const
inline

Definition at line 121 of file diyfp.h.

121  {
122  DiyFp res = *this;
123  while (!(res.f & (kDpHiddenBit << 1))) {
124  res.f <<= 1;
125  res.e--;
126  }
127  res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
128  res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
129  return res;
130  }
static const int kDiySignificandSize
Definition: diyfp.h:161
static const uint64_t kDpHiddenBit
Definition: diyfp.h:169
static const int kDpSignificandSize
Definition: diyfp.h:162
void internal::DiyFp::NormalizedBoundaries ( DiyFp minus,
DiyFp plus 
) const
inline

Definition at line 132 of file diyfp.h.

132  {
133  DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary();
134  DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1);
135  mi.f <<= mi.e - pl.e;
136  mi.e = pl.e;
137  *plus = pl;
138  *minus = mi;
139  }
uint64_t f
Definition: diyfp.h:171
static const uint64_t kDpHiddenBit
Definition: diyfp.h:169
DiyFp internal::DiyFp::operator* ( const DiyFp rhs) const
inline

mult_round

Definition at line 71 of file diyfp.h.

71  {
72 #if defined(_MSC_VER) && defined(_M_AMD64)
73  uint64_t h;
74  uint64_t l = _umul128(f, rhs.f, &h);
75  if (l & (uint64_t(1) << 63)) // rounding
76  h++;
77  return DiyFp(h, e + rhs.e + 64);
78 #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
79  __extension__ typedef unsigned __int128 uint128;
80  uint128 p = static_cast<uint128>(f) * static_cast<uint128>(rhs.f);
81  uint64_t h = static_cast<uint64_t>(p >> 64);
82  uint64_t l = static_cast<uint64_t>(p);
83  if (l & (uint64_t(1) << 63)) // rounding
84  h++;
85  return DiyFp(h, e + rhs.e + 64);
86 #else
87  const uint64_t M32 = 0xFFFFFFFF;
88  const uint64_t a = f >> 32;
89  const uint64_t b = f & M32;
90  const uint64_t c = rhs.f >> 32;
91  const uint64_t d = rhs.f & M32;
92  const uint64_t ac = a * c;
93  const uint64_t bc = b * c;
94  const uint64_t ad = a * d;
95  const uint64_t bd = b * d;
96  uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32);
97  tmp += 1U << 31; /// mult_round
98  return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64);
99 #endif
100  }
static QStrList * l
Definition: config.cpp:1044
unsigned __int64 uint64_t
Definition: stdint.h:136
string tmp
Definition: languages.py:63
uint64_t f
Definition: diyfp.h:171
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
p
Definition: test.py:223
static bool * b
Definition: config.cpp:1043
h
training ###############################
Definition: train_cnn.py:186
DiyFp internal::DiyFp::operator- ( const DiyFp rhs) const
inline

Definition at line 67 of file diyfp.h.

67  {
68  return DiyFp(f - rhs.f, e);
69  }
uint64_t f
Definition: diyfp.h:171
double internal::DiyFp::ToDouble ( ) const
inline

Definition at line 141 of file diyfp.h.

141  {
142  union {
143  double d;
144  uint64_t u64;
145  }u;
147  if (e < kDpDenormalExponent) {
148  // Underflow.
149  return 0.0;
150  }
151  if (e >= kDpMaxExponent) {
152  // Overflow.
153  return std::numeric_limits<double>::infinity();
154  }
155  const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 :
156  static_cast<uint64_t>(e + kDpExponentBias);
157  u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize);
158  return u.d;
159  }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
static const int kDpExponentBias
Definition: diyfp.h:163
static const int kDpMaxExponent
Definition: diyfp.h:164
static const uint64_t kDpSignificandMask
Definition: diyfp.h:168
unsigned __int64 uint64_t
Definition: stdint.h:136
static const int kDpDenormalExponent
Definition: diyfp.h:166
uint64_t f
Definition: diyfp.h:171
static const uint64_t kDpHiddenBit
Definition: diyfp.h:169
static const int kDpSignificandSize
Definition: diyfp.h:162

Member Data Documentation

int internal::DiyFp::e

Definition at line 172 of file diyfp.h.

uint64_t internal::DiyFp::f

Definition at line 171 of file diyfp.h.

const int internal::DiyFp::kDiySignificandSize = 64
static

Definition at line 161 of file diyfp.h.

const int internal::DiyFp::kDpDenormalExponent = -kDpExponentBias + 1
static

Definition at line 166 of file diyfp.h.

const int internal::DiyFp::kDpExponentBias = 0x3FF + kDpSignificandSize
static

Definition at line 163 of file diyfp.h.

const uint64_t internal::DiyFp::kDpExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000)
static

Definition at line 167 of file diyfp.h.

const uint64_t internal::DiyFp::kDpHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000)
static

Definition at line 169 of file diyfp.h.

const int internal::DiyFp::kDpMaxExponent = 0x7FF - kDpExponentBias
static

Definition at line 164 of file diyfp.h.

const int internal::DiyFp::kDpMinExponent = -kDpExponentBias
static

Definition at line 165 of file diyfp.h.

const uint64_t internal::DiyFp::kDpSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF)
static

Definition at line 168 of file diyfp.h.

const int internal::DiyFp::kDpSignificandSize = 52
static

Definition at line 162 of file diyfp.h.


The documentation for this struct was generated from the following file: