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

Side by Side Diff: src/objects-inl.h

Issue 196139: X64: Convert smis to holding 32 bits of payload. (Closed)
Patch Set: Addressed review comments. Forwarded to head. Created 11 years, 2 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 | « src/objects.h ('k') | src/runtime.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 737 }
738 738
739 739
740 int Smi::value() { 740 int Smi::value() {
741 return Internals::SmiValue(this); 741 return Internals::SmiValue(this);
742 } 742 }
743 743
744 744
745 Smi* Smi::FromInt(int value) { 745 Smi* Smi::FromInt(int value) {
746 ASSERT(Smi::IsValid(value)); 746 ASSERT(Smi::IsValid(value));
747 int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
747 intptr_t tagged_value = 748 intptr_t tagged_value =
748 (static_cast<intptr_t>(value) << kSmiTagSize) | kSmiTag; 749 (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag;
749 return reinterpret_cast<Smi*>(tagged_value); 750 return reinterpret_cast<Smi*>(tagged_value);
750 } 751 }
751 752
752 753
753 Smi* Smi::FromIntptr(intptr_t value) { 754 Smi* Smi::FromIntptr(intptr_t value) {
754 ASSERT(Smi::IsValid(value)); 755 ASSERT(Smi::IsValid(value));
755 return reinterpret_cast<Smi*>((value << kSmiTagSize) | kSmiTag); 756 int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
757 return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag);
756 } 758 }
757 759
758 760
759 Failure::Type Failure::type() const { 761 Failure::Type Failure::type() const {
760 return static_cast<Type>(value() & kFailureTypeTagMask); 762 return static_cast<Type>(value() & kFailureTypeTagMask);
761 } 763 }
762 764
763 765
764 bool Failure::IsInternalError() const { 766 bool Failure::IsInternalError() const {
765 return type() == INTERNAL_ERROR; 767 return type() == INTERNAL_ERROR;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info); 827 ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info);
826 return reinterpret_cast<Failure*>( 828 return reinterpret_cast<Failure*>(
827 (static_cast<intptr_t>(info) << kFailureTagSize) | kFailureTag); 829 (static_cast<intptr_t>(info) << kFailureTagSize) | kFailureTag);
828 } 830 }
829 831
830 832
831 bool Smi::IsValid(intptr_t value) { 833 bool Smi::IsValid(intptr_t value) {
832 #ifdef DEBUG 834 #ifdef DEBUG
833 bool in_range = (value >= kMinValue) && (value <= kMaxValue); 835 bool in_range = (value >= kMinValue) && (value <= kMaxValue);
834 #endif 836 #endif
837
838 #ifdef V8_LONG_SMI
839 // To be representable as a long smi, the value must be a 32-bit integer.
840 bool result = (value == static_cast<int32_t>(value));
841 #else
835 // To be representable as an tagged small integer, the two 842 // To be representable as an tagged small integer, the two
836 // most-significant bits of 'value' must be either 00 or 11 due to 843 // most-significant bits of 'value' must be either 00 or 11 due to
837 // sign-extension. To check this we add 01 to the two 844 // sign-extension. To check this we add 01 to the two
838 // most-significant bits, and check if the most-significant bit is 0 845 // most-significant bits, and check if the most-significant bit is 0
839 // 846 //
840 // CAUTION: The original code below: 847 // CAUTION: The original code below:
841 // bool result = ((value + 0x40000000) & 0x80000000) == 0; 848 // bool result = ((value + 0x40000000) & 0x80000000) == 0;
842 // may lead to incorrect results according to the C language spec, and 849 // may lead to incorrect results according to the C language spec, and
843 // in fact doesn't work correctly with gcc4.1.1 in some cases: The 850 // in fact doesn't work correctly with gcc4.1.1 in some cases: The
844 // compiler may produce undefined results in case of signed integer 851 // compiler may produce undefined results in case of signed integer
845 // overflow. The computation must be done w/ unsigned ints. 852 // overflow. The computation must be done w/ unsigned ints.
846 bool result = 853 bool result = (static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U);
847 ((static_cast<unsigned int>(value) + 0x40000000U) & 0x80000000U) == 0; 854 #endif
848 ASSERT(result == in_range); 855 ASSERT(result == in_range);
849 return result; 856 return result;
850 } 857 }
851
852
853 bool Smi::IsIntptrValid(intptr_t value) {
854 #ifdef DEBUG
855 bool in_range = (value >= kMinValue) && (value <= kMaxValue);
856 #endif
857 // See Smi::IsValid(int) for description.
858 bool result =
859 ((static_cast<uintptr_t>(value) + 0x40000000U) < 0x80000000U);
860 ASSERT(result == in_range);
861 return result;
862 }
863 858
864 859
865 MapWord MapWord::FromMap(Map* map) { 860 MapWord MapWord::FromMap(Map* map) {
866 return MapWord(reinterpret_cast<uintptr_t>(map)); 861 return MapWord(reinterpret_cast<uintptr_t>(map));
867 } 862 }
868 863
869 864
870 Map* MapWord::ToMap() { 865 Map* MapWord::ToMap() {
871 return reinterpret_cast<Map*>(value_); 866 return reinterpret_cast<Map*>(value_);
872 } 867 }
(...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 #undef WRITE_INT_FIELD 2887 #undef WRITE_INT_FIELD
2893 #undef READ_SHORT_FIELD 2888 #undef READ_SHORT_FIELD
2894 #undef WRITE_SHORT_FIELD 2889 #undef WRITE_SHORT_FIELD
2895 #undef READ_BYTE_FIELD 2890 #undef READ_BYTE_FIELD
2896 #undef WRITE_BYTE_FIELD 2891 #undef WRITE_BYTE_FIELD
2897 2892
2898 2893
2899 } } // namespace v8::internal 2894 } } // namespace v8::internal
2900 2895
2901 #endif // V8_OBJECTS_INL_H_ 2896 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698