OLD | NEW |
---|---|
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 2697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2708 }; | 2708 }; |
2709 | 2709 |
2710 | 2710 |
2711 | 2711 |
2712 // --- I m p l e m e n t a t i o n --- | 2712 // --- I m p l e m e n t a t i o n --- |
2713 | 2713 |
2714 | 2714 |
2715 namespace internal { | 2715 namespace internal { |
2716 | 2716 |
2717 | 2717 |
2718 template <size_t ptr_size> struct SmiConstants; | |
2719 | |
2720 // Smi constants for 32-bit systems. | |
2721 template <> struct SmiConstants<4> { | |
2722 static const int kSmiTag = 0; | |
Christian Plesner Hansen
2009/10/16 09:39:10
Some of these constants seems to be independent of
Lasse Reichstein
2009/10/16 10:19:11
Done. This required moving the templates below the
| |
2723 static const int kSmiTagSize = 1; | |
2724 static const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | |
2725 static const int kSmiShiftSize = 0; | |
2726 static const int kSmiValueSize = 31; | |
2727 static inline int SmiToInt(internal::Object* value) { | |
2728 int shift_bits = kSmiTagSize + kSmiShiftSize; | |
2729 // Throw away top 32 bits and shift down (requires >> to be sign extending). | |
2730 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | |
2731 } | |
2732 }; | |
2733 | |
2734 // Smi constants for 64-bit systems. | |
2735 template <> struct SmiConstants<8> { | |
2736 static const int kSmiTag = 0; | |
2737 static const int kSmiTagSize = 1; | |
2738 static const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | |
2739 static const int kSmiShiftSize = 31; | |
2740 static const int kSmiValueSize = 32; | |
2741 static inline int SmiToInt(internal::Object* value) { | |
2742 int shift_bits = kSmiTagSize + kSmiShiftSize; | |
2743 // Shift down and throw away top 32 bits. | |
2744 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | |
2745 } | |
2746 }; | |
2747 | |
2748 | |
2718 // Tag information for HeapObject. | 2749 // Tag information for HeapObject. |
2719 const int kHeapObjectTag = 1; | 2750 const int kHeapObjectTag = 1; |
2720 const int kHeapObjectTagSize = 2; | 2751 const int kHeapObjectTagSize = 2; |
2721 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; | 2752 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
2722 | 2753 |
2723 #ifdef V8_TARGET_ARCH_X64 | |
2724 // Tag information for Smi. | 2754 // Tag information for Smi. |
2725 const int kSmiTag = 0; | 2755 const int kSmiTag = SmiConstants<sizeof(void*)>::kSmiTag; |
2726 const int kSmiTagSize = 1; | 2756 const int kSmiTagSize = SmiConstants<sizeof(void*)>::kSmiTagSize; |
2727 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | 2757 const intptr_t kSmiTagMask = SmiConstants<sizeof(void*)>::kSmiTagMask; |
2728 const int kSmiShiftSize = 31; | 2758 const int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize; |
2729 const int kSmiValueSize = 32; | 2759 const int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize; |
2730 #else | |
2731 // Tag information for Smi. | |
2732 const int kSmiTag = 0; | |
2733 const int kSmiTagSize = 1; | |
2734 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | |
2735 const int kSmiShiftSize = 0; | |
2736 const int kSmiValueSize = 31; | |
2737 #endif | |
2738 | 2760 |
2739 /** | 2761 /** |
2740 * This class exports constants and functionality from within v8 that | 2762 * This class exports constants and functionality from within v8 that |
2741 * is necessary to implement inline functions in the v8 api. Don't | 2763 * is necessary to implement inline functions in the v8 api. Don't |
2742 * depend on functions and constants defined here. | 2764 * depend on functions and constants defined here. |
2743 */ | 2765 */ |
2744 class Internals { | 2766 class Internals { |
2745 public: | 2767 public: |
2746 | 2768 |
2747 // These values match non-compiler-dependent values defined within | 2769 // These values match non-compiler-dependent values defined within |
(...skipping 16 matching lines...) Expand all Loading... | |
2764 static inline bool HasHeapObjectTag(internal::Object* value) { | 2786 static inline bool HasHeapObjectTag(internal::Object* value) { |
2765 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 2787 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
2766 kHeapObjectTag); | 2788 kHeapObjectTag); |
2767 } | 2789 } |
2768 | 2790 |
2769 static inline bool HasSmiTag(internal::Object* value) { | 2791 static inline bool HasSmiTag(internal::Object* value) { |
2770 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | 2792 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
2771 } | 2793 } |
2772 | 2794 |
2773 static inline int SmiValue(internal::Object* value) { | 2795 static inline int SmiValue(internal::Object* value) { |
2774 #ifdef V8_TARGET_ARCH_X64 | 2796 return SmiConstants<sizeof(void*)>::SmiToInt(value); |
2775 int shift_bits = kSmiTagSize + kSmiShiftSize; | |
2776 // Shift down and throw away top 32 bits. | |
2777 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | |
2778 #else | |
2779 int shift_bits = kSmiTagSize + kSmiShiftSize; | |
2780 // Throw away top 32 bits and shift down (requires >> to be sign extending). | |
2781 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | |
2782 #endif | |
2783 } | 2797 } |
2784 | 2798 |
2785 static inline bool IsExternalTwoByteString(int instance_type) { | 2799 static inline bool IsExternalTwoByteString(int instance_type) { |
2786 int representation = (instance_type & kFullStringRepresentationMask); | 2800 int representation = (instance_type & kFullStringRepresentationMask); |
2787 return representation == kExternalTwoByteRepresentationTag; | 2801 return representation == kExternalTwoByteRepresentationTag; |
2788 } | 2802 } |
2789 | 2803 |
2790 template <typename T> | 2804 template <typename T> |
2791 static inline T ReadField(Object* ptr, int offset) { | 2805 static inline T ReadField(Object* ptr, int offset) { |
2792 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | 2806 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3129 | 3143 |
3130 } // namespace v8 | 3144 } // namespace v8 |
3131 | 3145 |
3132 | 3146 |
3133 #undef V8EXPORT | 3147 #undef V8EXPORT |
3134 #undef V8EXPORT_INLINE | 3148 #undef V8EXPORT_INLINE |
3135 #undef TYPE_CHECK | 3149 #undef TYPE_CHECK |
3136 | 3150 |
3137 | 3151 |
3138 #endif // V8_H_ | 3152 #endif // V8_H_ |
OLD | NEW |