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

Side by Side Diff: src/codegen-ia32.cc

Issue 39336: Refactored the code for comparing the type of an object with a constant.... Base URL: http://v8.googlecode.com/svn/branches/experimental/global/
Patch Set: Created 11 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 ASSERT(kSmiTagSize == 1 && kSmiTag == 0); 1927 ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
1928 Result switch_value = frame_->Pop(); 1928 Result switch_value = frame_->Pop();
1929 switch_value.ToRegister(); 1929 switch_value.ToRegister();
1930 __ test(switch_value.reg(), Immediate(kSmiTagMask)); 1930 __ test(switch_value.reg(), Immediate(kSmiTagMask));
1931 is_smi.Branch(equal, &switch_value, taken); 1931 is_smi.Branch(equal, &switch_value, taken);
1932 1932
1933 // It's a heap object, not a smi or a failure. Check if it is a 1933 // It's a heap object, not a smi or a failure. Check if it is a
1934 // heap number. 1934 // heap number.
1935 Result temp = allocator()->Allocate(); 1935 Result temp = allocator()->Allocate();
1936 ASSERT(temp.is_valid()); 1936 ASSERT(temp.is_valid());
1937 __ mov(temp.reg(), FieldOperand(switch_value.reg(), HeapObject::kMapOffset)); 1937 __ CmpObjectType(switch_value.reg(), HEAP_NUMBER_TYPE, temp.reg());
1938 __ movzx_b(temp.reg(), FieldOperand(temp.reg(), Map::kInstanceTypeOffset));
1939 __ cmp(temp.reg(), HEAP_NUMBER_TYPE);
1940 temp.Unuse(); 1938 temp.Unuse();
1941 default_target->Branch(not_equal); 1939 default_target->Branch(not_equal);
1942 1940
1943 // The switch value is a heap number. Convert it to a smi. 1941 // The switch value is a heap number. Convert it to a smi.
1944 frame_->Push(&switch_value); 1942 frame_->Push(&switch_value);
1945 Result smi_value = frame_->CallRuntime(Runtime::kNumberToSmi, 1); 1943 Result smi_value = frame_->CallRuntime(Runtime::kNumberToSmi, 1);
1946 1944
1947 is_smi.Bind(&smi_value); 1945 is_smi.Bind(&smi_value);
1948 smi_value.ToRegister(); 1946 smi_value.ToRegister();
1949 // Convert the switch value to a 0-based table index. 1947 // Convert the switch value to a 0-based table index.
(...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after
4115 ASSERT(args->length() == 1); 4113 ASSERT(args->length() == 1);
4116 Load(args->at(0)); 4114 Load(args->at(0));
4117 Result value = frame_->Pop(); 4115 Result value = frame_->Pop();
4118 value.ToRegister(); 4116 value.ToRegister();
4119 ASSERT(value.is_valid()); 4117 ASSERT(value.is_valid());
4120 __ test(value.reg(), Immediate(kSmiTagMask)); 4118 __ test(value.reg(), Immediate(kSmiTagMask));
4121 destination()->false_target()->Branch(equal); 4119 destination()->false_target()->Branch(equal);
4122 // It is a heap object - get map. 4120 // It is a heap object - get map.
4123 Result temp = allocator()->Allocate(); 4121 Result temp = allocator()->Allocate();
4124 ASSERT(temp.is_valid()); 4122 ASSERT(temp.is_valid());
4125 __ mov(temp.reg(), FieldOperand(value.reg(), HeapObject::kMapOffset));
4126 __ movzx_b(temp.reg(), FieldOperand(temp.reg(), Map::kInstanceTypeOffset));
4127 // Check if the object is a JS array or not. 4123 // Check if the object is a JS array or not.
4128 __ cmp(temp.reg(), JS_ARRAY_TYPE); 4124 __ CmpObjectType(value.reg(), JS_ARRAY_TYPE, temp.reg());
4129 value.Unuse(); 4125 value.Unuse();
4130 temp.Unuse(); 4126 temp.Unuse();
4131 destination()->Split(equal); 4127 destination()->Split(equal);
4132 } 4128 }
4133 4129
4134 4130
4135 void CodeGenerator::GenerateArgumentsLength(ZoneList<Expression*>* args) { 4131 void CodeGenerator::GenerateArgumentsLength(ZoneList<Expression*>* args) {
4136 ASSERT(args->length() == 0); 4132 ASSERT(args->length() == 0);
4137 Result initial_value = allocator()->Allocate(eax); 4133 Result initial_value = allocator()->Allocate(eax);
4138 ASSERT(initial_value.is_valid()); 4134 ASSERT(initial_value.is_valid());
(...skipping 15 matching lines...) Expand all
4154 frame_->Dup(); 4150 frame_->Dup();
4155 Result object = frame_->Pop(); 4151 Result object = frame_->Pop();
4156 object.ToRegister(); 4152 object.ToRegister();
4157 ASSERT(object.is_valid()); 4153 ASSERT(object.is_valid());
4158 // if (object->IsSmi()) return object. 4154 // if (object->IsSmi()) return object.
4159 __ test(object.reg(), Immediate(kSmiTagMask)); 4155 __ test(object.reg(), Immediate(kSmiTagMask));
4160 leave.Branch(zero, taken); 4156 leave.Branch(zero, taken);
4161 // It is a heap object - get map. 4157 // It is a heap object - get map.
4162 Result temp = allocator()->Allocate(); 4158 Result temp = allocator()->Allocate();
4163 ASSERT(temp.is_valid()); 4159 ASSERT(temp.is_valid());
4164 __ mov(temp.reg(), FieldOperand(object.reg(), HeapObject::kMapOffset));
4165 __ movzx_b(temp.reg(), FieldOperand(temp.reg(), Map::kInstanceTypeOffset));
4166 // if (!object->IsJSValue()) return object. 4160 // if (!object->IsJSValue()) return object.
4167 __ cmp(temp.reg(), JS_VALUE_TYPE); 4161 __ CmpObjectType(object.reg(), JS_VALUE_TYPE, temp.reg());
4168 leave.Branch(not_equal, not_taken); 4162 leave.Branch(not_equal, not_taken);
4169 __ mov(temp.reg(), FieldOperand(object.reg(), JSValue::kValueOffset)); 4163 __ mov(temp.reg(), FieldOperand(object.reg(), JSValue::kValueOffset));
4170 object.Unuse(); 4164 object.Unuse();
4171 frame_->SetElementAt(0, &temp); 4165 frame_->SetElementAt(0, &temp);
4172 leave.Bind(); 4166 leave.Bind();
4173 } 4167 }
4174 4168
4175 4169
4176 void CodeGenerator::GenerateSetValueOf(ZoneList<Expression*>* args) { 4170 void CodeGenerator::GenerateSetValueOf(ZoneList<Expression*>* args) {
4177 ASSERT(args->length() == 2); 4171 ASSERT(args->length() == 2);
4178 JumpTarget leave(this); 4172 JumpTarget leave(this);
4179 Load(args->at(0)); // Load the object. 4173 Load(args->at(0)); // Load the object.
4180 Load(args->at(1)); // Load the value. 4174 Load(args->at(1)); // Load the value.
4181 Result value = frame_->Pop(); 4175 Result value = frame_->Pop();
4182 Result object = frame_->Pop(); 4176 Result object = frame_->Pop();
4183 value.ToRegister(); 4177 value.ToRegister();
4184 object.ToRegister(); 4178 object.ToRegister();
4185 4179
4186 // if (object->IsSmi()) return value. 4180 // if (object->IsSmi()) return value.
4187 __ test(object.reg(), Immediate(kSmiTagMask)); 4181 __ test(object.reg(), Immediate(kSmiTagMask));
4188 leave.Branch(zero, &value, taken); 4182 leave.Branch(zero, &value, taken);
4189 4183
4190 // It is a heap object - get its map. 4184 // It is a heap object - get its map.
4191 Result scratch = allocator_->Allocate(); 4185 Result scratch = allocator_->Allocate();
4192 ASSERT(scratch.is_valid()); 4186 ASSERT(scratch.is_valid());
4193 __ mov(scratch.reg(), FieldOperand(object.reg(), HeapObject::kMapOffset));
4194 __ movzx_b(scratch.reg(),
4195 FieldOperand(scratch.reg(), Map::kInstanceTypeOffset));
4196 // if (!object->IsJSValue()) return value. 4187 // if (!object->IsJSValue()) return value.
4197 __ cmp(scratch.reg(), JS_VALUE_TYPE); 4188 __ CmpObjectType(object.reg(), JS_VALUE_TYPE, scratch.reg());
4198 leave.Branch(not_equal, &value, not_taken); 4189 leave.Branch(not_equal, &value, not_taken);
4199 4190
4200 // Store the value. 4191 // Store the value.
4201 __ mov(FieldOperand(object.reg(), JSValue::kValueOffset), value.reg()); 4192 __ mov(FieldOperand(object.reg(), JSValue::kValueOffset), value.reg());
4202 // Update the write barrier. Save the value as it will be 4193 // Update the write barrier. Save the value as it will be
4203 // overwritten by the write barrier code and is needed afterward. 4194 // overwritten by the write barrier code and is needed afterward.
4204 Result duplicate_value = allocator_->Allocate(); 4195 Result duplicate_value = allocator_->Allocate();
4205 ASSERT(duplicate_value.is_valid()); 4196 ASSERT(duplicate_value.is_valid());
4206 __ mov(duplicate_value.reg(), value.reg()); 4197 __ mov(duplicate_value.reg(), value.reg());
4207 // The object register is also overwritten by the write barrier and 4198 // The object register is also overwritten by the write barrier and
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
4901 __ movzx_b(answer.reg(), 4892 __ movzx_b(answer.reg(),
4902 FieldOperand(answer.reg(), Map::kBitFieldOffset)); 4893 FieldOperand(answer.reg(), Map::kBitFieldOffset));
4903 __ test(answer.reg(), Immediate(1 << Map::kIsUndetectable)); 4894 __ test(answer.reg(), Immediate(1 << Map::kIsUndetectable));
4904 answer.Unuse(); 4895 answer.Unuse();
4905 destination()->Split(not_zero); 4896 destination()->Split(not_zero);
4906 4897
4907 } else if (check->Equals(Heap::function_symbol())) { 4898 } else if (check->Equals(Heap::function_symbol())) {
4908 __ test(answer.reg(), Immediate(kSmiTagMask)); 4899 __ test(answer.reg(), Immediate(kSmiTagMask));
4909 destination()->false_target()->Branch(zero); 4900 destination()->false_target()->Branch(zero);
4910 frame_->Spill(answer.reg()); 4901 frame_->Spill(answer.reg());
4911 __ mov(answer.reg(), FieldOperand(answer.reg(), HeapObject::kMapOffset)); 4902 __ CmpObjectType(answer.reg(), JS_FUNCTION_TYPE, answer.reg());
4912 __ movzx_b(answer.reg(),
4913 FieldOperand(answer.reg(), Map::kInstanceTypeOffset));
4914 __ cmp(answer.reg(), JS_FUNCTION_TYPE);
4915 answer.Unuse(); 4903 answer.Unuse();
4916 destination()->Split(equal); 4904 destination()->Split(equal);
4917 4905
4918 } else if (check->Equals(Heap::object_symbol())) { 4906 } else if (check->Equals(Heap::object_symbol())) {
4919 __ test(answer.reg(), Immediate(kSmiTagMask)); 4907 __ test(answer.reg(), Immediate(kSmiTagMask));
4920 destination()->false_target()->Branch(zero); 4908 destination()->false_target()->Branch(zero);
4921 __ cmp(answer.reg(), Factory::null_value()); 4909 __ cmp(answer.reg(), Factory::null_value());
4922 destination()->true_target()->Branch(equal); 4910 destination()->true_target()->Branch(equal);
4923 4911
4924 // It can be an undetectable object. 4912 // It can be an undetectable object.
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
6401 void CallFunctionStub::Generate(MacroAssembler* masm) { 6389 void CallFunctionStub::Generate(MacroAssembler* masm) {
6402 Label slow; 6390 Label slow;
6403 6391
6404 // Get the function to call from the stack. 6392 // Get the function to call from the stack.
6405 // +2 ~ receiver, return address 6393 // +2 ~ receiver, return address
6406 __ mov(edi, Operand(esp, (argc_ + 2) * kPointerSize)); 6394 __ mov(edi, Operand(esp, (argc_ + 2) * kPointerSize));
6407 6395
6408 // Check that the function really is a JavaScript function. 6396 // Check that the function really is a JavaScript function.
6409 __ test(edi, Immediate(kSmiTagMask)); 6397 __ test(edi, Immediate(kSmiTagMask));
6410 __ j(zero, &slow, not_taken); 6398 __ j(zero, &slow, not_taken);
6411 // Get the map. 6399 // Goto slow case if we do not have a function.
6412 __ mov(ecx, FieldOperand(edi, HeapObject::kMapOffset)); 6400 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
6413 __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset));
6414 __ cmp(ecx, JS_FUNCTION_TYPE);
6415 __ j(not_equal, &slow, not_taken); 6401 __ j(not_equal, &slow, not_taken);
6416 6402
6417 // Fast-case: Just invoke the function. 6403 // Fast-case: Just invoke the function.
6418 ParameterCount actual(argc_); 6404 ParameterCount actual(argc_);
6419 __ InvokeFunction(edi, actual, JUMP_FUNCTION); 6405 __ InvokeFunction(edi, actual, JUMP_FUNCTION);
6420 6406
6421 // Slow-case: Non-function called. 6407 // Slow-case: Non-function called.
6422 __ bind(&slow); 6408 __ bind(&slow);
6423 __ Set(eax, Immediate(argc_)); 6409 __ Set(eax, Immediate(argc_));
6424 __ Set(ebx, Immediate(0)); 6410 __ Set(ebx, Immediate(0));
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
6826 6812
6827 // Slow-case: Go through the JavaScript implementation. 6813 // Slow-case: Go through the JavaScript implementation.
6828 __ bind(&slow); 6814 __ bind(&slow);
6829 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); 6815 __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
6830 } 6816 }
6831 6817
6832 6818
6833 #undef __ 6819 #undef __
6834 6820
6835 } } // namespace v8::internal 6821 } } // namespace v8::internal
OLDNEW
« src/builtins-ia32.cc ('K') | « src/builtins-ia32.cc ('k') | src/ic-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698