V8 Project
v8::internal::DiyFp Class Reference

#include <diy-fp.h>

+ Collaboration diagram for v8::internal::DiyFp:

Public Member Functions

 DiyFp ()
 
 DiyFp (uint64_t f, int e)
 
void Subtract (const DiyFp &other)
 
void Multiply (const DiyFp &other)
 
void Normalize ()
 
uint64_t f () const
 
int e () const
 
void set_f (uint64_t new_value)
 
void set_e (int new_value)
 

Static Public Member Functions

static DiyFp Minus (const DiyFp &a, const DiyFp &b)
 
static DiyFp Times (const DiyFp &a, const DiyFp &b)
 
static DiyFp Normalize (const DiyFp &a)
 

Static Public Attributes

static const int kSignificandSize = 64
 

Private Attributes

uint64_t f_
 
int e_
 

Static Private Attributes

static const uint64_t kUint64MSB = static_cast<uint64_t>(1) << 63
 

Detailed Description

Definition at line 16 of file diy-fp.h.

Constructor & Destructor Documentation

◆ DiyFp() [1/2]

v8::internal::DiyFp::DiyFp ( )
inline

Definition at line 20 of file diy-fp.h.

20 : f_(0), e_(0) {}
uint64_t f_
Definition: diy-fp.h:88

◆ DiyFp() [2/2]

v8::internal::DiyFp::DiyFp ( uint64_t  f,
int  e 
)
inline

Definition at line 21 of file diy-fp.h.

21 : f_(f), e_(e) {}
uint64_t f() const
Definition: diy-fp.h:79
int e() const
Definition: diy-fp.h:80

Member Function Documentation

◆ e()

int v8::internal::DiyFp::e ( ) const
inline

Definition at line 80 of file diy-fp.h.

80 { return e_; }

References e_.

Referenced by v8::internal::BignumStrtod(), v8::internal::DigitGen(), v8::internal::DigitGenCounted(), v8::internal::DiyFpStrtod(), v8::internal::Double::DiyFpToUint64(), v8::internal::Grisu3(), v8::internal::Grisu3Counted(), Normalize(), and v8::internal::Double::NormalizedBoundaries().

+ Here is the caller graph for this function:

◆ f()

uint64_t v8::internal::DiyFp::f ( ) const
inline

Definition at line 79 of file diy-fp.h.

79 { return f_; }

References f_.

Referenced by v8::internal::BignumStrtod(), v8::internal::DigitGen(), v8::internal::DigitGenCounted(), v8::internal::DiyFpStrtod(), v8::internal::Double::DiyFpToUint64(), Normalize(), and v8::internal::Double::NormalizedBoundaries().

+ Here is the caller graph for this function:

◆ Minus()

static DiyFp v8::internal::DiyFp::Minus ( const DiyFp a,
const DiyFp b 
)
inlinestatic

Definition at line 36 of file diy-fp.h.

36  {
37  DiyFp result = a;
38  result.Subtract(b);
39  return result;
40  }

References Subtract().

Referenced by v8::internal::DigitGen().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Multiply()

void v8::internal::DiyFp::Multiply ( const DiyFp other)

Definition at line 13 of file diy-fp.cc.

13  {
14  // Simply "emulates" a 128 bit multiplication.
15  // However: the resulting number only contains 64 bits. The least
16  // significant 64 bits are only used for rounding the most significant 64
17  // bits.
18  const uint64_t kM32 = 0xFFFFFFFFu;
19  uint64_t a = f_ >> 32;
20  uint64_t b = f_ & kM32;
21  uint64_t c = other.f_ >> 32;
22  uint64_t d = other.f_ & kM32;
23  uint64_t ac = a * c;
24  uint64_t bc = b * c;
25  uint64_t ad = a * d;
26  uint64_t bd = b * d;
27  uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32);
28  // By adding 1U << 31 to tmp we round the final result.
29  // Halfway cases will be round up.
30  tmp += 1U << 31;
31  uint64_t result_f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
32  e_ += other.e_ + 64;
33  f_ = result_f;
34 }

References e_, and f_.

Referenced by v8::internal::DiyFpStrtod(), and Times().

+ Here is the caller graph for this function:

◆ Normalize() [1/2]

void v8::internal::DiyFp::Normalize ( )
inline

Definition at line 53 of file diy-fp.h.

53  {
54  DCHECK(f_ != 0);
55  uint64_t f = f_;
56  int e = e_;
57 
58  // This method is mainly called for normalizing boundaries. In general
59  // boundaries need to be shifted by 10 bits. We thus optimize for this case.
60  const uint64_t k10MSBits = static_cast<uint64_t>(0x3FF) << 54;
61  while ((f & k10MSBits) == 0) {
62  f <<= 10;
63  e -= 10;
64  }
65  while ((f & kUint64MSB) == 0) {
66  f <<= 1;
67  e--;
68  }
69  f_ = f;
70  e_ = e;
71  }
static const uint64_t kUint64MSB
Definition: diy-fp.h:86
#define DCHECK(condition)
Definition: logging.h:205

References DCHECK, e(), e_, f(), f_, and kUint64MSB.

Referenced by v8::internal::DiyFpStrtod(), Normalize(), and v8::internal::Double::NormalizedBoundaries().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Normalize() [2/2]

static DiyFp v8::internal::DiyFp::Normalize ( const DiyFp a)
inlinestatic

Definition at line 73 of file diy-fp.h.

73  {
74  DiyFp result = a;
75  result.Normalize();
76  return result;
77  }

References Normalize().

+ Here is the call graph for this function:

◆ set_e()

void v8::internal::DiyFp::set_e ( int  new_value)
inline

Definition at line 83 of file diy-fp.h.

83 { e_ = new_value; }

References e_.

Referenced by v8::internal::DiyFpStrtod(), and v8::internal::Double::NormalizedBoundaries().

+ Here is the caller graph for this function:

◆ set_f()

void v8::internal::DiyFp::set_f ( uint64_t  new_value)
inline

Definition at line 82 of file diy-fp.h.

82 { f_ = new_value; }

References f_.

Referenced by v8::internal::DigitGen(), v8::internal::DiyFpStrtod(), and v8::internal::Double::NormalizedBoundaries().

+ Here is the caller graph for this function:

◆ Subtract()

void v8::internal::DiyFp::Subtract ( const DiyFp other)
inline

Definition at line 27 of file diy-fp.h.

27  {
28  DCHECK(e_ == other.e_);
29  DCHECK(f_ >= other.f_);
30  f_ -= other.f_;
31  }

References DCHECK, e_, and f_.

Referenced by Minus().

+ Here is the caller graph for this function:

◆ Times()

static DiyFp v8::internal::DiyFp::Times ( const DiyFp a,
const DiyFp b 
)
inlinestatic

Definition at line 47 of file diy-fp.h.

47  {
48  DiyFp result = a;
49  result.Multiply(b);
50  return result;
51  }

References Multiply().

Referenced by v8::internal::Grisu3(), and v8::internal::Grisu3Counted().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ e_

int v8::internal::DiyFp::e_
private

Definition at line 89 of file diy-fp.h.

Referenced by e(), Multiply(), Normalize(), set_e(), and Subtract().

◆ f_

uint64_t v8::internal::DiyFp::f_
private

Definition at line 88 of file diy-fp.h.

Referenced by f(), Multiply(), Normalize(), set_f(), and Subtract().

◆ kSignificandSize

◆ kUint64MSB

const uint64_t v8::internal::DiyFp::kUint64MSB = static_cast<uint64_t>(1) << 63
staticprivate

Definition at line 86 of file diy-fp.h.

Referenced by Normalize().


The documentation for this class was generated from the following files: