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 6624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6635 Result temp = allocator()->Allocate(); | 6635 Result temp = allocator()->Allocate(); |
6636 ASSERT(temp.is_valid()); | 6636 ASSERT(temp.is_valid()); |
6637 // Check if the object is a JS array or not. | 6637 // Check if the object is a JS array or not. |
6638 __ CmpObjectType(value.reg(), JS_ARRAY_TYPE, temp.reg()); | 6638 __ CmpObjectType(value.reg(), JS_ARRAY_TYPE, temp.reg()); |
6639 value.Unuse(); | 6639 value.Unuse(); |
6640 temp.Unuse(); | 6640 temp.Unuse(); |
6641 destination()->Split(equal); | 6641 destination()->Split(equal); |
6642 } | 6642 } |
6643 | 6643 |
6644 | 6644 |
| 6645 void CodeGenerator::GenerateFastAsciiArrayJoin(ZoneList<Expression*>* args) { |
| 6646 ASSERT(args->length() == 2); |
| 6647 Load(args->at(1)); |
| 6648 Load(args->at(0)); |
| 6649 Result array_result = frame_->Pop(); |
| 6650 array_result.ToRegister(eax); |
| 6651 frame_->SpillAll(); |
| 6652 |
| 6653 Label bailout; |
| 6654 Label done; |
| 6655 // All aliases of the same register have disjoint lifetimes. |
| 6656 Register array = eax; |
| 6657 Register result_pos = no_reg; |
| 6658 |
| 6659 Register index = edi; |
| 6660 |
| 6661 Register current_string_length = ecx; // Will be ecx when live. |
| 6662 |
| 6663 Register current_string = edx; |
| 6664 |
| 6665 Register scratch = ebx; |
| 6666 |
| 6667 Register scratch_2 = esi; |
| 6668 Register new_padding_chars = scratch_2; |
| 6669 |
| 6670 Operand separator = Operand(esp, 4 * kPointerSize); // Already pushed. |
| 6671 Operand elements = Operand(esp, 3 * kPointerSize); |
| 6672 Operand result = Operand(esp, 2 * kPointerSize); |
| 6673 Operand padding_chars = Operand(esp, 1 * kPointerSize); |
| 6674 Operand array_length = Operand(esp, 0); |
| 6675 __ sub(Operand(esp), Immediate(4 * kPointerSize)); |
| 6676 |
| 6677 // Check that eax is a JSArray |
| 6678 __ test(array, Immediate(kSmiTagMask)); |
| 6679 __ j(zero, &bailout); |
| 6680 __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 6681 __ j(not_equal, &bailout); |
| 6682 |
| 6683 // Check that the array has fast elements. |
| 6684 __ test_b(FieldOperand(scratch, Map::kBitField2Offset), |
| 6685 1 << Map::kHasFastElements); |
| 6686 __ j(zero, &bailout); |
| 6687 |
| 6688 // If the array is empty, return the empty string. |
| 6689 __ mov(scratch, FieldOperand(array, JSArray::kLengthOffset)); |
| 6690 __ sar(scratch, 1); |
| 6691 Label non_trivial; |
| 6692 __ j(not_zero, &non_trivial); |
| 6693 __ mov(result, Factory::empty_string()); |
| 6694 __ jmp(&done); |
| 6695 |
| 6696 __ bind(&non_trivial); |
| 6697 __ mov(array_length, scratch); |
| 6698 |
| 6699 __ mov(scratch, FieldOperand(array, JSArray::kElementsOffset)); |
| 6700 __ mov(elements, scratch); |
| 6701 |
| 6702 // End of array's live range. |
| 6703 result_pos = array; |
| 6704 array = no_reg; |
| 6705 |
| 6706 |
| 6707 // Check that the separator is a flat ascii string. |
| 6708 __ mov(current_string, separator); |
| 6709 __ test(current_string, Immediate(kSmiTagMask)); |
| 6710 __ j(zero, &bailout); |
| 6711 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset)); |
| 6712 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 6713 __ and_(scratch, Immediate( |
| 6714 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
| 6715 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag); |
| 6716 __ j(not_equal, &bailout); |
| 6717 // If the separator is the empty string, replace it with NULL. |
| 6718 // The test for NULL is quicker than the empty string test, in a loop. |
| 6719 __ cmp(FieldOperand(current_string, SeqAsciiString::kLengthOffset), |
| 6720 Immediate(0)); |
| 6721 Label separator_checked; |
| 6722 __ j(not_zero, &separator_checked); |
| 6723 __ mov(separator, Immediate(0)); |
| 6724 __ bind(&separator_checked); |
| 6725 |
| 6726 // Check that elements[0] is a flat ascii string, and copy it in new space. |
| 6727 __ mov(scratch, elements); |
| 6728 __ mov(current_string, FieldOperand(scratch, FixedArray::kHeaderSize)); |
| 6729 __ test(current_string, Immediate(kSmiTagMask)); |
| 6730 __ j(zero, &bailout); |
| 6731 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset)); |
| 6732 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 6733 __ and_(scratch, Immediate( |
| 6734 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
| 6735 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag); |
| 6736 __ j(not_equal, &bailout); |
| 6737 |
| 6738 // Allocate space to copy it. Round up the size to the alignment granularity. |
| 6739 __ mov(current_string_length, |
| 6740 FieldOperand(current_string, String::kLengthOffset)); |
| 6741 __ shr(current_string_length, 1); |
| 6742 |
| 6743 // Live registers and stack values: |
| 6744 // current_string_length: length of elements[0]. |
| 6745 |
| 6746 // New string result in new space = elements[0] |
| 6747 __ AllocateAsciiString(result_pos, current_string_length, scratch_2, |
| 6748 index, no_reg, &bailout); |
| 6749 __ mov(result, result_pos); |
| 6750 |
| 6751 // Adjust current_string_length to include padding bytes at end of string. |
| 6752 // Keep track of the number of padding bytes. |
| 6753 __ mov(new_padding_chars, current_string_length); |
| 6754 __ add(Operand(current_string_length), Immediate(kObjectAlignmentMask)); |
| 6755 __ and_(Operand(current_string_length), Immediate(~kObjectAlignmentMask)); |
| 6756 __ sub(new_padding_chars, Operand(current_string_length)); |
| 6757 __ neg(new_padding_chars); |
| 6758 __ mov(padding_chars, new_padding_chars); |
| 6759 |
| 6760 Label copy_loop_1_done; |
| 6761 Label copy_loop_1; |
| 6762 __ test(current_string_length, Operand(current_string_length)); |
| 6763 __ j(zero, ©_loop_1_done); |
| 6764 __ bind(©_loop_1); |
| 6765 __ sub(Operand(current_string_length), Immediate(kPointerSize)); |
| 6766 __ mov(scratch, FieldOperand(current_string, current_string_length, |
| 6767 times_1, SeqAsciiString::kHeaderSize)); |
| 6768 __ mov(FieldOperand(result_pos, current_string_length, |
| 6769 times_1, SeqAsciiString::kHeaderSize), |
| 6770 scratch); |
| 6771 __ j(not_zero, ©_loop_1); |
| 6772 __ bind(©_loop_1_done); |
| 6773 |
| 6774 __ mov(index, Immediate(1)); |
| 6775 // Loop condition: while (index < length). |
| 6776 Label loop; |
| 6777 __ bind(&loop); |
| 6778 __ cmp(index, array_length); |
| 6779 __ j(greater_equal, &done); |
| 6780 |
| 6781 // If the separator is the empty string, signalled by NULL, skip it. |
| 6782 Label separator_done; |
| 6783 __ mov(current_string, separator); |
| 6784 __ test(current_string, Operand(current_string)); |
| 6785 __ j(zero, &separator_done); |
| 6786 |
| 6787 // Append separator to result. It is known to be a flat ascii string. |
| 6788 __ AppendStringToTopOfNewSpace(current_string, current_string_length, |
| 6789 result_pos, scratch, scratch_2, result, |
| 6790 padding_chars, &bailout); |
| 6791 __ bind(&separator_done); |
| 6792 |
| 6793 // Add next element of array to the end of the result. |
| 6794 // Get current_string = array[index]. |
| 6795 __ mov(scratch, elements); |
| 6796 __ mov(current_string, FieldOperand(scratch, index, |
| 6797 times_pointer_size, |
| 6798 FixedArray::kHeaderSize)); |
| 6799 // If current != flat ascii string drop result, return undefined. |
| 6800 __ test(current_string, Immediate(kSmiTagMask)); |
| 6801 __ j(zero, &bailout); |
| 6802 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset)); |
| 6803 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 6804 __ and_(scratch, Immediate( |
| 6805 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
| 6806 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag); |
| 6807 __ j(not_equal, &bailout); |
| 6808 |
| 6809 // Append current to the result. |
| 6810 __ AppendStringToTopOfNewSpace(current_string, current_string_length, |
| 6811 result_pos, scratch, scratch_2, result, |
| 6812 padding_chars, &bailout); |
| 6813 __ add(Operand(index), Immediate(1)); |
| 6814 __ jmp(&loop); // End while (index < length). |
| 6815 |
| 6816 __ bind(&bailout); |
| 6817 __ mov(result, Factory::undefined_value()); |
| 6818 __ bind(&done); |
| 6819 __ mov(eax, result); |
| 6820 // Drop temp values from the stack, and restore context register. |
| 6821 __ add(Operand(esp), Immediate(4 * kPointerSize)); |
| 6822 |
| 6823 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 6824 frame_->Drop(1); |
| 6825 frame_->Push(&array_result); |
| 6826 } |
| 6827 |
| 6828 |
6645 void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) { | 6829 void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) { |
6646 ASSERT(args->length() == 1); | 6830 ASSERT(args->length() == 1); |
6647 Load(args->at(0)); | 6831 Load(args->at(0)); |
6648 Result value = frame_->Pop(); | 6832 Result value = frame_->Pop(); |
6649 value.ToRegister(); | 6833 value.ToRegister(); |
6650 ASSERT(value.is_valid()); | 6834 ASSERT(value.is_valid()); |
6651 __ test(value.reg(), Immediate(kSmiTagMask)); | 6835 __ test(value.reg(), Immediate(kSmiTagMask)); |
6652 destination()->false_target()->Branch(equal); | 6836 destination()->false_target()->Branch(equal); |
6653 // It is a heap object - get map. | 6837 // It is a heap object - get map. |
6654 Result temp = allocator()->Allocate(); | 6838 Result temp = allocator()->Allocate(); |
(...skipping 3427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10082 masm.GetCode(&desc); | 10266 masm.GetCode(&desc); |
10083 // Call the function from C++. | 10267 // Call the function from C++. |
10084 return FUNCTION_CAST<MemCopyFunction>(buffer); | 10268 return FUNCTION_CAST<MemCopyFunction>(buffer); |
10085 } | 10269 } |
10086 | 10270 |
10087 #undef __ | 10271 #undef __ |
10088 | 10272 |
10089 } } // namespace v8::internal | 10273 } } // namespace v8::internal |
10090 | 10274 |
10091 #endif // V8_TARGET_ARCH_IA32 | 10275 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |