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

Unified Diff: src/regexp-macro-assembler-ia32.cc

Issue 16506: Recognize standard character classes and implement more efficient matchers. (Closed)
Patch Set: Now lints Created 11 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: src/regexp-macro-assembler-ia32.cc
diff --git a/src/regexp-macro-assembler-ia32.cc b/src/regexp-macro-assembler-ia32.cc
index 29d9d31f7bf6f525ee5207295ec5bc9ff1f66b13..6aebfa31af0a1b2e767ac84af8e7dba016cc34ad 100644
--- a/src/regexp-macro-assembler-ia32.cc
+++ b/src/regexp-macro-assembler-ia32.cc
@@ -406,6 +406,91 @@ void RegExpMacroAssemblerIA32::CheckNotCharacterAfterMinusAnd(
BranchOrBacktrack(not_equal, on_not_equal);
}
+bool RegExpMacroAssemblerIA32::CheckSpecialCharacterClass(uc16 type,
Mads Ager (chromium) 2009/01/02 10:51:06 A lot of unnamed constants are used in this code a
+ int cp_offset,
+ bool check_offset,
+ Label* on_no_match) {
+ switch (type) {
+ case 's':
+ if (mode_ == ASCII) {
+ if (check_offset) {
+ LoadCurrentCharacter(cp_offset, on_no_match);
+ } else {
+ LoadCurrentCharacterUnchecked(cp_offset, 1);
+ }
+ Label success;
+ __ cmp(current_character(), 0x20);
+ __ j(equal, &success);
+ __ sub(Operand(current_character()), Immediate(0x09));
+ __ cmp(current_character(), 0x05);
+ BranchOrBacktrack(above_equal, on_no_match);
+ __ bind(&success);
+ return true;
+ }
+ return false;
+ case 'S':
+ if (check_offset) {
+ LoadCurrentCharacter(cp_offset, on_no_match, 1);
+ } else {
+ LoadCurrentCharacterUnchecked(cp_offset, 1);
+ }
+ if (mode_ == ASCII) {
+ __ cmp(current_character(), 0x20);
+ BranchOrBacktrack(equal, on_no_match);
+ __ sub(Operand(current_character()), Immediate(0x09));
+ __ cmp(current_character(), 0x05);
+ BranchOrBacktrack(below, on_no_match);
+ return true;
+ }
+ return false;
+ case 'd':
+ if (check_offset) {
+ LoadCurrentCharacter(cp_offset, on_no_match, 1);
+ } else {
+ LoadCurrentCharacterUnchecked(cp_offset, 1);
+ }
+ __ sub(Operand(current_character()), Immediate('0'));
+ __ cmp(current_character(), '9' - '0');
+ BranchOrBacktrack(greater_equal, on_no_match);
+ return true;
+ case 'D':
+ if (check_offset) {
+ LoadCurrentCharacter(cp_offset, on_no_match, 1);
+ } else {
+ LoadCurrentCharacterUnchecked(cp_offset, 1);
+ }
+ __ sub(Operand(current_character()), Immediate('0'));
+ __ cmp(current_character(), '9' - '0');
+ BranchOrBacktrack(below, on_no_match);
+ return true;
+ case '.': {
+ if (check_offset) {
+ LoadCurrentCharacter(cp_offset, on_no_match, 1);
+ } else {
+ LoadCurrentCharacterUnchecked(cp_offset, 1);
+ }
+ __ sub(Operand(current_character()), Immediate(0x0a));
+ __ mov(eax, current_character());
+ __ and_(current_character(), 0x01);
+ __ shr(eax, 1);
+ __ xor_(current_character(), Operand(eax));
+ BranchOrBacktrack(equal, on_no_match);
+ if (mode_ == UC16) {
+ __ cmp(eax, (0x2028 - 0x0a) >> 1);
+ BranchOrBacktrack(equal, on_no_match);
+ }
+ return true;
+ }
+ case '*':
+ if (check_offset) {
+ CheckPosition(cp_offset, on_no_match);
+ }
+ return true;
+ // No custom implementation (yet): w, W, s(UC16), S(UC16).
+ default:
+ return false;
+ }
+}
void RegExpMacroAssemblerIA32::DispatchHalfNibbleMap(
uc16 start,
@@ -657,10 +742,7 @@ void RegExpMacroAssemblerIA32::LoadCurrentCharacter(int cp_offset,
int characters) {
ASSERT(cp_offset >= 0);
ASSERT(cp_offset < (1<<30)); // Be sane! (And ensure negation works)
- if (check_bounds) {
- __ cmp(edi, -(cp_offset + characters) * char_size());
- BranchOrBacktrack(greater, on_end_of_input);
- }
+ CheckPosition(cp_offset + characters - 1, on_end_of_input);
LoadCurrentCharacterUnchecked(cp_offset, characters);
}
@@ -815,6 +897,13 @@ size_t RegExpMacroAssemblerIA32::char_size() {
}
+void RegExpMacroAssemblerIA32::CheckPosition(int cp_offset,
+ Label* on_outside_input) {
+ __ cmp(edi, -cp_offset * char_size());
+ BranchOrBacktrack(greater_equal, on_outside_input);
+}
+
+
void RegExpMacroAssemblerIA32::BranchOrBacktrack(Condition condition,
Label* to) {
if (condition < 0) { // No condition

Powered by Google App Engine
This is Rietveld 408576698