• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_OBJECTS_HEAP_NUMBER_H_
6 #define V8_OBJECTS_HEAP_NUMBER_H_
7 
8 #include "src/objects/primitive-heap-object.h"
9 
10 // Has to be the last include (doesn't have include guards):
11 #include "src/objects/object-macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 #include "torque-generated/src/objects/heap-number-tq.inc"
17 
18 // The HeapNumber class describes heap allocated numbers that cannot be
19 // represented in a Smi (small integer).
20 class HeapNumber
21     : public TorqueGeneratedHeapNumber<HeapNumber, PrimitiveHeapObject> {
22  public:
23   // Since the value is read from the compiler, and it can't be done
24   // atomically, we signal both to TSAN and ourselves that this is a
25   // relaxed load and store.
26   inline uint64_t value_as_bits(RelaxedLoadTag) const;
27   inline void set_value_as_bits(uint64_t bits, RelaxedStoreTag);
28 
29   inline int get_exponent();
30   inline int get_sign();
31 
32   // Layout description.
33   // IEEE doubles are two 32 bit words.  The first is just mantissa, the second
34   // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit
35   // words within double numbers are endian dependent and they are set
36   // accordingly.
37 #if defined(V8_TARGET_LITTLE_ENDIAN)
38   static const int kMantissaOffset = kValueOffset;
39   static const int kExponentOffset = kValueOffset + 4;
40 #elif defined(V8_TARGET_BIG_ENDIAN)
41   static const int kMantissaOffset = kValueOffset + 4;
42   static const int kExponentOffset = kValueOffset;
43 #else
44 #error Unknown byte ordering
45 #endif
46 
47   static const uint32_t kSignMask = 0x80000000u;
48   static const uint32_t kExponentMask = 0x7ff00000u;
49   static const uint32_t kMantissaMask = 0xfffffu;
50   static const int kMantissaBits = 52;
51   static const int kExponentBits = 11;
52   static const int kExponentBias = 1023;
53   static const int kExponentShift = 20;
54   static const int kInfinityOrNanExponent =
55       (kExponentMask >> kExponentShift) - kExponentBias;
56   static const int kMantissaBitsInTopWord = 20;
57   static const int kNonMantissaBitsInTopWord = 12;
58 
59   DECL_PRINTER(HeapNumber)
60   V8_EXPORT_PRIVATE void HeapNumberShortPrint(std::ostream& os);
61 
62   class BodyDescriptor;
63 
64   TQ_OBJECT_CONSTRUCTORS(HeapNumber)
65 };
66 
67 }  // namespace internal
68 }  // namespace v8
69 
70 #include "src/objects/object-macros-undef.h"
71 
72 #endif  // V8_OBJECTS_HEAP_NUMBER_H_
73