Chromium Code Reviews| Index: runtime/vm/intrinsifier_ia32.cc |
| =================================================================== |
| --- runtime/vm/intrinsifier_ia32.cc (revision 4129) |
| +++ runtime/vm/intrinsifier_ia32.cc (working copy) |
| @@ -73,6 +73,8 @@ |
| V(GrowableObjectArray, get:length, GrowableArray_getLength) \ |
| V(GrowableObjectArray, [], GrowableArray_getIndexed) \ |
| V(GrowableObjectArray, []=, GrowableArray_setIndexed) \ |
| + V(_ByteArrayBase, get:length, ByteArrayBase_getLength) \ |
| + V(_ByteArrayBase, [], ByteArrayBase_getIndexed) \ |
|
siva
2012/02/11 01:39:29
The more interesting ones are the getInt8, getUint
srdjan
2012/02/12 06:52:24
Do we have existing code/benchmarks that are alrea
|
| V(ImmutableArray, [], Array_getIndexed) \ |
| V(ImmutableArray, get:length, Array_getLength) \ |
| V(Math, sqrt, Math_sqrt) \ |
| @@ -328,6 +330,48 @@ |
| } |
| +// Handles only class InternalByteArray. |
|
siva
2012/02/11 01:39:29
Would you at some point also implement a similar i
srdjan
2012/02/12 06:52:24
Yes.
|
| +static bool ByteArrayBase_getLength(Assembler* assembler) { |
| + ObjectStore* object_store = Isolate::Current()->object_store(); |
| + Label fall_through; |
| + __ movl(EAX, Address(ESP, + 1 * kWordSize)); |
| + __ movl(EBX, FieldAddress(EAX, Object::class_offset())); |
| + __ CompareObject(EBX, |
| + Class::ZoneHandle(object_store->internal_byte_array_class())); |
| + __ j(NOT_EQUAL, &fall_through); |
| + __ movl(EAX, FieldAddress(EAX, InternalByteArray::length_offset())); |
| + __ ret(); |
| + __ Bind(&fall_through); |
| + return false; |
| +} |
| + |
| + |
| +// Handles only class InternalByteArray. |
| +static bool ByteArrayBase_getIndexed(Assembler* assembler) { |
| + ObjectStore* object_store = Isolate::Current()->object_store(); |
| + Label fall_through; |
| + __ movl(EAX, Address(ESP, + 2 * kWordSize)); // Array. |
| + __ movl(EBX, FieldAddress(EAX, Object::class_offset())); |
| + __ CompareObject(EBX, |
| + Class::ZoneHandle(object_store->internal_byte_array_class())); |
| + __ j(NOT_EQUAL, &fall_through); |
| + __ movl(EBX, Address(ESP, + 1 * kWordSize)); // Index. |
| + __ testl(EBX, Immediate(kSmiTagMask)); |
| + __ j(NOT_ZERO, &fall_through, Assembler::kNearJump); // Non-smi index. |
| + // Range check. |
| + __ cmpl(EBX, FieldAddress(EAX, InternalByteArray::length_offset())); |
| + // Runtime throws exception. |
| + __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump); |
| + __ SmiUntag(EBX); |
| + __ movzxb(EAX, |
| + FieldAddress(EAX, EBX, TIMES_1, InternalByteArray::data_offset())); |
| + __ SmiTag(EAX); |
|
siva
2012/02/11 01:39:29
Perhaps a comment that values stored in the byte a
srdjan
2012/02/12 06:52:24
Done.
|
| + __ ret(); |
| + __ Bind(&fall_through); |
| + return false; |
| +} |
| + |
| + |
| // Tests if two top most arguments are smis, jumps to label not_smi if not. |
| // Topmost argument is in EAX. |
| static void TestBothArgumentsSmis(Assembler* assembler, Label* not_smi) { |
| @@ -1154,10 +1198,35 @@ |
| const char* function_name = String::Handle(function.name()).ToCString(); |
| const Class& function_class = Class::Handle(function.owner()); |
| const char* class_name = String::Handle(function_class.Name()).ToCString(); |
| + // Only core library methods can be intrinsified. |
| + const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| + const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); |
| + if ((function_class.library() != core_lib.raw()) && |
| + (function_class.library() != core_impl_lib.raw())) { |
| + return false; |
| + } |
| #define FIND_INTRINSICS(test_class_name, test_function_name, destination) \ |
| - if ((strcmp(#test_function_name, function_name) == 0) && \ |
| - (strcmp(#test_class_name, class_name) == 0)) { \ |
| - return destination(assembler); \ |
| + if ((#test_class_name[0] == '_') && (class_name[0] == '_')) { \ |
| + if (strcmp(#test_function_name, function_name) == 0) { \ |
| + String& test_str = String::Handle(String::New(#test_class_name)); \ |
| + String& test_str_with_key = String::Handle(); \ |
| + test_str_with_key = \ |
| + String::Concat(test_str, String::Handle(core_lib.private_key())); \ |
| + if (strcmp(test_str_with_key.ToCString(), class_name) == 0) { \ |
| + return destination(assembler); \ |
| + } \ |
| + test_str_with_key = \ |
| + String::Concat(test_str, \ |
| + String::Handle(core_impl_lib.private_key())); \ |
| + if (strcmp(test_str_with_key.ToCString(), class_name) == 0) { \ |
| + return destination(assembler); \ |
| + } \ |
| + } \ |
|
siva
2012/02/11 01:39:29
This piece of code here seems too big to repeat fo
srdjan
2012/02/12 06:52:24
Good point. Done.
|
| + } else { \ |
| + if ((strcmp(#test_function_name, function_name) == 0) && \ |
| + (strcmp(#test_class_name, class_name) == 0)) { \ |
| + return destination(assembler); \ |
| + } \ |
| } \ |
| INTRINSIC_LIST(FIND_INTRINSICS); |