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

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

Issue 720001: Correct handling of adding a string and a smal integer... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-636.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8546 matching lines...) Expand 10 before | Expand all | Expand 10 after
8557 case Token::ADD: { 8557 case Token::ADD: {
8558 // Test for string arguments before calling runtime. 8558 // Test for string arguments before calling runtime.
8559 Label not_strings, not_string1, string1, string1_smi2; 8559 Label not_strings, not_string1, string1, string1_smi2;
8560 8560
8561 // If this stub has already generated FP-specific code then the arguments 8561 // If this stub has already generated FP-specific code then the arguments
8562 // are already in edx, eax 8562 // are already in edx, eax
8563 if (!ShouldGenerateFPCode() && !HasArgsInRegisters()) { 8563 if (!ShouldGenerateFPCode() && !HasArgsInRegisters()) {
8564 GenerateLoadArguments(masm); 8564 GenerateLoadArguments(masm);
8565 } 8565 }
8566 8566
8567 __ test(edx, Immediate(kSmiTagMask)); 8567 // Registers containing left and right operands respectively.
8568 Register lhs, rhs;
8569 if (HasArgsReversed()) {
8570 lhs = eax;
8571 rhs = edx;
8572 } else {
8573 lhs = edx;
8574 rhs = eax;
8575 }
8576
8577 // Test if first argument is a string.
8578 __ test(lhs, Immediate(kSmiTagMask));
8568 __ j(zero, &not_string1); 8579 __ j(zero, &not_string1);
8569 __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ecx); 8580 __ CmpObjectType(lhs, FIRST_NONSTRING_TYPE, ecx);
8570 __ j(above_equal, &not_string1); 8581 __ j(above_equal, &not_string1);
8571 8582
8572 // First argument is a string, test second. 8583 // First argument is a string, test second.
8573 __ test(eax, Immediate(kSmiTagMask)); 8584 __ test(rhs, Immediate(kSmiTagMask));
8574 __ j(zero, &string1_smi2); 8585 __ j(zero, &string1_smi2);
8575 __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ecx); 8586 __ CmpObjectType(rhs, FIRST_NONSTRING_TYPE, ecx);
8576 __ j(above_equal, &string1); 8587 __ j(above_equal, &string1);
8577 8588
8578 // First and second argument are strings. Jump to the string add stub. 8589 // First and second argument are strings. Jump to the string add stub.
8579 StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); 8590 StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB);
8580 __ TailCallStub(&string_add_stub); 8591 __ TailCallStub(&string_add_stub);
8581 8592
8582 __ bind(&string1_smi2); 8593 __ bind(&string1_smi2);
8583 // First argument is a string, second is a smi. Try to lookup the number 8594 // First argument is a string, second is a smi. Try to lookup the number
8584 // string for the smi in the number string cache. 8595 // string for the smi in the number string cache.
8585 NumberToStringStub::GenerateLookupNumberStringCache( 8596 NumberToStringStub::GenerateLookupNumberStringCache(
8586 masm, eax, edi, ebx, ecx, true, &string1); 8597 masm, rhs, edi, ebx, ecx, true, &string1);
8587 8598
8588 // Call the string add stub to make the result. 8599 // Replace second argument on stack and tailcall string add stub to make
8589 __ EnterInternalFrame(); 8600 // the result.
8590 __ push(edx); // Original first argument. 8601 __ mov(Operand(esp, 1 * kPointerSize), edi);
8591 __ push(edi); // Number to string result for second argument. 8602 __ TailCallStub(&string_add_stub);
8592 __ CallStub(&string_add_stub);
8593 __ LeaveInternalFrame();
8594 __ ret(2 * kPointerSize);
8595 8603
8604 // Only first argument is a string.
8596 __ bind(&string1); 8605 __ bind(&string1);
8597 __ InvokeBuiltin( 8606 __ InvokeBuiltin(Builtins::STRING_ADD_LEFT, JUMP_FUNCTION);
8598 HasArgsReversed() ?
8599 Builtins::STRING_ADD_RIGHT :
8600 Builtins::STRING_ADD_LEFT,
8601 JUMP_FUNCTION);
8602 8607
8603 // First argument was not a string, test second. 8608 // First argument was not a string, test second.
8604 __ bind(&not_string1); 8609 __ bind(&not_string1);
8605 __ test(eax, Immediate(kSmiTagMask)); 8610 __ test(rhs, Immediate(kSmiTagMask));
8606 __ j(zero, &not_strings); 8611 __ j(zero, &not_strings);
8607 __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ecx); 8612 __ CmpObjectType(rhs, FIRST_NONSTRING_TYPE, ecx);
8608 __ j(above_equal, &not_strings); 8613 __ j(above_equal, &not_strings);
8609 8614
8610 // Only second argument is a string. 8615 // Only second argument is a string.
8611 __ InvokeBuiltin( 8616 __ InvokeBuiltin(Builtins::STRING_ADD_RIGHT, JUMP_FUNCTION);
8612 HasArgsReversed() ?
8613 Builtins::STRING_ADD_LEFT :
8614 Builtins::STRING_ADD_RIGHT,
8615 JUMP_FUNCTION);
8616 8617
8617 __ bind(&not_strings); 8618 __ bind(&not_strings);
8618 // Neither argument is a string. 8619 // Neither argument is a string.
8619 __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); 8620 __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION);
8620 break; 8621 break;
8621 } 8622 }
8622 case Token::SUB: 8623 case Token::SUB:
8623 __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); 8624 __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION);
8624 break; 8625 break;
8625 case Token::MUL: 8626 case Token::MUL:
(...skipping 3126 matching lines...) Expand 10 before | Expand all | Expand 10 after
11752 11753
11753 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) 11754 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
11754 // tagged as a small integer. 11755 // tagged as a small integer.
11755 __ bind(&runtime); 11756 __ bind(&runtime);
11756 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); 11757 __ TailCallRuntime(Runtime::kStringCompare, 2, 1);
11757 } 11758 }
11758 11759
11759 #undef __ 11760 #undef __
11760 11761
11761 } } // namespace v8::internal 11762 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-636.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698