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

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

Issue 12944: * Implemented case-insensitive back-reference matching in irregexp-ia32. (Closed)
Patch Set: Review comments addressed Created 12 years 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
« no previous file with comments | « src/regexp-macro-assembler-ia32.h ('k') | test/cctest/test-regexp.cc » ('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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <string.h> 28 #include <string.h>
29 #include "v8.h" 29 #include "v8.h"
30 #include "unicode.h"
30 #include "log.h" 31 #include "log.h"
31 #include "ast.h" 32 #include "ast.h"
32 #include "macro-assembler.h" 33 #include "macro-assembler.h"
33 #include "regexp-macro-assembler.h" 34 #include "regexp-macro-assembler.h"
34 #include "macro-assembler-ia32.h" 35 #include "macro-assembler-ia32.h"
35 #include "regexp-macro-assembler-ia32.h" 36 #include "regexp-macro-assembler-ia32.h"
36 37
37 namespace v8 { namespace internal { 38 namespace v8 { namespace internal {
38 39
39 /* 40 /*
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 234
234 235
235 void RegExpMacroAssemblerIA32::CheckCurrentPosition(int register_index, 236 void RegExpMacroAssemblerIA32::CheckCurrentPosition(int register_index,
236 Label* on_equal) { 237 Label* on_equal) {
237 __ cmp(edi, register_location(register_index)); 238 __ cmp(edi, register_location(register_index));
238 BranchOrBacktrack(equal, on_equal); 239 BranchOrBacktrack(equal, on_equal);
239 } 240 }
240 241
241 242
242 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase( 243 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase(
243 int start_reg, Label* on_no_match) { 244 int start_reg,
245 Label* on_no_match) {
244 Label fallthrough; 246 Label fallthrough;
245 __ mov(eax, register_location(start_reg)); 247 __ mov(eax, register_location(start_reg));
246 __ mov(ecx, register_location(start_reg + 1)); 248 __ mov(ecx, register_location(start_reg + 1));
247 __ sub(ecx, Operand(eax)); // Length to check. 249 __ sub(ecx, Operand(eax)); // Length to check.
248 __ j(less, on_no_match); 250 BranchOrBacktrack(less, on_no_match);
249 __ j(equal, &fallthrough); 251 __ j(equal, &fallthrough);
250 252
251 UNIMPLEMENTED(); // TODO(lrn): Call runtime function to do test. 253 if (mode_ == ASCII) {
254 Label success;
255 Label fail;
256 __ push(esi);
257 __ push(edi);
258 __ add(edi, Operand(esi));
259 __ add(esi, Operand(eax));
260 Label loop;
261 __ bind(&loop);
262 __ rep_cmpsb();
263 __ j(equal, &success);
264 // Compare lower-case if letters.
265 __ movzx_b(eax, Operand(edi, -1));
266 __ or_(eax, 0x20); // To-lower-case
267 __ lea(ebx, Operand(eax, -'a'));
268 __ cmp(ebx, static_cast<int32_t>('z' - 'a'));
269 __ j(above, &fail);
270 __ movzx_b(ebx, Operand(esi, -1));
271 __ or_(ebx, 0x20); // To-lower-case
272 __ cmp(eax, Operand(ebx));
273 __ j(not_equal, &fail);
274 __ or_(ecx, Operand(ecx));
275 __ j(not_equal, &loop);
276 __ jmp(&success);
252 277
278 __ bind(&fail);
279 __ pop(edi);
280 __ pop(esi);
281 BranchOrBacktrack(no_condition, on_no_match);
282
283 __ bind(&success);
284 __ pop(eax); // discard original value of edi
285 __ pop(esi);
286 __ sub(edi, Operand(esi));
287 } else {
288 // store state
289 __ push(esi);
290 __ push(edi);
291 __ push(ecx);
292 // align stack
293 int frameAlignment = OS::ActivationFrameAlignment();
294 if (frameAlignment != 0) {
295 __ mov(ebx, esp);
296 __ sub(Operand(esp), Immediate(5 * kPointerSize)); // args + esp.
297 ASSERT(IsPowerOf2(frameAlignment));
298 __ and_(esp, -frameAlignment);
299 __ mov(Operand(esp, 4 * kPointerSize), ebx);
300 } else {
301 __ sub(Operand(esp), Immediate(4 * kPointerSize));
302 }
303 // Put arguments on stack.
304 __ mov(Operand(esp, 3 * kPointerSize), ecx);
305 __ mov(ebx, Operand(ebp, kInputEndOffset));
306 __ add(edi, Operand(ebx));
307 __ mov(Operand(esp, 2 * kPointerSize), edi);
308 __ add(eax, Operand(ebx));
309 __ mov(Operand(esp, 1 * kPointerSize), eax);
310 __ mov(eax, Operand(ebp, kInputBuffer));
311 __ mov(Operand(esp, 0 * kPointerSize), eax);
312 Address function_address = FUNCTION_ADDR(&CaseInsensitiveCompareUC16);
313 __ mov(Operand(eax),
314 Immediate(reinterpret_cast<int32_t>(function_address)));
315 __ call(Operand(eax));
316 if (frameAlignment != 0) {
317 __ mov(esp, Operand(esp, 4 * kPointerSize));
318 } else {
319 __ add(Operand(esp), Immediate(4 * sizeof(int32_t)));
320 }
321 __ pop(ecx);
322 __ pop(edi);
323 __ pop(esi);
324 __ or_(eax, Operand(eax));
325 BranchOrBacktrack(zero, on_no_match);
326 __ add(edi, Operand(ecx));
327 }
253 __ bind(&fallthrough); 328 __ bind(&fallthrough);
254 } 329 }
255 330
256 331
257 void RegExpMacroAssemblerIA32::CheckNotBackReference( 332 void RegExpMacroAssemblerIA32::CheckNotBackReference(
258 int start_reg, Label* on_no_match) { 333 int start_reg,
334 Label* on_no_match) {
259 Label fallthrough; 335 Label fallthrough;
260 __ mov(eax, register_location(start_reg)); 336 __ mov(eax, register_location(start_reg));
261 __ mov(ecx, register_location(start_reg + 1)); 337 __ mov(ecx, register_location(start_reg + 1));
262 __ sub(ecx, Operand(eax)); // Length to check. 338 __ sub(ecx, Operand(eax)); // Length to check.
263 BranchOrBacktrack(less, on_no_match); 339 BranchOrBacktrack(less, on_no_match);
264 __ j(equal, &fallthrough); 340 __ j(equal, &fallthrough);
265 // Check that there are sufficient characters left in the input. 341 // Check that there are sufficient characters left in the input.
266 __ mov(ebx, edi); 342 __ mov(ebx, edi);
267 __ add(ebx, Operand(ecx)); 343 __ add(ebx, Operand(ecx));
268 BranchOrBacktrack(greater, on_no_match); 344 BranchOrBacktrack(greater, on_no_match);
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 __ mov(register_location(reg), edi); 655 __ mov(register_location(reg), edi);
580 } 656 }
581 657
582 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) { 658 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) {
583 __ mov(register_location(reg), esp); 659 __ mov(register_location(reg), esp);
584 } 660 }
585 661
586 662
587 // Private methods: 663 // Private methods:
588 664
665
666 static unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize;
667
668
669 int RegExpMacroAssemblerIA32::CaseInsensitiveCompareUC16(uc16** buffer,
670 int byte_offset1,
671 int byte_offset2,
672 size_t byte_length) {
673 ASSERT(byte_length % 2 == 0);
674 Address buffer_address = reinterpret_cast<Address>(*buffer);
675 uc16* substring1 = reinterpret_cast<uc16*>(buffer_address + byte_offset1);
676 uc16* substring2 = reinterpret_cast<uc16*>(buffer_address + byte_offset2);
677 size_t length = byte_length >> 1;
678
679 for (size_t i = 0; i < length; i++) {
680 unibrow::uchar c1 = substring1[i];
681 unibrow::uchar c2 = substring2[i];
682 if (c1 != c2) {
683 canonicalize.get(c1, '\0', &c1);
684 if (c1 != c2) {
685 canonicalize.get(c2, '\0', &c2);
686 if (c1 != c2) {
687 return 0;
688 }
689 }
690 }
691 }
692 return 1;
693 }
694
695
589 Operand RegExpMacroAssemblerIA32::register_location(int register_index) { 696 Operand RegExpMacroAssemblerIA32::register_location(int register_index) {
590 ASSERT(register_index < (1<<30)); 697 ASSERT(register_index < (1<<30));
591 if (num_registers_ <= register_index) { 698 if (num_registers_ <= register_index) {
592 num_registers_ = register_index + 1; 699 num_registers_ = register_index + 1;
593 } 700 }
594 return Operand(ebp, -(register_index + 1) * kPointerSize); 701 return Operand(ebp, -(register_index + 1) * kPointerSize);
595 } 702 }
596 703
597 704
598 Register RegExpMacroAssemblerIA32::current_character() { 705 Register RegExpMacroAssemblerIA32::current_character() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 782
676 783
677 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, 784 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg,
678 ArraySlice* buffer) { 785 ArraySlice* buffer) {
679 __ mov(reg, buffer->array()); 786 __ mov(reg, buffer->array());
680 __ add(Operand(reg), Immediate(buffer->base_offset())); 787 __ add(Operand(reg), Immediate(buffer->base_offset()));
681 } 788 }
682 789
683 #undef __ 790 #undef __
684 }} // namespace v8::internal 791 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/regexp-macro-assembler-ia32.h ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698