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

Side by Side Diff: src/ppc/regexp-macro-assembler-ppc.cc

Issue 571173003: PowerPC specific sub-directories (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments Created 6 years, 1 month 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/ppc/regexp-macro-assembler-ppc.h ('k') | src/ppc/simulator-ppc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "src/v8.h"
6
7 #if V8_TARGET_ARCH_PPC
8
9 #include "src/base/bits.h"
10 #include "src/code-stubs.h"
11 #include "src/cpu-profiler.h"
12 #include "src/log.h"
13 #include "src/macro-assembler.h"
14 #include "src/regexp-macro-assembler.h"
15 #include "src/regexp-stack.h"
16 #include "src/unicode.h"
17
18 #include "src/ppc/regexp-macro-assembler-ppc.h"
19
20 namespace v8 {
21 namespace internal {
22
23 #ifndef V8_INTERPRETED_REGEXP
24 /*
25 * This assembler uses the following register assignment convention
26 * - r25: Temporarily stores the index of capture start after a matching pass
27 * for a global regexp.
28 * - r26: Pointer to current code object (Code*) including heap object tag.
29 * - r27: Current position in input, as negative offset from end of string.
30 * Please notice that this is the byte offset, not the character offset!
31 * - r28: Currently loaded character. Must be loaded using
32 * LoadCurrentCharacter before using any of the dispatch methods.
33 * - r29: Points to tip of backtrack stack
34 * - r30: End of input (points to byte after last character in input).
35 * - r31: Frame pointer. Used to access arguments, local variables and
36 * RegExp registers.
37 * - r12: IP register, used by assembler. Very volatile.
38 * - r1/sp : Points to tip of C stack.
39 *
40 * The remaining registers are free for computations.
41 * Each call to a public method should retain this convention.
42 *
43 * The stack will have the following structure:
44 * - fp[44] Isolate* isolate (address of the current isolate)
45 * - fp[40] secondary link/return address used by native call.
46 * - fp[36] lr save area (currently unused)
47 * - fp[32] backchain (currently unused)
48 * --- sp when called ---
49 * - fp[28] return address (lr).
50 * - fp[24] old frame pointer (r31).
51 * - fp[0..20] backup of registers r25..r30
52 * --- frame pointer ----
53 * - fp[-4] direct_call (if 1, direct call from JavaScript code,
54 * if 0, call through the runtime system).
55 * - fp[-8] stack_area_base (high end of the memory area to use as
56 * backtracking stack).
57 * - fp[-12] capture array size (may fit multiple sets of matches)
58 * - fp[-16] int* capture_array (int[num_saved_registers_], for output).
59 * - fp[-20] end of input (address of end of string).
60 * - fp[-24] start of input (address of first character in string).
61 * - fp[-28] start index (character index of start).
62 * - fp[-32] void* input_string (location of a handle containing the string).
63 * - fp[-36] success counter (only for global regexps to count matches).
64 * - fp[-40] Offset of location before start of input (effectively character
65 * position -1). Used to initialize capture registers to a
66 * non-position.
67 * - fp[-44] At start (if 1, we are starting at the start of the
68 * string, otherwise 0)
69 * - fp[-48] register 0 (Only positions must be stored in the first
70 * - register 1 num_saved_registers_ registers)
71 * - ...
72 * - register num_registers-1
73 * --- sp ---
74 *
75 * The first num_saved_registers_ registers are initialized to point to
76 * "character -1" in the string (i.e., char_size() bytes before the first
77 * character of the string). The remaining registers start out as garbage.
78 *
79 * The data up to the return address must be placed there by the calling
80 * code and the remaining arguments are passed in registers, e.g. by calling the
81 * code entry as cast to a function with the signature:
82 * int (*match)(String* input_string,
83 * int start_index,
84 * Address start,
85 * Address end,
86 * int* capture_output_array,
87 * byte* stack_area_base,
88 * Address secondary_return_address, // Only used by native call.
89 * bool direct_call = false)
90 * The call is performed by NativeRegExpMacroAssembler::Execute()
91 * (in regexp-macro-assembler.cc) via the CALL_GENERATED_REGEXP_CODE macro
92 * in ppc/simulator-ppc.h.
93 * When calling as a non-direct call (i.e., from C++ code), the return address
94 * area is overwritten with the LR register by the RegExp code. When doing a
95 * direct call from generated code, the return address is placed there by
96 * the calling code, as in a normal exit frame.
97 */
98
99 #define __ ACCESS_MASM(masm_)
100
101 RegExpMacroAssemblerPPC::RegExpMacroAssemblerPPC(Mode mode,
102 int registers_to_save,
103 Zone* zone)
104 : NativeRegExpMacroAssembler(zone),
105 masm_(new MacroAssembler(zone->isolate(), NULL, kRegExpCodeSize)),
106 mode_(mode),
107 num_registers_(registers_to_save),
108 num_saved_registers_(registers_to_save),
109 entry_label_(),
110 start_label_(),
111 success_label_(),
112 backtrack_label_(),
113 exit_label_(),
114 internal_failure_label_() {
115 DCHECK_EQ(0, registers_to_save % 2);
116
117 // Called from C
118 #if ABI_USES_FUNCTION_DESCRIPTORS
119 __ function_descriptor();
120 #endif
121
122 __ b(&entry_label_); // We'll write the entry code later.
123 // If the code gets too big or corrupted, an internal exception will be
124 // raised, and we will exit right away.
125 __ bind(&internal_failure_label_);
126 __ li(r3, Operand(FAILURE));
127 __ Ret();
128 __ bind(&start_label_); // And then continue from here.
129 }
130
131
132 RegExpMacroAssemblerPPC::~RegExpMacroAssemblerPPC() {
133 delete masm_;
134 // Unuse labels in case we throw away the assembler without calling GetCode.
135 entry_label_.Unuse();
136 start_label_.Unuse();
137 success_label_.Unuse();
138 backtrack_label_.Unuse();
139 exit_label_.Unuse();
140 check_preempt_label_.Unuse();
141 stack_overflow_label_.Unuse();
142 internal_failure_label_.Unuse();
143 }
144
145
146 int RegExpMacroAssemblerPPC::stack_limit_slack() {
147 return RegExpStack::kStackLimitSlack;
148 }
149
150
151 void RegExpMacroAssemblerPPC::AdvanceCurrentPosition(int by) {
152 if (by != 0) {
153 __ addi(current_input_offset(), current_input_offset(),
154 Operand(by * char_size()));
155 }
156 }
157
158
159 void RegExpMacroAssemblerPPC::AdvanceRegister(int reg, int by) {
160 DCHECK(reg >= 0);
161 DCHECK(reg < num_registers_);
162 if (by != 0) {
163 __ LoadP(r3, register_location(reg), r0);
164 __ mov(r0, Operand(by));
165 __ add(r3, r3, r0);
166 __ StoreP(r3, register_location(reg), r0);
167 }
168 }
169
170
171 void RegExpMacroAssemblerPPC::Backtrack() {
172 CheckPreemption();
173 // Pop Code* offset from backtrack stack, add Code* and jump to location.
174 Pop(r3);
175 __ add(r3, r3, code_pointer());
176 __ mtctr(r3);
177 __ bctr();
178 }
179
180
181 void RegExpMacroAssemblerPPC::Bind(Label* label) { __ bind(label); }
182
183
184 void RegExpMacroAssemblerPPC::CheckCharacter(uint32_t c, Label* on_equal) {
185 __ Cmpli(current_character(), Operand(c), r0);
186 BranchOrBacktrack(eq, on_equal);
187 }
188
189
190 void RegExpMacroAssemblerPPC::CheckCharacterGT(uc16 limit, Label* on_greater) {
191 __ Cmpli(current_character(), Operand(limit), r0);
192 BranchOrBacktrack(gt, on_greater);
193 }
194
195
196 void RegExpMacroAssemblerPPC::CheckAtStart(Label* on_at_start) {
197 Label not_at_start;
198 // Did we start the match at the start of the string at all?
199 __ LoadP(r3, MemOperand(frame_pointer(), kStartIndex));
200 __ cmpi(r3, Operand::Zero());
201 BranchOrBacktrack(ne, &not_at_start);
202
203 // If we did, are we still at the start of the input?
204 __ LoadP(r4, MemOperand(frame_pointer(), kInputStart));
205 __ mr(r0, current_input_offset());
206 __ add(r3, end_of_input_address(), r0);
207 __ cmp(r4, r3);
208 BranchOrBacktrack(eq, on_at_start);
209 __ bind(&not_at_start);
210 }
211
212
213 void RegExpMacroAssemblerPPC::CheckNotAtStart(Label* on_not_at_start) {
214 // Did we start the match at the start of the string at all?
215 __ LoadP(r3, MemOperand(frame_pointer(), kStartIndex));
216 __ cmpi(r3, Operand::Zero());
217 BranchOrBacktrack(ne, on_not_at_start);
218 // If we did, are we still at the start of the input?
219 __ LoadP(r4, MemOperand(frame_pointer(), kInputStart));
220 __ add(r3, end_of_input_address(), current_input_offset());
221 __ cmp(r3, r4);
222 BranchOrBacktrack(ne, on_not_at_start);
223 }
224
225
226 void RegExpMacroAssemblerPPC::CheckCharacterLT(uc16 limit, Label* on_less) {
227 __ Cmpli(current_character(), Operand(limit), r0);
228 BranchOrBacktrack(lt, on_less);
229 }
230
231
232 void RegExpMacroAssemblerPPC::CheckGreedyLoop(Label* on_equal) {
233 Label backtrack_non_equal;
234 __ LoadP(r3, MemOperand(backtrack_stackpointer(), 0));
235 __ cmp(current_input_offset(), r3);
236 __ bne(&backtrack_non_equal);
237 __ addi(backtrack_stackpointer(), backtrack_stackpointer(),
238 Operand(kPointerSize));
239
240 __ bind(&backtrack_non_equal);
241 BranchOrBacktrack(eq, on_equal);
242 }
243
244
245 void RegExpMacroAssemblerPPC::CheckNotBackReferenceIgnoreCase(
246 int start_reg, Label* on_no_match) {
247 Label fallthrough;
248 __ LoadP(r3, register_location(start_reg), r0); // Index of start of capture
249 __ LoadP(r4, register_location(start_reg + 1), r0); // Index of end
250 __ sub(r4, r4, r3, LeaveOE, SetRC); // Length of capture.
251
252 // If length is zero, either the capture is empty or it is not participating.
253 // In either case succeed immediately.
254 __ beq(&fallthrough, cr0);
255
256 // Check that there are enough characters left in the input.
257 __ add(r0, r4, current_input_offset(), LeaveOE, SetRC);
258 // __ cmn(r1, Operand(current_input_offset()));
259 BranchOrBacktrack(gt, on_no_match, cr0);
260
261 if (mode_ == LATIN1) {
262 Label success;
263 Label fail;
264 Label loop_check;
265
266 // r3 - offset of start of capture
267 // r4 - length of capture
268 __ add(r3, r3, end_of_input_address());
269 __ add(r5, end_of_input_address(), current_input_offset());
270 __ add(r4, r3, r4);
271
272 // r3 - Address of start of capture.
273 // r4 - Address of end of capture
274 // r5 - Address of current input position.
275
276 Label loop;
277 __ bind(&loop);
278 __ lbz(r6, MemOperand(r3));
279 __ addi(r3, r3, Operand(char_size()));
280 __ lbz(r25, MemOperand(r5));
281 __ addi(r5, r5, Operand(char_size()));
282 __ cmp(r25, r6);
283 __ beq(&loop_check);
284
285 // Mismatch, try case-insensitive match (converting letters to lower-case).
286 __ ori(r6, r6, Operand(0x20)); // Convert capture character to lower-case.
287 __ ori(r25, r25, Operand(0x20)); // Also convert input character.
288 __ cmp(r25, r6);
289 __ bne(&fail);
290 __ subi(r6, r6, Operand('a'));
291 __ cmpli(r6, Operand('z' - 'a')); // Is r6 a lowercase letter?
292 __ ble(&loop_check); // In range 'a'-'z'.
293 // Latin-1: Check for values in range [224,254] but not 247.
294 __ subi(r6, r6, Operand(224 - 'a'));
295 __ cmpli(r6, Operand(254 - 224));
296 __ bgt(&fail); // Weren't Latin-1 letters.
297 __ cmpi(r6, Operand(247 - 224)); // Check for 247.
298 __ beq(&fail);
299
300 __ bind(&loop_check);
301 __ cmp(r3, r4);
302 __ blt(&loop);
303 __ b(&success);
304
305 __ bind(&fail);
306 BranchOrBacktrack(al, on_no_match);
307
308 __ bind(&success);
309 // Compute new value of character position after the matched part.
310 __ sub(current_input_offset(), r5, end_of_input_address());
311 } else {
312 DCHECK(mode_ == UC16);
313 int argument_count = 4;
314 __ PrepareCallCFunction(argument_count, r5);
315
316 // r3 - offset of start of capture
317 // r4 - length of capture
318
319 // Put arguments into arguments registers.
320 // Parameters are
321 // r3: Address byte_offset1 - Address captured substring's start.
322 // r4: Address byte_offset2 - Address of current character position.
323 // r5: size_t byte_length - length of capture in bytes(!)
324 // r6: Isolate* isolate
325
326 // Address of start of capture.
327 __ add(r3, r3, end_of_input_address());
328 // Length of capture.
329 __ mr(r5, r4);
330 // Save length in callee-save register for use on return.
331 __ mr(r25, r4);
332 // Address of current input position.
333 __ add(r4, current_input_offset(), end_of_input_address());
334 // Isolate.
335 __ mov(r6, Operand(ExternalReference::isolate_address(isolate())));
336
337 {
338 AllowExternalCallThatCantCauseGC scope(masm_);
339 ExternalReference function =
340 ExternalReference::re_case_insensitive_compare_uc16(isolate());
341 __ CallCFunction(function, argument_count);
342 }
343
344 // Check if function returned non-zero for success or zero for failure.
345 __ cmpi(r3, Operand::Zero());
346 BranchOrBacktrack(eq, on_no_match);
347 // On success, increment position by length of capture.
348 __ add(current_input_offset(), current_input_offset(), r25);
349 }
350
351 __ bind(&fallthrough);
352 }
353
354
355 void RegExpMacroAssemblerPPC::CheckNotBackReference(int start_reg,
356 Label* on_no_match) {
357 Label fallthrough;
358 Label success;
359
360 // Find length of back-referenced capture.
361 __ LoadP(r3, register_location(start_reg), r0);
362 __ LoadP(r4, register_location(start_reg + 1), r0);
363 __ sub(r4, r4, r3, LeaveOE, SetRC); // Length to check.
364 // Succeed on empty capture (including no capture).
365 __ beq(&fallthrough, cr0);
366
367 // Check that there are enough characters left in the input.
368 __ add(r0, r4, current_input_offset(), LeaveOE, SetRC);
369 BranchOrBacktrack(gt, on_no_match, cr0);
370
371 // Compute pointers to match string and capture string
372 __ add(r3, r3, end_of_input_address());
373 __ add(r5, end_of_input_address(), current_input_offset());
374 __ add(r4, r4, r3);
375
376 Label loop;
377 __ bind(&loop);
378 if (mode_ == LATIN1) {
379 __ lbz(r6, MemOperand(r3));
380 __ addi(r3, r3, Operand(char_size()));
381 __ lbz(r25, MemOperand(r5));
382 __ addi(r5, r5, Operand(char_size()));
383 } else {
384 DCHECK(mode_ == UC16);
385 __ lhz(r6, MemOperand(r3));
386 __ addi(r3, r3, Operand(char_size()));
387 __ lhz(r25, MemOperand(r5));
388 __ addi(r5, r5, Operand(char_size()));
389 }
390 __ cmp(r6, r25);
391 BranchOrBacktrack(ne, on_no_match);
392 __ cmp(r3, r4);
393 __ blt(&loop);
394
395 // Move current character position to position after match.
396 __ sub(current_input_offset(), r5, end_of_input_address());
397 __ bind(&fallthrough);
398 }
399
400
401 void RegExpMacroAssemblerPPC::CheckNotCharacter(unsigned c,
402 Label* on_not_equal) {
403 __ Cmpli(current_character(), Operand(c), r0);
404 BranchOrBacktrack(ne, on_not_equal);
405 }
406
407
408 void RegExpMacroAssemblerPPC::CheckCharacterAfterAnd(uint32_t c, uint32_t mask,
409 Label* on_equal) {
410 __ mov(r0, Operand(mask));
411 if (c == 0) {
412 __ and_(r3, current_character(), r0, SetRC);
413 } else {
414 __ and_(r3, current_character(), r0);
415 __ Cmpli(r3, Operand(c), r0, cr0);
416 }
417 BranchOrBacktrack(eq, on_equal, cr0);
418 }
419
420
421 void RegExpMacroAssemblerPPC::CheckNotCharacterAfterAnd(unsigned c,
422 unsigned mask,
423 Label* on_not_equal) {
424 __ mov(r0, Operand(mask));
425 if (c == 0) {
426 __ and_(r3, current_character(), r0, SetRC);
427 } else {
428 __ and_(r3, current_character(), r0);
429 __ Cmpli(r3, Operand(c), r0, cr0);
430 }
431 BranchOrBacktrack(ne, on_not_equal, cr0);
432 }
433
434
435 void RegExpMacroAssemblerPPC::CheckNotCharacterAfterMinusAnd(
436 uc16 c, uc16 minus, uc16 mask, Label* on_not_equal) {
437 DCHECK(minus < String::kMaxUtf16CodeUnit);
438 __ subi(r3, current_character(), Operand(minus));
439 __ mov(r0, Operand(mask));
440 __ and_(r3, r3, r0);
441 __ Cmpli(r3, Operand(c), r0);
442 BranchOrBacktrack(ne, on_not_equal);
443 }
444
445
446 void RegExpMacroAssemblerPPC::CheckCharacterInRange(uc16 from, uc16 to,
447 Label* on_in_range) {
448 __ mov(r0, Operand(from));
449 __ sub(r3, current_character(), r0);
450 __ Cmpli(r3, Operand(to - from), r0);
451 BranchOrBacktrack(le, on_in_range); // Unsigned lower-or-same condition.
452 }
453
454
455 void RegExpMacroAssemblerPPC::CheckCharacterNotInRange(uc16 from, uc16 to,
456 Label* on_not_in_range) {
457 __ mov(r0, Operand(from));
458 __ sub(r3, current_character(), r0);
459 __ Cmpli(r3, Operand(to - from), r0);
460 BranchOrBacktrack(gt, on_not_in_range); // Unsigned higher condition.
461 }
462
463
464 void RegExpMacroAssemblerPPC::CheckBitInTable(Handle<ByteArray> table,
465 Label* on_bit_set) {
466 __ mov(r3, Operand(table));
467 if (mode_ != LATIN1 || kTableMask != String::kMaxOneByteCharCode) {
468 __ andi(r4, current_character(), Operand(kTableSize - 1));
469 __ addi(r4, r4, Operand(ByteArray::kHeaderSize - kHeapObjectTag));
470 } else {
471 __ addi(r4, current_character(),
472 Operand(ByteArray::kHeaderSize - kHeapObjectTag));
473 }
474 __ lbzx(r3, MemOperand(r3, r4));
475 __ cmpi(r3, Operand::Zero());
476 BranchOrBacktrack(ne, on_bit_set);
477 }
478
479
480 bool RegExpMacroAssemblerPPC::CheckSpecialCharacterClass(uc16 type,
481 Label* on_no_match) {
482 // Range checks (c in min..max) are generally implemented by an unsigned
483 // (c - min) <= (max - min) check
484 switch (type) {
485 case 's':
486 // Match space-characters
487 if (mode_ == LATIN1) {
488 // One byte space characters are '\t'..'\r', ' ' and \u00a0.
489 Label success;
490 __ cmpi(current_character(), Operand(' '));
491 __ beq(&success);
492 // Check range 0x09..0x0d
493 __ subi(r3, current_character(), Operand('\t'));
494 __ cmpli(r3, Operand('\r' - '\t'));
495 __ ble(&success);
496 // \u00a0 (NBSP).
497 __ cmpi(r3, Operand(0x00a0 - '\t'));
498 BranchOrBacktrack(ne, on_no_match);
499 __ bind(&success);
500 return true;
501 }
502 return false;
503 case 'S':
504 // The emitted code for generic character classes is good enough.
505 return false;
506 case 'd':
507 // Match ASCII digits ('0'..'9')
508 __ subi(r3, current_character(), Operand('0'));
509 __ cmpli(r3, Operand('9' - '0'));
510 BranchOrBacktrack(gt, on_no_match);
511 return true;
512 case 'D':
513 // Match non ASCII-digits
514 __ subi(r3, current_character(), Operand('0'));
515 __ cmpli(r3, Operand('9' - '0'));
516 BranchOrBacktrack(le, on_no_match);
517 return true;
518 case '.': {
519 // Match non-newlines (not 0x0a('\n'), 0x0d('\r'), 0x2028 and 0x2029)
520 __ xori(r3, current_character(), Operand(0x01));
521 // See if current character is '\n'^1 or '\r'^1, i.e., 0x0b or 0x0c
522 __ subi(r3, r3, Operand(0x0b));
523 __ cmpli(r3, Operand(0x0c - 0x0b));
524 BranchOrBacktrack(le, on_no_match);
525 if (mode_ == UC16) {
526 // Compare original value to 0x2028 and 0x2029, using the already
527 // computed (current_char ^ 0x01 - 0x0b). I.e., check for
528 // 0x201d (0x2028 - 0x0b) or 0x201e.
529 __ subi(r3, r3, Operand(0x2028 - 0x0b));
530 __ cmpli(r3, Operand(1));
531 BranchOrBacktrack(le, on_no_match);
532 }
533 return true;
534 }
535 case 'n': {
536 // Match newlines (0x0a('\n'), 0x0d('\r'), 0x2028 and 0x2029)
537 __ xori(r3, current_character(), Operand(0x01));
538 // See if current character is '\n'^1 or '\r'^1, i.e., 0x0b or 0x0c
539 __ subi(r3, r3, Operand(0x0b));
540 __ cmpli(r3, Operand(0x0c - 0x0b));
541 if (mode_ == LATIN1) {
542 BranchOrBacktrack(gt, on_no_match);
543 } else {
544 Label done;
545 __ ble(&done);
546 // Compare original value to 0x2028 and 0x2029, using the already
547 // computed (current_char ^ 0x01 - 0x0b). I.e., check for
548 // 0x201d (0x2028 - 0x0b) or 0x201e.
549 __ subi(r3, r3, Operand(0x2028 - 0x0b));
550 __ cmpli(r3, Operand(1));
551 BranchOrBacktrack(gt, on_no_match);
552 __ bind(&done);
553 }
554 return true;
555 }
556 case 'w': {
557 if (mode_ != LATIN1) {
558 // Table is 256 entries, so all Latin1 characters can be tested.
559 __ cmpi(current_character(), Operand('z'));
560 BranchOrBacktrack(gt, on_no_match);
561 }
562 ExternalReference map = ExternalReference::re_word_character_map();
563 __ mov(r3, Operand(map));
564 __ lbzx(r3, MemOperand(r3, current_character()));
565 __ cmpli(r3, Operand::Zero());
566 BranchOrBacktrack(eq, on_no_match);
567 return true;
568 }
569 case 'W': {
570 Label done;
571 if (mode_ != LATIN1) {
572 // Table is 256 entries, so all Latin1 characters can be tested.
573 __ cmpli(current_character(), Operand('z'));
574 __ bgt(&done);
575 }
576 ExternalReference map = ExternalReference::re_word_character_map();
577 __ mov(r3, Operand(map));
578 __ lbzx(r3, MemOperand(r3, current_character()));
579 __ cmpli(r3, Operand::Zero());
580 BranchOrBacktrack(ne, on_no_match);
581 if (mode_ != LATIN1) {
582 __ bind(&done);
583 }
584 return true;
585 }
586 case '*':
587 // Match any character.
588 return true;
589 // No custom implementation (yet): s(UC16), S(UC16).
590 default:
591 return false;
592 }
593 }
594
595
596 void RegExpMacroAssemblerPPC::Fail() {
597 __ li(r3, Operand(FAILURE));
598 __ b(&exit_label_);
599 }
600
601
602 Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) {
603 Label return_r3;
604
605 if (masm_->has_exception()) {
606 // If the code gets corrupted due to long regular expressions and lack of
607 // space on trampolines, an internal exception flag is set. If this case
608 // is detected, we will jump into exit sequence right away.
609 __ bind_to(&entry_label_, internal_failure_label_.pos());
610 } else {
611 // Finalize code - write the entry point code now we know how many
612 // registers we need.
613
614 // Entry code:
615 __ bind(&entry_label_);
616
617 // Tell the system that we have a stack frame. Because the type
618 // is MANUAL, no is generated.
619 FrameScope scope(masm_, StackFrame::MANUAL);
620
621 // Ensure register assigments are consistent with callee save mask
622 DCHECK(r25.bit() & kRegExpCalleeSaved);
623 DCHECK(code_pointer().bit() & kRegExpCalleeSaved);
624 DCHECK(current_input_offset().bit() & kRegExpCalleeSaved);
625 DCHECK(current_character().bit() & kRegExpCalleeSaved);
626 DCHECK(backtrack_stackpointer().bit() & kRegExpCalleeSaved);
627 DCHECK(end_of_input_address().bit() & kRegExpCalleeSaved);
628 DCHECK(frame_pointer().bit() & kRegExpCalleeSaved);
629
630 // Actually emit code to start a new stack frame.
631 // Push arguments
632 // Save callee-save registers.
633 // Start new stack frame.
634 // Store link register in existing stack-cell.
635 // Order here should correspond to order of offset constants in header file.
636 RegList registers_to_retain = kRegExpCalleeSaved;
637 RegList argument_registers = r3.bit() | r4.bit() | r5.bit() | r6.bit() |
638 r7.bit() | r8.bit() | r9.bit() | r10.bit();
639 __ mflr(r0);
640 __ push(r0);
641 __ MultiPush(argument_registers | registers_to_retain);
642 // Set frame pointer in space for it if this is not a direct call
643 // from generated code.
644 __ addi(frame_pointer(), sp, Operand(8 * kPointerSize));
645 __ li(r3, Operand::Zero());
646 __ push(r3); // Make room for success counter and initialize it to 0.
647 __ push(r3); // Make room for "position - 1" constant (value is irrelevant)
648 // Check if we have space on the stack for registers.
649 Label stack_limit_hit;
650 Label stack_ok;
651
652 ExternalReference stack_limit =
653 ExternalReference::address_of_stack_limit(isolate());
654 __ mov(r3, Operand(stack_limit));
655 __ LoadP(r3, MemOperand(r3));
656 __ sub(r3, sp, r3, LeaveOE, SetRC);
657 // Handle it if the stack pointer is already below the stack limit.
658 __ ble(&stack_limit_hit, cr0);
659 // Check if there is room for the variable number of registers above
660 // the stack limit.
661 __ Cmpli(r3, Operand(num_registers_ * kPointerSize), r0);
662 __ bge(&stack_ok);
663 // Exit with OutOfMemory exception. There is not enough space on the stack
664 // for our working registers.
665 __ li(r3, Operand(EXCEPTION));
666 __ b(&return_r3);
667
668 __ bind(&stack_limit_hit);
669 CallCheckStackGuardState(r3);
670 __ cmpi(r3, Operand::Zero());
671 // If returned value is non-zero, we exit with the returned value as result.
672 __ bne(&return_r3);
673
674 __ bind(&stack_ok);
675
676 // Allocate space on stack for registers.
677 __ Add(sp, sp, -num_registers_ * kPointerSize, r0);
678 // Load string end.
679 __ LoadP(end_of_input_address(), MemOperand(frame_pointer(), kInputEnd));
680 // Load input start.
681 __ LoadP(r3, MemOperand(frame_pointer(), kInputStart));
682 // Find negative length (offset of start relative to end).
683 __ sub(current_input_offset(), r3, end_of_input_address());
684 // Set r3 to address of char before start of the input string
685 // (effectively string position -1).
686 __ LoadP(r4, MemOperand(frame_pointer(), kStartIndex));
687 __ subi(r3, current_input_offset(), Operand(char_size()));
688 if (mode_ == UC16) {
689 __ ShiftLeftImm(r0, r4, Operand(1));
690 __ sub(r3, r3, r0);
691 } else {
692 __ sub(r3, r3, r4);
693 }
694 // Store this value in a local variable, for use when clearing
695 // position registers.
696 __ StoreP(r3, MemOperand(frame_pointer(), kInputStartMinusOne));
697
698 // Initialize code pointer register
699 __ mov(code_pointer(), Operand(masm_->CodeObject()));
700
701 Label load_char_start_regexp, start_regexp;
702 // Load newline if index is at start, previous character otherwise.
703 __ cmpi(r4, Operand::Zero());
704 __ bne(&load_char_start_regexp);
705 __ li(current_character(), Operand('\n'));
706 __ b(&start_regexp);
707
708 // Global regexp restarts matching here.
709 __ bind(&load_char_start_regexp);
710 // Load previous char as initial value of current character register.
711 LoadCurrentCharacterUnchecked(-1, 1);
712 __ bind(&start_regexp);
713
714 // Initialize on-stack registers.
715 if (num_saved_registers_ > 0) { // Always is, if generated from a regexp.
716 // Fill saved registers with initial value = start offset - 1
717 if (num_saved_registers_ > 8) {
718 // One slot beyond address of register 0.
719 __ addi(r4, frame_pointer(), Operand(kRegisterZero + kPointerSize));
720 __ li(r5, Operand(num_saved_registers_));
721 __ mtctr(r5);
722 Label init_loop;
723 __ bind(&init_loop);
724 __ StorePU(r3, MemOperand(r4, -kPointerSize));
725 __ bdnz(&init_loop);
726 } else {
727 for (int i = 0; i < num_saved_registers_; i++) {
728 __ StoreP(r3, register_location(i), r0);
729 }
730 }
731 }
732
733 // Initialize backtrack stack pointer.
734 __ LoadP(backtrack_stackpointer(),
735 MemOperand(frame_pointer(), kStackHighEnd));
736
737 __ b(&start_label_);
738
739 // Exit code:
740 if (success_label_.is_linked()) {
741 // Save captures when successful.
742 __ bind(&success_label_);
743 if (num_saved_registers_ > 0) {
744 // copy captures to output
745 __ LoadP(r4, MemOperand(frame_pointer(), kInputStart));
746 __ LoadP(r3, MemOperand(frame_pointer(), kRegisterOutput));
747 __ LoadP(r5, MemOperand(frame_pointer(), kStartIndex));
748 __ sub(r4, end_of_input_address(), r4);
749 // r4 is length of input in bytes.
750 if (mode_ == UC16) {
751 __ ShiftRightImm(r4, r4, Operand(1));
752 }
753 // r4 is length of input in characters.
754 __ add(r4, r4, r5);
755 // r4 is length of string in characters.
756
757 DCHECK_EQ(0, num_saved_registers_ % 2);
758 // Always an even number of capture registers. This allows us to
759 // unroll the loop once to add an operation between a load of a register
760 // and the following use of that register.
761 for (int i = 0; i < num_saved_registers_; i += 2) {
762 __ LoadP(r5, register_location(i), r0);
763 __ LoadP(r6, register_location(i + 1), r0);
764 if (i == 0 && global_with_zero_length_check()) {
765 // Keep capture start in r25 for the zero-length check later.
766 __ mr(r25, r5);
767 }
768 if (mode_ == UC16) {
769 __ ShiftRightArithImm(r5, r5, 1);
770 __ add(r5, r4, r5);
771 __ ShiftRightArithImm(r6, r6, 1);
772 __ add(r6, r4, r6);
773 } else {
774 __ add(r5, r4, r5);
775 __ add(r6, r4, r6);
776 }
777 __ stw(r5, MemOperand(r3));
778 __ addi(r3, r3, Operand(kIntSize));
779 __ stw(r6, MemOperand(r3));
780 __ addi(r3, r3, Operand(kIntSize));
781 }
782 }
783
784 if (global()) {
785 // Restart matching if the regular expression is flagged as global.
786 __ LoadP(r3, MemOperand(frame_pointer(), kSuccessfulCaptures));
787 __ LoadP(r4, MemOperand(frame_pointer(), kNumOutputRegisters));
788 __ LoadP(r5, MemOperand(frame_pointer(), kRegisterOutput));
789 // Increment success counter.
790 __ addi(r3, r3, Operand(1));
791 __ StoreP(r3, MemOperand(frame_pointer(), kSuccessfulCaptures));
792 // Capture results have been stored, so the number of remaining global
793 // output registers is reduced by the number of stored captures.
794 __ subi(r4, r4, Operand(num_saved_registers_));
795 // Check whether we have enough room for another set of capture results.
796 __ cmpi(r4, Operand(num_saved_registers_));
797 __ blt(&return_r3);
798
799 __ StoreP(r4, MemOperand(frame_pointer(), kNumOutputRegisters));
800 // Advance the location for output.
801 __ addi(r5, r5, Operand(num_saved_registers_ * kIntSize));
802 __ StoreP(r5, MemOperand(frame_pointer(), kRegisterOutput));
803
804 // Prepare r3 to initialize registers with its value in the next run.
805 __ LoadP(r3, MemOperand(frame_pointer(), kInputStartMinusOne));
806
807 if (global_with_zero_length_check()) {
808 // Special case for zero-length matches.
809 // r25: capture start index
810 __ cmp(current_input_offset(), r25);
811 // Not a zero-length match, restart.
812 __ bne(&load_char_start_regexp);
813 // Offset from the end is zero if we already reached the end.
814 __ cmpi(current_input_offset(), Operand::Zero());
815 __ beq(&exit_label_);
816 // Advance current position after a zero-length match.
817 __ addi(current_input_offset(), current_input_offset(),
818 Operand((mode_ == UC16) ? 2 : 1));
819 }
820
821 __ b(&load_char_start_regexp);
822 } else {
823 __ li(r3, Operand(SUCCESS));
824 }
825 }
826
827 // Exit and return r3
828 __ bind(&exit_label_);
829 if (global()) {
830 __ LoadP(r3, MemOperand(frame_pointer(), kSuccessfulCaptures));
831 }
832
833 __ bind(&return_r3);
834 // Skip sp past regexp registers and local variables..
835 __ mr(sp, frame_pointer());
836 // Restore registers r25..r31 and return (restoring lr to pc).
837 __ MultiPop(registers_to_retain);
838 __ pop(r0);
839 __ mtctr(r0);
840 __ bctr();
841
842 // Backtrack code (branch target for conditional backtracks).
843 if (backtrack_label_.is_linked()) {
844 __ bind(&backtrack_label_);
845 Backtrack();
846 }
847
848 Label exit_with_exception;
849
850 // Preempt-code
851 if (check_preempt_label_.is_linked()) {
852 SafeCallTarget(&check_preempt_label_);
853
854 CallCheckStackGuardState(r3);
855 __ cmpi(r3, Operand::Zero());
856 // If returning non-zero, we should end execution with the given
857 // result as return value.
858 __ bne(&return_r3);
859
860 // String might have moved: Reload end of string from frame.
861 __ LoadP(end_of_input_address(), MemOperand(frame_pointer(), kInputEnd));
862 SafeReturn();
863 }
864
865 // Backtrack stack overflow code.
866 if (stack_overflow_label_.is_linked()) {
867 SafeCallTarget(&stack_overflow_label_);
868 // Reached if the backtrack-stack limit has been hit.
869 Label grow_failed;
870
871 // Call GrowStack(backtrack_stackpointer(), &stack_base)
872 static const int num_arguments = 3;
873 __ PrepareCallCFunction(num_arguments, r3);
874 __ mr(r3, backtrack_stackpointer());
875 __ addi(r4, frame_pointer(), Operand(kStackHighEnd));
876 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
877 ExternalReference grow_stack =
878 ExternalReference::re_grow_stack(isolate());
879 __ CallCFunction(grow_stack, num_arguments);
880 // If return NULL, we have failed to grow the stack, and
881 // must exit with a stack-overflow exception.
882 __ cmpi(r3, Operand::Zero());
883 __ beq(&exit_with_exception);
884 // Otherwise use return value as new stack pointer.
885 __ mr(backtrack_stackpointer(), r3);
886 // Restore saved registers and continue.
887 SafeReturn();
888 }
889
890 if (exit_with_exception.is_linked()) {
891 // If any of the code above needed to exit with an exception.
892 __ bind(&exit_with_exception);
893 // Exit with Result EXCEPTION(-1) to signal thrown exception.
894 __ li(r3, Operand(EXCEPTION));
895 __ b(&return_r3);
896 }
897 }
898
899 CodeDesc code_desc;
900 masm_->GetCode(&code_desc);
901 Handle<Code> code = isolate()->factory()->NewCode(
902 code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject());
903 PROFILE(masm_->isolate(), RegExpCodeCreateEvent(*code, *source));
904 return Handle<HeapObject>::cast(code);
905 }
906
907
908 void RegExpMacroAssemblerPPC::GoTo(Label* to) { BranchOrBacktrack(al, to); }
909
910
911 void RegExpMacroAssemblerPPC::IfRegisterGE(int reg, int comparand,
912 Label* if_ge) {
913 __ LoadP(r3, register_location(reg), r0);
914 __ Cmpi(r3, Operand(comparand), r0);
915 BranchOrBacktrack(ge, if_ge);
916 }
917
918
919 void RegExpMacroAssemblerPPC::IfRegisterLT(int reg, int comparand,
920 Label* if_lt) {
921 __ LoadP(r3, register_location(reg), r0);
922 __ Cmpi(r3, Operand(comparand), r0);
923 BranchOrBacktrack(lt, if_lt);
924 }
925
926
927 void RegExpMacroAssemblerPPC::IfRegisterEqPos(int reg, Label* if_eq) {
928 __ LoadP(r3, register_location(reg), r0);
929 __ cmp(r3, current_input_offset());
930 BranchOrBacktrack(eq, if_eq);
931 }
932
933
934 RegExpMacroAssembler::IrregexpImplementation
935 RegExpMacroAssemblerPPC::Implementation() {
936 return kPPCImplementation;
937 }
938
939
940 void RegExpMacroAssemblerPPC::LoadCurrentCharacter(int cp_offset,
941 Label* on_end_of_input,
942 bool check_bounds,
943 int characters) {
944 DCHECK(cp_offset >= -1); // ^ and \b can look behind one character.
945 DCHECK(cp_offset < (1 << 30)); // Be sane! (And ensure negation works)
946 if (check_bounds) {
947 CheckPosition(cp_offset + characters - 1, on_end_of_input);
948 }
949 LoadCurrentCharacterUnchecked(cp_offset, characters);
950 }
951
952
953 void RegExpMacroAssemblerPPC::PopCurrentPosition() {
954 Pop(current_input_offset());
955 }
956
957
958 void RegExpMacroAssemblerPPC::PopRegister(int register_index) {
959 Pop(r3);
960 __ StoreP(r3, register_location(register_index), r0);
961 }
962
963
964 void RegExpMacroAssemblerPPC::PushBacktrack(Label* label) {
965 __ mov_label_offset(r3, label);
966 Push(r3);
967 CheckStackLimit();
968 }
969
970
971 void RegExpMacroAssemblerPPC::PushCurrentPosition() {
972 Push(current_input_offset());
973 }
974
975
976 void RegExpMacroAssemblerPPC::PushRegister(int register_index,
977 StackCheckFlag check_stack_limit) {
978 __ LoadP(r3, register_location(register_index), r0);
979 Push(r3);
980 if (check_stack_limit) CheckStackLimit();
981 }
982
983
984 void RegExpMacroAssemblerPPC::ReadCurrentPositionFromRegister(int reg) {
985 __ LoadP(current_input_offset(), register_location(reg), r0);
986 }
987
988
989 void RegExpMacroAssemblerPPC::ReadStackPointerFromRegister(int reg) {
990 __ LoadP(backtrack_stackpointer(), register_location(reg), r0);
991 __ LoadP(r3, MemOperand(frame_pointer(), kStackHighEnd));
992 __ add(backtrack_stackpointer(), backtrack_stackpointer(), r3);
993 }
994
995
996 void RegExpMacroAssemblerPPC::SetCurrentPositionFromEnd(int by) {
997 Label after_position;
998 __ Cmpi(current_input_offset(), Operand(-by * char_size()), r0);
999 __ bge(&after_position);
1000 __ mov(current_input_offset(), Operand(-by * char_size()));
1001 // On RegExp code entry (where this operation is used), the character before
1002 // the current position is expected to be already loaded.
1003 // We have advanced the position, so it's safe to read backwards.
1004 LoadCurrentCharacterUnchecked(-1, 1);
1005 __ bind(&after_position);
1006 }
1007
1008
1009 void RegExpMacroAssemblerPPC::SetRegister(int register_index, int to) {
1010 DCHECK(register_index >= num_saved_registers_); // Reserved for positions!
1011 __ mov(r3, Operand(to));
1012 __ StoreP(r3, register_location(register_index), r0);
1013 }
1014
1015
1016 bool RegExpMacroAssemblerPPC::Succeed() {
1017 __ b(&success_label_);
1018 return global();
1019 }
1020
1021
1022 void RegExpMacroAssemblerPPC::WriteCurrentPositionToRegister(int reg,
1023 int cp_offset) {
1024 if (cp_offset == 0) {
1025 __ StoreP(current_input_offset(), register_location(reg), r0);
1026 } else {
1027 __ mov(r0, Operand(cp_offset * char_size()));
1028 __ add(r3, current_input_offset(), r0);
1029 __ StoreP(r3, register_location(reg), r0);
1030 }
1031 }
1032
1033
1034 void RegExpMacroAssemblerPPC::ClearRegisters(int reg_from, int reg_to) {
1035 DCHECK(reg_from <= reg_to);
1036 __ LoadP(r3, MemOperand(frame_pointer(), kInputStartMinusOne));
1037 for (int reg = reg_from; reg <= reg_to; reg++) {
1038 __ StoreP(r3, register_location(reg), r0);
1039 }
1040 }
1041
1042
1043 void RegExpMacroAssemblerPPC::WriteStackPointerToRegister(int reg) {
1044 __ LoadP(r4, MemOperand(frame_pointer(), kStackHighEnd));
1045 __ sub(r3, backtrack_stackpointer(), r4);
1046 __ StoreP(r3, register_location(reg), r0);
1047 }
1048
1049
1050 // Private methods:
1051
1052 void RegExpMacroAssemblerPPC::CallCheckStackGuardState(Register scratch) {
1053 int frame_alignment = masm_->ActivationFrameAlignment();
1054 int stack_space = kNumRequiredStackFrameSlots;
1055 int stack_passed_arguments = 1; // space for return address pointer
1056
1057 // The following stack manipulation logic is similar to
1058 // PrepareCallCFunction. However, we need an extra slot on the
1059 // stack to house the return address parameter.
1060 if (frame_alignment > kPointerSize) {
1061 // Make stack end at alignment and make room for stack arguments
1062 // -- preserving original value of sp.
1063 __ mr(scratch, sp);
1064 __ addi(sp, sp, Operand(-(stack_passed_arguments + 1) * kPointerSize));
1065 DCHECK(base::bits::IsPowerOfTwo32(frame_alignment));
1066 __ ClearRightImm(sp, sp, Operand(WhichPowerOf2(frame_alignment)));
1067 __ StoreP(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
1068 } else {
1069 // Make room for stack arguments
1070 stack_space += stack_passed_arguments;
1071 }
1072
1073 // Allocate frame with required slots to make ABI work.
1074 __ li(r0, Operand::Zero());
1075 __ StorePU(r0, MemOperand(sp, -stack_space * kPointerSize));
1076
1077 // RegExp code frame pointer.
1078 __ mr(r5, frame_pointer());
1079 // Code* of self.
1080 __ mov(r4, Operand(masm_->CodeObject()));
1081 // r3 will point to the return address, placed by DirectCEntry.
1082 __ addi(r3, sp, Operand(kStackFrameExtraParamSlot * kPointerSize));
1083
1084 ExternalReference stack_guard_check =
1085 ExternalReference::re_check_stack_guard_state(isolate());
1086 __ mov(ip, Operand(stack_guard_check));
1087 DirectCEntryStub stub(isolate());
1088 stub.GenerateCall(masm_, ip);
1089
1090 // Restore the stack pointer
1091 stack_space = kNumRequiredStackFrameSlots + stack_passed_arguments;
1092 if (frame_alignment > kPointerSize) {
1093 __ LoadP(sp, MemOperand(sp, stack_space * kPointerSize));
1094 } else {
1095 __ addi(sp, sp, Operand(stack_space * kPointerSize));
1096 }
1097
1098 __ mov(code_pointer(), Operand(masm_->CodeObject()));
1099 }
1100
1101
1102 // Helper function for reading a value out of a stack frame.
1103 template <typename T>
1104 static T& frame_entry(Address re_frame, int frame_offset) {
1105 return reinterpret_cast<T&>(Memory::int32_at(re_frame + frame_offset));
1106 }
1107
1108
1109 int RegExpMacroAssemblerPPC::CheckStackGuardState(Address* return_address,
1110 Code* re_code,
1111 Address re_frame) {
1112 Isolate* isolate = frame_entry<Isolate*>(re_frame, kIsolate);
1113 StackLimitCheck check(isolate);
1114 if (check.JsHasOverflowed()) {
1115 isolate->StackOverflow();
1116 return EXCEPTION;
1117 }
1118
1119 // If not real stack overflow the stack guard was used to interrupt
1120 // execution for another purpose.
1121
1122 // If this is a direct call from JavaScript retry the RegExp forcing the call
1123 // through the runtime system. Currently the direct call cannot handle a GC.
1124 if (frame_entry<int>(re_frame, kDirectCall) == 1) {
1125 return RETRY;
1126 }
1127
1128 // Prepare for possible GC.
1129 HandleScope handles(isolate);
1130 Handle<Code> code_handle(re_code);
1131
1132 Handle<String> subject(frame_entry<String*>(re_frame, kInputString));
1133
1134 // Current string.
1135 bool is_one_byte = subject->IsOneByteRepresentationUnderneath();
1136
1137 DCHECK(re_code->instruction_start() <= *return_address);
1138 DCHECK(*return_address <=
1139 re_code->instruction_start() + re_code->instruction_size());
1140
1141 Object* result = isolate->stack_guard()->HandleInterrupts();
1142
1143 if (*code_handle != re_code) { // Return address no longer valid
1144 intptr_t delta = code_handle->address() - re_code->address();
1145 // Overwrite the return address on the stack.
1146 *return_address += delta;
1147 }
1148
1149 if (result->IsException()) {
1150 return EXCEPTION;
1151 }
1152
1153 Handle<String> subject_tmp = subject;
1154 int slice_offset = 0;
1155
1156 // Extract the underlying string and the slice offset.
1157 if (StringShape(*subject_tmp).IsCons()) {
1158 subject_tmp = Handle<String>(ConsString::cast(*subject_tmp)->first());
1159 } else if (StringShape(*subject_tmp).IsSliced()) {
1160 SlicedString* slice = SlicedString::cast(*subject_tmp);
1161 subject_tmp = Handle<String>(slice->parent());
1162 slice_offset = slice->offset();
1163 }
1164
1165 // String might have changed.
1166 if (subject_tmp->IsOneByteRepresentation() != is_one_byte) {
1167 // If we changed between an Latin1 and an UC16 string, the specialized
1168 // code cannot be used, and we need to restart regexp matching from
1169 // scratch (including, potentially, compiling a new version of the code).
1170 return RETRY;
1171 }
1172
1173 // Otherwise, the content of the string might have moved. It must still
1174 // be a sequential or external string with the same content.
1175 // Update the start and end pointers in the stack frame to the current
1176 // location (whether it has actually moved or not).
1177 DCHECK(StringShape(*subject_tmp).IsSequential() ||
1178 StringShape(*subject_tmp).IsExternal());
1179
1180 // The original start address of the characters to match.
1181 const byte* start_address = frame_entry<const byte*>(re_frame, kInputStart);
1182
1183 // Find the current start address of the same character at the current string
1184 // position.
1185 int start_index = frame_entry<intptr_t>(re_frame, kStartIndex);
1186 const byte* new_address =
1187 StringCharacterPosition(*subject_tmp, start_index + slice_offset);
1188
1189 if (start_address != new_address) {
1190 // If there is a difference, update the object pointer and start and end
1191 // addresses in the RegExp stack frame to match the new value.
1192 const byte* end_address = frame_entry<const byte*>(re_frame, kInputEnd);
1193 int byte_length = static_cast<int>(end_address - start_address);
1194 frame_entry<const String*>(re_frame, kInputString) = *subject;
1195 frame_entry<const byte*>(re_frame, kInputStart) = new_address;
1196 frame_entry<const byte*>(re_frame, kInputEnd) = new_address + byte_length;
1197 } else if (frame_entry<const String*>(re_frame, kInputString) != *subject) {
1198 // Subject string might have been a ConsString that underwent
1199 // short-circuiting during GC. That will not change start_address but
1200 // will change pointer inside the subject handle.
1201 frame_entry<const String*>(re_frame, kInputString) = *subject;
1202 }
1203
1204 return 0;
1205 }
1206
1207
1208 MemOperand RegExpMacroAssemblerPPC::register_location(int register_index) {
1209 DCHECK(register_index < (1 << 30));
1210 if (num_registers_ <= register_index) {
1211 num_registers_ = register_index + 1;
1212 }
1213 return MemOperand(frame_pointer(),
1214 kRegisterZero - register_index * kPointerSize);
1215 }
1216
1217
1218 void RegExpMacroAssemblerPPC::CheckPosition(int cp_offset,
1219 Label* on_outside_input) {
1220 __ Cmpi(current_input_offset(), Operand(-cp_offset * char_size()), r0);
1221 BranchOrBacktrack(ge, on_outside_input);
1222 }
1223
1224
1225 void RegExpMacroAssemblerPPC::BranchOrBacktrack(Condition condition, Label* to,
1226 CRegister cr) {
1227 if (condition == al) { // Unconditional.
1228 if (to == NULL) {
1229 Backtrack();
1230 return;
1231 }
1232 __ b(to);
1233 return;
1234 }
1235 if (to == NULL) {
1236 __ b(condition, &backtrack_label_, cr);
1237 return;
1238 }
1239 __ b(condition, to, cr);
1240 }
1241
1242
1243 void RegExpMacroAssemblerPPC::SafeCall(Label* to, Condition cond,
1244 CRegister cr) {
1245 __ b(cond, to, cr, SetLK);
1246 }
1247
1248
1249 void RegExpMacroAssemblerPPC::SafeReturn() {
1250 __ pop(r0);
1251 __ mov(ip, Operand(masm_->CodeObject()));
1252 __ add(r0, r0, ip);
1253 __ mtlr(r0);
1254 __ blr();
1255 }
1256
1257
1258 void RegExpMacroAssemblerPPC::SafeCallTarget(Label* name) {
1259 __ bind(name);
1260 __ mflr(r0);
1261 __ mov(ip, Operand(masm_->CodeObject()));
1262 __ sub(r0, r0, ip);
1263 __ push(r0);
1264 }
1265
1266
1267 void RegExpMacroAssemblerPPC::Push(Register source) {
1268 DCHECK(!source.is(backtrack_stackpointer()));
1269 __ StorePU(source, MemOperand(backtrack_stackpointer(), -kPointerSize));
1270 }
1271
1272
1273 void RegExpMacroAssemblerPPC::Pop(Register target) {
1274 DCHECK(!target.is(backtrack_stackpointer()));
1275 __ LoadP(target, MemOperand(backtrack_stackpointer()));
1276 __ addi(backtrack_stackpointer(), backtrack_stackpointer(),
1277 Operand(kPointerSize));
1278 }
1279
1280
1281 void RegExpMacroAssemblerPPC::CheckPreemption() {
1282 // Check for preemption.
1283 ExternalReference stack_limit =
1284 ExternalReference::address_of_stack_limit(isolate());
1285 __ mov(r3, Operand(stack_limit));
1286 __ LoadP(r3, MemOperand(r3));
1287 __ cmpl(sp, r3);
1288 SafeCall(&check_preempt_label_, le);
1289 }
1290
1291
1292 void RegExpMacroAssemblerPPC::CheckStackLimit() {
1293 ExternalReference stack_limit =
1294 ExternalReference::address_of_regexp_stack_limit(isolate());
1295 __ mov(r3, Operand(stack_limit));
1296 __ LoadP(r3, MemOperand(r3));
1297 __ cmpl(backtrack_stackpointer(), r3);
1298 SafeCall(&stack_overflow_label_, le);
1299 }
1300
1301
1302 bool RegExpMacroAssemblerPPC::CanReadUnaligned() {
1303 return CpuFeatures::IsSupported(UNALIGNED_ACCESSES) && !slow_safe();
1304 }
1305
1306
1307 void RegExpMacroAssemblerPPC::LoadCurrentCharacterUnchecked(int cp_offset,
1308 int characters) {
1309 Register offset = current_input_offset();
1310 if (cp_offset != 0) {
1311 // r25 is not being used to store the capture start index at this point.
1312 __ addi(r25, current_input_offset(), Operand(cp_offset * char_size()));
1313 offset = r25;
1314 }
1315 // The lwz, stw, lhz, sth instructions can do unaligned accesses, if the CPU
1316 // and the operating system running on the target allow it.
1317 // We assume we don't want to do unaligned loads on PPC, so this function
1318 // must only be used to load a single character at a time.
1319
1320 DCHECK(characters == 1);
1321 __ add(current_character(), end_of_input_address(), offset);
1322 if (mode_ == LATIN1) {
1323 __ lbz(current_character(), MemOperand(current_character()));
1324 } else {
1325 DCHECK(mode_ == UC16);
1326 __ lhz(current_character(), MemOperand(current_character()));
1327 }
1328 }
1329
1330
1331 #undef __
1332
1333 #endif // V8_INTERPRETED_REGEXP
1334 }
1335 } // namespace v8::internal
1336
1337 #endif // V8_TARGET_ARCH_PPC
OLDNEW
« no previous file with comments | « src/ppc/regexp-macro-assembler-ppc.h ('k') | src/ppc/simulator-ppc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698