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

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

Issue 863633002: Use signaling NaN for holes in fixed double arrays. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Restore SSE2 Created 5 years, 11 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
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 // Review notes: 5 // Review notes:
6 // 6 //
7 // - The use of macros in these inline functions may seem superfluous 7 // - The use of macros in these inline functions may seem superfluous
8 // but it is absolutely needed to make sure gcc generates optimal 8 // but it is absolutely needed to make sure gcc generates optimal
9 // code. gcc is not happy when attempting to inline too deep. 9 // code. gcc is not happy when attempting to inline too deep.
10 // 10 //
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 1316
1317 #define WRITE_UINT32_FIELD(p, offset, value) \ 1317 #define WRITE_UINT32_FIELD(p, offset, value) \
1318 (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value) 1318 (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value)
1319 1319
1320 #define READ_INT32_FIELD(p, offset) \ 1320 #define READ_INT32_FIELD(p, offset) \
1321 (*reinterpret_cast<const int32_t*>(FIELD_ADDR_CONST(p, offset))) 1321 (*reinterpret_cast<const int32_t*>(FIELD_ADDR_CONST(p, offset)))
1322 1322
1323 #define WRITE_INT32_FIELD(p, offset, value) \ 1323 #define WRITE_INT32_FIELD(p, offset, value) \
1324 (*reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset)) = value) 1324 (*reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset)) = value)
1325 1325
1326 #define READ_UINT64_FIELD(p, offset) \
1327 (*reinterpret_cast<const uint64_t*>(FIELD_ADDR_CONST(p, offset)))
1328
1329 #define WRITE_UINT64_FIELD(p, offset, value) \
1330 (*reinterpret_cast<uint64_t*>(FIELD_ADDR(p, offset)) = value)
1331
1326 #define READ_INT64_FIELD(p, offset) \ 1332 #define READ_INT64_FIELD(p, offset) \
1327 (*reinterpret_cast<const int64_t*>(FIELD_ADDR_CONST(p, offset))) 1333 (*reinterpret_cast<const int64_t*>(FIELD_ADDR_CONST(p, offset)))
1328 1334
1329 #define WRITE_INT64_FIELD(p, offset, value) \ 1335 #define WRITE_INT64_FIELD(p, offset, value) \
1330 (*reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset)) = value) 1336 (*reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset)) = value)
1331 1337
1332 #define READ_SHORT_FIELD(p, offset) \ 1338 #define READ_SHORT_FIELD(p, offset) \
1333 (*reinterpret_cast<const uint16_t*>(FIELD_ADDR_CONST(p, offset))) 1339 (*reinterpret_cast<const uint16_t*>(FIELD_ADDR_CONST(p, offset)))
1334 1340
1335 #define WRITE_SHORT_FIELD(p, offset, value) \ 1341 #define WRITE_SHORT_FIELD(p, offset, value) \
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 void FixedArray::set(int index, Object* value) { 2287 void FixedArray::set(int index, Object* value) {
2282 DCHECK_NE(GetHeap()->fixed_cow_array_map(), map()); 2288 DCHECK_NE(GetHeap()->fixed_cow_array_map(), map());
2283 DCHECK_EQ(FIXED_ARRAY_TYPE, map()->instance_type()); 2289 DCHECK_EQ(FIXED_ARRAY_TYPE, map()->instance_type());
2284 DCHECK(index >= 0 && index < this->length()); 2290 DCHECK(index >= 0 && index < this->length());
2285 int offset = kHeaderSize + index * kPointerSize; 2291 int offset = kHeaderSize + index * kPointerSize;
2286 WRITE_FIELD(this, offset, value); 2292 WRITE_FIELD(this, offset, value);
2287 WRITE_BARRIER(GetHeap(), this, offset, value); 2293 WRITE_BARRIER(GetHeap(), this, offset, value);
2288 } 2294 }
2289 2295
2290 2296
2291 inline bool FixedDoubleArray::is_the_hole_nan(double value) {
2292 return bit_cast<uint64_t, double>(value) == kHoleNanInt64;
2293 }
2294
2295
2296 inline double FixedDoubleArray::hole_nan_as_double() {
2297 return bit_cast<double, uint64_t>(kHoleNanInt64);
2298 }
2299
2300
2301 inline double FixedDoubleArray::canonical_not_the_hole_nan_as_double() {
2302 DCHECK(bit_cast<uint64_t>(base::OS::nan_value()) != kHoleNanInt64);
2303 DCHECK((bit_cast<uint64_t>(base::OS::nan_value()) >> 32) != kHoleNanUpper32);
2304 return base::OS::nan_value();
2305 }
2306
2307
2308 double FixedDoubleArray::get_scalar(int index) { 2297 double FixedDoubleArray::get_scalar(int index) {
2309 DCHECK(map() != GetHeap()->fixed_cow_array_map() && 2298 DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
2310 map() != GetHeap()->fixed_array_map()); 2299 map() != GetHeap()->fixed_array_map());
2311 DCHECK(index >= 0 && index < this->length()); 2300 DCHECK(index >= 0 && index < this->length());
2312 double result = READ_DOUBLE_FIELD(this, kHeaderSize + index * kDoubleSize); 2301 DCHECK(!is_the_hole(index));
2313 DCHECK(!is_the_hole_nan(result)); 2302 return READ_DOUBLE_FIELD(this, kHeaderSize + index * kDoubleSize);
2314 return result;
2315 } 2303 }
2316 2304
2317 int64_t FixedDoubleArray::get_representation(int index) { 2305
2306 uint64_t FixedDoubleArray::get_representation(int index) {
2318 DCHECK(map() != GetHeap()->fixed_cow_array_map() && 2307 DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
2319 map() != GetHeap()->fixed_array_map()); 2308 map() != GetHeap()->fixed_array_map());
2320 DCHECK(index >= 0 && index < this->length()); 2309 DCHECK(index >= 0 && index < this->length());
2321 return READ_INT64_FIELD(this, kHeaderSize + index * kDoubleSize); 2310 int offset = kHeaderSize + index * kDoubleSize;
2311 return READ_UINT64_FIELD(this, offset);
2322 } 2312 }
2323 2313
2324 2314
2325 Handle<Object> FixedDoubleArray::get(Handle<FixedDoubleArray> array, 2315 Handle<Object> FixedDoubleArray::get(Handle<FixedDoubleArray> array,
2326 int index) { 2316 int index) {
2327 if (array->is_the_hole(index)) { 2317 if (array->is_the_hole(index)) {
2328 return array->GetIsolate()->factory()->the_hole_value(); 2318 return array->GetIsolate()->factory()->the_hole_value();
2329 } else { 2319 } else {
2330 return array->GetIsolate()->factory()->NewNumber(array->get_scalar(index)); 2320 return array->GetIsolate()->factory()->NewNumber(array->get_scalar(index));
2331 } 2321 }
2332 } 2322 }
2333 2323
2334 2324
2335 void FixedDoubleArray::set(int index, double value) { 2325 void FixedDoubleArray::set(int index, double value) {
2336 DCHECK(map() != GetHeap()->fixed_cow_array_map() && 2326 DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
2337 map() != GetHeap()->fixed_array_map()); 2327 map() != GetHeap()->fixed_array_map());
2338 int offset = kHeaderSize + index * kDoubleSize; 2328 int offset = kHeaderSize + index * kDoubleSize;
2339 if (std::isnan(value)) value = canonical_not_the_hole_nan_as_double(); 2329 if (std::isnan(value)) {
2340 WRITE_DOUBLE_FIELD(this, offset, value); 2330 WRITE_UINT64_FIELD(this, offset, V8_UINT64_C(0xFFFFFFFFFFFFFFFF));
2331 } else {
2332 WRITE_DOUBLE_FIELD(this, offset, value);
2333 }
2334 DCHECK(!is_the_hole(index));
2341 } 2335 }
2342 2336
2343 2337
2344 void FixedDoubleArray::set_the_hole(int index) { 2338 void FixedDoubleArray::set_the_hole(int index) {
2345 DCHECK(map() != GetHeap()->fixed_cow_array_map() && 2339 DCHECK(map() != GetHeap()->fixed_cow_array_map() &&
2346 map() != GetHeap()->fixed_array_map()); 2340 map() != GetHeap()->fixed_array_map());
2347 int offset = kHeaderSize + index * kDoubleSize; 2341 int offset = kHeaderSize + index * kDoubleSize;
2348 WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); 2342 WRITE_UINT64_FIELD(this, offset, kHoleNanInt64);
2349 } 2343 }
2350 2344
2351 2345
2352 bool FixedDoubleArray::is_the_hole(int index) { 2346 bool FixedDoubleArray::is_the_hole(int index) {
2353 int offset = kHeaderSize + index * kDoubleSize; 2347 return get_representation(index) == kHoleNanInt64;
2354 return is_the_hole_nan(READ_DOUBLE_FIELD(this, offset));
2355 } 2348 }
2356 2349
2357 2350
2358 double* FixedDoubleArray::data_start() { 2351 double* FixedDoubleArray::data_start() {
2359 return reinterpret_cast<double*>(FIELD_ADDR(this, kHeaderSize)); 2352 return reinterpret_cast<double*>(FIELD_ADDR(this, kHeaderSize));
2360 } 2353 }
2361 2354
2362 2355
2363 void FixedDoubleArray::FillWithHoles(int from, int to) { 2356 void FixedDoubleArray::FillWithHoles(int from, int to) {
2364 for (int i = from; i < to; i++) { 2357 for (int i = from; i < to; i++) {
(...skipping 5142 matching lines...) Expand 10 before | Expand all | Expand 10 after
7507 #undef READ_SHORT_FIELD 7500 #undef READ_SHORT_FIELD
7508 #undef WRITE_SHORT_FIELD 7501 #undef WRITE_SHORT_FIELD
7509 #undef READ_BYTE_FIELD 7502 #undef READ_BYTE_FIELD
7510 #undef WRITE_BYTE_FIELD 7503 #undef WRITE_BYTE_FIELD
7511 #undef NOBARRIER_READ_BYTE_FIELD 7504 #undef NOBARRIER_READ_BYTE_FIELD
7512 #undef NOBARRIER_WRITE_BYTE_FIELD 7505 #undef NOBARRIER_WRITE_BYTE_FIELD
7513 7506
7514 } } // namespace v8::internal 7507 } } // namespace v8::internal
7515 7508
7516 #endif // V8_OBJECTS_INL_H_ 7509 #endif // V8_OBJECTS_INL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698