| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 | 1025 |
| 1026 int Smi::value() { | 1026 int Smi::value() { |
| 1027 return Internals::SmiValue(this); | 1027 return Internals::SmiValue(this); |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 | 1030 |
| 1031 Smi* Smi::FromInt(int value) { | 1031 Smi* Smi::FromInt(int value) { |
| 1032 ASSERT(Smi::IsValid(value)); | 1032 ASSERT(Smi::IsValid(value)); |
| 1033 int smi_shift_bits = kSmiTagSize + kSmiShiftSize; | 1033 return reinterpret_cast<Smi*>(Internals::IntToSmi(value)); |
| 1034 intptr_t tagged_value = | |
| 1035 (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; | |
| 1036 return reinterpret_cast<Smi*>(tagged_value); | |
| 1037 } | 1034 } |
| 1038 | 1035 |
| 1039 | 1036 |
| 1040 Smi* Smi::FromIntptr(intptr_t value) { | 1037 Smi* Smi::FromIntptr(intptr_t value) { |
| 1041 ASSERT(Smi::IsValid(value)); | 1038 ASSERT(Smi::IsValid(value)); |
| 1042 int smi_shift_bits = kSmiTagSize + kSmiShiftSize; | 1039 int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 1043 return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag); | 1040 return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag); |
| 1044 } | 1041 } |
| 1045 | 1042 |
| 1046 | 1043 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info); | 1101 ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info); |
| 1105 // Fill the unused bits with a pattern that's easy to recognize in crash | 1102 // Fill the unused bits with a pattern that's easy to recognize in crash |
| 1106 // dumps. | 1103 // dumps. |
| 1107 static const int kFailureMagicPattern = 0x0BAD0000; | 1104 static const int kFailureMagicPattern = 0x0BAD0000; |
| 1108 return reinterpret_cast<Failure*>( | 1105 return reinterpret_cast<Failure*>( |
| 1109 (info << kFailureTagSize) | kFailureTag | kFailureMagicPattern); | 1106 (info << kFailureTagSize) | kFailureTag | kFailureMagicPattern); |
| 1110 } | 1107 } |
| 1111 | 1108 |
| 1112 | 1109 |
| 1113 bool Smi::IsValid(intptr_t value) { | 1110 bool Smi::IsValid(intptr_t value) { |
| 1114 #ifdef DEBUG | 1111 bool result = Internals::IsValidSmi(value); |
| 1115 bool in_range = (value >= kMinValue) && (value <= kMaxValue); | 1112 ASSERT_EQ(result, value >= kMinValue && value <= kMaxValue); |
| 1116 #endif | |
| 1117 | |
| 1118 #ifdef V8_TARGET_ARCH_X64 | |
| 1119 // To be representable as a long smi, the value must be a 32-bit integer. | |
| 1120 bool result = (value == static_cast<int32_t>(value)); | |
| 1121 #else | |
| 1122 // To be representable as an tagged small integer, the two | |
| 1123 // most-significant bits of 'value' must be either 00 or 11 due to | |
| 1124 // sign-extension. To check this we add 01 to the two | |
| 1125 // most-significant bits, and check if the most-significant bit is 0 | |
| 1126 // | |
| 1127 // CAUTION: The original code below: | |
| 1128 // bool result = ((value + 0x40000000) & 0x80000000) == 0; | |
| 1129 // may lead to incorrect results according to the C language spec, and | |
| 1130 // in fact doesn't work correctly with gcc4.1.1 in some cases: The | |
| 1131 // compiler may produce undefined results in case of signed integer | |
| 1132 // overflow. The computation must be done w/ unsigned ints. | |
| 1133 bool result = (static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U); | |
| 1134 #endif | |
| 1135 ASSERT(result == in_range); | |
| 1136 return result; | 1113 return result; |
| 1137 } | 1114 } |
| 1138 | 1115 |
| 1139 | 1116 |
| 1140 MapWord MapWord::FromMap(Map* map) { | 1117 MapWord MapWord::FromMap(Map* map) { |
| 1141 return MapWord(reinterpret_cast<uintptr_t>(map)); | 1118 return MapWord(reinterpret_cast<uintptr_t>(map)); |
| 1142 } | 1119 } |
| 1143 | 1120 |
| 1144 | 1121 |
| 1145 Map* MapWord::ToMap() { | 1122 Map* MapWord::ToMap() { |
| (...skipping 5069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6215 #undef WRITE_UINT32_FIELD | 6192 #undef WRITE_UINT32_FIELD |
| 6216 #undef READ_SHORT_FIELD | 6193 #undef READ_SHORT_FIELD |
| 6217 #undef WRITE_SHORT_FIELD | 6194 #undef WRITE_SHORT_FIELD |
| 6218 #undef READ_BYTE_FIELD | 6195 #undef READ_BYTE_FIELD |
| 6219 #undef WRITE_BYTE_FIELD | 6196 #undef WRITE_BYTE_FIELD |
| 6220 | 6197 |
| 6221 | 6198 |
| 6222 } } // namespace v8::internal | 6199 } } // namespace v8::internal |
| 6223 | 6200 |
| 6224 #endif // V8_OBJECTS_INL_H_ | 6201 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |