| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // The intrinsic code below is executed before a method has built its frame. | 5 // The intrinsic code below is executed before a method has built its frame. |
| 6 // The return address is on the stack and the arguments below it. | 6 // The return address is on the stack and the arguments below it. |
| 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. | 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. |
| 8 // Each intrinsification method returns true if the corresponding | 8 // Each intrinsification method returns true if the corresponding |
| 9 // Dart method was intrinsified. | 9 // Dart method was intrinsified. |
| 10 | 10 |
| 11 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. | 11 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 12 #if defined(TARGET_ARCH_IA32) | 12 #if defined(TARGET_ARCH_IA32) |
| 13 | 13 |
| 14 #include "vm/intrinsifier.h" | 14 #include "vm/intrinsifier.h" |
| 15 | 15 |
| 16 #include "vm/assembler.h" | 16 #include "vm/assembler.h" |
| 17 #include "vm/assembler_macros.h" | 17 #include "vm/assembler_macros.h" |
| 18 #include "vm/object.h" | 18 #include "vm/object.h" |
| 19 #include "vm/object_store.h" | 19 #include "vm/object_store.h" |
| 20 #include "vm/os.h" | 20 #include "vm/os.h" |
| 21 #include "vm/stub_code.h" | 21 #include "vm/stub_code.h" |
| 22 | 22 |
| 23 namespace dart { | 23 namespace dart { |
| 24 | 24 |
| 25 DECLARE_FLAG(bool, enable_type_checks); | 25 DECLARE_FLAG(bool, enable_type_checks); |
| 26 | 26 |
| 27 | |
| 28 #define __ assembler-> | 27 #define __ assembler-> |
| 29 | 28 |
| 30 bool Intrinsifier::ObjectArray_Allocate(Assembler* assembler) { | 29 bool Intrinsifier::ObjectArray_Allocate(Assembler* assembler) { |
| 31 // This snippet of inlined code uses the following registers: | 30 // This snippet of inlined code uses the following registers: |
| 32 // EAX, EBX, EDI | 31 // EAX, EBX, EDI |
| 33 // and the newly allocated object is returned in EAX. | 32 // and the newly allocated object is returned in EAX. |
| 34 const intptr_t kTypeArgumentsOffset = 2 * kWordSize; | 33 const intptr_t kTypeArgumentsOffset = 2 * kWordSize; |
| 35 const intptr_t kArrayLengthOffset = 1 * kWordSize; | 34 const intptr_t kArrayLengthOffset = 1 * kWordSize; |
| 36 Label fall_through; | 35 Label fall_through; |
| 37 | 36 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 return false; | 424 return false; |
| 426 } | 425 } |
| 427 __ movl(EAX, Address(ESP, + 2 * kWordSize)); | 426 __ movl(EAX, Address(ESP, + 2 * kWordSize)); |
| 428 __ movl(EBX, Address(ESP, + 1 * kWordSize)); | 427 __ movl(EBX, Address(ESP, + 1 * kWordSize)); |
| 429 __ movl(FieldAddress(EAX, GrowableObjectArray::data_offset()), EBX); | 428 __ movl(FieldAddress(EAX, GrowableObjectArray::data_offset()), EBX); |
| 430 __ ret(); | 429 __ ret(); |
| 431 return true; | 430 return true; |
| 432 } | 431 } |
| 433 | 432 |
| 434 | 433 |
| 435 // Handles only class InternalByteArray. | |
| 436 bool Intrinsifier::ByteArrayBase_getLength(Assembler* assembler) { | |
| 437 ObjectStore* object_store = Isolate::Current()->object_store(); | |
| 438 Label fall_through; | |
| 439 __ movl(EAX, Address(ESP, + 1 * kWordSize)); | |
| 440 __ movl(EBX, FieldAddress(EAX, Object::class_offset())); | |
| 441 __ CompareObject(EBX, | |
| 442 Class::ZoneHandle(object_store->internal_byte_array_class())); | |
| 443 __ j(NOT_EQUAL, &fall_through); | |
| 444 __ movl(EAX, FieldAddress(EAX, InternalByteArray::length_offset())); | |
| 445 __ ret(); | |
| 446 __ Bind(&fall_through); | |
| 447 return false; | |
| 448 } | |
| 449 | |
| 450 | |
| 451 // Handles only class InternalByteArray. | |
| 452 bool Intrinsifier::ByteArrayBase_getIndexed(Assembler* assembler) { | |
| 453 ObjectStore* object_store = Isolate::Current()->object_store(); | |
| 454 Label fall_through; | |
| 455 __ movl(EAX, Address(ESP, + 2 * kWordSize)); // Array. | |
| 456 __ movl(EBX, FieldAddress(EAX, Object::class_offset())); | |
| 457 __ CompareObject(EBX, | |
| 458 Class::ZoneHandle(object_store->internal_byte_array_class())); | |
| 459 __ j(NOT_EQUAL, &fall_through); | |
| 460 __ movl(EBX, Address(ESP, + 1 * kWordSize)); // Index. | |
| 461 __ testl(EBX, Immediate(kSmiTagMask)); | |
| 462 __ j(NOT_ZERO, &fall_through, Assembler::kNearJump); // Non-smi index. | |
| 463 // Range check. | |
| 464 __ cmpl(EBX, FieldAddress(EAX, InternalByteArray::length_offset())); | |
| 465 // Runtime throws exception. | |
| 466 __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump); | |
| 467 __ SmiUntag(EBX); | |
| 468 __ movzxb(EAX, | |
| 469 FieldAddress(EAX, EBX, TIMES_1, InternalByteArray::data_offset())); | |
| 470 // The values stored in the byte array are regular, untagged values, | |
| 471 // therefore they need to be tagged. | |
| 472 __ SmiTag(EAX); | |
| 473 __ ret(); | |
| 474 __ Bind(&fall_through); | |
| 475 return false; | |
| 476 } | |
| 477 | |
| 478 | |
| 479 // Tests if two top most arguments are smis, jumps to label not_smi if not. | 434 // Tests if two top most arguments are smis, jumps to label not_smi if not. |
| 480 // Topmost argument is in EAX. | 435 // Topmost argument is in EAX. |
| 481 static void TestBothArgumentsSmis(Assembler* assembler, Label* not_smi) { | 436 static void TestBothArgumentsSmis(Assembler* assembler, Label* not_smi) { |
| 482 __ movl(EAX, Address(ESP, + 1 * kWordSize)); | 437 __ movl(EAX, Address(ESP, + 1 * kWordSize)); |
| 483 __ movl(EBX, Address(ESP, + 2 * kWordSize)); | 438 __ movl(EBX, Address(ESP, + 2 * kWordSize)); |
| 484 __ orl(EBX, EAX); | 439 __ orl(EBX, EAX); |
| 485 __ testl(EBX, Immediate(kSmiTagMask)); | 440 __ testl(EBX, Immediate(kSmiTagMask)); |
| 486 __ j(NOT_ZERO, not_smi, Assembler::kNearJump); | 441 __ j(NOT_ZERO, not_smi, Assembler::kNearJump); |
| 487 } | 442 } |
| 488 | 443 |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 __ Bind(&is_true); | 1292 __ Bind(&is_true); |
| 1338 __ LoadObject(EAX, bool_true); | 1293 __ LoadObject(EAX, bool_true); |
| 1339 __ ret(); | 1294 __ ret(); |
| 1340 return true; | 1295 return true; |
| 1341 } | 1296 } |
| 1342 | 1297 |
| 1343 #undef __ | 1298 #undef __ |
| 1344 } // namespace dart | 1299 } // namespace dart |
| 1345 | 1300 |
| 1346 #endif // defined TARGET_ARCH_IA32 | 1301 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |