Author: [email protected]
Date: Thu Feb 19 02:03:27 2009
New Revision: 1311

Modified:
    branches/bleeding_edge/src/bytecodes-irregexp.h
    branches/bleeding_edge/src/interpreter-irregexp.cc
    branches/bleeding_edge/src/jsregexp.cc
    branches/bleeding_edge/src/regexp-macro-assembler-irregexp-inl.h
    branches/bleeding_edge/src/regexp-macro-assembler-irregexp.cc
    branches/bleeding_edge/src/regexp-macro-assembler-irregexp.h

Log:
A little peephole optimization for the Irregexp bytecode interpreter.
Review URL: http://codereview.chromium.org/21481

Modified: branches/bleeding_edge/src/bytecodes-irregexp.h
==============================================================================
--- branches/bleeding_edge/src/bytecodes-irregexp.h     (original)
+++ branches/bleeding_edge/src/bytecodes-irregexp.h     Thu Feb 19 02:03:27 2009
@@ -1,4 +1,4 @@
-// Copyright 2008 the V8 project authors. All rights reserved.
+// Copyright 2008-2009 the V8 project authors. All rights reserved.
  // Redistribution and use in source and binary forms, with or without
  // modification, are permitted provided that the following conditions are
  // met:
@@ -86,7 +86,8 @@
  V(CHECK_REGISTER_EQ_POS, 43, 8) /* bc8 reg_idx24  
addr32                     */ \
  V(CHECK_AT_START,    44, 8)   /* bc8 pad24  
addr32                           */ \
  V(CHECK_NOT_AT_START, 45, 8)  /* bc8 pad24  
addr32                           */ \
-V(CHECK_GREEDY,      46, 8)   /* bc8 pad24  
addr32                           */
+V(CHECK_GREEDY,      46, 8)   /* bc8 pad24  
addr32                           */ \
+V(ADVANCE_CP_AND_GOTO, 47, 8) /* bc8 offset24  
addr32                        */

  #define DECLARE_BYTECODES(name, code, length) \
    static const int BC_##name = code;

Modified: branches/bleeding_edge/src/interpreter-irregexp.cc
==============================================================================
--- branches/bleeding_edge/src/interpreter-irregexp.cc  (original)
+++ branches/bleeding_edge/src/interpreter-irregexp.cc  Thu Feb 19 02:03:27  
2009
@@ -238,6 +238,10 @@
        BYTECODE(GOTO)
          pc = code_base + Load32Aligned(pc + 4);
          break;
+      BYTECODE(ADVANCE_CP_AND_GOTO)
+        current += insn >> BYTECODE_SHIFT;
+        pc = code_base + Load32Aligned(pc + 4);
+        break;
        BYTECODE(CHECK_GREEDY)
          if (current == backtrack_sp[-1]) {
            backtrack_sp--;

Modified: branches/bleeding_edge/src/jsregexp.cc
==============================================================================
--- branches/bleeding_edge/src/jsregexp.cc      (original)
+++ branches/bleeding_edge/src/jsregexp.cc      Thu Feb 19 02:03:27 2009
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2006-2009 the V8 project authors. All rights reserved.
  // Redistribution and use in source and binary forms, with or without
  // modification, are permitted provided that the following conditions are
  // met:

Modified: branches/bleeding_edge/src/regexp-macro-assembler-irregexp-inl.h
==============================================================================
--- branches/bleeding_edge/src/regexp-macro-assembler-irregexp-inl.h     
(original)
+++ branches/bleeding_edge/src/regexp-macro-assembler-irregexp-inl.h    Thu  
Feb 19 02:03:27 2009
@@ -1,4 +1,4 @@
-// Copyright 2008 the V8 project authors. All rights reserved.
+// Copyright 2008-2009 the V8 project authors. All rights reserved.
  // Redistribution and use in source and binary forms, with or without
  // modification, are permitted provided that the following conditions are
  // met:

Modified: branches/bleeding_edge/src/regexp-macro-assembler-irregexp.cc
==============================================================================
--- branches/bleeding_edge/src/regexp-macro-assembler-irregexp.cc       
(original)
+++ branches/bleeding_edge/src/regexp-macro-assembler-irregexp.cc       Thu Feb 
 
19 02:03:27 2009
@@ -1,4 +1,4 @@
-// Copyright 2008 the V8 project authors. All rights reserved.
+// Copyright 2008-2009 the V8 project authors. All rights reserved.
  // Redistribution and use in source and binary forms, with or without
  // modification, are permitted provided that the following conditions are
  // met:
@@ -39,7 +39,8 @@
  RegExpMacroAssemblerIrregexp::RegExpMacroAssemblerIrregexp(Vector<byte>  
buffer)
      : buffer_(buffer),
        pc_(0),
-      own_buffer_(false) {
+      own_buffer_(false),
+      advance_current_end_(kInvalidPC) {
  }


@@ -55,6 +56,7 @@


  void RegExpMacroAssemblerIrregexp::Bind(Label* l) {
+  advance_current_end_ = kInvalidPC;
    ASSERT(!l->is_bound());
    if (l->is_linked()) {
      int pos = l->pos();
@@ -172,8 +174,17 @@


  void RegExpMacroAssemblerIrregexp::GoTo(Label* l) {
-  Emit(BC_GOTO, 0);
-  EmitOrLink(l);
+  if (advance_current_end_ == pc_) {
+    // Combine advance current and goto.
+    pc_ = advance_current_start_;
+    Emit(BC_ADVANCE_CP_AND_GOTO, advance_current_offset_);
+    EmitOrLink(l);
+    advance_current_end_ = kInvalidPC;
+  } else {
+    // Regular goto.
+    Emit(BC_GOTO, 0);
+    EmitOrLink(l);
+  }
  }


@@ -196,7 +207,10 @@
  void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) {
    ASSERT(by >= kMinCPOffset);
    ASSERT(by <= kMaxCPOffset);
+  advance_current_start_ = pc_;
+  advance_current_offset_ = by;
    Emit(BC_ADVANCE_CP, by);
+  advance_current_end_ = pc_;
  }



Modified: branches/bleeding_edge/src/regexp-macro-assembler-irregexp.h
==============================================================================
--- branches/bleeding_edge/src/regexp-macro-assembler-irregexp.h        
(original)
+++ branches/bleeding_edge/src/regexp-macro-assembler-irregexp.h        Thu Feb 
19  
02:03:27 2009
@@ -1,4 +1,4 @@
-// Copyright 2008 the V8 project authors. All rights reserved.
+// Copyright 2008-2009 the V8 project authors. All rights reserved.
  // Redistribution and use in source and binary forms, with or without
  // modification, are permitted provided that the following conditions are
  // met:
@@ -132,6 +132,12 @@
    // True if the assembler owns the buffer, false if buffer is external.
    bool own_buffer_;
    Label backtrack_;
+
+  int advance_current_start_;
+  int advance_current_offset_;
+  int advance_current_end_;
+
+  static const int kInvalidPC = -1;

    DISALLOW_IMPLICIT_CONSTRUCTORS(RegExpMacroAssemblerIrregexp);
  };

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to