| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 BranchOrBacktrack(not_equal, on_not_at_start); | 219 BranchOrBacktrack(not_equal, on_not_at_start); |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 void RegExpMacroAssemblerX64::CheckCharacterLT(uc16 limit, Label* on_less) { | 223 void RegExpMacroAssemblerX64::CheckCharacterLT(uc16 limit, Label* on_less) { |
| 224 __ cmpl(current_character(), Immediate(limit)); | 224 __ cmpl(current_character(), Immediate(limit)); |
| 225 BranchOrBacktrack(less, on_less); | 225 BranchOrBacktrack(less, on_less); |
| 226 } | 226 } |
| 227 | 227 |
| 228 | 228 |
| 229 void RegExpMacroAssemblerX64::CheckCharacters(Vector<const uc16> str, | |
| 230 int cp_offset, | |
| 231 Label* on_failure, | |
| 232 bool check_end_of_string) { | |
| 233 #ifdef DEBUG | |
| 234 // If input is ASCII, don't even bother calling here if the string to | |
| 235 // match contains a non-ASCII character. | |
| 236 if (mode_ == ASCII) { | |
| 237 ASSERT(String::IsOneByte(str.start(), str.length())); | |
| 238 } | |
| 239 #endif | |
| 240 int byte_length = str.length() * char_size(); | |
| 241 int byte_offset = cp_offset * char_size(); | |
| 242 if (check_end_of_string) { | |
| 243 // Check that there are at least str.length() characters left in the input. | |
| 244 __ cmpl(rdi, Immediate(-(byte_offset + byte_length))); | |
| 245 BranchOrBacktrack(greater, on_failure); | |
| 246 } | |
| 247 | |
| 248 if (on_failure == NULL) { | |
| 249 // Instead of inlining a backtrack, (re)use the global backtrack target. | |
| 250 on_failure = &backtrack_label_; | |
| 251 } | |
| 252 | |
| 253 // Do one character test first to minimize loading for the case that | |
| 254 // we don't match at all (loading more than one character introduces that | |
| 255 // chance of reading unaligned and reading across cache boundaries). | |
| 256 // If the first character matches, expect a larger chance of matching the | |
| 257 // string, and start loading more characters at a time. | |
| 258 if (mode_ == ASCII) { | |
| 259 __ cmpb(Operand(rsi, rdi, times_1, byte_offset), | |
| 260 Immediate(static_cast<int8_t>(str[0]))); | |
| 261 } else { | |
| 262 // Don't use 16-bit immediate. The size changing prefix throws off | |
| 263 // pre-decoding. | |
| 264 __ movzxwl(rax, | |
| 265 Operand(rsi, rdi, times_1, byte_offset)); | |
| 266 __ cmpl(rax, Immediate(static_cast<int32_t>(str[0]))); | |
| 267 } | |
| 268 BranchOrBacktrack(not_equal, on_failure); | |
| 269 | |
| 270 __ lea(rbx, Operand(rsi, rdi, times_1, 0)); | |
| 271 for (int i = 1, n = str.length(); i < n; ) { | |
| 272 if (mode_ == ASCII) { | |
| 273 if (i + 8 <= n) { | |
| 274 uint64_t combined_chars = | |
| 275 (static_cast<uint64_t>(str[i + 0]) << 0) || | |
| 276 (static_cast<uint64_t>(str[i + 1]) << 8) || | |
| 277 (static_cast<uint64_t>(str[i + 2]) << 16) || | |
| 278 (static_cast<uint64_t>(str[i + 3]) << 24) || | |
| 279 (static_cast<uint64_t>(str[i + 4]) << 32) || | |
| 280 (static_cast<uint64_t>(str[i + 5]) << 40) || | |
| 281 (static_cast<uint64_t>(str[i + 6]) << 48) || | |
| 282 (static_cast<uint64_t>(str[i + 7]) << 56); | |
| 283 __ movq(rax, combined_chars, RelocInfo::NONE64); | |
| 284 __ cmpq(rax, Operand(rbx, byte_offset + i)); | |
| 285 i += 8; | |
| 286 } else if (i + 4 <= n) { | |
| 287 uint32_t combined_chars = | |
| 288 (static_cast<uint32_t>(str[i + 0]) << 0) || | |
| 289 (static_cast<uint32_t>(str[i + 1]) << 8) || | |
| 290 (static_cast<uint32_t>(str[i + 2]) << 16) || | |
| 291 (static_cast<uint32_t>(str[i + 3]) << 24); | |
| 292 __ cmpl(Operand(rbx, byte_offset + i), Immediate(combined_chars)); | |
| 293 i += 4; | |
| 294 } else { | |
| 295 __ cmpb(Operand(rbx, byte_offset + i), | |
| 296 Immediate(static_cast<int8_t>(str[i]))); | |
| 297 i++; | |
| 298 } | |
| 299 } else { | |
| 300 ASSERT(mode_ == UC16); | |
| 301 if (i + 4 <= n) { | |
| 302 uint64_t combined_chars = *reinterpret_cast<const uint64_t*>(&str[i]); | |
| 303 __ movq(rax, combined_chars, RelocInfo::NONE64); | |
| 304 __ cmpq(rax, | |
| 305 Operand(rsi, rdi, times_1, byte_offset + i * sizeof(uc16))); | |
| 306 i += 4; | |
| 307 } else if (i + 2 <= n) { | |
| 308 uint32_t combined_chars = *reinterpret_cast<const uint32_t*>(&str[i]); | |
| 309 __ cmpl(Operand(rsi, rdi, times_1, byte_offset + i * sizeof(uc16)), | |
| 310 Immediate(combined_chars)); | |
| 311 i += 2; | |
| 312 } else { | |
| 313 __ movzxwl(rax, | |
| 314 Operand(rsi, rdi, times_1, byte_offset + i * sizeof(uc16))); | |
| 315 __ cmpl(rax, Immediate(str[i])); | |
| 316 i++; | |
| 317 } | |
| 318 } | |
| 319 BranchOrBacktrack(not_equal, on_failure); | |
| 320 } | |
| 321 } | |
| 322 | |
| 323 | |
| 324 void RegExpMacroAssemblerX64::CheckGreedyLoop(Label* on_equal) { | 229 void RegExpMacroAssemblerX64::CheckGreedyLoop(Label* on_equal) { |
| 325 Label fallthrough; | 230 Label fallthrough; |
| 326 __ cmpl(rdi, Operand(backtrack_stackpointer(), 0)); | 231 __ cmpl(rdi, Operand(backtrack_stackpointer(), 0)); |
| 327 __ j(not_equal, &fallthrough); | 232 __ j(not_equal, &fallthrough); |
| 328 Drop(); | 233 Drop(); |
| 329 BranchOrBacktrack(no_condition, on_equal); | 234 BranchOrBacktrack(no_condition, on_equal); |
| 330 __ bind(&fallthrough); | 235 __ bind(&fallthrough); |
| 331 } | 236 } |
| 332 | 237 |
| 333 | 238 |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 } | 1439 } |
| 1535 } | 1440 } |
| 1536 | 1441 |
| 1537 #undef __ | 1442 #undef __ |
| 1538 | 1443 |
| 1539 #endif // V8_INTERPRETED_REGEXP | 1444 #endif // V8_INTERPRETED_REGEXP |
| 1540 | 1445 |
| 1541 }} // namespace v8::internal | 1446 }} // namespace v8::internal |
| 1542 | 1447 |
| 1543 #endif // V8_TARGET_ARCH_X64 | 1448 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |