Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: include/v8.h

Issue 527603002: Use the "enum hack" to fix the SmiTagging constants. (Closed) Base URL: git@github.com:v8/v8.git@master
Patch Set: fix typo Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/compiler/change-lowering.cc » ('j') | src/compiler/change-lowering.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** \mainpage V8 API Reference Guide 5 /** \mainpage V8 API Reference Guide
6 * 6 *
7 * V8 is Google's open source JavaScript engine. 7 * V8 is Google's open source JavaScript engine.
8 * 8 *
9 * This set of documents provides reference material generated from the 9 * This set of documents provides reference material generated from the
10 * V8 header file, include/v8.h. 10 * V8 header file, include/v8.h.
(...skipping 5588 matching lines...) Expand 10 before | Expand all | Expand 10 after
5599 template<int kSmiShiftSize> 5599 template<int kSmiShiftSize>
5600 V8_INLINE internal::Object* IntToSmi(int value) { 5600 V8_INLINE internal::Object* IntToSmi(int value) {
5601 int smi_shift_bits = kSmiTagSize + kSmiShiftSize; 5601 int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
5602 intptr_t tagged_value = 5602 intptr_t tagged_value =
5603 (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; 5603 (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag;
5604 return reinterpret_cast<internal::Object*>(tagged_value); 5604 return reinterpret_cast<internal::Object*>(tagged_value);
5605 } 5605 }
5606 5606
5607 // Smi constants for 32-bit systems. 5607 // Smi constants for 32-bit systems.
5608 template <> struct SmiTagging<4> { 5608 template <> struct SmiTagging<4> {
5609 static const int kSmiShiftSize = 0; 5609 enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
5610 static const int kSmiValueSize = 31;
5611 V8_INLINE static int SmiToInt(const internal::Object* value) { 5610 V8_INLINE static int SmiToInt(const internal::Object* value) {
5612 int shift_bits = kSmiTagSize + kSmiShiftSize; 5611 int shift_bits = kSmiTagSize + kSmiShiftSize;
5613 // Throw away top 32 bits and shift down (requires >> to be sign extending). 5612 // Throw away top 32 bits and shift down (requires >> to be sign extending).
5614 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; 5613 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
5615 } 5614 }
5616 V8_INLINE static internal::Object* IntToSmi(int value) { 5615 V8_INLINE static internal::Object* IntToSmi(int value) {
5617 return internal::IntToSmi<kSmiShiftSize>(value); 5616 return internal::IntToSmi<kSmiShiftSize>(value);
5618 } 5617 }
5619 V8_INLINE static bool IsValidSmi(intptr_t value) { 5618 V8_INLINE static bool IsValidSmi(intptr_t value) {
5620 // To be representable as an tagged small integer, the two 5619 // To be representable as an tagged small integer, the two
5621 // most-significant bits of 'value' must be either 00 or 11 due to 5620 // most-significant bits of 'value' must be either 00 or 11 due to
5622 // sign-extension. To check this we add 01 to the two 5621 // sign-extension. To check this we add 01 to the two
5623 // most-significant bits, and check if the most-significant bit is 0 5622 // most-significant bits, and check if the most-significant bit is 0
5624 // 5623 //
5625 // CAUTION: The original code below: 5624 // CAUTION: The original code below:
5626 // bool result = ((value + 0x40000000) & 0x80000000) == 0; 5625 // bool result = ((value + 0x40000000) & 0x80000000) == 0;
5627 // may lead to incorrect results according to the C language spec, and 5626 // may lead to incorrect results according to the C language spec, and
5628 // in fact doesn't work correctly with gcc4.1.1 in some cases: The 5627 // in fact doesn't work correctly with gcc4.1.1 in some cases: The
5629 // compiler may produce undefined results in case of signed integer 5628 // compiler may produce undefined results in case of signed integer
5630 // overflow. The computation must be done w/ unsigned ints. 5629 // overflow. The computation must be done w/ unsigned ints.
5631 return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U; 5630 return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
5632 } 5631 }
5633 }; 5632 };
5634 5633
5635 // Smi constants for 64-bit systems. 5634 // Smi constants for 64-bit systems.
5636 template <> struct SmiTagging<8> { 5635 template <> struct SmiTagging<8> {
5637 static const int kSmiShiftSize = 31; 5636 enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
5638 static const int kSmiValueSize = 32;
5639 V8_INLINE static int SmiToInt(const internal::Object* value) { 5637 V8_INLINE static int SmiToInt(const internal::Object* value) {
5640 int shift_bits = kSmiTagSize + kSmiShiftSize; 5638 int shift_bits = kSmiTagSize + kSmiShiftSize;
5641 // Shift down and throw away top 32 bits. 5639 // Shift down and throw away top 32 bits.
5642 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); 5640 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
5643 } 5641 }
5644 V8_INLINE static internal::Object* IntToSmi(int value) { 5642 V8_INLINE static internal::Object* IntToSmi(int value) {
5645 return internal::IntToSmi<kSmiShiftSize>(value); 5643 return internal::IntToSmi<kSmiShiftSize>(value);
5646 } 5644 }
5647 V8_INLINE static bool IsValidSmi(intptr_t value) { 5645 V8_INLINE static bool IsValidSmi(intptr_t value) {
5648 // To be representable as a long smi, the value must be a 32-bit integer. 5646 // To be representable as a long smi, the value must be a 32-bit integer.
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after
6822 */ 6820 */
6823 6821
6824 6822
6825 } // namespace v8 6823 } // namespace v8
6826 6824
6827 6825
6828 #undef TYPE_CHECK 6826 #undef TYPE_CHECK
6829 6827
6830 6828
6831 #endif // V8_H_ 6829 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler/change-lowering.cc » ('j') | src/compiler/change-lowering.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698