Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
| 6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
| 7 | |
| 8 #include "src/code-factory.h" | |
| 7 #include "src/elements.h" | 9 #include "src/elements.h" |
| 8 | 10 |
| 9 namespace v8 { | 11 namespace v8 { |
| 10 namespace internal { | 12 namespace internal { |
| 11 | 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 inline bool ClampedToInteger(Isolate* isolate, Object* object, int* out) { | 16 inline bool ClampedToInteger(Isolate* isolate, Object* object, int* out) { |
| 15 // This is an extended version of ECMA-262 7.1.11 handling signed values | 17 // This is an extended version of ECMA-262 7.1.11 handling signed values |
| 16 // Try to convert object to a number and clamp values to [kMinInt, kMaxInt] | 18 // Try to convert object to a number and clamp values to [kMinInt, kMaxInt] |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 map != context->fast_aliased_arguments_map()) { | 50 map != context->fast_aliased_arguments_map()) { |
| 49 return false; | 51 return false; |
| 50 } | 52 } |
| 51 DCHECK(object->HasFastElements() || object->HasFastArgumentsElements()); | 53 DCHECK(object->HasFastElements() || object->HasFastArgumentsElements()); |
| 52 Object* len_obj = object->InObjectPropertyAt(JSArgumentsObject::kLengthIndex); | 54 Object* len_obj = object->InObjectPropertyAt(JSArgumentsObject::kLengthIndex); |
| 53 if (!len_obj->IsSmi()) return false; | 55 if (!len_obj->IsSmi()) return false; |
| 54 *out = Max(0, Smi::cast(len_obj)->value()); | 56 *out = Max(0, Smi::cast(len_obj)->value()); |
| 55 return *out <= object->elements()->length(); | 57 return *out <= object->elements()->length(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 inline bool PrototypeHasNoElements(Isolate* isolate, JSObject* object) { | |
|
caitp
2016/07/21 03:28:55
Moved to JSObject to be usable from other files
| |
| 59 DisallowHeapAllocation no_gc; | |
| 60 HeapObject* prototype = HeapObject::cast(object->map()->prototype()); | |
| 61 HeapObject* null = isolate->heap()->null_value(); | |
| 62 HeapObject* empty = isolate->heap()->empty_fixed_array(); | |
| 63 while (prototype != null) { | |
| 64 Map* map = prototype->map(); | |
| 65 if (map->instance_type() <= LAST_CUSTOM_ELEMENTS_RECEIVER) return false; | |
| 66 if (JSObject::cast(prototype)->elements() != empty) return false; | |
| 67 prototype = HeapObject::cast(map->prototype()); | |
| 68 } | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 inline bool IsJSArrayFastElementMovingAllowed(Isolate* isolate, | 60 inline bool IsJSArrayFastElementMovingAllowed(Isolate* isolate, |
| 73 JSArray* receiver) { | 61 JSArray* receiver) { |
| 74 return PrototypeHasNoElements(isolate, receiver); | 62 return JSObject::PrototypeHasNoElements(isolate, receiver); |
| 75 } | 63 } |
| 76 | 64 |
| 77 inline bool HasSimpleElements(JSObject* current) { | 65 inline bool HasSimpleElements(JSObject* current) { |
| 78 return current->map()->instance_type() > LAST_CUSTOM_ELEMENTS_RECEIVER && | 66 return current->map()->instance_type() > LAST_CUSTOM_ELEMENTS_RECEIVER && |
| 79 !current->GetElementsAccessor()->HasAccessors(current); | 67 !current->GetElementsAccessor()->HasAccessors(current); |
| 80 } | 68 } |
| 81 | 69 |
| 82 inline bool HasOnlySimpleReceiverElements(Isolate* isolate, | 70 inline bool HasOnlySimpleReceiverElements(Isolate* isolate, |
| 83 JSObject* receiver) { | 71 JSObject* receiver) { |
| 84 // Check that we have no accessors on the receiver's elements. | 72 // Check that we have no accessors on the receiver's elements. |
| 85 if (!HasSimpleElements(receiver)) return false; | 73 if (!HasSimpleElements(receiver)) return false; |
| 86 return PrototypeHasNoElements(isolate, receiver); | 74 return JSObject::PrototypeHasNoElements(isolate, receiver); |
| 87 } | 75 } |
| 88 | 76 |
| 89 inline bool HasOnlySimpleElements(Isolate* isolate, JSReceiver* receiver) { | 77 inline bool HasOnlySimpleElements(Isolate* isolate, JSReceiver* receiver) { |
| 90 DisallowHeapAllocation no_gc; | 78 DisallowHeapAllocation no_gc; |
| 91 PrototypeIterator iter(isolate, receiver, kStartAtReceiver); | 79 PrototypeIterator iter(isolate, receiver, kStartAtReceiver); |
| 92 for (; !iter.IsAtEnd(); iter.Advance()) { | 80 for (; !iter.IsAtEnd(); iter.Advance()) { |
| 93 if (iter.GetCurrent()->IsJSProxy()) return false; | 81 if (iter.GetCurrent()->IsJSProxy()) return false; |
| 94 JSObject* current = iter.GetCurrent<JSObject>(); | 82 JSObject* current = iter.GetCurrent<JSObject>(); |
| 95 if (!HasSimpleElements(current)) return false; | 83 if (!HasSimpleElements(current)) return false; |
| 96 } | 84 } |
| (...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 assembler->Return(assembler->BooleanConstant(true)); | 1252 assembler->Return(assembler->BooleanConstant(true)); |
| 1265 | 1253 |
| 1266 assembler->Bind(&return_false); | 1254 assembler->Bind(&return_false); |
| 1267 assembler->Return(assembler->BooleanConstant(false)); | 1255 assembler->Return(assembler->BooleanConstant(false)); |
| 1268 | 1256 |
| 1269 assembler->Bind(&call_runtime); | 1257 assembler->Bind(&call_runtime); |
| 1270 assembler->Return( | 1258 assembler->Return( |
| 1271 assembler->CallRuntime(Runtime::kArrayIsArray, context, object)); | 1259 assembler->CallRuntime(Runtime::kArrayIsArray, context, object)); |
| 1272 } | 1260 } |
| 1273 | 1261 |
| 1262 void Builtins::Generate_ArrayIncludes(CodeStubAssembler* assembler) { | |
| 1263 typedef compiler::Node Node; | |
| 1264 typedef CodeStubAssembler::Label Label; | |
| 1265 typedef CodeStubAssembler::Variable Variable; | |
| 1266 | |
| 1267 Node* array = assembler->Parameter(0); | |
| 1268 Node* search_element = assembler->Parameter(1); | |
| 1269 Node* start_from = assembler->Parameter(2); | |
| 1270 Node* context = assembler->Parameter(3 + 2); | |
| 1271 | |
| 1272 Node* int32_zero = assembler->Int32Constant(0); | |
| 1273 Node* int32_one = assembler->Int32Constant(1); | |
| 1274 | |
| 1275 Node* the_hole = assembler->TheHoleConstant(); | |
| 1276 Node* undefined = assembler->UndefinedConstant(); | |
| 1277 Node* heap_number_map = assembler->HeapNumberMapConstant(); | |
| 1278 | |
| 1279 Variable len_var(assembler, MachineRepresentation::kWord32), | |
| 1280 k_var(assembler, MachineRepresentation::kWord32), | |
| 1281 n_var(assembler, MachineRepresentation::kWord32); | |
| 1282 | |
| 1283 Label init_k(assembler), return_true(assembler), return_false(assembler), | |
| 1284 call_runtime(assembler); | |
| 1285 | |
| 1286 Label init_len(assembler); | |
| 1287 | |
| 1288 // Take slow path if not a JSArray, if retrieving elements requires | |
| 1289 // traversing prototype, or if access checks are required. | |
| 1290 assembler->BranchIfFastJSArray(array, context, &init_len, &call_runtime); | |
| 1291 | |
| 1292 assembler->Bind(&init_len); | |
| 1293 { | |
| 1294 len_var.Bind(assembler->SmiToWord( | |
| 1295 assembler->LoadObjectField(array, JSArray::kLengthOffset))); | |
| 1296 | |
| 1297 assembler->GotoUnless(assembler->Word32Equal(len_var.value(), int32_zero), | |
| 1298 &init_k); | |
| 1299 assembler->Return(assembler->BooleanConstant(false)); | |
| 1300 } | |
| 1301 | |
| 1302 assembler->Bind(&init_k); | |
| 1303 { | |
| 1304 Label done(assembler), init_k_smi(assembler), init_k_heap_num(assembler), | |
| 1305 init_k_zero(assembler), init_k_n(assembler); | |
| 1306 Callable call_to_integer = CodeFactory::ToInteger(assembler->isolate()); | |
| 1307 Node* tagged_n = assembler->CallStub(call_to_integer, context, start_from); | |
| 1308 | |
| 1309 assembler->Branch(assembler->WordIsSmi(tagged_n), &init_k_smi, | |
| 1310 &init_k_heap_num); | |
| 1311 | |
| 1312 assembler->Bind(&init_k_smi); | |
| 1313 { | |
| 1314 n_var.Bind(assembler->SmiToWord32(tagged_n)); | |
| 1315 assembler->Goto(&init_k_n); | |
| 1316 } | |
| 1317 | |
| 1318 assembler->Bind(&init_k_heap_num); | |
| 1319 { | |
| 1320 Label do_return_false(assembler); | |
| 1321 Node* fp_len = assembler->ChangeInt32ToFloat64(len_var.value()); | |
| 1322 Node* fp_n = assembler->LoadHeapNumberValue(tagged_n); | |
| 1323 assembler->GotoIf(assembler->Float64GreaterThanOrEqual(fp_n, fp_len), | |
| 1324 &do_return_false); | |
| 1325 n_var.Bind(assembler->TruncateFloat64ToWord32(fp_n)); | |
| 1326 assembler->Goto(&init_k_n); | |
| 1327 | |
| 1328 assembler->Bind(&do_return_false); | |
| 1329 { | |
| 1330 k_var.Bind(int32_zero); | |
| 1331 assembler->Goto(&return_false); | |
| 1332 } | |
| 1333 } | |
| 1334 | |
| 1335 assembler->Bind(&init_k_n); | |
| 1336 { | |
| 1337 Label if_positive(assembler), if_negative(assembler), done(assembler); | |
| 1338 assembler->Branch(assembler->Int32LessThan(n_var.value(), int32_zero), | |
| 1339 &if_negative, &if_positive); | |
| 1340 | |
| 1341 assembler->Bind(&if_positive); | |
| 1342 { | |
| 1343 k_var.Bind(n_var.value()); | |
| 1344 assembler->Goto(&done); | |
| 1345 } | |
| 1346 | |
| 1347 assembler->Bind(&if_negative); | |
| 1348 { | |
| 1349 k_var.Bind(assembler->Int32Add(len_var.value(), n_var.value())); | |
| 1350 assembler->Branch(assembler->Int32LessThan(k_var.value(), int32_zero), | |
| 1351 &init_k_zero, &done); | |
| 1352 } | |
| 1353 | |
| 1354 assembler->Bind(&init_k_zero); | |
| 1355 { | |
| 1356 k_var.Bind(int32_zero); | |
| 1357 assembler->Goto(&done); | |
| 1358 } | |
| 1359 | |
| 1360 assembler->Bind(&done); | |
| 1361 } | |
| 1362 } | |
| 1363 | |
| 1364 static int32_t kElementsKind[] = { | |
| 1365 FAST_SMI_ELEMENTS, FAST_HOLEY_SMI_ELEMENTS, FAST_ELEMENTS, | |
| 1366 FAST_HOLEY_ELEMENTS, FAST_DOUBLE_ELEMENTS, FAST_HOLEY_DOUBLE_ELEMENTS, | |
| 1367 }; | |
| 1368 | |
| 1369 Label if_smiorobjects(assembler), if_packed_doubles(assembler), | |
| 1370 if_holey_doubles(assembler); | |
| 1371 Label* element_kind_handlers[] = {&if_smiorobjects, &if_smiorobjects, | |
| 1372 &if_smiorobjects, &if_smiorobjects, | |
| 1373 &if_packed_doubles, &if_holey_doubles}; | |
| 1374 | |
| 1375 Node* map = assembler->LoadMap(array); | |
| 1376 Node* bit_field2 = assembler->LoadMapBitField2(map); | |
| 1377 Node* elements_kind = | |
| 1378 assembler->BitFieldDecode<Map::ElementsKindBits>(bit_field2); | |
| 1379 Node* elements = assembler->LoadElements(array); | |
| 1380 assembler->Switch(elements_kind, &return_false, kElementsKind, | |
| 1381 element_kind_handlers, arraysize(kElementsKind)); | |
| 1382 | |
| 1383 assembler->Bind(&if_smiorobjects); | |
| 1384 { | |
| 1385 Variable search_num(assembler, MachineRepresentation::kFloat64); | |
| 1386 Label ident_loop(assembler, &k_var), heap_num_loop(assembler, &search_num), | |
| 1387 string_loop(assembler, &k_var), simd_loop(assembler), | |
| 1388 undef_loop(assembler, &k_var), not_smi(assembler), | |
| 1389 not_heap_num(assembler); | |
| 1390 | |
| 1391 assembler->GotoUnless(assembler->WordIsSmi(search_element), ¬_smi); | |
| 1392 search_num.Bind(assembler->SmiToFloat64(search_element)); | |
| 1393 assembler->Goto(&heap_num_loop); | |
| 1394 | |
| 1395 assembler->Bind(¬_smi); | |
| 1396 assembler->GotoIf(assembler->WordEqual(search_element, undefined), | |
| 1397 &undef_loop); | |
| 1398 Node* map = assembler->LoadMap(search_element); | |
| 1399 assembler->GotoIf(assembler->WordNotEqual(map, heap_number_map), | |
| 1400 ¬_heap_num); | |
| 1401 search_num.Bind(assembler->LoadHeapNumberValue(search_element)); | |
| 1402 assembler->Goto(&heap_num_loop); | |
| 1403 | |
| 1404 assembler->Bind(¬_heap_num); | |
| 1405 Node* search_type = assembler->LoadMapInstanceType(map); | |
| 1406 assembler->GotoIf( | |
| 1407 assembler->Int32LessThan( | |
| 1408 search_type, assembler->Int32Constant(FIRST_NONSTRING_TYPE)), | |
| 1409 &string_loop); | |
| 1410 assembler->GotoIf( | |
| 1411 assembler->WordEqual(search_type, | |
| 1412 assembler->Int32Constant(SIMD128_VALUE_TYPE)), | |
| 1413 &simd_loop); | |
| 1414 assembler->Goto(&ident_loop); | |
| 1415 | |
| 1416 assembler->Bind(&ident_loop); | |
| 1417 { | |
| 1418 assembler->GotoUnless( | |
| 1419 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1420 &return_false); | |
| 1421 Node* element_k = | |
| 1422 assembler->LoadFixedArrayElement(elements, k_var.value()); | |
| 1423 assembler->GotoIf(assembler->WordEqual(element_k, search_element), | |
| 1424 &return_true); | |
| 1425 | |
| 1426 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1427 assembler->Goto(&ident_loop); | |
| 1428 } | |
| 1429 | |
| 1430 assembler->Bind(&undef_loop); | |
| 1431 { | |
| 1432 assembler->GotoUnless( | |
| 1433 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1434 &return_false); | |
| 1435 Node* element_k = | |
| 1436 assembler->LoadFixedArrayElement(elements, k_var.value()); | |
| 1437 assembler->GotoIf(assembler->WordEqual(element_k, undefined), | |
| 1438 &return_true); | |
| 1439 assembler->GotoIf(assembler->WordEqual(element_k, the_hole), | |
| 1440 &return_true); | |
| 1441 | |
| 1442 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1443 assembler->Goto(&undef_loop); | |
| 1444 } | |
| 1445 | |
| 1446 assembler->Bind(&heap_num_loop); | |
| 1447 { | |
| 1448 Label nan_loop(assembler, &k_var), not_nan_loop(assembler, &k_var); | |
| 1449 assembler->BranchIfFloat64IsNaN(search_num.value(), &nan_loop, | |
| 1450 ¬_nan_loop); | |
| 1451 | |
| 1452 assembler->Bind(¬_nan_loop); | |
| 1453 { | |
| 1454 Label continue_loop(assembler), not_smi(assembler); | |
| 1455 assembler->GotoUnless( | |
| 1456 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1457 &return_false); | |
| 1458 Node* element_k = | |
| 1459 assembler->LoadFixedArrayElement(elements, k_var.value()); | |
| 1460 assembler->GotoUnless(assembler->WordIsSmi(element_k), ¬_smi); | |
| 1461 assembler->Branch( | |
| 1462 assembler->Float64Equal(search_num.value(), | |
| 1463 assembler->SmiToFloat64(element_k)), | |
| 1464 &return_true, &continue_loop); | |
| 1465 | |
| 1466 assembler->Bind(¬_smi); | |
| 1467 assembler->GotoIf(assembler->WordNotEqual(assembler->LoadMap(element_k), | |
| 1468 heap_number_map), | |
| 1469 &continue_loop); | |
| 1470 assembler->BranchIfFloat64Equal( | |
| 1471 search_num.value(), assembler->LoadHeapNumberValue(element_k), | |
| 1472 &return_true, &continue_loop); | |
| 1473 | |
| 1474 assembler->Bind(&continue_loop); | |
| 1475 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1476 assembler->Goto(¬_nan_loop); | |
| 1477 } | |
| 1478 | |
| 1479 assembler->Bind(&nan_loop); | |
| 1480 { | |
| 1481 Label continue_loop(assembler); | |
| 1482 assembler->GotoUnless( | |
| 1483 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1484 &return_false); | |
| 1485 Node* element_k = | |
| 1486 assembler->LoadFixedArrayElement(elements, k_var.value()); | |
| 1487 assembler->GotoIf(assembler->WordIsSmi(element_k), &continue_loop); | |
| 1488 assembler->GotoIf(assembler->WordNotEqual(assembler->LoadMap(element_k), | |
| 1489 heap_number_map), | |
| 1490 &continue_loop); | |
| 1491 assembler->BranchIfFloat64IsNaN( | |
| 1492 assembler->LoadHeapNumberValue(element_k), &return_true, | |
| 1493 &continue_loop); | |
| 1494 | |
| 1495 assembler->Bind(&continue_loop); | |
| 1496 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1497 assembler->Goto(&nan_loop); | |
| 1498 } | |
| 1499 } | |
| 1500 | |
| 1501 assembler->Bind(&string_loop); | |
| 1502 { | |
| 1503 Label continue_loop(assembler); | |
| 1504 assembler->GotoUnless( | |
| 1505 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1506 &return_false); | |
| 1507 Node* element_k = | |
| 1508 assembler->LoadFixedArrayElement(elements, k_var.value()); | |
| 1509 assembler->GotoIf(assembler->WordIsSmi(element_k), &continue_loop); | |
| 1510 assembler->GotoUnless(assembler->Int32LessThan( | |
| 1511 assembler->LoadMapInstanceType(element_k), | |
| 1512 assembler->Int32Constant(FIRST_NONSTRING_TYPE)), | |
| 1513 &continue_loop); | |
| 1514 | |
| 1515 // TODO(bmeurer): Consider inlining the StringEqual logic here. | |
| 1516 Callable callable = CodeFactory::StringEqual(assembler->isolate()); | |
| 1517 Node* result = | |
| 1518 assembler->CallStub(callable, context, search_element, element_k); | |
| 1519 assembler->Branch( | |
| 1520 assembler->WordEqual(assembler->BooleanConstant(true), result), | |
| 1521 &return_true, &continue_loop); | |
| 1522 | |
| 1523 assembler->Bind(&continue_loop); | |
| 1524 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1525 assembler->Goto(&string_loop); | |
| 1526 } | |
| 1527 | |
| 1528 assembler->Bind(&simd_loop); | |
| 1529 { | |
| 1530 Label continue_loop(assembler, &k_var), loop_body(assembler, &k_var); | |
| 1531 Node* map = assembler->LoadMap(search_element); | |
| 1532 | |
| 1533 assembler->Goto(&loop_body); | |
| 1534 assembler->Bind(&loop_body); | |
| 1535 assembler->GotoUnless( | |
| 1536 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1537 &return_false); | |
| 1538 | |
| 1539 Node* element_k = | |
| 1540 assembler->LoadFixedArrayElement(elements, k_var.value()); | |
| 1541 assembler->GotoIf(assembler->WordIsSmi(element_k), &continue_loop); | |
| 1542 | |
| 1543 Node* map_k = assembler->LoadMap(element_k); | |
| 1544 assembler->BranchIfSimd128Equal(search_element, map, element_k, map_k, | |
| 1545 &return_true, &continue_loop); | |
| 1546 | |
| 1547 assembler->Bind(&continue_loop); | |
| 1548 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1549 assembler->Goto(&loop_body); | |
| 1550 } | |
| 1551 } | |
| 1552 | |
| 1553 assembler->Bind(&if_packed_doubles); | |
| 1554 { | |
| 1555 Label nan_loop(assembler, &k_var), not_nan_loop(assembler, &k_var), | |
| 1556 hole_loop(assembler, &k_var), search_notnan(assembler); | |
| 1557 Variable search_num(assembler, MachineRepresentation::kFloat64); | |
| 1558 | |
| 1559 assembler->GotoUnless(assembler->WordIsSmi(search_element), &search_notnan); | |
| 1560 search_num.Bind(assembler->SmiToFloat64(search_element)); | |
| 1561 assembler->Goto(¬_nan_loop); | |
| 1562 | |
| 1563 assembler->Bind(&search_notnan); | |
| 1564 assembler->GotoIf(assembler->WordNotEqual( | |
| 1565 assembler->LoadMap(search_element), heap_number_map), | |
| 1566 &return_false); | |
| 1567 | |
| 1568 search_num.Bind(assembler->LoadHeapNumberValue(search_element)); | |
| 1569 | |
| 1570 assembler->BranchIfFloat64IsNaN(search_num.value(), &nan_loop, | |
| 1571 ¬_nan_loop); | |
| 1572 | |
| 1573 // Search for HeapNumber | |
| 1574 assembler->Bind(¬_nan_loop); | |
| 1575 { | |
| 1576 Label continue_loop(assembler); | |
| 1577 assembler->GotoUnless( | |
| 1578 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1579 &return_false); | |
| 1580 Node* element_k = assembler->LoadFixedDoubleArrayElement( | |
| 1581 elements, k_var.value(), MachineType::Float64()); | |
| 1582 assembler->BranchIfFloat64Equal(element_k, search_num.value(), | |
| 1583 &return_true, &continue_loop); | |
| 1584 assembler->Bind(&continue_loop); | |
| 1585 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1586 assembler->Goto(¬_nan_loop); | |
| 1587 } | |
| 1588 | |
| 1589 // Search for NaN | |
| 1590 assembler->Bind(&nan_loop); | |
| 1591 { | |
| 1592 Label continue_loop(assembler); | |
| 1593 assembler->GotoUnless( | |
| 1594 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1595 &return_false); | |
| 1596 Node* element_k = assembler->LoadFixedDoubleArrayElement( | |
| 1597 elements, k_var.value(), MachineType::Float64()); | |
| 1598 assembler->BranchIfFloat64IsNaN(element_k, &return_true, &continue_loop); | |
| 1599 assembler->Bind(&continue_loop); | |
| 1600 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1601 assembler->Goto(&nan_loop); | |
| 1602 } | |
| 1603 } | |
| 1604 | |
| 1605 assembler->Bind(&if_holey_doubles); | |
| 1606 { | |
| 1607 Label nan_loop(assembler, &k_var), not_nan_loop(assembler, &k_var), | |
| 1608 hole_loop(assembler, &k_var), search_notnan(assembler); | |
| 1609 Variable search_num(assembler, MachineRepresentation::kFloat64); | |
| 1610 | |
| 1611 assembler->GotoUnless(assembler->WordIsSmi(search_element), &search_notnan); | |
| 1612 search_num.Bind(assembler->SmiToFloat64(search_element)); | |
| 1613 assembler->Goto(¬_nan_loop); | |
| 1614 | |
| 1615 assembler->Bind(&search_notnan); | |
| 1616 assembler->GotoIf(assembler->WordEqual(search_element, undefined), | |
| 1617 &hole_loop); | |
| 1618 assembler->GotoIf(assembler->WordNotEqual( | |
| 1619 assembler->LoadMap(search_element), heap_number_map), | |
| 1620 &return_false); | |
| 1621 | |
| 1622 search_num.Bind(assembler->LoadHeapNumberValue(search_element)); | |
| 1623 | |
| 1624 assembler->BranchIfFloat64IsNaN(search_num.value(), &nan_loop, | |
| 1625 ¬_nan_loop); | |
| 1626 | |
| 1627 // Search for HeapNumber | |
| 1628 assembler->Bind(¬_nan_loop); | |
| 1629 { | |
| 1630 Label continue_loop(assembler); | |
| 1631 assembler->GotoUnless( | |
| 1632 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1633 &return_false); | |
| 1634 | |
| 1635 if (kPointerSize == kDoubleSize) { | |
| 1636 Node* element = assembler->LoadFixedDoubleArrayElement( | |
| 1637 elements, k_var.value(), MachineType::Uint64()); | |
| 1638 Node* the_hole = assembler->Int64Constant(kHoleNanInt64); | |
| 1639 assembler->GotoIf(assembler->Word64Equal(element, the_hole), | |
| 1640 &continue_loop); | |
| 1641 } else { | |
| 1642 Node* element_upper = assembler->LoadFixedDoubleArrayElement( | |
| 1643 elements, k_var.value(), MachineType::Uint32(), | |
| 1644 kIeeeDoubleExponentWordOffset); | |
| 1645 assembler->GotoIf( | |
| 1646 assembler->Word32Equal(element_upper, | |
| 1647 assembler->Int32Constant(kHoleNanUpper32)), | |
| 1648 &continue_loop); | |
| 1649 } | |
| 1650 | |
| 1651 Node* element_k = assembler->LoadFixedDoubleArrayElement( | |
| 1652 elements, k_var.value(), MachineType::Float64()); | |
| 1653 assembler->BranchIfFloat64Equal(element_k, search_num.value(), | |
| 1654 &return_true, &continue_loop); | |
| 1655 assembler->Bind(&continue_loop); | |
| 1656 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1657 assembler->Goto(¬_nan_loop); | |
| 1658 } | |
| 1659 | |
| 1660 // Search for NaN | |
| 1661 assembler->Bind(&nan_loop); | |
| 1662 { | |
| 1663 Label continue_loop(assembler); | |
| 1664 assembler->GotoUnless( | |
| 1665 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1666 &return_false); | |
| 1667 | |
| 1668 if (kPointerSize == kDoubleSize) { | |
| 1669 Node* element = assembler->LoadFixedDoubleArrayElement( | |
| 1670 elements, k_var.value(), MachineType::Uint64()); | |
| 1671 Node* the_hole = assembler->Int64Constant(kHoleNanInt64); | |
| 1672 assembler->GotoIf(assembler->Word64Equal(element, the_hole), | |
| 1673 &continue_loop); | |
| 1674 } else { | |
| 1675 Node* element_upper = assembler->LoadFixedDoubleArrayElement( | |
| 1676 elements, k_var.value(), MachineType::Uint32(), | |
| 1677 kIeeeDoubleExponentWordOffset); | |
| 1678 assembler->GotoIf( | |
| 1679 assembler->Word32Equal(element_upper, | |
| 1680 assembler->Int32Constant(kHoleNanUpper32)), | |
| 1681 &continue_loop); | |
| 1682 } | |
| 1683 | |
| 1684 Node* element_k = assembler->LoadFixedDoubleArrayElement( | |
| 1685 elements, k_var.value(), MachineType::Float64()); | |
| 1686 assembler->BranchIfFloat64IsNaN(element_k, &return_true, &continue_loop); | |
| 1687 assembler->Bind(&continue_loop); | |
| 1688 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1689 assembler->Goto(&nan_loop); | |
| 1690 } | |
| 1691 | |
| 1692 // Search for the Hole | |
| 1693 assembler->Bind(&hole_loop); | |
| 1694 { | |
| 1695 assembler->GotoUnless( | |
| 1696 assembler->Int32LessThan(k_var.value(), len_var.value()), | |
| 1697 &return_false); | |
| 1698 | |
| 1699 if (kPointerSize == kDoubleSize) { | |
| 1700 Node* element = assembler->LoadFixedDoubleArrayElement( | |
| 1701 elements, k_var.value(), MachineType::Uint64()); | |
| 1702 Node* the_hole = assembler->Int64Constant(kHoleNanInt64); | |
| 1703 assembler->GotoIf(assembler->Word64Equal(element, the_hole), | |
| 1704 &return_true); | |
| 1705 } else { | |
| 1706 Node* element_upper = assembler->LoadFixedDoubleArrayElement( | |
| 1707 elements, k_var.value(), MachineType::Uint32(), | |
| 1708 kIeeeDoubleExponentWordOffset); | |
| 1709 assembler->GotoIf( | |
| 1710 assembler->Word32Equal(element_upper, | |
| 1711 assembler->Int32Constant(kHoleNanUpper32)), | |
| 1712 &return_true); | |
| 1713 } | |
| 1714 | |
| 1715 k_var.Bind(assembler->Int32Add(k_var.value(), int32_one)); | |
| 1716 assembler->Goto(&hole_loop); | |
| 1717 } | |
| 1718 } | |
| 1719 | |
| 1720 assembler->Bind(&return_true); | |
| 1721 assembler->Return(assembler->BooleanConstant(true)); | |
| 1722 | |
| 1723 assembler->Bind(&return_false); | |
| 1724 assembler->Return(assembler->BooleanConstant(false)); | |
| 1725 | |
| 1726 assembler->Bind(&call_runtime); | |
| 1727 assembler->Return(assembler->CallRuntime(Runtime::kArrayIncludes_Slow, | |
| 1728 context, array, search_element, | |
| 1729 start_from)); | |
| 1730 } | |
| 1731 | |
| 1274 } // namespace internal | 1732 } // namespace internal |
| 1275 } // namespace v8 | 1733 } // namespace v8 |
| OLD | NEW |