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

Side by Side Diff: src/interpreter-irregexp.cc

Issue 14194: * Generate quick checks based on mask and compare for... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' 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 | Annotate | Revision Log
« no previous file with comments | « src/bytecodes-irregexp.h ('k') | src/jsregexp.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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 return true; 75 return true;
76 } 76 }
77 77
78 78
79 #ifdef DEBUG 79 #ifdef DEBUG
80 static void TraceInterpreter(const byte* code_base, 80 static void TraceInterpreter(const byte* code_base,
81 const byte* pc, 81 const byte* pc,
82 int stack_depth, 82 int stack_depth,
83 int current_position, 83 int current_position,
84 uint32_t current_char,
84 int bytecode_length, 85 int bytecode_length,
85 const char* bytecode_name) { 86 const char* bytecode_name) {
86 if (FLAG_trace_regexp_bytecodes) { 87 if (FLAG_trace_regexp_bytecodes) {
87 PrintF("pc = %02x, sp = %d, current = %d, bc = %s", 88 bool printable = (current_char < 127 && current_char >= 32);
89 const char* format =
90 printable ?
91 "pc = %02x, sp = %d, curpos = %d, curchar = %08x (%c), bc = %s" :
92 "pc = %02x, sp = %d, curpos = %d, curchar = %08x .%c., bc = %s";
93 PrintF(format,
88 pc - code_base, 94 pc - code_base,
89 stack_depth, 95 stack_depth,
90 current_position, 96 current_position,
97 current_char,
98 printable ? current_char : '.',
91 bytecode_name); 99 bytecode_name);
92 for (int i = 1; i < bytecode_length; i++) { 100 for (int i = 1; i < bytecode_length; i++) {
93 printf(", %02x", pc[i]); 101 printf(", %02x", pc[i]);
94 } 102 }
103 printf(" ");
104 for (int i = 1; i < bytecode_length; i++) {
105 unsigned char b = pc[i];
106 if (b < 127 && b >= 32) {
107 printf("%c", b);
108 } else {
109 printf(".");
110 }
111 }
95 printf("\n"); 112 printf("\n");
96 } 113 }
97 } 114 }
98 115
99 116
100 #define BYTECODE(name) \ 117 #define BYTECODE(name) \
101 case BC_##name: \ 118 case BC_##name: \
102 TraceInterpreter(code_base, \ 119 TraceInterpreter(code_base, \
103 pc, \ 120 pc, \
104 backtrack_sp - backtrack_stack, \ 121 backtrack_sp - backtrack_stack, \
105 current, \ 122 current, \
123 current_char, \
106 BC_##name##_LENGTH, \ 124 BC_##name##_LENGTH, \
107 #name); 125 #name);
108 #else 126 #else
109 #define BYTECODE(name) \ 127 #define BYTECODE(name) \
110 case BC_##name: 128 case BC_##name:
111 #endif 129 #endif
112 130
113 131
114 132
115 template <typename Char> 133 template <typename Char>
116 static bool RawMatch(const byte* code_base, 134 static bool RawMatch(const byte* code_base,
117 Vector<const Char> subject, 135 Vector<const Char> subject,
118 int* registers, 136 int* registers,
119 int current, 137 int current,
120 int current_char) { 138 uint32_t current_char) {
121 const byte* pc = code_base; 139 const byte* pc = code_base;
122 static const int kBacktrackStackSize = 10000; 140 static const int kBacktrackStackSize = 10000;
123 int backtrack_stack[kBacktrackStackSize]; 141 int backtrack_stack[kBacktrackStackSize];
124 int backtrack_stack_space = kBacktrackStackSize; 142 int backtrack_stack_space = kBacktrackStackSize;
125 int* backtrack_sp = backtrack_stack; 143 int* backtrack_sp = backtrack_stack;
126 #ifdef DEBUG 144 #ifdef DEBUG
127 if (FLAG_trace_regexp_bytecodes) { 145 if (FLAG_trace_regexp_bytecodes) {
128 PrintF("\n\nStart bytecode interpreter\n\n"); 146 PrintF("\n\nStart bytecode interpreter\n\n");
129 } 147 }
130 #endif 148 #endif
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 pc += BC_LOAD_CURRENT_CHAR_LENGTH; 244 pc += BC_LOAD_CURRENT_CHAR_LENGTH;
227 } 245 }
228 break; 246 break;
229 } 247 }
230 BYTECODE(LOAD_CURRENT_CHAR_UNCHECKED) { 248 BYTECODE(LOAD_CURRENT_CHAR_UNCHECKED) {
231 int pos = current + Load32(pc + 1); 249 int pos = current + Load32(pc + 1);
232 current_char = subject[pos]; 250 current_char = subject[pos];
233 pc += BC_LOAD_CURRENT_CHAR_UNCHECKED_LENGTH; 251 pc += BC_LOAD_CURRENT_CHAR_UNCHECKED_LENGTH;
234 break; 252 break;
235 } 253 }
254 BYTECODE(LOAD_2_CURRENT_CHARS) {
255 int pos = current + Load32(pc + 1);
256 if (pos + 2 > subject.length()) {
257 pc = code_base + Load32(pc + 5);
258 } else {
259 Char next = subject[pos + 1];
260 current_char =
261 (subject[pos] | (next << (kBitsPerByte * sizeof(Char))));
262 pc += BC_LOAD_2_CURRENT_CHARS_LENGTH;
263 }
264 break;
265 }
266 BYTECODE(LOAD_2_CURRENT_CHARS_UNCHECKED) {
267 int pos = current + Load32(pc + 1);
268 Char next = subject[pos + 1];
269 current_char = (subject[pos] | (next << (kBitsPerByte * sizeof(Char))));
270 pc += BC_LOAD_2_CURRENT_CHARS_UNCHECKED_LENGTH;
271 break;
272 }
273 BYTECODE(LOAD_4_CURRENT_CHARS) {
274 ASSERT(sizeof(Char) == 1);
275 int pos = current + Load32(pc + 1);
276 if (pos + 4 > subject.length()) {
277 pc = code_base + Load32(pc + 5);
278 } else {
279 Char next1 = subject[pos + 1];
280 Char next2 = subject[pos + 2];
281 Char next3 = subject[pos + 3];
282 current_char = (subject[pos] |
283 (next1 << 8) |
284 (next2 << 16) |
285 (next3 << 24));
286 pc += BC_LOAD_4_CURRENT_CHARS_LENGTH;
287 }
288 break;
289 }
290 BYTECODE(LOAD_4_CURRENT_CHARS_UNCHECKED) {
291 ASSERT(sizeof(Char) == 1);
292 int pos = current + Load32(pc + 1);
293 Char next1 = subject[pos + 1];
294 Char next2 = subject[pos + 2];
295 Char next3 = subject[pos + 3];
296 current_char = (subject[pos] |
297 (next1 << 8) |
298 (next2 << 16) |
299 (next3 << 24));
300 pc += BC_LOAD_4_CURRENT_CHARS_UNCHECKED_LENGTH;
301 break;
302 }
236 BYTECODE(CHECK_CHAR) { 303 BYTECODE(CHECK_CHAR) {
237 int c = Load16(pc + 1); 304 uint32_t c = Load32(pc + 1);
238 if (c == current_char) { 305 if (c == current_char) {
239 pc = code_base + Load32(pc + 3); 306 pc = code_base + Load32(pc + 5);
240 } else { 307 } else {
241 pc += BC_CHECK_CHAR_LENGTH; 308 pc += BC_CHECK_CHAR_LENGTH;
242 } 309 }
243 break; 310 break;
244 } 311 }
245 BYTECODE(CHECK_NOT_CHAR) { 312 BYTECODE(CHECK_NOT_CHAR) {
246 int c = Load16(pc + 1); 313 uint32_t c = Load32(pc + 1);
247 if (c != current_char) { 314 if (c != current_char) {
248 pc = code_base + Load32(pc + 3); 315 pc = code_base + Load32(pc + 5);
249 } else { 316 } else {
250 pc += BC_CHECK_NOT_CHAR_LENGTH; 317 pc += BC_CHECK_NOT_CHAR_LENGTH;
251 } 318 }
252 break; 319 break;
253 } 320 }
254 BYTECODE(OR_CHECK_NOT_CHAR) { 321 BYTECODE(AND_CHECK_CHAR) {
255 int c = Load16(pc + 1); 322 uint32_t c = Load32(pc + 1);
256 if (c != (current_char | Load16(pc + 3))) { 323 if (c == (current_char & Load32(pc + 5))) {
257 pc = code_base + Load32(pc + 5); 324 pc = code_base + Load32(pc + 9);
258 } else { 325 } else {
259 pc += BC_OR_CHECK_NOT_CHAR_LENGTH; 326 pc += BC_AND_CHECK_CHAR_LENGTH;
260 } 327 }
261 break; 328 break;
262 } 329 }
263 BYTECODE(MINUS_OR_CHECK_NOT_CHAR) { 330 BYTECODE(AND_CHECK_NOT_CHAR) {
264 int c = Load16(pc + 1); 331 uint32_t c = Load32(pc + 1);
265 int m = Load16(pc + 3); 332 if (c != (current_char & Load32(pc + 5))) {
266 if (c != ((current_char - m) | m)) { 333 pc = code_base + Load32(pc + 9);
267 pc = code_base + Load32(pc + 5);
268 } else { 334 } else {
269 pc += BC_MINUS_OR_CHECK_NOT_CHAR_LENGTH; 335 pc += BC_AND_CHECK_NOT_CHAR_LENGTH;
336 }
337 break;
338 }
339 BYTECODE(MINUS_AND_CHECK_NOT_CHAR) {
340 uint32_t c = Load16(pc + 1);
341 uint32_t minus = Load16(pc + 3);
342 uint32_t mask = Load16(pc + 5);
343 if (c != ((current_char - minus) & mask)) {
344 pc = code_base + Load32(pc + 7);
345 } else {
346 pc += BC_MINUS_AND_CHECK_NOT_CHAR_LENGTH;
270 } 347 }
271 break; 348 break;
272 } 349 }
273 BYTECODE(CHECK_LT) { 350 BYTECODE(CHECK_LT) {
274 int limit = Load16(pc + 1); 351 uint32_t limit = Load16(pc + 1);
275 if (current_char < limit) { 352 if (current_char < limit) {
276 pc = code_base + Load32(pc + 3); 353 pc = code_base + Load32(pc + 3);
277 } else { 354 } else {
278 pc += BC_CHECK_LT_LENGTH; 355 pc += BC_CHECK_LT_LENGTH;
279 } 356 }
280 break; 357 break;
281 } 358 }
282 BYTECODE(CHECK_GT) { 359 BYTECODE(CHECK_GT) {
283 int limit = Load16(pc + 1); 360 uint32_t limit = Load16(pc + 1);
284 if (current_char > limit) { 361 if (current_char > limit) {
285 pc = code_base + Load32(pc + 3); 362 pc = code_base + Load32(pc + 3);
286 } else { 363 } else {
287 pc += BC_CHECK_GT_LENGTH; 364 pc += BC_CHECK_GT_LENGTH;
288 } 365 }
289 break; 366 break;
290 } 367 }
291 BYTECODE(CHECK_REGISTER_LT) 368 BYTECODE(CHECK_REGISTER_LT)
292 if (registers[pc[1]] < Load16(pc + 2)) { 369 if (registers[pc[1]] < Load16(pc + 2)) {
293 pc = code_base + Load32(pc + 4); 370 pc = code_base + Load32(pc + 4);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 if (start_position != 0) previous_char = subject_vector[start_position - 1]; 521 if (start_position != 0) previous_char = subject_vector[start_position - 1];
445 return RawMatch(code_base, 522 return RawMatch(code_base,
446 subject_vector, 523 subject_vector,
447 registers, 524 registers,
448 start_position, 525 start_position,
449 previous_char); 526 previous_char);
450 } 527 }
451 } 528 }
452 529
453 } } // namespace v8::internal 530 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bytecodes-irregexp.h ('k') | src/jsregexp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698