1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #if V8_TARGET_ARCH_IA32
6
7 #include "src/regexp/ia32/regexp-macro-assembler-ia32.h"
8
9 #include "src/assembler-inl.h"
10 #include "src/log.h"
11 #include "src/macro-assembler.h"
12 #include "src/objects-inl.h"
13 #include "src/regexp/regexp-macro-assembler.h"
14 #include "src/regexp/regexp-stack.h"
15 #include "src/unicode.h"
16
17 namespace v8 {
18 namespace internal {
19
20 #ifndef V8_INTERPRETED_REGEXP
21 /*
22 * This assembler uses the following register assignment convention
23 * - edx : Current character. Must be loaded using LoadCurrentCharacter
24 * before using any of the dispatch methods. Temporarily stores the
25 * index of capture start after a matching pass for a global regexp.
26 * - edi : Current position in input, as negative offset from end of string.
27 * Please notice that this is the byte offset, not the character offset!
28 * - esi : end of input (points to byte after last character in input).
29 * - ebp : Frame pointer. Used to access arguments, local variables and
30 * RegExp registers.
31 * - esp : Points to tip of C stack.
32 * - ecx : Points to tip of backtrack stack
33 *
34 * The registers eax and ebx are free to use for computations.
35 *
36 * Each call to a public method should retain this convention.
37 * The stack will have the following structure:
38 * - Isolate* isolate (address of the current isolate)
39 * - direct_call (if 1, direct call from JavaScript code, if 0
40 * call through the runtime system)
41 * - stack_area_base (high end of the memory area to use as
42 * backtracking stack)
43 * - capture array size (may fit multiple sets of matches)
44 * - int* capture_array (int[num_saved_registers_], for output).
45 * - end of input (address of end of string)
46 * - start of input (address of first character in string)
47 * - start index (character index of start)
48 * - String* input_string (location of a handle containing the string)
49 * --- frame alignment (if applicable) ---
50 * - return address
51 * ebp-> - old ebp
52 * - backup of caller esi
53 * - backup of caller edi
54 * - backup of caller ebx
55 * - success counter (only for global regexps to count matches).
56 * - Offset of location before start of input (effectively character
57 * string start - 1). Used to initialize capture registers to a
58 * non-position.
59 * - register 0 ebp[-4] (only positions must be stored in the first
60 * - register 1 ebp[-8] num_saved_registers_ registers)
61 * - ...
62 *
63 * The first num_saved_registers_ registers are initialized to point to
64 * "character -1" in the string (i.e., char_size() bytes before the first
65 * character of the string). The remaining registers starts out as garbage.
66 *
67 * The data up to the return address must be placed there by the calling
68 * code, by calling the code entry as cast to a function with the signature:
69 * int (*match)(String* input_string,
70 * int start_index,
71 * Address start,
72 * Address end,
73 * int* capture_output_array,
74 * int num_capture_registers,
75 * byte* stack_area_base,
76 * bool direct_call = false,
77 * Isolate* isolate);
78 */
79
80 #define __ ACCESS_MASM(masm_)
81
RegExpMacroAssemblerIA32(Isolate * isolate,Zone * zone,Mode mode,int registers_to_save)82 RegExpMacroAssemblerIA32::RegExpMacroAssemblerIA32(Isolate* isolate, Zone* zone,
83 Mode mode,
84 int registers_to_save)
85 : NativeRegExpMacroAssembler(isolate, zone),
86 masm_(new MacroAssembler(isolate, nullptr, kRegExpCodeSize,
87 CodeObjectRequired::kYes)),
88 mode_(mode),
89 num_registers_(registers_to_save),
90 num_saved_registers_(registers_to_save),
91 entry_label_(),
92 start_label_(),
93 success_label_(),
94 backtrack_label_(),
95 exit_label_() {
96 DCHECK_EQ(0, registers_to_save % 2);
97 __ jmp(&entry_label_); // We'll write the entry code later.
98 __ bind(&start_label_); // And then continue from here.
99 }
100
101
~RegExpMacroAssemblerIA32()102 RegExpMacroAssemblerIA32::~RegExpMacroAssemblerIA32() {
103 delete masm_;
104 // Unuse labels in case we throw away the assembler without calling GetCode.
105 entry_label_.Unuse();
106 start_label_.Unuse();
107 success_label_.Unuse();
108 backtrack_label_.Unuse();
109 exit_label_.Unuse();
110 check_preempt_label_.Unuse();
111 stack_overflow_label_.Unuse();
112 }
113
114
stack_limit_slack()115 int RegExpMacroAssemblerIA32::stack_limit_slack() {
116 return RegExpStack::kStackLimitSlack;
117 }
118
119
AdvanceCurrentPosition(int by)120 void RegExpMacroAssemblerIA32::AdvanceCurrentPosition(int by) {
121 if (by != 0) {
122 __ add(edi, Immediate(by * char_size()));
123 }
124 }
125
126
AdvanceRegister(int reg,int by)127 void RegExpMacroAssemblerIA32::AdvanceRegister(int reg, int by) {
128 DCHECK_LE(0, reg);
129 DCHECK_GT(num_registers_, reg);
130 if (by != 0) {
131 __ add(register_location(reg), Immediate(by));
132 }
133 }
134
135
Backtrack()136 void RegExpMacroAssemblerIA32::Backtrack() {
137 CheckPreemption();
138 // Pop Code* offset from backtrack stack, add Code* and jump to location.
139 Pop(ebx);
140 __ add(ebx, Immediate(masm_->CodeObject()));
141 __ jmp(ebx);
142 }
143
144
Bind(Label * label)145 void RegExpMacroAssemblerIA32::Bind(Label* label) {
146 __ bind(label);
147 }
148
149
CheckCharacter(uint32_t c,Label * on_equal)150 void RegExpMacroAssemblerIA32::CheckCharacter(uint32_t c, Label* on_equal) {
151 __ cmp(current_character(), c);
152 BranchOrBacktrack(equal, on_equal);
153 }
154
155
CheckCharacterGT(uc16 limit,Label * on_greater)156 void RegExpMacroAssemblerIA32::CheckCharacterGT(uc16 limit, Label* on_greater) {
157 __ cmp(current_character(), limit);
158 BranchOrBacktrack(greater, on_greater);
159 }
160
161
CheckAtStart(Label * on_at_start)162 void RegExpMacroAssemblerIA32::CheckAtStart(Label* on_at_start) {
163 __ lea(eax, Operand(edi, -char_size()));
164 __ cmp(eax, Operand(ebp, kStringStartMinusOne));
165 BranchOrBacktrack(equal, on_at_start);
166 }
167
168
CheckNotAtStart(int cp_offset,Label * on_not_at_start)169 void RegExpMacroAssemblerIA32::CheckNotAtStart(int cp_offset,
170 Label* on_not_at_start) {
171 __ lea(eax, Operand(edi, -char_size() + cp_offset * char_size()));
172 __ cmp(eax, Operand(ebp, kStringStartMinusOne));
173 BranchOrBacktrack(not_equal, on_not_at_start);
174 }
175
176
CheckCharacterLT(uc16 limit,Label * on_less)177 void RegExpMacroAssemblerIA32::CheckCharacterLT(uc16 limit, Label* on_less) {
178 __ cmp(current_character(), limit);
179 BranchOrBacktrack(less, on_less);
180 }
181
182
CheckGreedyLoop(Label * on_equal)183 void RegExpMacroAssemblerIA32::CheckGreedyLoop(Label* on_equal) {
184 Label fallthrough;
185 __ cmp(edi, Operand(backtrack_stackpointer(), 0));
186 __ j(not_equal, &fallthrough);
187 __ add(backtrack_stackpointer(), Immediate(kPointerSize)); // Pop.
188 BranchOrBacktrack(no_condition, on_equal);
189 __ bind(&fallthrough);
190 }
191
192
CheckNotBackReferenceIgnoreCase(int start_reg,bool read_backward,bool unicode,Label * on_no_match)193 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase(
194 int start_reg, bool read_backward, bool unicode, Label* on_no_match) {
195 Label fallthrough;
196 __ mov(edx, register_location(start_reg)); // Index of start of capture
197 __ mov(ebx, register_location(start_reg + 1)); // Index of end of capture
198 __ sub(ebx, edx); // Length of capture.
199
200 // At this point, the capture registers are either both set or both cleared.
201 // If the capture length is zero, then the capture is either empty or cleared.
202 // Fall through in both cases.
203 __ j(equal, &fallthrough);
204
205 // Check that there are sufficient characters left in the input.
206 if (read_backward) {
207 __ mov(eax, Operand(ebp, kStringStartMinusOne));
208 __ add(eax, ebx);
209 __ cmp(edi, eax);
210 BranchOrBacktrack(less_equal, on_no_match);
211 } else {
212 __ mov(eax, edi);
213 __ add(eax, ebx);
214 BranchOrBacktrack(greater, on_no_match);
215 }
216
217 if (mode_ == LATIN1) {
218 Label success;
219 Label fail;
220 Label loop_increment;
221 // Save register contents to make the registers available below.
222 __ push(edi);
223 __ push(backtrack_stackpointer());
224 // After this, the eax, ecx, and edi registers are available.
225
226 __ add(edx, esi); // Start of capture
227 __ add(edi, esi); // Start of text to match against capture.
228 if (read_backward) {
229 __ sub(edi, ebx); // Offset by length when matching backwards.
230 }
231 __ add(ebx, edi); // End of text to match against capture.
232
233 Label loop;
234 __ bind(&loop);
235 __ movzx_b(eax, Operand(edi, 0));
236 __ cmpb_al(Operand(edx, 0));
237 __ j(equal, &loop_increment);
238
239 // Mismatch, try case-insensitive match (converting letters to lower-case).
240 __ or_(eax, 0x20); // Convert match character to lower-case.
241 __ lea(ecx, Operand(eax, -'a'));
242 __ cmp(ecx, static_cast<int32_t>('z' - 'a')); // Is eax a lowercase letter?
243 Label convert_capture;
244 __ j(below_equal, &convert_capture); // In range 'a'-'z'.
245 // Latin-1: Check for values in range [224,254] but not 247.
246 __ sub(ecx, Immediate(224 - 'a'));
247 __ cmp(ecx, Immediate(254 - 224));
248 __ j(above, &fail); // Weren't Latin-1 letters.
249 __ cmp(ecx, Immediate(247 - 224)); // Check for 247.
250 __ j(equal, &fail);
251 __ bind(&convert_capture);
252 // Also convert capture character.
253 __ movzx_b(ecx, Operand(edx, 0));
254 __ or_(ecx, 0x20);
255
256 __ cmp(eax, ecx);
257 __ j(not_equal, &fail);
258
259 __ bind(&loop_increment);
260 // Increment pointers into match and capture strings.
261 __ add(edx, Immediate(1));
262 __ add(edi, Immediate(1));
263 // Compare to end of match, and loop if not done.
264 __ cmp(edi, ebx);
265 __ j(below, &loop);
266 __ jmp(&success);
267
268 __ bind(&fail);
269 // Restore original values before failing.
270 __ pop(backtrack_stackpointer());
271 __ pop(edi);
272 BranchOrBacktrack(no_condition, on_no_match);
273
274 __ bind(&success);
275 // Restore original value before continuing.
276 __ pop(backtrack_stackpointer());
277 // Drop original value of character position.
278 __ add(esp, Immediate(kPointerSize));
279 // Compute new value of character position after the matched part.
280 __ sub(edi, esi);
281 if (read_backward) {
282 // Subtract match length if we matched backward.
283 __ add(edi, register_location(start_reg));
284 __ sub(edi, register_location(start_reg + 1));
285 }
286 } else {
287 DCHECK(mode_ == UC16);
288 // Save registers before calling C function.
289 __ push(esi);
290 __ push(edi);
291 __ push(backtrack_stackpointer());
292 __ push(ebx);
293
294 static const int argument_count = 4;
295 __ PrepareCallCFunction(argument_count, ecx);
296 // Put arguments into allocated stack area, last argument highest on stack.
297 // Parameters are
298 // Address byte_offset1 - Address captured substring's start.
299 // Address byte_offset2 - Address of current character position.
300 // size_t byte_length - length of capture in bytes(!)
301 // Isolate* isolate or 0 if unicode flag.
302
303 // Set isolate.
304 #ifdef V8_INTL_SUPPORT
305 if (unicode) {
306 __ mov(Operand(esp, 3 * kPointerSize), Immediate(0));
307 } else // NOLINT
308 #endif // V8_INTL_SUPPORT
309 {
310 __ mov(Operand(esp, 3 * kPointerSize),
311 Immediate(ExternalReference::isolate_address(isolate())));
312 }
313 // Set byte_length.
314 __ mov(Operand(esp, 2 * kPointerSize), ebx);
315 // Set byte_offset2.
316 // Found by adding negative string-end offset of current position (edi)
317 // to end of string.
318 __ add(edi, esi);
319 if (read_backward) {
320 __ sub(edi, ebx); // Offset by length when matching backwards.
321 }
322 __ mov(Operand(esp, 1 * kPointerSize), edi);
323 // Set byte_offset1.
324 // Start of capture, where edx already holds string-end negative offset.
325 __ add(edx, esi);
326 __ mov(Operand(esp, 0 * kPointerSize), edx);
327
328 {
329 AllowExternalCallThatCantCauseGC scope(masm_);
330 ExternalReference compare =
331 ExternalReference::re_case_insensitive_compare_uc16(isolate());
332 __ CallCFunction(compare, argument_count);
333 }
334 // Pop original values before reacting on result value.
335 __ pop(ebx);
336 __ pop(backtrack_stackpointer());
337 __ pop(edi);
338 __ pop(esi);
339
340 // Check if function returned non-zero for success or zero for failure.
341 __ or_(eax, eax);
342 BranchOrBacktrack(zero, on_no_match);
343 // On success, advance position by length of capture.
344 if (read_backward) {
345 __ sub(edi, ebx);
346 } else {
347 __ add(edi, ebx);
348 }
349 }
350 __ bind(&fallthrough);
351 }
352
353
CheckNotBackReference(int start_reg,bool read_backward,Label * on_no_match)354 void RegExpMacroAssemblerIA32::CheckNotBackReference(int start_reg,
355 bool read_backward,
356 Label* on_no_match) {
357 Label fallthrough;
358 Label success;
359 Label fail;
360
361 // Find length of back-referenced capture.
362 __ mov(edx, register_location(start_reg));
363 __ mov(eax, register_location(start_reg + 1));
364 __ sub(eax, edx); // Length to check.
365
366 // At this point, the capture registers are either both set or both cleared.
367 // If the capture length is zero, then the capture is either empty or cleared.
368 // Fall through in both cases.
369 __ j(equal, &fallthrough);
370
371 // Check that there are sufficient characters left in the input.
372 if (read_backward) {
373 __ mov(ebx, Operand(ebp, kStringStartMinusOne));
374 __ add(ebx, eax);
375 __ cmp(edi, ebx);
376 BranchOrBacktrack(less_equal, on_no_match);
377 } else {
378 __ mov(ebx, edi);
379 __ add(ebx, eax);
380 BranchOrBacktrack(greater, on_no_match);
381 }
382
383 // Save register to make it available below.
384 __ push(backtrack_stackpointer());
385
386 // Compute pointers to match string and capture string
387 __ add(edx, esi); // Start of capture.
388 __ lea(ebx, Operand(esi, edi, times_1, 0)); // Start of match.
389 if (read_backward) {
390 __ sub(ebx, eax); // Offset by length when matching backwards.
391 }
392 __ lea(ecx, Operand(eax, ebx, times_1, 0)); // End of match
393
394 Label loop;
395 __ bind(&loop);
396 if (mode_ == LATIN1) {
397 __ movzx_b(eax, Operand(edx, 0));
398 __ cmpb_al(Operand(ebx, 0));
399 } else {
400 DCHECK(mode_ == UC16);
401 __ movzx_w(eax, Operand(edx, 0));
402 __ cmpw_ax(Operand(ebx, 0));
403 }
404 __ j(not_equal, &fail);
405 // Increment pointers into capture and match string.
406 __ add(edx, Immediate(char_size()));
407 __ add(ebx, Immediate(char_size()));
408 // Check if we have reached end of match area.
409 __ cmp(ebx, ecx);
410 __ j(below, &loop);
411 __ jmp(&success);
412
413 __ bind(&fail);
414 // Restore backtrack stackpointer.
415 __ pop(backtrack_stackpointer());
416 BranchOrBacktrack(no_condition, on_no_match);
417
418 __ bind(&success);
419 // Move current character position to position after match.
420 __ mov(edi, ecx);
421 __ sub(edi, esi);
422 if (read_backward) {
423 // Subtract match length if we matched backward.
424 __ add(edi, register_location(start_reg));
425 __ sub(edi, register_location(start_reg + 1));
426 }
427 // Restore backtrack stackpointer.
428 __ pop(backtrack_stackpointer());
429
430 __ bind(&fallthrough);
431 }
432
433
CheckNotCharacter(uint32_t c,Label * on_not_equal)434 void RegExpMacroAssemblerIA32::CheckNotCharacter(uint32_t c,
435 Label* on_not_equal) {
436 __ cmp(current_character(), c);
437 BranchOrBacktrack(not_equal, on_not_equal);
438 }
439
440
CheckCharacterAfterAnd(uint32_t c,uint32_t mask,Label * on_equal)441 void RegExpMacroAssemblerIA32::CheckCharacterAfterAnd(uint32_t c,
442 uint32_t mask,
443 Label* on_equal) {
444 if (c == 0) {
445 __ test(current_character(), Immediate(mask));
446 } else {
447 __ mov(eax, mask);
448 __ and_(eax, current_character());
449 __ cmp(eax, c);
450 }
451 BranchOrBacktrack(equal, on_equal);
452 }
453
454
CheckNotCharacterAfterAnd(uint32_t c,uint32_t mask,Label * on_not_equal)455 void RegExpMacroAssemblerIA32::CheckNotCharacterAfterAnd(uint32_t c,
456 uint32_t mask,
457 Label* on_not_equal) {
458 if (c == 0) {
459 __ test(current_character(), Immediate(mask));
460 } else {
461 __ mov(eax, mask);
462 __ and_(eax, current_character());
463 __ cmp(eax, c);
464 }
465 BranchOrBacktrack(not_equal, on_not_equal);
466 }
467
468
CheckNotCharacterAfterMinusAnd(uc16 c,uc16 minus,uc16 mask,Label * on_not_equal)469 void RegExpMacroAssemblerIA32::CheckNotCharacterAfterMinusAnd(
470 uc16 c,
471 uc16 minus,
472 uc16 mask,
473 Label* on_not_equal) {
474 DCHECK_GT(String::kMaxUtf16CodeUnit, minus);
475 __ lea(eax, Operand(current_character(), -minus));
476 if (c == 0) {
477 __ test(eax, Immediate(mask));
478 } else {
479 __ and_(eax, mask);
480 __ cmp(eax, c);
481 }
482 BranchOrBacktrack(not_equal, on_not_equal);
483 }
484
485
CheckCharacterInRange(uc16 from,uc16 to,Label * on_in_range)486 void RegExpMacroAssemblerIA32::CheckCharacterInRange(
487 uc16 from,
488 uc16 to,
489 Label* on_in_range) {
490 __ lea(eax, Operand(current_character(), -from));
491 __ cmp(eax, to - from);
492 BranchOrBacktrack(below_equal, on_in_range);
493 }
494
495
CheckCharacterNotInRange(uc16 from,uc16 to,Label * on_not_in_range)496 void RegExpMacroAssemblerIA32::CheckCharacterNotInRange(
497 uc16 from,
498 uc16 to,
499 Label* on_not_in_range) {
500 __ lea(eax, Operand(current_character(), -from));
501 __ cmp(eax, to - from);
502 BranchOrBacktrack(above, on_not_in_range);
503 }
504
505
CheckBitInTable(Handle<ByteArray> table,Label * on_bit_set)506 void RegExpMacroAssemblerIA32::CheckBitInTable(
507 Handle<ByteArray> table,
508 Label* on_bit_set) {
509 __ mov(eax, Immediate(table));
510 Register index = current_character();
511 if (mode_ != LATIN1 || kTableMask != String::kMaxOneByteCharCode) {
512 __ mov(ebx, kTableSize - 1);
513 __ and_(ebx, current_character());
514 index = ebx;
515 }
516 __ cmpb(FieldOperand(eax, index, times_1, ByteArray::kHeaderSize),
517 Immediate(0));
518 BranchOrBacktrack(not_equal, on_bit_set);
519 }
520
521
CheckSpecialCharacterClass(uc16 type,Label * on_no_match)522 bool RegExpMacroAssemblerIA32::CheckSpecialCharacterClass(uc16 type,
523 Label* on_no_match) {
524 // Range checks (c in min..max) are generally implemented by an unsigned
525 // (c - min) <= (max - min) check
526 switch (type) {
527 case 's':
528 // Match space-characters
529 if (mode_ == LATIN1) {
530 // One byte space characters are '\t'..'\r', ' ' and \u00a0.
531 Label success;
532 __ cmp(current_character(), ' ');
533 __ j(equal, &success, Label::kNear);
534 // Check range 0x09..0x0D
535 __ lea(eax, Operand(current_character(), -'\t'));
536 __ cmp(eax, '\r' - '\t');
537 __ j(below_equal, &success, Label::kNear);
538 // \u00a0 (NBSP).
539 __ cmp(eax, 0x00A0 - '\t');
540 BranchOrBacktrack(not_equal, on_no_match);
541 __ bind(&success);
542 return true;
543 }
544 return false;
545 case 'S':
546 // The emitted code for generic character classes is good enough.
547 return false;
548 case 'd':
549 // Match ASCII digits ('0'..'9')
550 __ lea(eax, Operand(current_character(), -'0'));
551 __ cmp(eax, '9' - '0');
552 BranchOrBacktrack(above, on_no_match);
553 return true;
554 case 'D':
555 // Match non ASCII-digits
556 __ lea(eax, Operand(current_character(), -'0'));
557 __ cmp(eax, '9' - '0');
558 BranchOrBacktrack(below_equal, on_no_match);
559 return true;
560 case '.': {
561 // Match non-newlines (not 0x0A('\n'), 0x0D('\r'), 0x2028 and 0x2029)
562 __ mov(eax, current_character());
563 __ xor_(eax, Immediate(0x01));
564 // See if current character is '\n'^1 or '\r'^1, i.e., 0x0B or 0x0C
565 __ sub(eax, Immediate(0x0B));
566 __ cmp(eax, 0x0C - 0x0B);
567 BranchOrBacktrack(below_equal, on_no_match);
568 if (mode_ == UC16) {
569 // Compare original value to 0x2028 and 0x2029, using the already
570 // computed (current_char ^ 0x01 - 0x0B). I.e., check for
571 // 0x201D (0x2028 - 0x0B) or 0x201E.
572 __ sub(eax, Immediate(0x2028 - 0x0B));
573 __ cmp(eax, 0x2029 - 0x2028);
574 BranchOrBacktrack(below_equal, on_no_match);
575 }
576 return true;
577 }
578 case 'w': {
579 if (mode_ != LATIN1) {
580 // Table is 256 entries, so all Latin1 characters can be tested.
581 __ cmp(current_character(), Immediate('z'));
582 BranchOrBacktrack(above, on_no_match);
583 }
584 DCHECK_EQ(0, word_character_map[0]); // Character '\0' is not a word char.
585 ExternalReference word_map =
586 ExternalReference::re_word_character_map(isolate());
587 __ test_b(current_character(),
588 masm_->StaticArray(current_character(), times_1, word_map));
589 BranchOrBacktrack(zero, on_no_match);
590 return true;
591 }
592 case 'W': {
593 Label done;
594 if (mode_ != LATIN1) {
595 // Table is 256 entries, so all Latin1 characters can be tested.
596 __ cmp(current_character(), Immediate('z'));
597 __ j(above, &done);
598 }
599 DCHECK_EQ(0, word_character_map[0]); // Character '\0' is not a word char.
600 ExternalReference word_map =
601 ExternalReference::re_word_character_map(isolate());
602 __ test_b(current_character(),
603 masm_->StaticArray(current_character(), times_1, word_map));
604 BranchOrBacktrack(not_zero, on_no_match);
605 if (mode_ != LATIN1) {
606 __ bind(&done);
607 }
608 return true;
609 }
610 // Non-standard classes (with no syntactic shorthand) used internally.
611 case '*':
612 // Match any character.
613 return true;
614 case 'n': {
615 // Match newlines (0x0A('\n'), 0x0D('\r'), 0x2028 or 0x2029).
616 // The opposite of '.'.
617 __ mov(eax, current_character());
618 __ xor_(eax, Immediate(0x01));
619 // See if current character is '\n'^1 or '\r'^1, i.e., 0x0B or 0x0C
620 __ sub(eax, Immediate(0x0B));
621 __ cmp(eax, 0x0C - 0x0B);
622 if (mode_ == LATIN1) {
623 BranchOrBacktrack(above, on_no_match);
624 } else {
625 Label done;
626 BranchOrBacktrack(below_equal, &done);
627 DCHECK_EQ(UC16, mode_);
628 // Compare original value to 0x2028 and 0x2029, using the already
629 // computed (current_char ^ 0x01 - 0x0B). I.e., check for
630 // 0x201D (0x2028 - 0x0B) or 0x201E.
631 __ sub(eax, Immediate(0x2028 - 0x0B));
632 __ cmp(eax, 1);
633 BranchOrBacktrack(above, on_no_match);
634 __ bind(&done);
635 }
636 return true;
637 }
638 // No custom implementation (yet): s(UC16), S(UC16).
639 default:
640 return false;
641 }
642 }
643
644
Fail()645 void RegExpMacroAssemblerIA32::Fail() {
646 STATIC_ASSERT(FAILURE == 0); // Return value for failure is zero.
647 if (!global()) {
648 __ Move(eax, Immediate(FAILURE));
649 }
650 __ jmp(&exit_label_);
651 }
652
653
GetCode(Handle<String> source)654 Handle<HeapObject> RegExpMacroAssemblerIA32::GetCode(Handle<String> source) {
655 Label return_eax;
656 // Finalize code - write the entry point code now we know how many
657 // registers we need.
658
659 // Entry code:
660 __ bind(&entry_label_);
661
662 // Tell the system that we have a stack frame. Because the type is MANUAL, no
663 // code is generated.
664 FrameScope scope(masm_, StackFrame::MANUAL);
665
666 // Actually emit code to start a new stack frame.
667 __ push(ebp);
668 __ mov(ebp, esp);
669 // Save callee-save registers. Order here should correspond to order of
670 // kBackup_ebx etc.
671 __ push(esi);
672 __ push(edi);
673 __ push(ebx); // Callee-save on MacOS.
674 __ push(Immediate(0)); // Number of successful matches in a global regexp.
675 __ push(Immediate(0)); // Make room for "string start - 1" constant.
676
677 // Check if we have space on the stack for registers.
678 Label stack_limit_hit;
679 Label stack_ok;
680
681 ExternalReference stack_limit =
682 ExternalReference::address_of_stack_limit(isolate());
683 __ mov(ecx, esp);
684 __ sub(ecx, masm_->StaticVariable(stack_limit));
685 // Handle it if the stack pointer is already below the stack limit.
686 __ j(below_equal, &stack_limit_hit);
687 // Check if there is room for the variable number of registers above
688 // the stack limit.
689 __ cmp(ecx, num_registers_ * kPointerSize);
690 __ j(above_equal, &stack_ok);
691 // Exit with OutOfMemory exception. There is not enough space on the stack
692 // for our working registers.
693 __ mov(eax, EXCEPTION);
694 __ jmp(&return_eax);
695
696 __ bind(&stack_limit_hit);
697 CallCheckStackGuardState(ebx);
698 __ or_(eax, eax);
699 // If returned value is non-zero, we exit with the returned value as result.
700 __ j(not_zero, &return_eax);
701
702 __ bind(&stack_ok);
703 // Load start index for later use.
704 __ mov(ebx, Operand(ebp, kStartIndex));
705
706 // Allocate space on stack for registers.
707 __ sub(esp, Immediate(num_registers_ * kPointerSize));
708 // Load string length.
709 __ mov(esi, Operand(ebp, kInputEnd));
710 // Load input position.
711 __ mov(edi, Operand(ebp, kInputStart));
712 // Set up edi to be negative offset from string end.
713 __ sub(edi, esi);
714
715 // Set eax to address of char before start of the string.
716 // (effectively string position -1).
717 __ neg(ebx);
718 if (mode_ == UC16) {
719 __ lea(eax, Operand(edi, ebx, times_2, -char_size()));
720 } else {
721 __ lea(eax, Operand(edi, ebx, times_1, -char_size()));
722 }
723 // Store this value in a local variable, for use when clearing
724 // position registers.
725 __ mov(Operand(ebp, kStringStartMinusOne), eax);
726
727 #if V8_OS_WIN
728 // Ensure that we write to each stack page, in order. Skipping a page
729 // on Windows can cause segmentation faults. Assuming page size is 4k.
730 const int kPageSize = 4096;
731 const int kRegistersPerPage = kPageSize / kPointerSize;
732 for (int i = num_saved_registers_ + kRegistersPerPage - 1;
733 i < num_registers_;
734 i += kRegistersPerPage) {
735 __ mov(register_location(i), eax); // One write every page.
736 }
737 #endif // V8_OS_WIN
738
739 Label load_char_start_regexp, start_regexp;
740 // Load newline if index is at start, previous character otherwise.
741 __ cmp(Operand(ebp, kStartIndex), Immediate(0));
742 __ j(not_equal, &load_char_start_regexp, Label::kNear);
743 __ mov(current_character(), '\n');
744 __ jmp(&start_regexp, Label::kNear);
745
746 // Global regexp restarts matching here.
747 __ bind(&load_char_start_regexp);
748 // Load previous char as initial value of current character register.
749 LoadCurrentCharacterUnchecked(-1, 1);
750 __ bind(&start_regexp);
751
752 // Initialize on-stack registers.
753 if (num_saved_registers_ > 0) { // Always is, if generated from a regexp.
754 // Fill saved registers with initial value = start offset - 1
755 // Fill in stack push order, to avoid accessing across an unwritten
756 // page (a problem on Windows).
757 if (num_saved_registers_ > 8) {
758 __ mov(ecx, kRegisterZero);
759 Label init_loop;
760 __ bind(&init_loop);
761 __ mov(Operand(ebp, ecx, times_1, 0), eax);
762 __ sub(ecx, Immediate(kPointerSize));
763 __ cmp(ecx, kRegisterZero - num_saved_registers_ * kPointerSize);
764 __ j(greater, &init_loop);
765 } else { // Unroll the loop.
766 for (int i = 0; i < num_saved_registers_; i++) {
767 __ mov(register_location(i), eax);
768 }
769 }
770 }
771
772 // Initialize backtrack stack pointer.
773 __ mov(backtrack_stackpointer(), Operand(ebp, kStackHighEnd));
774
775 __ jmp(&start_label_);
776
777 // Exit code:
778 if (success_label_.is_linked()) {
779 // Save captures when successful.
780 __ bind(&success_label_);
781 if (num_saved_registers_ > 0) {
782 // copy captures to output
783 __ mov(ebx, Operand(ebp, kRegisterOutput));
784 __ mov(ecx, Operand(ebp, kInputEnd));
785 __ mov(edx, Operand(ebp, kStartIndex));
786 __ sub(ecx, Operand(ebp, kInputStart));
787 if (mode_ == UC16) {
788 __ lea(ecx, Operand(ecx, edx, times_2, 0));
789 } else {
790 __ add(ecx, edx);
791 }
792 for (int i = 0; i < num_saved_registers_; i++) {
793 __ mov(eax, register_location(i));
794 if (i == 0 && global_with_zero_length_check()) {
795 // Keep capture start in edx for the zero-length check later.
796 __ mov(edx, eax);
797 }
798 // Convert to index from start of string, not end.
799 __ add(eax, ecx);
800 if (mode_ == UC16) {
801 __ sar(eax, 1); // Convert byte index to character index.
802 }
803 __ mov(Operand(ebx, i * kPointerSize), eax);
804 }
805 }
806
807 if (global()) {
808 // Restart matching if the regular expression is flagged as global.
809 // Increment success counter.
810 __ inc(Operand(ebp, kSuccessfulCaptures));
811 // Capture results have been stored, so the number of remaining global
812 // output registers is reduced by the number of stored captures.
813 __ mov(ecx, Operand(ebp, kNumOutputRegisters));
814 __ sub(ecx, Immediate(num_saved_registers_));
815 // Check whether we have enough room for another set of capture results.
816 __ cmp(ecx, Immediate(num_saved_registers_));
817 __ j(less, &exit_label_);
818
819 __ mov(Operand(ebp, kNumOutputRegisters), ecx);
820 // Advance the location for output.
821 __ add(Operand(ebp, kRegisterOutput),
822 Immediate(num_saved_registers_ * kPointerSize));
823
824 // Prepare eax to initialize registers with its value in the next run.
825 __ mov(eax, Operand(ebp, kStringStartMinusOne));
826
827 if (global_with_zero_length_check()) {
828 // Special case for zero-length matches.
829 // edx: capture start index
830 __ cmp(edi, edx);
831 // Not a zero-length match, restart.
832 __ j(not_equal, &load_char_start_regexp);
833 // edi (offset from the end) is zero if we already reached the end.
834 __ test(edi, edi);
835 __ j(zero, &exit_label_, Label::kNear);
836 // Advance current position after a zero-length match.
837 Label advance;
838 __ bind(&advance);
839 if (mode_ == UC16) {
840 __ add(edi, Immediate(2));
841 } else {
842 __ inc(edi);
843 }
844 if (global_unicode()) CheckNotInSurrogatePair(0, &advance);
845 }
846 __ jmp(&load_char_start_regexp);
847 } else {
848 __ mov(eax, Immediate(SUCCESS));
849 }
850 }
851
852 __ bind(&exit_label_);
853 if (global()) {
854 // Return the number of successful captures.
855 __ mov(eax, Operand(ebp, kSuccessfulCaptures));
856 }
857
858 __ bind(&return_eax);
859 // Skip esp past regexp registers.
860 __ lea(esp, Operand(ebp, kBackup_ebx));
861 // Restore callee-save registers.
862 __ pop(ebx);
863 __ pop(edi);
864 __ pop(esi);
865 // Exit function frame, restore previous one.
866 __ pop(ebp);
867 __ ret(0);
868
869 // Backtrack code (branch target for conditional backtracks).
870 if (backtrack_label_.is_linked()) {
871 __ bind(&backtrack_label_);
872 Backtrack();
873 }
874
875 Label exit_with_exception;
876
877 // Preempt-code
878 if (check_preempt_label_.is_linked()) {
879 SafeCallTarget(&check_preempt_label_);
880
881 __ push(backtrack_stackpointer());
882 __ push(edi);
883
884 CallCheckStackGuardState(ebx);
885 __ or_(eax, eax);
886 // If returning non-zero, we should end execution with the given
887 // result as return value.
888 __ j(not_zero, &return_eax);
889
890 __ pop(edi);
891 __ pop(backtrack_stackpointer());
892 // String might have moved: Reload esi from frame.
893 __ mov(esi, Operand(ebp, kInputEnd));
894 SafeReturn();
895 }
896
897 // Backtrack stack overflow code.
898 if (stack_overflow_label_.is_linked()) {
899 SafeCallTarget(&stack_overflow_label_);
900 // Reached if the backtrack-stack limit has been hit.
901
902 Label grow_failed;
903 // Save registers before calling C function
904 __ push(esi);
905 __ push(edi);
906
907 // Call GrowStack(backtrack_stackpointer())
908 static const int num_arguments = 3;
909 __ PrepareCallCFunction(num_arguments, ebx);
910 __ mov(Operand(esp, 2 * kPointerSize),
911 Immediate(ExternalReference::isolate_address(isolate())));
912 __ lea(eax, Operand(ebp, kStackHighEnd));
913 __ mov(Operand(esp, 1 * kPointerSize), eax);
914 __ mov(Operand(esp, 0 * kPointerSize), backtrack_stackpointer());
915 ExternalReference grow_stack =
916 ExternalReference::re_grow_stack(isolate());
917 __ CallCFunction(grow_stack, num_arguments);
918 // If return nullptr, we have failed to grow the stack, and
919 // must exit with a stack-overflow exception.
920 __ or_(eax, eax);
921 __ j(equal, &exit_with_exception);
922 // Otherwise use return value as new stack pointer.
923 __ mov(backtrack_stackpointer(), eax);
924 // Restore saved registers and continue.
925 __ pop(edi);
926 __ pop(esi);
927 SafeReturn();
928 }
929
930 if (exit_with_exception.is_linked()) {
931 // If any of the code above needed to exit with an exception.
932 __ bind(&exit_with_exception);
933 // Exit with Result EXCEPTION(-1) to signal thrown exception.
934 __ mov(eax, EXCEPTION);
935 __ jmp(&return_eax);
936 }
937
938 CodeDesc code_desc;
939 masm_->GetCode(masm_->isolate(), &code_desc);
940 Handle<Code> code = isolate()->factory()->NewCode(code_desc, Code::REGEXP,
941 masm_->CodeObject());
942 PROFILE(masm_->isolate(),
943 RegExpCodeCreateEvent(AbstractCode::cast(*code), *source));
944 return Handle<HeapObject>::cast(code);
945 }
946
947
GoTo(Label * to)948 void RegExpMacroAssemblerIA32::GoTo(Label* to) {
949 BranchOrBacktrack(no_condition, to);
950 }
951
952
IfRegisterGE(int reg,int comparand,Label * if_ge)953 void RegExpMacroAssemblerIA32::IfRegisterGE(int reg,
954 int comparand,
955 Label* if_ge) {
956 __ cmp(register_location(reg), Immediate(comparand));
957 BranchOrBacktrack(greater_equal, if_ge);
958 }
959
960
IfRegisterLT(int reg,int comparand,Label * if_lt)961 void RegExpMacroAssemblerIA32::IfRegisterLT(int reg,
962 int comparand,
963 Label* if_lt) {
964 __ cmp(register_location(reg), Immediate(comparand));
965 BranchOrBacktrack(less, if_lt);
966 }
967
968
IfRegisterEqPos(int reg,Label * if_eq)969 void RegExpMacroAssemblerIA32::IfRegisterEqPos(int reg,
970 Label* if_eq) {
971 __ cmp(edi, register_location(reg));
972 BranchOrBacktrack(equal, if_eq);
973 }
974
975
976 RegExpMacroAssembler::IrregexpImplementation
Implementation()977 RegExpMacroAssemblerIA32::Implementation() {
978 return kIA32Implementation;
979 }
980
981
LoadCurrentCharacter(int cp_offset,Label * on_end_of_input,bool check_bounds,int characters)982 void RegExpMacroAssemblerIA32::LoadCurrentCharacter(int cp_offset,
983 Label* on_end_of_input,
984 bool check_bounds,
985 int characters) {
986 DCHECK(cp_offset < (1<<30)); // Be sane! (And ensure negation works)
987 if (check_bounds) {
988 if (cp_offset >= 0) {
989 CheckPosition(cp_offset + characters - 1, on_end_of_input);
990 } else {
991 CheckPosition(cp_offset, on_end_of_input);
992 }
993 }
994 LoadCurrentCharacterUnchecked(cp_offset, characters);
995 }
996
997
PopCurrentPosition()998 void RegExpMacroAssemblerIA32::PopCurrentPosition() {
999 Pop(edi);
1000 }
1001
1002
PopRegister(int register_index)1003 void RegExpMacroAssemblerIA32::PopRegister(int register_index) {
1004 Pop(eax);
1005 __ mov(register_location(register_index), eax);
1006 }
1007
1008
PushBacktrack(Label * label)1009 void RegExpMacroAssemblerIA32::PushBacktrack(Label* label) {
1010 Push(Immediate::CodeRelativeOffset(label));
1011 CheckStackLimit();
1012 }
1013
1014
PushCurrentPosition()1015 void RegExpMacroAssemblerIA32::PushCurrentPosition() {
1016 Push(edi);
1017 }
1018
1019
PushRegister(int register_index,StackCheckFlag check_stack_limit)1020 void RegExpMacroAssemblerIA32::PushRegister(int register_index,
1021 StackCheckFlag check_stack_limit) {
1022 __ mov(eax, register_location(register_index));
1023 Push(eax);
1024 if (check_stack_limit) CheckStackLimit();
1025 }
1026
1027
ReadCurrentPositionFromRegister(int reg)1028 void RegExpMacroAssemblerIA32::ReadCurrentPositionFromRegister(int reg) {
1029 __ mov(edi, register_location(reg));
1030 }
1031
1032
ReadStackPointerFromRegister(int reg)1033 void RegExpMacroAssemblerIA32::ReadStackPointerFromRegister(int reg) {
1034 __ mov(backtrack_stackpointer(), register_location(reg));
1035 __ add(backtrack_stackpointer(), Operand(ebp, kStackHighEnd));
1036 }
1037
SetCurrentPositionFromEnd(int by)1038 void RegExpMacroAssemblerIA32::SetCurrentPositionFromEnd(int by) {
1039 Label after_position;
1040 __ cmp(edi, -by * char_size());
1041 __ j(greater_equal, &after_position, Label::kNear);
1042 __ mov(edi, -by * char_size());
1043 // On RegExp code entry (where this operation is used), the character before
1044 // the current position is expected to be already loaded.
1045 // We have advanced the position, so it's safe to read backwards.
1046 LoadCurrentCharacterUnchecked(-1, 1);
1047 __ bind(&after_position);
1048 }
1049
1050
SetRegister(int register_index,int to)1051 void RegExpMacroAssemblerIA32::SetRegister(int register_index, int to) {
1052 DCHECK(register_index >= num_saved_registers_); // Reserved for positions!
1053 __ mov(register_location(register_index), Immediate(to));
1054 }
1055
1056
Succeed()1057 bool RegExpMacroAssemblerIA32::Succeed() {
1058 __ jmp(&success_label_);
1059 return global();
1060 }
1061
1062
WriteCurrentPositionToRegister(int reg,int cp_offset)1063 void RegExpMacroAssemblerIA32::WriteCurrentPositionToRegister(int reg,
1064 int cp_offset) {
1065 if (cp_offset == 0) {
1066 __ mov(register_location(reg), edi);
1067 } else {
1068 __ lea(eax, Operand(edi, cp_offset * char_size()));
1069 __ mov(register_location(reg), eax);
1070 }
1071 }
1072
1073
ClearRegisters(int reg_from,int reg_to)1074 void RegExpMacroAssemblerIA32::ClearRegisters(int reg_from, int reg_to) {
1075 DCHECK(reg_from <= reg_to);
1076 __ mov(eax, Operand(ebp, kStringStartMinusOne));
1077 for (int reg = reg_from; reg <= reg_to; reg++) {
1078 __ mov(register_location(reg), eax);
1079 }
1080 }
1081
1082
WriteStackPointerToRegister(int reg)1083 void RegExpMacroAssemblerIA32::WriteStackPointerToRegister(int reg) {
1084 __ mov(eax, backtrack_stackpointer());
1085 __ sub(eax, Operand(ebp, kStackHighEnd));
1086 __ mov(register_location(reg), eax);
1087 }
1088
1089
1090 // Private methods:
1091
CallCheckStackGuardState(Register scratch)1092 void RegExpMacroAssemblerIA32::CallCheckStackGuardState(Register scratch) {
1093 static const int num_arguments = 3;
1094 __ PrepareCallCFunction(num_arguments, scratch);
1095 // RegExp code frame pointer.
1096 __ mov(Operand(esp, 2 * kPointerSize), ebp);
1097 // Code* of self.
1098 __ mov(Operand(esp, 1 * kPointerSize), Immediate(masm_->CodeObject()));
1099 // Next address on the stack (will be address of return address).
1100 __ lea(eax, Operand(esp, -kPointerSize));
1101 __ mov(Operand(esp, 0 * kPointerSize), eax);
1102 ExternalReference check_stack_guard =
1103 ExternalReference::re_check_stack_guard_state(isolate());
1104 __ CallCFunction(check_stack_guard, num_arguments);
1105 }
1106
1107
1108 // Helper function for reading a value out of a stack frame.
1109 template <typename T>
frame_entry(Address re_frame,int frame_offset)1110 static T& frame_entry(Address re_frame, int frame_offset) {
1111 return reinterpret_cast<T&>(Memory<int32_t>(re_frame + frame_offset));
1112 }
1113
1114
1115 template <typename T>
frame_entry_address(Address re_frame,int frame_offset)1116 static T* frame_entry_address(Address re_frame, int frame_offset) {
1117 return reinterpret_cast<T*>(re_frame + frame_offset);
1118 }
1119
1120
CheckStackGuardState(Address * return_address,Code * re_code,Address re_frame)1121 int RegExpMacroAssemblerIA32::CheckStackGuardState(Address* return_address,
1122 Code* re_code,
1123 Address re_frame) {
1124 return NativeRegExpMacroAssembler::CheckStackGuardState(
1125 frame_entry<Isolate*>(re_frame, kIsolate),
1126 frame_entry<int>(re_frame, kStartIndex),
1127 frame_entry<int>(re_frame, kDirectCall) == 1, return_address, re_code,
1128 frame_entry_address<String*>(re_frame, kInputString),
1129 frame_entry_address<const byte*>(re_frame, kInputStart),
1130 frame_entry_address<const byte*>(re_frame, kInputEnd));
1131 }
1132
1133
register_location(int register_index)1134 Operand RegExpMacroAssemblerIA32::register_location(int register_index) {
1135 DCHECK(register_index < (1<<30));
1136 if (num_registers_ <= register_index) {
1137 num_registers_ = register_index + 1;
1138 }
1139 return Operand(ebp, kRegisterZero - register_index * kPointerSize);
1140 }
1141
1142
CheckPosition(int cp_offset,Label * on_outside_input)1143 void RegExpMacroAssemblerIA32::CheckPosition(int cp_offset,
1144 Label* on_outside_input) {
1145 if (cp_offset >= 0) {
1146 __ cmp(edi, -cp_offset * char_size());
1147 BranchOrBacktrack(greater_equal, on_outside_input);
1148 } else {
1149 __ lea(eax, Operand(edi, cp_offset * char_size()));
1150 __ cmp(eax, Operand(ebp, kStringStartMinusOne));
1151 BranchOrBacktrack(less_equal, on_outside_input);
1152 }
1153 }
1154
1155
BranchOrBacktrack(Condition condition,Label * to)1156 void RegExpMacroAssemblerIA32::BranchOrBacktrack(Condition condition,
1157 Label* to) {
1158 if (condition < 0) { // No condition
1159 if (to == nullptr) {
1160 Backtrack();
1161 return;
1162 }
1163 __ jmp(to);
1164 return;
1165 }
1166 if (to == nullptr) {
1167 __ j(condition, &backtrack_label_);
1168 return;
1169 }
1170 __ j(condition, to);
1171 }
1172
1173
SafeCall(Label * to)1174 void RegExpMacroAssemblerIA32::SafeCall(Label* to) {
1175 Label return_to;
1176 __ push(Immediate::CodeRelativeOffset(&return_to));
1177 __ jmp(to);
1178 __ bind(&return_to);
1179 }
1180
1181
SafeReturn()1182 void RegExpMacroAssemblerIA32::SafeReturn() {
1183 __ pop(ebx);
1184 __ add(ebx, Immediate(masm_->CodeObject()));
1185 __ jmp(ebx);
1186 }
1187
1188
SafeCallTarget(Label * name)1189 void RegExpMacroAssemblerIA32::SafeCallTarget(Label* name) {
1190 __ bind(name);
1191 }
1192
1193
Push(Register source)1194 void RegExpMacroAssemblerIA32::Push(Register source) {
1195 DCHECK(source != backtrack_stackpointer());
1196 // Notice: This updates flags, unlike normal Push.
1197 __ sub(backtrack_stackpointer(), Immediate(kPointerSize));
1198 __ mov(Operand(backtrack_stackpointer(), 0), source);
1199 }
1200
1201
Push(Immediate value)1202 void RegExpMacroAssemblerIA32::Push(Immediate value) {
1203 // Notice: This updates flags, unlike normal Push.
1204 __ sub(backtrack_stackpointer(), Immediate(kPointerSize));
1205 __ mov(Operand(backtrack_stackpointer(), 0), value);
1206 }
1207
1208
Pop(Register target)1209 void RegExpMacroAssemblerIA32::Pop(Register target) {
1210 DCHECK(target != backtrack_stackpointer());
1211 __ mov(target, Operand(backtrack_stackpointer(), 0));
1212 // Notice: This updates flags, unlike normal Pop.
1213 __ add(backtrack_stackpointer(), Immediate(kPointerSize));
1214 }
1215
1216
CheckPreemption()1217 void RegExpMacroAssemblerIA32::CheckPreemption() {
1218 // Check for preemption.
1219 Label no_preempt;
1220 ExternalReference stack_limit =
1221 ExternalReference::address_of_stack_limit(isolate());
1222 __ cmp(esp, masm_->StaticVariable(stack_limit));
1223 __ j(above, &no_preempt);
1224
1225 SafeCall(&check_preempt_label_);
1226
1227 __ bind(&no_preempt);
1228 }
1229
1230
CheckStackLimit()1231 void RegExpMacroAssemblerIA32::CheckStackLimit() {
1232 Label no_stack_overflow;
1233 ExternalReference stack_limit =
1234 ExternalReference::address_of_regexp_stack_limit(isolate());
1235 __ cmp(backtrack_stackpointer(), masm_->StaticVariable(stack_limit));
1236 __ j(above, &no_stack_overflow);
1237
1238 SafeCall(&stack_overflow_label_);
1239
1240 __ bind(&no_stack_overflow);
1241 }
1242
1243
LoadCurrentCharacterUnchecked(int cp_offset,int characters)1244 void RegExpMacroAssemblerIA32::LoadCurrentCharacterUnchecked(int cp_offset,
1245 int characters) {
1246 if (mode_ == LATIN1) {
1247 if (characters == 4) {
1248 __ mov(current_character(), Operand(esi, edi, times_1, cp_offset));
1249 } else if (characters == 2) {
1250 __ movzx_w(current_character(), Operand(esi, edi, times_1, cp_offset));
1251 } else {
1252 DCHECK_EQ(1, characters);
1253 __ movzx_b(current_character(), Operand(esi, edi, times_1, cp_offset));
1254 }
1255 } else {
1256 DCHECK(mode_ == UC16);
1257 if (characters == 2) {
1258 __ mov(current_character(),
1259 Operand(esi, edi, times_1, cp_offset * sizeof(uc16)));
1260 } else {
1261 DCHECK_EQ(1, characters);
1262 __ movzx_w(current_character(),
1263 Operand(esi, edi, times_1, cp_offset * sizeof(uc16)));
1264 }
1265 }
1266 }
1267
1268
1269 #undef __
1270
1271 #endif // V8_INTERPRETED_REGEXP
1272
1273 } // namespace internal
1274 } // namespace v8
1275
1276 #endif // V8_TARGET_ARCH_IA32
1277