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

Side by Side Diff: src/jsregexp.cc

Issue 12469: * Better factoring of ARM/IA32 code in irregexp. (Closed)
Patch Set: Dropped the unifying ...-native.h file. 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/frames-inl.h ('k') | src/jsregexp-inl.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 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 25 matching lines...) Expand all
36 #include "jsregexp-inl.h" 36 #include "jsregexp-inl.h"
37 #include "platform.h" 37 #include "platform.h"
38 #include "runtime.h" 38 #include "runtime.h"
39 #include "top.h" 39 #include "top.h"
40 #include "compilation-cache.h" 40 #include "compilation-cache.h"
41 #include "string-stream.h" 41 #include "string-stream.h"
42 #include "parser.h" 42 #include "parser.h"
43 #include "assembler-irregexp.h" 43 #include "assembler-irregexp.h"
44 #include "regexp-macro-assembler.h" 44 #include "regexp-macro-assembler.h"
45 #include "regexp-macro-assembler-irregexp.h" 45 #include "regexp-macro-assembler-irregexp.h"
46 #if defined __arm__ || defined __thumb__ || defined ARM 46
47 // include regexp-macro-assembler-arm.h when created. 47 #ifdef ARM
48 #else // ia32 48 #include "regexp-macro-assembler-arm.h"
49 #else // IA32
50 #include "macro-assembler-ia32.h"
49 #include "regexp-macro-assembler-ia32.h" 51 #include "regexp-macro-assembler-ia32.h"
50 #endif 52 #endif
53
51 #include "interpreter-irregexp.h" 54 #include "interpreter-irregexp.h"
52 55
53 // Including pcre.h undefines DEBUG to avoid getting debug output from 56 // Including pcre.h undefines DEBUG to avoid getting debug output from
54 // the JSCRE implementation. Make sure to redefine it in debug mode 57 // the JSCRE implementation. Make sure to redefine it in debug mode
55 // after having included the header file. 58 // after having included the header file.
56 #ifdef DEBUG 59 #ifdef DEBUG
57 #include "third_party/jscre/pcre.h" 60 #include "third_party/jscre/pcre.h"
58 #define DEBUG 61 #define DEBUG
59 #else 62 #else
60 #include "third_party/jscre/pcre.h" 63 #include "third_party/jscre/pcre.h"
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 if (rc) { 512 if (rc) {
510 // Capture values are relative to start_offset only. 513 // Capture values are relative to start_offset only.
511 for (int i = 0; i < offsets_vector_length; i++) { 514 for (int i = 0; i < offsets_vector_length; i++) {
512 if (offsets_vector[i] >= 0) { 515 if (offsets_vector[i] >= 0) {
513 offsets_vector[i] += previous_index; 516 offsets_vector[i] += previous_index;
514 } 517 }
515 } 518 }
516 } 519 }
517 break; 520 break;
518 } 521 }
522 default:
523 case RegExpMacroAssembler::kARMImplementation:
524 UNREACHABLE();
525 rc = false;
526 break;
519 case RegExpMacroAssembler::kBytecodeImplementation: { 527 case RegExpMacroAssembler::kBytecodeImplementation: {
520 Handle<ByteArray> byte_codes = IrregexpCode(regexp); 528 Handle<ByteArray> byte_codes = IrregexpCode(regexp);
521 529
522 rc = IrregexpInterpreter::Match(byte_codes, 530 rc = IrregexpInterpreter::Match(byte_codes,
523 two_byte_subject, 531 two_byte_subject,
524 offsets_vector, 532 offsets_vector,
525 previous_index); 533 previous_index);
526 break; 534 break;
527 } 535 }
528 case RegExpMacroAssembler::kARMImplementation:
529 default:
530 UNREACHABLE();
531 rc = false;
532 break;
533 } 536 }
534 } 537 }
535 538
536 if (!rc) { 539 if (!rc) {
537 return Factory::null_value(); 540 return Factory::null_value();
538 } 541 }
539 542
540 Handle<FixedArray> array = Factory::NewFixedArray(2 * (num_captures+1)); 543 Handle<FixedArray> array = Factory::NewFixedArray(2 * (num_captures+1));
541 // The captures come in (start, end+1) pairs. 544 // The captures come in (start, end+1) pairs.
542 for (int i = 0; i < 2 * (num_captures+1); i += 2) { 545 for (int i = 0; i < 2 * (num_captures+1); i += 2) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 for (int i = 0; i < 2 * (num_captures+1); i += 2) { 596 for (int i = 0; i < 2 * (num_captures+1); i += 2) {
594 array->set(i, Smi::FromInt(offsets_vector[i])); 597 array->set(i, Smi::FromInt(offsets_vector[i]));
595 array->set(i+1, Smi::FromInt(offsets_vector[i+1])); 598 array->set(i+1, Smi::FromInt(offsets_vector[i+1]));
596 } 599 }
597 return Factory::NewJSArrayWithElements(array); 600 return Factory::NewJSArrayWithElements(array);
598 } 601 }
599 602
600 603
601 class OffsetsVector { 604 class OffsetsVector {
602 public: 605 public:
603 inline OffsetsVector(int num_registers) 606 inline OffsetsVector(int num_registers) :
604 : offsets_vector_length_(num_registers) { 607 offsets_vector_length_(num_registers) {
605 if (offsets_vector_length_ > kStaticOffsetsVectorSize) { 608 if (offsets_vector_length_ > kStaticOffsetsVectorSize) {
606 vector_ = NewArray<int>(offsets_vector_length_); 609 vector_ = NewArray<int>(offsets_vector_length_);
607 } else { 610 } else {
608 vector_ = static_offsets_vector_; 611 vector_ = static_offsets_vector_;
609 } 612 }
610 } 613 }
611 614
612 615
613 inline ~OffsetsVector() { 616 inline ~OffsetsVector() {
614 if (offsets_vector_length_ > kStaticOffsetsVectorSize) { 617 if (offsets_vector_length_ > kStaticOffsetsVectorSize) {
(...skipping 18 matching lines...) Expand all
633 static const int kStaticOffsetsVectorSize = 50; 636 static const int kStaticOffsetsVectorSize = 50;
634 static int static_offsets_vector_[kStaticOffsetsVectorSize]; 637 static int static_offsets_vector_[kStaticOffsetsVectorSize];
635 }; 638 };
636 639
637 640
638 int OffsetsVector::static_offsets_vector_[ 641 int OffsetsVector::static_offsets_vector_[
639 OffsetsVector::kStaticOffsetsVectorSize]; 642 OffsetsVector::kStaticOffsetsVectorSize];
640 643
641 644
642 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> regexp, 645 Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> regexp,
643 Handle<String> subject, 646 Handle<String> subject,
644 Handle<Object> index) { 647 Handle<Object> index) {
645 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP); 648 ASSERT_EQ(regexp->TypeTag(), JSRegExp::IRREGEXP);
646 ASSERT(!regexp->DataAt(JSRegExp::kIrregexpDataIndex)->IsUndefined()); 649 ASSERT(!regexp->DataAt(JSRegExp::kIrregexpDataIndex)->IsUndefined());
647 650
648 // Prepare space for the return values. 651 // Prepare space for the return values.
649 int number_of_registers = IrregexpNumberOfRegisters(regexp); 652 int number_of_registers = IrregexpNumberOfRegisters(regexp);
650 OffsetsVector offsets(number_of_registers); 653 OffsetsVector offsets(number_of_registers);
651 654
652 int num_captures = IrregexpNumberOfCaptures(regexp); 655 int num_captures = IrregexpNumberOfCaptures(regexp);
653 656
654 int previous_index = static_cast<int>(DoubleToInteger(index->Number())); 657 int previous_index = static_cast<int>(DoubleToInteger(index->Number()));
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 if (matches->IsNull()) { // Exited loop normally. 800 if (matches->IsNull()) { // Exited loop normally.
798 return result; 801 return result;
799 } else { // Exited loop with the exception in matches. 802 } else { // Exited loop with the exception in matches.
800 return matches; 803 return matches;
801 } 804 }
802 } 805 }
803 806
804 807
805 int RegExpImpl::JscreNumberOfCaptures(Handle<JSRegExp> re) { 808 int RegExpImpl::JscreNumberOfCaptures(Handle<JSRegExp> re) {
806 FixedArray* value = FixedArray::cast(re->DataAt(JSRegExp::kJscreDataIndex)); 809 FixedArray* value = FixedArray::cast(re->DataAt(JSRegExp::kJscreDataIndex));
807 return Smi::cast(value->get(kJscreNumberOfCapturesIndex))-> value(); 810 return Smi::cast(value->get(kJscreNumberOfCapturesIndex))->
811 value();
808 } 812 }
809 813
810 814
811 ByteArray* RegExpImpl::JscreInternal(Handle<JSRegExp> re) { 815 ByteArray* RegExpImpl::JscreInternal(Handle<JSRegExp> re) {
812 FixedArray* value = FixedArray::cast(re->DataAt(JSRegExp::kJscreDataIndex)); 816 FixedArray* value = FixedArray::cast(re->DataAt(JSRegExp::kJscreDataIndex));
813 return ByteArray::cast(value->get(kJscreInternalIndex)); 817 return ByteArray::cast(value->get(kJscreInternalIndex));
814 } 818 }
815 819
816 820
817 int RegExpImpl::IrregexpNumberOfCaptures(Handle<JSRegExp> re) { 821 int RegExpImpl::IrregexpNumberOfCaptures(Handle<JSRegExp> re) {
(...skipping 1754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2572 captured_body, 2576 captured_body,
2573 compiler.backtrack()); 2577 compiler.backtrack());
2574 if (node_return != NULL) *node_return = node; 2578 if (node_return != NULL) *node_return = node;
2575 Analysis analysis; 2579 Analysis analysis;
2576 analysis.EnsureAnalyzed(node); 2580 analysis.EnsureAnalyzed(node);
2577 2581
2578 if (!FLAG_irregexp) { 2582 if (!FLAG_irregexp) {
2579 return Handle<FixedArray>::null(); 2583 return Handle<FixedArray>::null();
2580 } 2584 }
2581 2585
2582 #if !(defined ARM || defined __arm__ || defined __thumb__) 2586 if (FLAG_irregexp_native) {
2583 if (FLAG_irregexp_native) { // Flag only checked in IA32 mode. 2587 #ifdef ARM
2584 // TODO(lrn) Move compilation to a later point in the life-cycle 2588 UNIMPLEMENTED();
2585 // of the RegExp. We don't know the type of input string yet. 2589 #else // IA32
2586 // For now, always assume two-byte strings.
2587 RegExpMacroAssemblerIA32 macro_assembler(RegExpMacroAssemblerIA32::UC16, 2590 RegExpMacroAssemblerIA32 macro_assembler(RegExpMacroAssemblerIA32::UC16,
2588 (input->capture_count + 1) * 2); 2591 (input->capture_count + 1) * 2);
2589 return compiler.Assemble(&macro_assembler, 2592 return compiler.Assemble(&macro_assembler,
2590 node, 2593 node,
2591 input->capture_count); 2594 input->capture_count);
2595 #endif
2592 } 2596 }
2593 #endif
2594 byte codes[1024]; 2597 byte codes[1024];
2595 IrregexpAssembler assembler(Vector<byte>(codes, 1024)); 2598 IrregexpAssembler assembler(Vector<byte>(codes, 1024));
2596 RegExpMacroAssemblerIrregexp macro_assembler(&assembler); 2599 RegExpMacroAssemblerIrregexp macro_assembler(&assembler);
2597 return compiler.Assemble(&macro_assembler, 2600 return compiler.Assemble(&macro_assembler,
2598 node, 2601 node,
2599 input->capture_count); 2602 input->capture_count);
2600 } 2603 }
2601 2604
2602 2605
2603 }} // namespace v8::internal 2606 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/frames-inl.h ('k') | src/jsregexp-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698