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

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: Addressed comment 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') | no next file with comments »
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; 5610 static int SmiShiftSize() { return kSmiShiftSize; }
5611 static int SmiValueSize() { return kSmiValueSize; }
5611 V8_INLINE static int SmiToInt(const internal::Object* value) { 5612 V8_INLINE static int SmiToInt(const internal::Object* value) {
5612 int shift_bits = kSmiTagSize + kSmiShiftSize; 5613 int shift_bits = kSmiTagSize + kSmiShiftSize;
5613 // Throw away top 32 bits and shift down (requires >> to be sign extending). 5614 // 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; 5615 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
5615 } 5616 }
5616 V8_INLINE static internal::Object* IntToSmi(int value) { 5617 V8_INLINE static internal::Object* IntToSmi(int value) {
5617 return internal::IntToSmi<kSmiShiftSize>(value); 5618 return internal::IntToSmi<kSmiShiftSize>(value);
5618 } 5619 }
5619 V8_INLINE static bool IsValidSmi(intptr_t value) { 5620 V8_INLINE static bool IsValidSmi(intptr_t value) {
5620 // To be representable as an tagged small integer, the two 5621 // To be representable as an tagged small integer, the two
5621 // most-significant bits of 'value' must be either 00 or 11 due to 5622 // 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 5623 // sign-extension. To check this we add 01 to the two
5623 // most-significant bits, and check if the most-significant bit is 0 5624 // most-significant bits, and check if the most-significant bit is 0
5624 // 5625 //
5625 // CAUTION: The original code below: 5626 // CAUTION: The original code below:
5626 // bool result = ((value + 0x40000000) & 0x80000000) == 0; 5627 // bool result = ((value + 0x40000000) & 0x80000000) == 0;
5627 // may lead to incorrect results according to the C language spec, and 5628 // 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 5629 // 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 5630 // compiler may produce undefined results in case of signed integer
5630 // overflow. The computation must be done w/ unsigned ints. 5631 // overflow. The computation must be done w/ unsigned ints.
5631 return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U; 5632 return static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U;
5632 } 5633 }
5633 }; 5634 };
5634 5635
5635 // Smi constants for 64-bit systems. 5636 // Smi constants for 64-bit systems.
5636 template <> struct SmiTagging<8> { 5637 template <> struct SmiTagging<8> {
5637 static const int kSmiShiftSize = 31; 5638 enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
5638 static const int kSmiValueSize = 32; 5639 static int SmiShiftSize() { return kSmiShiftSize; }
5640 static int SmiValueSize() { return kSmiValueSize; }
5639 V8_INLINE static int SmiToInt(const internal::Object* value) { 5641 V8_INLINE static int SmiToInt(const internal::Object* value) {
5640 int shift_bits = kSmiTagSize + kSmiShiftSize; 5642 int shift_bits = kSmiTagSize + kSmiShiftSize;
5641 // Shift down and throw away top 32 bits. 5643 // Shift down and throw away top 32 bits.
5642 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); 5644 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
5643 } 5645 }
5644 V8_INLINE static internal::Object* IntToSmi(int value) { 5646 V8_INLINE static internal::Object* IntToSmi(int value) {
5645 return internal::IntToSmi<kSmiShiftSize>(value); 5647 return internal::IntToSmi<kSmiShiftSize>(value);
5646 } 5648 }
5647 V8_INLINE static bool IsValidSmi(intptr_t value) { 5649 V8_INLINE static bool IsValidSmi(intptr_t value) {
5648 // To be representable as a long smi, the value must be a 32-bit integer. 5650 // 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 */ 6824 */
6823 6825
6824 6826
6825 } // namespace v8 6827 } // namespace v8
6826 6828
6827 6829
6828 #undef TYPE_CHECK 6830 #undef TYPE_CHECK
6829 6831
6830 6832
6831 #endif // V8_H_ 6833 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler/change-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698