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_INL_H_ 6 #define V8_OBJECTS_HEAP_NUMBER_INL_H_ 7 8 #include "src/objects/heap-number.h" 9 10 #include "src/objects/objects-inl.h" 11 #include "src/objects/primitive-heap-object-inl.h" 12 13 // Has to be the last include (doesn't have include guards): 14 #include "src/objects/object-macros.h" 15 16 namespace v8 { 17 namespace internal { 18 19 #include "torque-generated/src/objects/heap-number-tq-inl.inc" 20 TQ_OBJECT_CONSTRUCTORS_IMPL(HeapNumber)21TQ_OBJECT_CONSTRUCTORS_IMPL(HeapNumber) 22 23 uint64_t HeapNumber::value_as_bits(RelaxedLoadTag) const { 24 uint64_t value; 25 base::Relaxed_Memcpy( 26 reinterpret_cast<base::Atomic8*>(&value), 27 reinterpret_cast<base::Atomic8*>(field_address(kValueOffset)), 28 sizeof(uint64_t)); 29 // Bug(v8:8875): HeapNumber's double may be unaligned. 30 return value; 31 } 32 set_value_as_bits(uint64_t bits,RelaxedStoreTag)33void HeapNumber::set_value_as_bits(uint64_t bits, RelaxedStoreTag) { 34 base::Relaxed_Memcpy( 35 reinterpret_cast<base::Atomic8*>(field_address(kValueOffset)), 36 reinterpret_cast<base::Atomic8*>(&bits), sizeof(uint64_t)); 37 } 38 get_exponent()39int HeapNumber::get_exponent() { 40 return ((ReadField<int>(kExponentOffset) & kExponentMask) >> kExponentShift) - 41 kExponentBias; 42 } 43 get_sign()44int HeapNumber::get_sign() { 45 return ReadField<int>(kExponentOffset) & kSignMask; 46 } 47 48 } // namespace internal 49 } // namespace v8 50 51 #include "src/objects/object-macros-undef.h" 52 53 #endif // V8_OBJECTS_HEAP_NUMBER_INL_H_ 54