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

Side by Side Diff: src/regexp-macro-assembler-ia32.cc

Issue 18842: Experimental: periodic merge of the bleeding_edge branch to the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 11 years, 11 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/regexp-macro-assembler-ia32.h ('k') | src/regexp-macro-assembler-irregexp.h » ('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 2008 the V8 project authors. All rights reserved. 1 // Copyright 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 BranchOrBacktrack(equal, on_equal); 167 BranchOrBacktrack(equal, on_equal);
168 } 168 }
169 169
170 170
171 void RegExpMacroAssemblerIA32::CheckCharacterGT(uc16 limit, Label* on_greater) { 171 void RegExpMacroAssemblerIA32::CheckCharacterGT(uc16 limit, Label* on_greater) {
172 __ cmp(current_character(), limit); 172 __ cmp(current_character(), limit);
173 BranchOrBacktrack(greater, on_greater); 173 BranchOrBacktrack(greater, on_greater);
174 } 174 }
175 175
176 176
177 void RegExpMacroAssemblerIA32::CheckAtStart(Label* on_at_start) {
178 Label ok;
179 // Did we start the match at the start of the string at all?
180 __ cmp(Operand(ebp, kAtStart), Immediate(0));
181 BranchOrBacktrack(equal, &ok);
182 // If we did, are we still at the start of the input?
183 __ mov(eax, Operand(ebp, kInputEndOffset));
184 __ add(eax, Operand(edi));
185 __ cmp(eax, Operand(ebp, kInputStartOffset));
186 BranchOrBacktrack(equal, on_at_start);
187 __ bind(&ok);
188 }
189
190
177 void RegExpMacroAssemblerIA32::CheckNotAtStart(Label* on_not_at_start) { 191 void RegExpMacroAssemblerIA32::CheckNotAtStart(Label* on_not_at_start) {
178 // Did we start the match at the start of the string at all? 192 // Did we start the match at the start of the string at all?
179 __ cmp(Operand(ebp, kAtStart), Immediate(0)); 193 __ cmp(Operand(ebp, kAtStart), Immediate(0));
180 BranchOrBacktrack(equal, on_not_at_start); 194 BranchOrBacktrack(equal, on_not_at_start);
181 // If we did, are we still at the start of the input? 195 // If we did, are we still at the start of the input?
182 __ mov(eax, Operand(ebp, kInputEndOffset)); 196 __ mov(eax, Operand(ebp, kInputEndOffset));
183 __ add(eax, Operand(edi)); 197 __ add(eax, Operand(edi));
184 __ cmp(eax, Operand(ebp, kInputStartOffset)); 198 __ cmp(eax, Operand(ebp, kInputStartOffset));
185 BranchOrBacktrack(not_equal, on_not_at_start); 199 BranchOrBacktrack(not_equal, on_not_at_start);
186 } 200 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // Compute new value of character position after the matched part. 324 // Compute new value of character position after the matched part.
311 __ sub(edi, Operand(esi)); 325 __ sub(edi, Operand(esi));
312 } else { 326 } else {
313 ASSERT(mode_ == UC16); 327 ASSERT(mode_ == UC16);
314 // Save registers before calling C function. 328 // Save registers before calling C function.
315 __ push(esi); 329 __ push(esi);
316 __ push(edi); 330 __ push(edi);
317 __ push(backtrack_stackpointer()); 331 __ push(backtrack_stackpointer());
318 __ push(ebx); 332 __ push(ebx);
319 const int four_arguments = 4; 333 const int four_arguments = 4;
320 FrameAlign(four_arguments); 334 FrameAlign(four_arguments, ecx);
321 // Put arguments into allocated stack area. 335 // Put arguments into allocated stack area, last argument highest on stack.
336 // Parameters are
337 // UC16** buffer - really the String** of the input string
338 // int byte_offset1 - byte offset from *buffer of start of capture
339 // int byte_offset2 - byte offset from *buffer of current position
340 // size_t byte_length - length of capture in bytes(!)
341
342 // Set byte_length.
322 __ mov(Operand(esp, 3 * kPointerSize), ebx); 343 __ mov(Operand(esp, 3 * kPointerSize), ebx);
344 // Set byte_offset2.
345 // Found by adding negative string-end offset of current position (edi)
346 // to String** offset of end of string.
323 __ mov(ecx, Operand(ebp, kInputEndOffset)); 347 __ mov(ecx, Operand(ebp, kInputEndOffset));
324 __ add(edi, Operand(ecx)); 348 __ add(edi, Operand(ecx));
325 __ mov(Operand(esp, 2 * kPointerSize), edi); 349 __ mov(Operand(esp, 2 * kPointerSize), edi);
350 // Set byte_offset1.
351 // Start of capture, where eax already holds string-end negative offset.
326 __ add(eax, Operand(ecx)); 352 __ add(eax, Operand(ecx));
327 __ mov(Operand(esp, 1 * kPointerSize), eax); 353 __ mov(Operand(esp, 1 * kPointerSize), eax);
354 // Set buffer. Original String** parameter to regexp code.
328 __ mov(eax, Operand(ebp, kInputBuffer)); 355 __ mov(eax, Operand(ebp, kInputBuffer));
329 __ mov(Operand(esp, 0 * kPointerSize), eax); 356 __ mov(Operand(esp, 0 * kPointerSize), eax);
357
330 Address function_address = FUNCTION_ADDR(&CaseInsensitiveCompareUC16); 358 Address function_address = FUNCTION_ADDR(&CaseInsensitiveCompareUC16);
331 CallCFunction(function_address, four_arguments); 359 CallCFunction(function_address, four_arguments);
332 // Pop original values before reacting on result value. 360 // Pop original values before reacting on result value.
333 __ pop(ebx); 361 __ pop(ebx);
334 __ pop(backtrack_stackpointer()); 362 __ pop(backtrack_stackpointer());
335 __ pop(edi); 363 __ pop(edi);
336 __ pop(esi); 364 __ pop(esi);
337 365
338 // Check if function returned non-zero for success or zero for failure. 366 // Check if function returned non-zero for success or zero for failure.
339 __ or_(eax, Operand(eax)); 367 __ or_(eax, Operand(eax));
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 // Check if there is room for the variable number of registers above 653 // Check if there is room for the variable number of registers above
626 // the stack limit. 654 // the stack limit.
627 __ cmp(ecx, num_registers_ * kPointerSize); 655 __ cmp(ecx, num_registers_ * kPointerSize);
628 __ j(above_equal, &stack_ok, taken); 656 __ j(above_equal, &stack_ok, taken);
629 // Exit with exception. 657 // Exit with exception.
630 __ mov(eax, EXCEPTION); 658 __ mov(eax, EXCEPTION);
631 __ jmp(&exit_label_); 659 __ jmp(&exit_label_);
632 660
633 __ bind(&stack_limit_hit); 661 __ bind(&stack_limit_hit);
634 int num_arguments = 2; 662 int num_arguments = 2;
635 FrameAlign(num_arguments); 663 FrameAlign(num_arguments, ebx);
636 __ mov(Operand(esp, 1 * kPointerSize), Immediate(self_)); 664 __ mov(Operand(esp, 1 * kPointerSize), Immediate(self_));
637 __ lea(eax, Operand(esp, -kPointerSize)); 665 __ lea(eax, Operand(esp, -kPointerSize));
638 __ mov(Operand(esp, 0 * kPointerSize), eax); 666 __ mov(Operand(esp, 0 * kPointerSize), eax);
639 CallCFunction(FUNCTION_ADDR(&CheckStackGuardState), num_arguments); 667 CallCFunction(FUNCTION_ADDR(&CheckStackGuardState), num_arguments);
640 __ or_(eax, Operand(eax)); 668 __ or_(eax, Operand(eax));
641 // If returned value is non-zero, the stack guard reports the actual 669 // If returned value is non-zero, the stack guard reports the actual
642 // stack limit being hit and an exception has already been raised. 670 // stack limit being hit and an exception has already been raised.
643 // Otherwise it was a preemption and we just check the limit again. 671 // Otherwise it was a preemption and we just check the limit again.
644 __ j(equal, &retry_stack_check); 672 __ j(equal, &retry_stack_check);
645 // Return value was non-zero. Exit with exception. 673 // Return value was non-zero. Exit with exception.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 __ mov(eax, Immediate(SUCCESS)); 753 __ mov(eax, Immediate(SUCCESS));
726 } 754 }
727 // Exit and return eax 755 // Exit and return eax
728 __ bind(&exit_label_); 756 __ bind(&exit_label_);
729 // Skip esp past regexp registers. 757 // Skip esp past regexp registers.
730 __ lea(esp, Operand(ebp, kBackup_ebx)); 758 __ lea(esp, Operand(ebp, kBackup_ebx));
731 // Restore callee-save registers. 759 // Restore callee-save registers.
732 __ pop(ebx); 760 __ pop(ebx);
733 __ pop(edi); 761 __ pop(edi);
734 __ pop(esi); 762 __ pop(esi);
735 // Exit function frame, restore previus one. 763 // Exit function frame, restore previous one.
736 __ pop(ebp); 764 __ pop(ebp);
737 __ ret(0); 765 __ ret(0);
738 766
739 // Backtrack code (branch target for conditional backtracks). 767 // Backtrack code (branch target for conditional backtracks).
740 if (backtrack_label_.is_linked()) { 768 if (backtrack_label_.is_linked()) {
741 __ bind(&backtrack_label_); 769 __ bind(&backtrack_label_);
742 Backtrack(); 770 Backtrack();
743 } 771 }
744 772
745 Label exit_with_exception; 773 Label exit_with_exception;
746 774
747 // Preempt-code 775 // Preempt-code
748 if (check_preempt_label_.is_linked()) { 776 if (check_preempt_label_.is_linked()) {
749 __ bind(&check_preempt_label_); 777 __ bind(&check_preempt_label_);
750 778
751 __ push(backtrack_stackpointer()); 779 __ push(backtrack_stackpointer());
752 __ push(edi); 780 __ push(edi);
753 781
754 Label retry; 782 Label retry;
755 783
756 __ bind(&retry); 784 __ bind(&retry);
757 int num_arguments = 2; 785 int num_arguments = 2;
758 FrameAlign(num_arguments); 786 FrameAlign(num_arguments, ebx);
759 __ mov(Operand(esp, 1 * kPointerSize), Immediate(self_)); 787 __ mov(Operand(esp, 1 * kPointerSize), Immediate(self_));
760 __ lea(eax, Operand(esp, -kPointerSize)); 788 __ lea(eax, Operand(esp, -kPointerSize));
761 __ mov(Operand(esp, 0 * kPointerSize), eax); 789 __ mov(Operand(esp, 0 * kPointerSize), eax);
762 CallCFunction(FUNCTION_ADDR(&CheckStackGuardState), num_arguments); 790 CallCFunction(FUNCTION_ADDR(&CheckStackGuardState), num_arguments);
763 // Return value must be zero. We cannot have a stack overflow at 791 // Return value must be zero. We cannot have a stack overflow at
764 // this point, since we checked the stack on entry and haven't 792 // this point, since we checked the stack on entry and haven't
765 // pushed anything since, that we haven't also popped again. 793 // pushed anything since, that we haven't also popped again.
766 794
767 ExternalReference stack_guard_limit = 795 ExternalReference stack_guard_limit =
768 ExternalReference::address_of_stack_guard_limit(); 796 ExternalReference::address_of_stack_guard_limit();
(...skipping 15 matching lines...) Expand all
784 __ bind(&stack_overflow_label_); 812 __ bind(&stack_overflow_label_);
785 // Reached if the backtrack-stack limit has been hit. 813 // Reached if the backtrack-stack limit has been hit.
786 814
787 Label grow_failed; 815 Label grow_failed;
788 // Save registers before calling C function 816 // Save registers before calling C function
789 __ push(esi); 817 __ push(esi);
790 __ push(edi); 818 __ push(edi);
791 819
792 // Call GrowStack(backtrack_stackpointer()) 820 // Call GrowStack(backtrack_stackpointer())
793 int num_arguments = 1; 821 int num_arguments = 1;
794 FrameAlign(num_arguments); 822 FrameAlign(num_arguments, ebx);
795 __ mov(Operand(esp, 0), backtrack_stackpointer()); 823 __ mov(Operand(esp, 0), backtrack_stackpointer());
796 CallCFunction(FUNCTION_ADDR(&GrowStack), num_arguments); 824 CallCFunction(FUNCTION_ADDR(&GrowStack), num_arguments);
797 // If return NULL, we have failed to grow the stack, and 825 // If return NULL, we have failed to grow the stack, and
798 // must exit with a stack-overflow exception. 826 // must exit with a stack-overflow exception.
799 __ or_(eax, Operand(eax)); 827 __ or_(eax, Operand(eax));
800 __ j(equal, &exit_with_exception); 828 __ j(equal, &exit_with_exception);
801 // Otherwise use return value as new stack pointer. 829 // Otherwise use return value as new stack pointer.
802 __ mov(backtrack_stackpointer(), eax); 830 __ mov(backtrack_stackpointer(), eax);
803 // Restore saved registers and continue. 831 // Restore saved registers and continue.
804 __ pop(edi); 832 __ pop(edi);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 RegExpMacroAssembler::IrregexpImplementation 884 RegExpMacroAssembler::IrregexpImplementation
857 RegExpMacroAssemblerIA32::Implementation() { 885 RegExpMacroAssemblerIA32::Implementation() {
858 return kIA32Implementation; 886 return kIA32Implementation;
859 } 887 }
860 888
861 889
862 void RegExpMacroAssemblerIA32::LoadCurrentCharacter(int cp_offset, 890 void RegExpMacroAssemblerIA32::LoadCurrentCharacter(int cp_offset,
863 Label* on_end_of_input, 891 Label* on_end_of_input,
864 bool check_bounds, 892 bool check_bounds,
865 int characters) { 893 int characters) {
866 ASSERT(cp_offset >= 0); 894 ASSERT(cp_offset >= -1); // ^ and \b can look behind one character.
867 ASSERT(cp_offset < (1<<30)); // Be sane! (And ensure negation works) 895 ASSERT(cp_offset < (1<<30)); // Be sane! (And ensure negation works)
868 CheckPosition(cp_offset + characters - 1, on_end_of_input); 896 CheckPosition(cp_offset + characters - 1, on_end_of_input);
869 LoadCurrentCharacterUnchecked(cp_offset, characters); 897 LoadCurrentCharacterUnchecked(cp_offset, characters);
870 } 898 }
871 899
872 900
873 void RegExpMacroAssemblerIA32::PopCurrentPosition() { 901 void RegExpMacroAssemblerIA32::PopCurrentPosition() {
874 Pop(edi); 902 Pop(edi);
875 } 903 }
876 904
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 int cp_offset) { 953 int cp_offset) {
926 if (cp_offset == 0) { 954 if (cp_offset == 0) {
927 __ mov(register_location(reg), edi); 955 __ mov(register_location(reg), edi);
928 } else { 956 } else {
929 __ lea(eax, Operand(edi, cp_offset * char_size())); 957 __ lea(eax, Operand(edi, cp_offset * char_size()));
930 __ mov(register_location(reg), eax); 958 __ mov(register_location(reg), eax);
931 } 959 }
932 } 960 }
933 961
934 962
935 void RegExpMacroAssemblerIA32::ClearRegister(int reg) { 963 void RegExpMacroAssemblerIA32::ClearRegisters(int reg_from, int reg_to) {
964 ASSERT(reg_from <= reg_to);
936 __ mov(eax, Operand(ebp, kInputStartMinusOne)); 965 __ mov(eax, Operand(ebp, kInputStartMinusOne));
937 __ mov(register_location(reg), eax); 966 for (int reg = reg_from; reg <= reg_to; reg++) {
967 __ mov(register_location(reg), eax);
968 }
938 } 969 }
939 970
940 971
941 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) { 972 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) {
942 __ mov(register_location(reg), backtrack_stackpointer()); 973 __ mov(register_location(reg), backtrack_stackpointer());
943 } 974 }
944 975
945 976
946 // Private methods: 977 // Private methods:
947 978
(...skipping 18 matching lines...) Expand all
966 void* stack_top = RegExpStack::stack_top(); 997 void* stack_top = RegExpStack::stack_top();
967 998
968 int result = matcher_func(input, 999 int result = matcher_func(input,
969 start_offset, 1000 start_offset,
970 end_offset, 1001 end_offset,
971 output, 1002 output,
972 at_start_val, 1003 at_start_val,
973 stack_top); 1004 stack_top);
974 1005
975 if (result < 0 && !Top::has_pending_exception()) { 1006 if (result < 0 && !Top::has_pending_exception()) {
976 // We detected a stack overflow in RegExp code, but haven't created 1007 // We detected a stack overflow (on the backtrack stack) in RegExp code,
977 // the exception yet. 1008 // but haven't created the exception yet.
978 Top::StackOverflow(); 1009 Top::StackOverflow();
979 } 1010 }
980 return (result < 0) ? EXCEPTION : (result ? SUCCESS : FAILURE); 1011 return (result < 0) ? EXCEPTION : (result ? SUCCESS : FAILURE);
981 } 1012 }
982 1013
983 1014
984 int RegExpMacroAssemblerIA32::CaseInsensitiveCompareUC16(uc16** buffer, 1015 int RegExpMacroAssemblerIA32::CaseInsensitiveCompareUC16(uc16** buffer,
985 int byte_offset1, 1016 int byte_offset1,
986 int byte_offset2, 1017 int byte_offset2,
987 size_t byte_length) { 1018 size_t byte_length) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 __ cmp(backtrack_stackpointer(), Operand::StaticVariable(stack_limit)); 1179 __ cmp(backtrack_stackpointer(), Operand::StaticVariable(stack_limit));
1149 __ j(above, &no_stack_overflow); 1180 __ j(above, &no_stack_overflow);
1150 1181
1151 SafeCall(&stack_overflow_label_); 1182 SafeCall(&stack_overflow_label_);
1152 1183
1153 __ bind(&no_stack_overflow); 1184 __ bind(&no_stack_overflow);
1154 } 1185 }
1155 } 1186 }
1156 1187
1157 1188
1158 void RegExpMacroAssemblerIA32::FrameAlign(int num_arguments) { 1189 void RegExpMacroAssemblerIA32::FrameAlign(int num_arguments, Register scratch) {
1190 // TODO(lrn): Since we no longer use the system stack arbitrarily, we
1191 // know the current stack alignment - esp points to the last regexp register.
1192 // We can do this simpler then.
1159 int frameAlignment = OS::ActivationFrameAlignment(); 1193 int frameAlignment = OS::ActivationFrameAlignment();
1160 if (frameAlignment != 0) { 1194 if (frameAlignment != 0) {
1161 // Make stack end at alignment and make room for num_arguments words 1195 // Make stack end at alignment and make room for num_arguments words
1162 // and the original value of esp. 1196 // and the original value of esp.
1163 __ mov(ebx, esp); 1197 __ mov(scratch, esp);
1164 __ sub(Operand(esp), Immediate((num_arguments + 1) * kPointerSize)); 1198 __ sub(Operand(esp), Immediate((num_arguments + 1) * kPointerSize));
1165 ASSERT(IsPowerOf2(frameAlignment)); 1199 ASSERT(IsPowerOf2(frameAlignment));
1166 __ and_(esp, -frameAlignment); 1200 __ and_(esp, -frameAlignment);
1167 __ mov(Operand(esp, num_arguments * kPointerSize), ebx); 1201 __ mov(Operand(esp, num_arguments * kPointerSize), scratch);
1168 } else { 1202 } else {
1169 __ sub(Operand(esp), Immediate(num_arguments * kPointerSize)); 1203 __ sub(Operand(esp), Immediate(num_arguments * kPointerSize));
1170 } 1204 }
1171 } 1205 }
1172 1206
1173 1207
1174 void RegExpMacroAssemblerIA32::CallCFunction(Address function_address, 1208 void RegExpMacroAssemblerIA32::CallCFunction(Address function_address,
1175 int num_arguments) { 1209 int num_arguments) {
1176 __ mov(Operand(eax), Immediate(reinterpret_cast<int32_t>(function_address))); 1210 __ mov(Operand(eax), Immediate(reinterpret_cast<int32_t>(function_address)));
1177 __ call(Operand(eax)); 1211 __ call(Operand(eax));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 1243
1210 1244
1211 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, 1245 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg,
1212 ArraySlice* buffer) { 1246 ArraySlice* buffer) {
1213 __ mov(reg, buffer->array()); 1247 __ mov(reg, buffer->array());
1214 __ add(Operand(reg), Immediate(buffer->base_offset())); 1248 __ add(Operand(reg), Immediate(buffer->base_offset()));
1215 } 1249 }
1216 1250
1217 #undef __ 1251 #undef __
1218 }} // namespace v8::internal 1252 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/regexp-macro-assembler-ia32.h ('k') | src/regexp-macro-assembler-irregexp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698