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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 #ifdef DEBUG |
1115 bool in_range = (value >= kMinValue) && (value <= kMaxValue); | 1112 bool in_range = (value >= kMinValue) && (value <= kMaxValue); |
Sven Panne
2013/05/21 14:14:56
Not from your CL, but anyway: Can we inline this a
dcarney
2013/05/21 15:14:44
okay
| |
1116 #endif | 1113 #endif |
1117 | 1114 bool result = Internals::IsValidSmi(value); |
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); | 1115 ASSERT(result == in_range); |
1136 return result; | 1116 return result; |
1137 } | 1117 } |
1138 | 1118 |
1139 | 1119 |
1140 MapWord MapWord::FromMap(Map* map) { | 1120 MapWord MapWord::FromMap(Map* map) { |
1141 return MapWord(reinterpret_cast<uintptr_t>(map)); | 1121 return MapWord(reinterpret_cast<uintptr_t>(map)); |
1142 } | 1122 } |
1143 | 1123 |
1144 | 1124 |
(...skipping 5076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6221 #undef WRITE_UINT32_FIELD | 6201 #undef WRITE_UINT32_FIELD |
6222 #undef READ_SHORT_FIELD | 6202 #undef READ_SHORT_FIELD |
6223 #undef WRITE_SHORT_FIELD | 6203 #undef WRITE_SHORT_FIELD |
6224 #undef READ_BYTE_FIELD | 6204 #undef READ_BYTE_FIELD |
6225 #undef WRITE_BYTE_FIELD | 6205 #undef WRITE_BYTE_FIELD |
6226 | 6206 |
6227 | 6207 |
6228 } } // namespace v8::internal | 6208 } } // namespace v8::internal |
6229 | 6209 |
6230 #endif // V8_OBJECTS_INL_H_ | 6210 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |