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