OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 6147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6158 Result map = allocator()->Allocate(); | 6158 Result map = allocator()->Allocate(); |
6159 ASSERT(map.is_valid()); | 6159 ASSERT(map.is_valid()); |
6160 __ mov(map.reg(), FieldOperand(obj.reg(), HeapObject::kMapOffset)); | 6160 __ mov(map.reg(), FieldOperand(obj.reg(), HeapObject::kMapOffset)); |
6161 // Undetectable objects behave like undefined when tested with typeof. | 6161 // Undetectable objects behave like undefined when tested with typeof. |
6162 __ movzx_b(map.reg(), FieldOperand(map.reg(), Map::kBitFieldOffset)); | 6162 __ movzx_b(map.reg(), FieldOperand(map.reg(), Map::kBitFieldOffset)); |
6163 __ test(map.reg(), Immediate(1 << Map::kIsUndetectable)); | 6163 __ test(map.reg(), Immediate(1 << Map::kIsUndetectable)); |
6164 destination()->false_target()->Branch(not_zero); | 6164 destination()->false_target()->Branch(not_zero); |
6165 __ mov(map.reg(), FieldOperand(obj.reg(), HeapObject::kMapOffset)); | 6165 __ mov(map.reg(), FieldOperand(obj.reg(), HeapObject::kMapOffset)); |
6166 __ movzx_b(map.reg(), FieldOperand(map.reg(), Map::kInstanceTypeOffset)); | 6166 __ movzx_b(map.reg(), FieldOperand(map.reg(), Map::kInstanceTypeOffset)); |
6167 __ cmp(map.reg(), FIRST_JS_OBJECT_TYPE); | 6167 __ cmp(map.reg(), FIRST_JS_OBJECT_TYPE); |
6168 destination()->false_target()->Branch(less); | 6168 destination()->false_target()->Branch(below); |
6169 __ cmp(map.reg(), LAST_JS_OBJECT_TYPE); | 6169 __ cmp(map.reg(), LAST_JS_OBJECT_TYPE); |
6170 obj.Unuse(); | 6170 obj.Unuse(); |
6171 map.Unuse(); | 6171 map.Unuse(); |
6172 destination()->Split(less_equal); | 6172 destination()->Split(below_equal); |
6173 } | 6173 } |
6174 | 6174 |
6175 | 6175 |
6176 void CodeGenerator::GenerateIsFunction(ZoneList<Expression*>* args) { | 6176 void CodeGenerator::GenerateIsFunction(ZoneList<Expression*>* args) { |
6177 // This generates a fast version of: | 6177 // This generates a fast version of: |
6178 // (%_ClassOf(arg) === 'Function') | 6178 // (%_ClassOf(arg) === 'Function') |
6179 ASSERT(args->length() == 1); | 6179 ASSERT(args->length() == 1); |
6180 Load(args->at(0)); | 6180 Load(args->at(0)); |
6181 Result obj = frame_->Pop(); | 6181 Result obj = frame_->Pop(); |
6182 obj.ToRegister(); | 6182 obj.ToRegister(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6275 // If the object is a smi, we return null. | 6275 // If the object is a smi, we return null. |
6276 __ test(obj.reg(), Immediate(kSmiTagMask)); | 6276 __ test(obj.reg(), Immediate(kSmiTagMask)); |
6277 null.Branch(zero); | 6277 null.Branch(zero); |
6278 | 6278 |
6279 // Check that the object is a JS object but take special care of JS | 6279 // Check that the object is a JS object but take special care of JS |
6280 // functions to make sure they have 'Function' as their class. | 6280 // functions to make sure they have 'Function' as their class. |
6281 { Result tmp = allocator()->Allocate(); | 6281 { Result tmp = allocator()->Allocate(); |
6282 __ mov(obj.reg(), FieldOperand(obj.reg(), HeapObject::kMapOffset)); | 6282 __ mov(obj.reg(), FieldOperand(obj.reg(), HeapObject::kMapOffset)); |
6283 __ movzx_b(tmp.reg(), FieldOperand(obj.reg(), Map::kInstanceTypeOffset)); | 6283 __ movzx_b(tmp.reg(), FieldOperand(obj.reg(), Map::kInstanceTypeOffset)); |
6284 __ cmp(tmp.reg(), FIRST_JS_OBJECT_TYPE); | 6284 __ cmp(tmp.reg(), FIRST_JS_OBJECT_TYPE); |
6285 null.Branch(less); | 6285 null.Branch(below); |
6286 | 6286 |
6287 // As long as JS_FUNCTION_TYPE is the last instance type and it is | 6287 // As long as JS_FUNCTION_TYPE is the last instance type and it is |
6288 // right after LAST_JS_OBJECT_TYPE, we can avoid checking for | 6288 // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
6289 // LAST_JS_OBJECT_TYPE. | 6289 // LAST_JS_OBJECT_TYPE. |
6290 ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); | 6290 ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
6291 ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); | 6291 ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
6292 __ cmp(tmp.reg(), JS_FUNCTION_TYPE); | 6292 __ cmp(tmp.reg(), JS_FUNCTION_TYPE); |
6293 function.Branch(equal); | 6293 function.Branch(equal); |
6294 } | 6294 } |
6295 | 6295 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6865 frame_->Spill(index2.reg()); | 6865 frame_->Spill(index2.reg()); |
6866 | 6866 |
6867 DeferredSwapElements* deferred = new DeferredSwapElements(object.reg(), | 6867 DeferredSwapElements* deferred = new DeferredSwapElements(object.reg(), |
6868 index1.reg(), | 6868 index1.reg(), |
6869 index2.reg()); | 6869 index2.reg()); |
6870 | 6870 |
6871 // Fetch the map and check if array is in fast case. | 6871 // Fetch the map and check if array is in fast case. |
6872 // Check that object doesn't require security checks and | 6872 // Check that object doesn't require security checks and |
6873 // has no indexed interceptor. | 6873 // has no indexed interceptor. |
6874 __ CmpObjectType(object.reg(), FIRST_JS_OBJECT_TYPE, tmp1.reg()); | 6874 __ CmpObjectType(object.reg(), FIRST_JS_OBJECT_TYPE, tmp1.reg()); |
6875 deferred->Branch(less); | 6875 deferred->Branch(below); |
6876 __ movzx_b(tmp1.reg(), FieldOperand(tmp1.reg(), Map::kBitFieldOffset)); | 6876 __ movzx_b(tmp1.reg(), FieldOperand(tmp1.reg(), Map::kBitFieldOffset)); |
6877 __ test(tmp1.reg(), Immediate(KeyedLoadIC::kSlowCaseBitFieldMask)); | 6877 __ test(tmp1.reg(), Immediate(KeyedLoadIC::kSlowCaseBitFieldMask)); |
6878 deferred->Branch(not_zero); | 6878 deferred->Branch(not_zero); |
6879 | 6879 |
6880 // Check the object's elements are in fast case. | 6880 // Check the object's elements are in fast case. |
6881 __ mov(tmp1.reg(), FieldOperand(object.reg(), JSObject::kElementsOffset)); | 6881 __ mov(tmp1.reg(), FieldOperand(object.reg(), JSObject::kElementsOffset)); |
6882 __ cmp(FieldOperand(tmp1.reg(), HeapObject::kMapOffset), | 6882 __ cmp(FieldOperand(tmp1.reg(), HeapObject::kMapOffset), |
6883 Immediate(Factory::fixed_array_map())); | 6883 Immediate(Factory::fixed_array_map())); |
6884 deferred->Branch(not_equal); | 6884 deferred->Branch(not_equal); |
6885 | 6885 |
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8185 __ CmpObjectType(answer.reg(), JS_REGEXP_TYPE, map.reg()); | 8185 __ CmpObjectType(answer.reg(), JS_REGEXP_TYPE, map.reg()); |
8186 destination()->false_target()->Branch(equal); | 8186 destination()->false_target()->Branch(equal); |
8187 | 8187 |
8188 // It can be an undetectable object. | 8188 // It can be an undetectable object. |
8189 __ movzx_b(map.reg(), FieldOperand(map.reg(), Map::kBitFieldOffset)); | 8189 __ movzx_b(map.reg(), FieldOperand(map.reg(), Map::kBitFieldOffset)); |
8190 __ test(map.reg(), Immediate(1 << Map::kIsUndetectable)); | 8190 __ test(map.reg(), Immediate(1 << Map::kIsUndetectable)); |
8191 destination()->false_target()->Branch(not_zero); | 8191 destination()->false_target()->Branch(not_zero); |
8192 __ mov(map.reg(), FieldOperand(answer.reg(), HeapObject::kMapOffset)); | 8192 __ mov(map.reg(), FieldOperand(answer.reg(), HeapObject::kMapOffset)); |
8193 __ movzx_b(map.reg(), FieldOperand(map.reg(), Map::kInstanceTypeOffset)); | 8193 __ movzx_b(map.reg(), FieldOperand(map.reg(), Map::kInstanceTypeOffset)); |
8194 __ cmp(map.reg(), FIRST_JS_OBJECT_TYPE); | 8194 __ cmp(map.reg(), FIRST_JS_OBJECT_TYPE); |
8195 destination()->false_target()->Branch(less); | 8195 destination()->false_target()->Branch(below); |
8196 __ cmp(map.reg(), LAST_JS_OBJECT_TYPE); | 8196 __ cmp(map.reg(), LAST_JS_OBJECT_TYPE); |
8197 answer.Unuse(); | 8197 answer.Unuse(); |
8198 map.Unuse(); | 8198 map.Unuse(); |
8199 destination()->Split(less_equal); | 8199 destination()->Split(below_equal); |
8200 } else { | 8200 } else { |
8201 // Uncommon case: typeof testing against a string literal that is | 8201 // Uncommon case: typeof testing against a string literal that is |
8202 // never returned from the typeof operator. | 8202 // never returned from the typeof operator. |
8203 answer.Unuse(); | 8203 answer.Unuse(); |
8204 destination()->Goto(false); | 8204 destination()->Goto(false); |
8205 } | 8205 } |
8206 return; | 8206 return; |
8207 } else if (op == Token::LT && | 8207 } else if (op == Token::LT && |
8208 right->AsLiteral() != NULL && | 8208 right->AsLiteral() != NULL && |
8209 right->AsLiteral()->handle()->IsHeapNumber()) { | 8209 right->AsLiteral()->handle()->IsHeapNumber()) { |
(...skipping 3385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11595 // There is no test for undetectability in strict equality. | 11595 // There is no test for undetectability in strict equality. |
11596 | 11596 |
11597 // Get the type of the first operand. | 11597 // Get the type of the first operand. |
11598 __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); | 11598 __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
11599 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); | 11599 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
11600 | 11600 |
11601 // If the first object is a JS object, we have done pointer comparison. | 11601 // If the first object is a JS object, we have done pointer comparison. |
11602 ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); | 11602 ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
11603 Label first_non_object; | 11603 Label first_non_object; |
11604 __ cmp(ecx, FIRST_JS_OBJECT_TYPE); | 11604 __ cmp(ecx, FIRST_JS_OBJECT_TYPE); |
11605 __ j(less, &first_non_object); | 11605 __ j(below, &first_non_object); |
11606 | 11606 |
11607 // Return non-zero (eax is not zero) | 11607 // Return non-zero (eax is not zero) |
11608 Label return_not_equal; | 11608 Label return_not_equal; |
11609 ASSERT(kHeapObjectTag != 0); | 11609 ASSERT(kHeapObjectTag != 0); |
11610 __ bind(&return_not_equal); | 11610 __ bind(&return_not_equal); |
11611 __ ret(0); | 11611 __ ret(0); |
11612 | 11612 |
11613 __ bind(&first_non_object); | 11613 __ bind(&first_non_object); |
11614 // Check for oddballs: true, false, null, undefined. | 11614 // Check for oddballs: true, false, null, undefined. |
11615 __ cmp(ecx, ODDBALL_TYPE); | 11615 __ cmp(ecx, ODDBALL_TYPE); |
11616 __ j(equal, &return_not_equal); | 11616 __ j(equal, &return_not_equal); |
11617 | 11617 |
11618 __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); | 11618 __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset)); |
11619 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); | 11619 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
11620 | 11620 |
11621 __ cmp(ecx, FIRST_JS_OBJECT_TYPE); | 11621 __ cmp(ecx, FIRST_JS_OBJECT_TYPE); |
11622 __ j(greater_equal, &return_not_equal); | 11622 __ j(above_equal, &return_not_equal); |
11623 | 11623 |
11624 // Check for oddballs: true, false, null, undefined. | 11624 // Check for oddballs: true, false, null, undefined. |
11625 __ cmp(ecx, ODDBALL_TYPE); | 11625 __ cmp(ecx, ODDBALL_TYPE); |
11626 __ j(equal, &return_not_equal); | 11626 __ j(equal, &return_not_equal); |
11627 | 11627 |
11628 // Fall through to the general case. | 11628 // Fall through to the general case. |
11629 } | 11629 } |
11630 __ bind(&slow); | 11630 __ bind(&slow); |
11631 } | 11631 } |
11632 | 11632 |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12260 // Get the object - go slow case if it's a smi. | 12260 // Get the object - go slow case if it's a smi. |
12261 Label slow; | 12261 Label slow; |
12262 __ mov(eax, Operand(esp, 2 * kPointerSize)); // 2 ~ return address, function | 12262 __ mov(eax, Operand(esp, 2 * kPointerSize)); // 2 ~ return address, function |
12263 __ test(eax, Immediate(kSmiTagMask)); | 12263 __ test(eax, Immediate(kSmiTagMask)); |
12264 __ j(zero, &slow, not_taken); | 12264 __ j(zero, &slow, not_taken); |
12265 | 12265 |
12266 // Check that the left hand is a JS object. | 12266 // Check that the left hand is a JS object. |
12267 __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); // eax - object map | 12267 __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); // eax - object map |
12268 __ movzx_b(ecx, FieldOperand(eax, Map::kInstanceTypeOffset)); // ecx - type | 12268 __ movzx_b(ecx, FieldOperand(eax, Map::kInstanceTypeOffset)); // ecx - type |
12269 __ cmp(ecx, FIRST_JS_OBJECT_TYPE); | 12269 __ cmp(ecx, FIRST_JS_OBJECT_TYPE); |
12270 __ j(less, &slow, not_taken); | 12270 __ j(below, &slow, not_taken); |
12271 __ cmp(ecx, LAST_JS_OBJECT_TYPE); | 12271 __ cmp(ecx, LAST_JS_OBJECT_TYPE); |
12272 __ j(greater, &slow, not_taken); | 12272 __ j(above, &slow, not_taken); |
12273 | 12273 |
12274 // Get the prototype of the function. | 12274 // Get the prototype of the function. |
12275 __ mov(edx, Operand(esp, 1 * kPointerSize)); // 1 ~ return address | 12275 __ mov(edx, Operand(esp, 1 * kPointerSize)); // 1 ~ return address |
12276 // edx is function, eax is map. | 12276 // edx is function, eax is map. |
12277 | 12277 |
12278 // Look up the function and the map in the instanceof cache. | 12278 // Look up the function and the map in the instanceof cache. |
12279 Label miss; | 12279 Label miss; |
12280 ExternalReference roots_address = ExternalReference::roots_address(); | 12280 ExternalReference roots_address = ExternalReference::roots_address(); |
12281 __ mov(ecx, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); | 12281 __ mov(ecx, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
12282 __ cmp(edx, Operand::StaticArray(ecx, times_pointer_size, roots_address)); | 12282 __ cmp(edx, Operand::StaticArray(ecx, times_pointer_size, roots_address)); |
12283 __ j(not_equal, &miss); | 12283 __ j(not_equal, &miss); |
12284 __ mov(ecx, Immediate(Heap::kInstanceofCacheMapRootIndex)); | 12284 __ mov(ecx, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
12285 __ cmp(eax, Operand::StaticArray(ecx, times_pointer_size, roots_address)); | 12285 __ cmp(eax, Operand::StaticArray(ecx, times_pointer_size, roots_address)); |
12286 __ j(not_equal, &miss); | 12286 __ j(not_equal, &miss); |
12287 __ mov(ecx, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); | 12287 __ mov(ecx, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
12288 __ mov(eax, Operand::StaticArray(ecx, times_pointer_size, roots_address)); | 12288 __ mov(eax, Operand::StaticArray(ecx, times_pointer_size, roots_address)); |
12289 __ ret(2 * kPointerSize); | 12289 __ ret(2 * kPointerSize); |
12290 | 12290 |
12291 __ bind(&miss); | 12291 __ bind(&miss); |
12292 __ TryGetFunctionPrototype(edx, ebx, ecx, &slow); | 12292 __ TryGetFunctionPrototype(edx, ebx, ecx, &slow); |
12293 | 12293 |
12294 // Check that the function prototype is a JS object. | 12294 // Check that the function prototype is a JS object. |
12295 __ test(ebx, Immediate(kSmiTagMask)); | 12295 __ test(ebx, Immediate(kSmiTagMask)); |
12296 __ j(zero, &slow, not_taken); | 12296 __ j(zero, &slow, not_taken); |
12297 __ mov(ecx, FieldOperand(ebx, HeapObject::kMapOffset)); | 12297 __ mov(ecx, FieldOperand(ebx, HeapObject::kMapOffset)); |
12298 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); | 12298 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
12299 __ cmp(ecx, FIRST_JS_OBJECT_TYPE); | 12299 __ cmp(ecx, FIRST_JS_OBJECT_TYPE); |
12300 __ j(less, &slow, not_taken); | 12300 __ j(below, &slow, not_taken); |
12301 __ cmp(ecx, LAST_JS_OBJECT_TYPE); | 12301 __ cmp(ecx, LAST_JS_OBJECT_TYPE); |
12302 __ j(greater, &slow, not_taken); | 12302 __ j(above, &slow, not_taken); |
12303 | 12303 |
12304 // Register mapping: | 12304 // Register mapping: |
12305 // eax is object map. | 12305 // eax is object map. |
12306 // edx is function. | 12306 // edx is function. |
12307 // ebx is function prototype. | 12307 // ebx is function prototype. |
12308 __ mov(ecx, Immediate(Heap::kInstanceofCacheMapRootIndex)); | 12308 __ mov(ecx, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
12309 __ mov(Operand::StaticArray(ecx, times_pointer_size, roots_address), eax); | 12309 __ mov(Operand::StaticArray(ecx, times_pointer_size, roots_address), eax); |
12310 __ mov(ecx, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); | 12310 __ mov(ecx, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
12311 __ mov(Operand::StaticArray(ecx, times_pointer_size, roots_address), edx); | 12311 __ mov(Operand::StaticArray(ecx, times_pointer_size, roots_address), edx); |
12312 | 12312 |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13292 // tagged as a small integer. | 13292 // tagged as a small integer. |
13293 __ bind(&runtime); | 13293 __ bind(&runtime); |
13294 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); | 13294 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
13295 } | 13295 } |
13296 | 13296 |
13297 #undef __ | 13297 #undef __ |
13298 | 13298 |
13299 } } // namespace v8::internal | 13299 } } // namespace v8::internal |
13300 | 13300 |
13301 #endif // V8_TARGET_ARCH_IA32 | 13301 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |