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

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

Issue 6491: Refactor the arguments access code to make it easier to read. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 2 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
« no previous file with comments | « src/codegen-arm.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4777 matching lines...) Expand 10 before | Expand all | Expand 10 after
4788 __ fld_d(FieldOperand(edx, HeapNumber::kValueOffset)); 4788 __ fld_d(FieldOperand(edx, HeapNumber::kValueOffset));
4789 __ fchs(); 4789 __ fchs();
4790 __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); 4790 __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
4791 4791
4792 __ bind(&done); 4792 __ bind(&done);
4793 4793
4794 __ StubReturn(1); 4794 __ StubReturn(1);
4795 } 4795 }
4796 4796
4797 4797
4798 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { 4798 void ArgumentsAccessStub::GenerateReadLength(MacroAssembler* masm) {
4799 // If we're reading an element we need to check that the key is a smi. 4799 // Check if the calling frame is an arguments adaptor frame.
4800 Label adaptor;
4801 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
4802 __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
4803 __ cmp(ecx, ArgumentsAdaptorFrame::SENTINEL);
4804 __ j(equal, &adaptor);
4805
4806 // Nothing to do: The formal number of parameters has already been
4807 // passed in register eax by calling function. Just return it.
4808 __ ret(0);
4809
4810 // Arguments adaptor case: Read the arguments length from the
4811 // adaptor frame and return it.
4812 __ bind(&adaptor);
4813 __ mov(eax, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4814 __ ret(0);
4815 }
4816
4817
4818 void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
4819 // The displacement is used for skipping the frame pointer on the
4820 // stack. It is the offset of the last parameter (if any) relative
4821 // to the frame pointer.
4822 static const int kDisplacement = 1 * kPointerSize;
4823
4824 // Check that the key is a smi.
4800 Label slow; 4825 Label slow;
4801 if (type_ == READ_ELEMENT) { 4826 __ mov(ebx, Operand(esp, 1 * kPointerSize)); // skip return address
4802 __ mov(ebx, Operand(esp, 1 * kPointerSize)); // skip return address 4827 __ test(ebx, Immediate(kSmiTagMask));
4803 __ test(ebx, Immediate(kSmiTagMask)); 4828 __ j(not_zero, &slow, not_taken);
4804 __ j(not_zero, &slow, not_taken);
4805 }
4806 4829
4807 // Check if the calling frame is an arguments adaptor frame. 4830 // Check if the calling frame is an arguments adaptor frame.
4808 Label adaptor; 4831 Label adaptor;
4809 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); 4832 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
4810 __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); 4833 __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
4811 __ cmp(ecx, ArgumentsAdaptorFrame::SENTINEL); 4834 __ cmp(ecx, ArgumentsAdaptorFrame::SENTINEL);
4812 if (type_ == NEW_OBJECT) { 4835 __ j(equal, &adaptor);
4813 __ j(not_equal, &slow);
4814 } else {
4815 __ j(equal, &adaptor);
4816 }
4817 4836
4818 // The displacement is used for skipping the return address on the 4837 // Check index against formal parameters count limit passed in
4819 // stack. It is the offset of the last parameter (if any) relative 4838 // through register eax. Use unsigned comparison to get negative
4820 // to the frame pointer. 4839 // check for free.
4821 static const int kDisplacement = 1 * kPointerSize; 4840 __ cmp(ebx, Operand(eax));
4841 __ j(above_equal, &slow, not_taken);
4842
4843 // Read the argument from the stack and return it.
4822 ASSERT(kSmiTagSize == 1 && kSmiTag == 0); // shifting code depends on this 4844 ASSERT(kSmiTagSize == 1 && kSmiTag == 0); // shifting code depends on this
4845 __ lea(edx, Operand(ebp, eax, times_2, 0));
4846 __ neg(ebx);
4847 __ mov(eax, Operand(edx, ebx, times_2, kDisplacement));
4848 __ ret(0);
4823 4849
4824 if (type_ == READ_LENGTH) { 4850 // Arguments adaptor case: Check index against actual arguments
4825 // Nothing to do: The formal number of parameters has already been 4851 // limit found in the arguments adaptor frame. Use unsigned
4826 // passed in register eax by calling function. Just return it. 4852 // comparison to get negative check for free.
4827 __ ret(0); 4853 __ bind(&adaptor);
4828 } else if (type_ == READ_ELEMENT) { 4854 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4829 // Check index against formal parameters count limit passed in 4855 __ cmp(ebx, Operand(ecx));
4830 // through register eax. Use unsigned comparison to get negative 4856 __ j(above_equal, &slow, not_taken);
4831 // check for free.
4832 __ cmp(ebx, Operand(eax));
4833 __ j(above_equal, &slow, not_taken);
4834 4857
4835 // Read the argument from the stack and return it. 4858 // Read the argument from the stack and return it.
4836 __ lea(edx, Operand(ebp, eax, times_2, 0)); 4859 ASSERT(kSmiTagSize == 1 && kSmiTag == 0); // shifting code depends on this
4837 __ neg(ebx); 4860 __ lea(edx, Operand(edx, ecx, times_2, 0));
4838 __ mov(eax, Operand(edx, ebx, times_2, kDisplacement)); 4861 __ neg(ebx);
4839 __ ret(0); 4862 __ mov(eax, Operand(edx, ebx, times_2, kDisplacement));
4840 } else { 4863 __ ret(0);
4841 ASSERT(type_ == NEW_OBJECT);
4842 // Do nothing here.
4843 }
4844
4845 // Arguments adaptor case: Find the length or the actual argument in
4846 // the calling frame.
4847 __ bind(&adaptor);
4848 if (type_ == READ_LENGTH) {
4849 // Read the arguments length from the adaptor frame and return it.
4850 __ mov(eax, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4851 __ ret(0);
4852 } else if (type_ == READ_ELEMENT) {
4853 // Check index against actual arguments limit found in the
4854 // arguments adaptor frame. Use unsigned comparison to get
4855 // negative check for free.
4856 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4857 __ cmp(ebx, Operand(ecx));
4858 __ j(above_equal, &slow, not_taken);
4859
4860 // Read the argument from the stack and return it.
4861 __ lea(edx, Operand(edx, ecx, times_2, 0));
4862 __ neg(ebx);
4863 __ mov(eax, Operand(edx, ebx, times_2, kDisplacement));
4864 __ ret(0);
4865 } else {
4866 ASSERT(type_ == NEW_OBJECT);
4867 // Patch the arguments.length and the parameters pointer.
4868 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4869 __ mov(Operand(esp, 1 * kPointerSize), ecx);
4870 __ lea(edx, Operand(edx, ecx, times_2, kDisplacement + 1 * kPointerSize));
4871 __ mov(Operand(esp, 2 * kPointerSize), edx);
4872 __ bind(&slow);
4873 __ TailCallRuntime(ExternalReference(Runtime::kNewArgumentsFast), 3);
4874 }
4875 4864
4876 // Slow-case: Handle non-smi or out-of-bounds access to arguments 4865 // Slow-case: Handle non-smi or out-of-bounds access to arguments
4877 // by calling the runtime system. 4866 // by calling the runtime system.
4878 if (type_ == READ_ELEMENT) { 4867 __ bind(&slow);
4879 __ bind(&slow); 4868 __ TailCallRuntime(ExternalReference(Runtime::kGetArgumentsProperty), 1);
4880 __ TailCallRuntime(ExternalReference(Runtime::kGetArgumentsProperty), 1); 4869 }
4881 } 4870
4871
4872 void ArgumentsAccessStub::GenerateNewObject(MacroAssembler* masm) {
4873 // The displacement is used for skipping the return address and the
4874 // frame pointer on the stack. It is the offset of the last
4875 // parameter (if any) relative to the frame pointer.
4876 static const int kDisplacement = 2 * kPointerSize;
4877
4878 // Check if the calling frame is an arguments adaptor frame.
4879 Label runtime;
4880 __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset));
4881 __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset));
4882 __ cmp(ecx, ArgumentsAdaptorFrame::SENTINEL);
4883 __ j(not_equal, &runtime);
4884
4885 // Patch the arguments.length and the parameters pointer.
4886 __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset));
4887 __ mov(Operand(esp, 1 * kPointerSize), ecx);
4888 __ lea(edx, Operand(edx, ecx, times_2, kDisplacement));
4889 __ mov(Operand(esp, 2 * kPointerSize), edx);
4890
4891 // Do the runtime call to allocate the arguments object.
4892 __ bind(&runtime);
4893 __ TailCallRuntime(ExternalReference(Runtime::kNewArgumentsFast), 3);
4882 } 4894 }
4883 4895
4884 4896
4885 void CompareStub::Generate(MacroAssembler* masm) { 4897 void CompareStub::Generate(MacroAssembler* masm) {
4886 Label call_builtin, done; 4898 Label call_builtin, done;
4887 // Save the return address (and get it off the stack). 4899 // Save the return address (and get it off the stack).
4888 __ pop(ecx); 4900 __ pop(ecx);
4889 4901
4890 // Push arguments. 4902 // Push arguments.
4891 __ push(eax); 4903 __ push(eax);
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
5337 bool is_eval) { 5349 bool is_eval) {
5338 Handle<Code> code = Ia32CodeGenerator::MakeCode(fun, script, is_eval); 5350 Handle<Code> code = Ia32CodeGenerator::MakeCode(fun, script, is_eval);
5339 if (!code.is_null()) { 5351 if (!code.is_null()) {
5340 Counters::total_compiled_code_size.Increment(code->instruction_size()); 5352 Counters::total_compiled_code_size.Increment(code->instruction_size());
5341 } 5353 }
5342 return code; 5354 return code;
5343 } 5355 }
5344 5356
5345 5357
5346 } } // namespace v8::internal 5358 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/codegen-arm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698