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

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

Issue 14886: Bring toiger up to date with bleeding edge 984. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/regexp-macro-assembler-ia32.h ('k') | src/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 102
103 RegExpMacroAssemblerIA32::~RegExpMacroAssemblerIA32() { 103 RegExpMacroAssemblerIA32::~RegExpMacroAssemblerIA32() {
104 delete masm_; 104 delete masm_;
105 // Unuse labels in case we throw away the assembler without calling GetCode. 105 // Unuse labels in case we throw away the assembler without calling GetCode.
106 entry_label_.Unuse(); 106 entry_label_.Unuse();
107 start_label_.Unuse(); 107 start_label_.Unuse();
108 success_label_.Unuse(); 108 success_label_.Unuse();
109 exit_label_.Unuse(); 109 exit_label_.Unuse();
110 check_preempt_label_.Unuse();
110 } 111 }
111 112
112 113
113 void RegExpMacroAssemblerIA32::AdvanceCurrentPosition(int by) { 114 void RegExpMacroAssemblerIA32::AdvanceCurrentPosition(int by) {
114 if (by != 0) { 115 if (by != 0) {
115 Label inside_string; 116 Label inside_string;
116 __ add(Operand(edi), Immediate(by * char_size())); 117 __ add(Operand(edi), Immediate(by * char_size()));
117 } 118 }
118 } 119 }
119 120
120 121
121 void RegExpMacroAssemblerIA32::AdvanceRegister(int reg, int by) { 122 void RegExpMacroAssemblerIA32::AdvanceRegister(int reg, int by) {
122 ASSERT(reg >= 0); 123 ASSERT(reg >= 0);
123 ASSERT(reg < num_registers_); 124 ASSERT(reg < num_registers_);
124 __ add(register_location(reg), Immediate(by)); 125 __ add(register_location(reg), Immediate(by));
125 } 126 }
126 127
127 128
128 void RegExpMacroAssemblerIA32::Backtrack() { 129 void RegExpMacroAssemblerIA32::Backtrack() {
129 __ pop(ecx); 130 SafeReturn();
130 __ add(Operand(ecx), Immediate(self_));
131 __ jmp(Operand(ecx));
132 } 131 }
133 132
134 133
135 void RegExpMacroAssemblerIA32::Bind(Label* label) { 134 void RegExpMacroAssemblerIA32::Bind(Label* label) {
136 __ bind(label); 135 __ bind(label);
137 } 136 }
138 137
139 void RegExpMacroAssemblerIA32::CheckBitmap(uc16 start, 138 void RegExpMacroAssemblerIA32::CheckBitmap(uc16 start,
140 Label* bitmap, 139 Label* bitmap,
141 Label* on_zero) { 140 Label* on_zero) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 int cp_offset, 186 int cp_offset,
188 Label* on_failure, 187 Label* on_failure,
189 bool check_end_of_string) { 188 bool check_end_of_string) {
190 int byte_length = str.length() * char_size(); 189 int byte_length = str.length() * char_size();
191 int byte_offset = cp_offset * char_size(); 190 int byte_offset = cp_offset * char_size();
192 if (check_end_of_string) { 191 if (check_end_of_string) {
193 __ cmp(Operand(edi), Immediate(-(byte_offset + byte_length))); 192 __ cmp(Operand(edi), Immediate(-(byte_offset + byte_length)));
194 BranchOrBacktrack(greater, on_failure); 193 BranchOrBacktrack(greater, on_failure);
195 } 194 }
196 195
197 if (str.length() <= kMaxInlineStringTests) { 196 Label backtrack;
198 for (int i = 0; i < str.length(); i++) { 197 if (on_failure == NULL) {
199 if (mode_ == ASCII) { 198 // Avoid inlining the Backtrack macro for each test.
200 __ cmpb(Operand(esi, edi, times_1, byte_offset + i), 199 Label skip_backtrack;
201 static_cast<int8_t>(str[i])); 200 __ jmp(&skip_backtrack);
202 } else { 201 __ bind(&backtrack);
203 ASSERT(mode_ == UC16); 202 Backtrack();
204 __ cmpw(Operand(esi, edi, times_1, byte_offset + i * sizeof(uc16)), 203 __ bind(&skip_backtrack);
205 Immediate(str[i])); 204 on_failure = &backtrack;
206 }
207 BranchOrBacktrack(not_equal, on_failure);
208 }
209 return;
210 } 205 }
211 206
212 ArraySlice constant_buffer = constants_.GetBuffer(str.length(), char_size()); 207 for (int i = 0; i < str.length(); i++) {
213 if (mode_ == ASCII) { 208 if (mode_ == ASCII) {
214 for (int i = 0; i < str.length(); i++) { 209 __ cmpb(Operand(esi, edi, times_1, byte_offset + i),
215 constant_buffer.at<char>(i) = static_cast<char>(str[i]); 210 static_cast<int8_t>(str[i]));
211 } else {
212 ASSERT(mode_ == UC16);
213 __ cmpw(Operand(esi, edi, times_1, byte_offset + i * sizeof(uc16)),
214 Immediate(str[i]));
216 } 215 }
217 } else { 216 BranchOrBacktrack(not_equal, on_failure);
218 memcpy(constant_buffer.location(),
219 str.start(),
220 str.length() * sizeof(uc16));
221 } 217 }
222
223 __ mov(eax, edi);
224 __ mov(ebx, esi);
225 __ lea(edi, Operand(esi, edi, times_1, byte_offset));
226 LoadConstantBufferAddress(esi, &constant_buffer);
227 __ mov(ecx, str.length());
228 if (char_size() == 1) {
229 __ rep_cmpsb();
230 } else {
231 ASSERT(char_size() == 2);
232 __ rep_cmpsw();
233 }
234 __ mov(esi, ebx);
235 __ mov(edi, eax);
236 BranchOrBacktrack(not_equal, on_failure);
237 } 218 }
238 219
239 220
240 void RegExpMacroAssemblerIA32::CheckGreedyLoop(Label* on_equal) { 221 void RegExpMacroAssemblerIA32::CheckGreedyLoop(Label* on_equal) {
241 Label fallthrough; 222 Label fallthrough;
242 __ cmp(edi, Operand(esp, 0)); 223 __ cmp(edi, Operand(esp, 0));
243 __ j(not_equal, &fallthrough); 224 __ j(not_equal, &fallthrough);
244 __ add(Operand(esp), Immediate(4)); // Pop. 225 __ add(Operand(esp), Immediate(4)); // Pop.
245 BranchOrBacktrack(no_condition, on_equal); 226 BranchOrBacktrack(no_condition, on_equal);
246 __ bind(&fallthrough); 227 __ bind(&fallthrough);
247 } 228 }
248 229
249 230
250 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase( 231 void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase(
251 int start_reg, 232 int start_reg,
252 Label* on_no_match) { 233 Label* on_no_match) {
253 Label fallthrough; 234 Label fallthrough;
254 __ mov(eax, register_location(start_reg)); 235 __ mov(edx, register_location(start_reg));
255 __ mov(ecx, register_location(start_reg + 1)); 236 __ mov(ecx, register_location(start_reg + 1));
256 __ sub(ecx, Operand(eax)); // Length to check. 237 __ sub(ecx, Operand(edx)); // Length to check.
257 BranchOrBacktrack(less, on_no_match); 238 BranchOrBacktrack(less, on_no_match);
258 __ j(equal, &fallthrough); 239 __ j(equal, &fallthrough);
259 240
260 if (mode_ == ASCII) { 241 if (mode_ == ASCII) {
261 Label success; 242 Label success;
262 Label fail; 243 Label fail;
263 __ push(esi); 244 Label loop_increment;
264 __ push(edi); 245 __ push(edi);
246 __ add(edx, Operand(esi));
265 __ add(edi, Operand(esi)); 247 __ add(edi, Operand(esi));
266 __ add(esi, Operand(eax)); 248 __ add(ecx, Operand(edi));
249
267 Label loop; 250 Label loop;
268 __ bind(&loop); 251 __ bind(&loop);
269 __ rep_cmpsb(); 252 __ movzx_b(eax, Operand(edi, 0));
270 __ j(equal, &success); 253 __ cmpb_al(Operand(edx, 0));
254 __ j(equal, &loop_increment);
255
271 // Compare lower-case if letters. 256 // Compare lower-case if letters.
272 __ movzx_b(eax, Operand(edi, -1)); 257 __ or_(eax, 0x20); // To lower-case.
273 __ or_(eax, 0x20); // To-lower-case
274 __ lea(ebx, Operand(eax, -'a')); 258 __ lea(ebx, Operand(eax, -'a'));
275 __ cmp(ebx, static_cast<int32_t>('z' - 'a')); 259 __ cmp(ebx, static_cast<int32_t>('z' - 'a'));
276 __ j(above, &fail); 260 __ j(above, &fail);
277 __ movzx_b(ebx, Operand(esi, -1)); 261 __ movzx_b(ebx, Operand(edx, 0));
278 __ or_(ebx, 0x20); // To-lower-case 262 __ or_(ebx, 0x20); // To-lower-case
279 __ cmp(eax, Operand(ebx)); 263 __ cmp(eax, Operand(ebx));
280 __ j(not_equal, &fail); 264 __ j(not_equal, &fail);
281 __ or_(ecx, Operand(ecx)); 265
282 __ j(not_equal, &loop); 266 __ bind(&loop_increment);
267 __ add(Operand(edx), Immediate(1));
268 __ add(Operand(edi), Immediate(1));
269 __ cmp(edi, Operand(ecx));
270 __ j(below, &loop, taken);
283 __ jmp(&success); 271 __ jmp(&success);
284 272
285 __ bind(&fail); 273 __ bind(&fail);
286 __ pop(edi); 274 __ pop(edi);
287 __ pop(esi);
288 BranchOrBacktrack(no_condition, on_no_match); 275 BranchOrBacktrack(no_condition, on_no_match);
289 276
290 __ bind(&success); 277 __ bind(&success);
291 __ pop(eax); // discard original value of edi 278 __ pop(eax); // discard original value of edi
292 __ pop(esi);
293 __ sub(edi, Operand(esi)); 279 __ sub(edi, Operand(esi));
294 } else { 280 } else {
295 // store state 281 ASSERT(mode_ == UC16);
296 __ push(esi); 282 __ push(esi);
297 __ push(edi); 283 __ push(edi);
298 __ push(ecx); 284 __ push(ecx);
299 // align stack 285 const int four_arguments = 4;
300 int frameAlignment = OS::ActivationFrameAlignment(); 286 FrameAlign(four_arguments);
301 if (frameAlignment != 0) {
302 __ mov(ebx, esp);
303 __ sub(Operand(esp), Immediate(5 * kPointerSize)); // args + esp.
304 ASSERT(IsPowerOf2(frameAlignment));
305 __ and_(esp, -frameAlignment);
306 __ mov(Operand(esp, 4 * kPointerSize), ebx);
307 } else {
308 __ sub(Operand(esp), Immediate(4 * kPointerSize));
309 }
310 // Put arguments on stack. 287 // Put arguments on stack.
311 __ mov(Operand(esp, 3 * kPointerSize), ecx); 288 __ mov(Operand(esp, 3 * kPointerSize), ecx);
312 __ mov(ebx, Operand(ebp, kInputEndOffset)); 289 __ mov(ebx, Operand(ebp, kInputEndOffset));
313 __ add(edi, Operand(ebx)); 290 __ add(edi, Operand(ebx));
314 __ mov(Operand(esp, 2 * kPointerSize), edi); 291 __ mov(Operand(esp, 2 * kPointerSize), edi);
315 __ add(eax, Operand(ebx)); 292 __ add(eax, Operand(ebx));
316 __ mov(Operand(esp, 1 * kPointerSize), eax); 293 __ mov(Operand(esp, 1 * kPointerSize), eax);
317 __ mov(eax, Operand(ebp, kInputBuffer)); 294 __ mov(eax, Operand(ebp, kInputBuffer));
318 __ mov(Operand(esp, 0 * kPointerSize), eax); 295 __ mov(Operand(esp, 0 * kPointerSize), eax);
319 Address function_address = FUNCTION_ADDR(&CaseInsensitiveCompareUC16); 296 Address function_address = FUNCTION_ADDR(&CaseInsensitiveCompareUC16);
320 __ mov(Operand(eax), 297 CallCFunction(function_address, four_arguments);
321 Immediate(reinterpret_cast<int32_t>(function_address)));
322 __ call(Operand(eax));
323 if (frameAlignment != 0) {
324 __ mov(esp, Operand(esp, 4 * kPointerSize));
325 } else {
326 __ add(Operand(esp), Immediate(4 * sizeof(int32_t)));
327 }
328 __ pop(ecx); 298 __ pop(ecx);
329 __ pop(edi); 299 __ pop(edi);
330 __ pop(esi); 300 __ pop(esi);
301
331 __ or_(eax, Operand(eax)); 302 __ or_(eax, Operand(eax));
332 BranchOrBacktrack(zero, on_no_match); 303 BranchOrBacktrack(zero, on_no_match);
333 __ add(edi, Operand(ecx)); 304 __ add(edi, Operand(ecx));
334 } 305 }
335 __ bind(&fallthrough); 306 __ bind(&fallthrough);
336 } 307 }
337 308
338 309
339 void RegExpMacroAssemblerIA32::CheckNotBackReference( 310 void RegExpMacroAssemblerIA32::CheckNotBackReference(
340 int start_reg, 311 int start_reg,
341 Label* on_no_match) { 312 Label* on_no_match) {
342 Label fallthrough; 313 Label fallthrough;
343 __ mov(eax, register_location(start_reg)); 314 Label success;
315 Label fail;
316 __ mov(edx, register_location(start_reg));
344 __ mov(ecx, register_location(start_reg + 1)); 317 __ mov(ecx, register_location(start_reg + 1));
345 __ sub(ecx, Operand(eax)); // Length to check. 318 __ sub(ecx, Operand(edx)); // Length to check.
346 BranchOrBacktrack(less, on_no_match); 319 BranchOrBacktrack(less, on_no_match);
347 __ j(equal, &fallthrough); 320 __ j(equal, &fallthrough);
348 // Check that there are sufficient characters left in the input. 321 // Check that there are sufficient characters left in the input.
322
349 __ mov(ebx, edi); 323 __ mov(ebx, edi);
350 __ add(ebx, Operand(ecx)); 324 __ add(ebx, Operand(ecx));
351 BranchOrBacktrack(greater, on_no_match); 325 BranchOrBacktrack(greater, on_no_match);
352 326
353 __ mov(ebx, edi); 327 __ mov(ebx, edi);
354 __ mov(edx, esi);
355 __ add(edi, Operand(esi)); 328 __ add(edi, Operand(esi));
356 __ add(esi, Operand(eax)); 329 __ add(edx, Operand(esi));
357 __ rep_cmpsb(); 330 __ add(ecx, Operand(edi));
358 __ mov(esi, edx); 331
359 Label success; 332 Label loop;
360 __ j(equal, &success); 333 __ bind(&loop);
334 if (mode_ == ASCII) {
335 __ movzx_b(eax, Operand(edx, 0));
336 __ cmpb_al(Operand(edi, 0));
337 } else {
338 ASSERT(mode_ == UC16);
339 __ movzx_w(eax, Operand(edx, 0));
340 __ cmpw_ax(Operand(edi, 0));
341 }
342 __ j(not_equal, &fail);
343 __ add(Operand(edx), Immediate(char_size()));
344 __ add(Operand(edi), Immediate(char_size()));
345 __ cmp(edi, Operand(ecx));
346 __ j(below, &loop);
347 __ jmp(&success);
348
349 __ bind(&fail);
361 __ mov(edi, ebx); 350 __ mov(edi, ebx);
362 BranchOrBacktrack(no_condition, on_no_match); 351 BranchOrBacktrack(no_condition, on_no_match);
363 352
364 __ bind(&success); 353 __ bind(&success);
365 __ sub(edi, Operand(esi)); 354 __ sub(edi, Operand(esi));
366
367 __ bind(&fallthrough); 355 __ bind(&fallthrough);
368 } 356 }
369 357
370 358
371 void RegExpMacroAssemblerIA32::CheckNotRegistersEqual(int reg1, 359 void RegExpMacroAssemblerIA32::CheckNotRegistersEqual(int reg1,
372 int reg2, 360 int reg2,
373 Label* on_not_equal) { 361 Label* on_not_equal) {
374 __ mov(eax, register_location(reg1)); 362 __ mov(eax, register_location(reg1));
375 __ cmp(eax, register_location(reg2)); 363 __ cmp(eax, register_location(reg2));
376 BranchOrBacktrack(not_equal, on_not_equal); 364 BranchOrBacktrack(not_equal, on_not_equal);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 __ cmp(Operand(ebp, kAtStart), Immediate(0)); 517 __ cmp(Operand(ebp, kAtStart), Immediate(0));
530 __ j(not_equal, &at_start); 518 __ j(not_equal, &at_start);
531 LoadCurrentCharacterUnchecked(-1); // Load previous char. 519 LoadCurrentCharacterUnchecked(-1); // Load previous char.
532 __ jmp(&start_label_); 520 __ jmp(&start_label_);
533 __ bind(&at_start); 521 __ bind(&at_start);
534 __ mov(current_character(), '\n'); 522 __ mov(current_character(), '\n');
535 __ jmp(&start_label_); 523 __ jmp(&start_label_);
536 524
537 525
538 // Exit code: 526 // Exit code:
539 // Success 527 if (success_label_.is_linked()) {
540 __ bind(&success_label_); 528 // Success
541 if (num_saved_registers_ > 0) { 529 __ bind(&success_label_);
542 // copy captures to output 530 if (num_saved_registers_ > 0) {
543 __ mov(ebx, Operand(ebp, kRegisterOutput)); 531 // copy captures to output
544 __ mov(ecx, Operand(ebp, kInputEndOffset)); 532 __ mov(ebx, Operand(ebp, kRegisterOutput));
545 __ sub(ecx, Operand(ebp, kInputStartOffset)); 533 __ mov(ecx, Operand(ebp, kInputEndOffset));
546 for (int i = 0; i < num_saved_registers_; i++) { 534 __ sub(ecx, Operand(ebp, kInputStartOffset));
547 __ mov(eax, register_location(i)); 535 for (int i = 0; i < num_saved_registers_; i++) {
548 __ add(eax, Operand(ecx)); // Convert to index from start, not end. 536 __ mov(eax, register_location(i));
549 if (char_size() > 1) { 537 __ add(eax, Operand(ecx)); // Convert to index from start, not end.
550 ASSERT(char_size() == 2); 538 if (mode_ == UC16) {
551 __ sar(eax, 1); // Convert to character index, not byte. 539 __ sar(eax, 1); // Convert byte index to character index.
540 }
541 __ mov(Operand(ebx, i * kPointerSize), eax);
552 } 542 }
553 __ mov(Operand(ebx, i * kPointerSize), eax);
554 } 543 }
544 __ mov(eax, Immediate(1));
555 } 545 }
556 __ mov(eax, Immediate(1));
557
558 // Exit and return eax 546 // Exit and return eax
559 __ bind(&exit_label_); 547 __ bind(&exit_label_);
560 __ leave(); 548 __ leave();
561 __ pop(ebx); 549 __ pop(ebx);
562 __ pop(edi); 550 __ pop(edi);
563 __ pop(esi); 551 __ pop(esi);
564 __ ret(0); 552 __ ret(0);
565 553
554 // Preempt-code
555 if (check_preempt_label_.is_linked()) {
556 __ bind(&check_preempt_label_);
557 // TODO(lrn): call C function to check the stack guard and return current
558 // stack state (0 = ok, positive = out of stack, negative = preempt).
559 // Then dispatch to an action depending on state, and loop.
560 __ push(edi);
561
562 Label retry;
563 Label stack_overflow;
564
565 __ bind(&retry);
566 int num_arguments = 2;
567 FrameAlign(num_arguments);
568 __ mov(Operand(esp, 1 * kPointerSize), Immediate(self_));
569 __ lea(eax, Operand(esp, -kPointerSize));
570 __ mov(Operand(esp, 0 * kPointerSize), eax);
571 CallCFunction(FUNCTION_ADDR(&CheckStackGuardState), num_arguments);
572
573 ExternalReference stack_guard_limit =
574 ExternalReference::address_of_stack_guard_limit();
575
576 __ or_(eax, Operand(eax));
577 __ j(not_equal, &stack_overflow);
578
579 __ cmp(esp, Operand::StaticVariable(stack_guard_limit));
580 __ j(below_equal, &retry);
581
582 __ pop(edi);
583 // String might have moved: Recompute esi from scratch.
584 __ mov(esi, Operand(esp, kInputBuffer));
585 __ mov(esi, Operand(esi, 0));
586 __ add(esi, Operand(esp, kInputEndOffset));
587 SafeReturn();
588
589 __ bind(&stack_overflow);
590 // Exit with result -1 to signal thrown exception.
591 __ mov(eax, -1);
592 __ jmp(&exit_label_);
593 }
594
566 CodeDesc code_desc; 595 CodeDesc code_desc;
567 masm_->GetCode(&code_desc); 596 masm_->GetCode(&code_desc);
568 Handle<Code> code = Factory::NewCode(code_desc, 597 Handle<Code> code = Factory::NewCode(code_desc,
569 NULL, 598 NULL,
570 Code::ComputeFlags(Code::REGEXP), 599 Code::ComputeFlags(Code::REGEXP),
571 self_); 600 self_);
572 LOG(CodeCreateEvent("RegExp", *code, *(source->ToCString()))); 601 LOG(CodeCreateEvent("RegExp", *code, *(source->ToCString())));
573 return Handle<Object>::cast(code); 602 return Handle<Object>::cast(code);
574 } 603 }
575 604
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 __ pop(edi); 644 __ pop(edi);
616 } 645 }
617 646
618 647
619 void RegExpMacroAssemblerIA32::PopRegister(int register_index) { 648 void RegExpMacroAssemblerIA32::PopRegister(int register_index) {
620 __ pop(register_location(register_index)); 649 __ pop(register_location(register_index));
621 } 650 }
622 651
623 652
624 void RegExpMacroAssemblerIA32::PushBacktrack(Label* label) { 653 void RegExpMacroAssemblerIA32::PushBacktrack(Label* label) {
625 // CheckStackLimit(); // Not ready yet. 654 __ push(Immediate::CodeRelativeOffset(label));
626 __ push(label, RelocInfo::NONE); 655 CheckStackLimit();
627 } 656 }
628 657
629 658
630 void RegExpMacroAssemblerIA32::PushCurrentPosition() { 659 void RegExpMacroAssemblerIA32::PushCurrentPosition() {
631 __ push(edi); 660 __ push(edi);
632 } 661 }
633 662
634 663
635 void RegExpMacroAssemblerIA32::PushRegister(int register_index) { 664 void RegExpMacroAssemblerIA32::PushRegister(int register_index) {
636 __ push(register_location(register_index)); 665 __ push(register_location(register_index));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 if (c1 != c2) { 732 if (c1 != c2) {
704 return 0; 733 return 0;
705 } 734 }
706 } 735 }
707 } 736 }
708 } 737 }
709 return 1; 738 return 1;
710 } 739 }
711 740
712 741
742 int RegExpMacroAssemblerIA32::CheckStackGuardState(Address return_address,
743 Code* re_code) {
744 if (StackGuard::IsStackOverflow()) {
745 Top::StackOverflow();
746 return 1;
747 }
748
749 // If not real stack overflow the stack guard was used to interrupt
750 // execution for another purpose.
751
752 // Prepare for possible GC.
753 Handle<Code> code_handle(re_code);
754 #ifdef DEBUG
755 CHECK(re_code->instruction_start() <= return_address);
756 CHECK(return_address <=
757 re_code->instruction_start() + re_code->instruction_size());
758 #endif
759
760 Object* result = Execution::HandleStackGuardInterrupt();
761
762 if (*code_handle != re_code) { // Return address no longer valid
763 int delta = *code_handle - re_code;
764 *reinterpret_cast<int32_t*>(return_address) += delta;
765 }
766
767 if (result->IsException()) {
768 return 1;
769 }
770 return 0;
771 }
772
773
713 Operand RegExpMacroAssemblerIA32::register_location(int register_index) { 774 Operand RegExpMacroAssemblerIA32::register_location(int register_index) {
714 ASSERT(register_index < (1<<30)); 775 ASSERT(register_index < (1<<30));
715 if (num_registers_ <= register_index) { 776 if (num_registers_ <= register_index) {
716 num_registers_ = register_index + 1; 777 num_registers_ = register_index + 1;
717 } 778 }
718 return Operand(ebp, -(register_index + 1) * kPointerSize); 779 return Operand(ebp, -(register_index + 1) * kPointerSize);
719 } 780 }
720 781
721 782
722 Register RegExpMacroAssemblerIA32::current_character() { 783 Register RegExpMacroAssemblerIA32::current_character() {
(...skipping 20 matching lines...) Expand all
743 Label skip; 804 Label skip;
744 __ j(NegateCondition(condition), &skip); 805 __ j(NegateCondition(condition), &skip);
745 Backtrack(); 806 Backtrack();
746 __ bind(&skip); 807 __ bind(&skip);
747 return; 808 return;
748 } 809 }
749 __ j(condition, to); 810 __ j(condition, to);
750 } 811 }
751 812
752 813
814 void RegExpMacroAssemblerIA32::SafeCall(Label* to) {
815 Label return_to;
816 __ push(Immediate::CodeRelativeOffset(&return_to));
817 __ jmp(to);
818 __ bind(&return_to);
819 }
820
821
822 void RegExpMacroAssemblerIA32::SafeReturn() {
823 __ pop(ecx);
824 __ add(Operand(ecx), Immediate(self_));
825 __ jmp(Operand(ecx));
826 }
827
828
753 void RegExpMacroAssemblerIA32::CheckStackLimit() { 829 void RegExpMacroAssemblerIA32::CheckStackLimit() {
754 if (FLAG_check_stack) { 830 if (FLAG_check_stack) {
755 // Check for preemption first. 831 // Check for preemption first.
756 Label no_preempt; 832 Label no_preempt;
757 Label retry_preempt;
758 // Check for preemption. 833 // Check for preemption.
759 ExternalReference stack_guard_limit = 834 ExternalReference stack_guard_limit =
760 ExternalReference::address_of_stack_guard_limit(); 835 ExternalReference::address_of_stack_guard_limit();
761 __ cmp(esp, Operand::StaticVariable(stack_guard_limit)); 836 __ cmp(esp, Operand::StaticVariable(stack_guard_limit));
762 __ j(above, &no_preempt, taken); 837 __ j(above, &no_preempt, taken);
763 __ push(edi); // Current position.
764 __ push(edx); // Current character.
765 // Restore original edi, esi.
766 __ mov(edi, Operand(ebp, kBackup_edi));
767 __ mov(esi, Operand(ebp, kBackup_esi));
768 838
769 __ bind(&retry_preempt); 839 SafeCall(&check_preempt_label_);
770 // simulate stack for Runtime call.
771 __ push(eax);
772 __ push(Immediate(Smi::FromInt(0))); // Dummy receiver
773 __ CallRuntime(Runtime::kStackGuard, 1);
774 __ pop(eax);
775
776 __ cmp(esp, Operand::StaticVariable(stack_guard_limit));
777 __ j(below_equal, &retry_preempt);
778
779 __ pop(edx);
780 __ pop(edi);
781 __ mov(esi, Operand(ebp, kInputBuffer));
782 __ mov(esi, Operand(esi, 0));
783 __ add(esi, Operand(ebp, kInputEndOffset));
784 840
785 __ bind(&no_preempt); 841 __ bind(&no_preempt);
786 } 842 }
787 } 843 }
788 844
789 845
846 void RegExpMacroAssemblerIA32::FrameAlign(int num_arguments) {
847 int frameAlignment = OS::ActivationFrameAlignment();
848 if (frameAlignment != 0) {
849 // Make stack end at alignment and make room for num_arguments words
850 // and the original value of esp.
851 __ mov(ebx, esp);
852 __ sub(Operand(esp), Immediate((num_arguments + 1) * kPointerSize));
853 ASSERT(IsPowerOf2(frameAlignment));
854 __ and_(esp, -frameAlignment);
855 __ mov(Operand(esp, num_arguments * kPointerSize), ebx);
856 } else {
857 __ sub(Operand(esp), Immediate(num_arguments * kPointerSize));
858 }
859 }
860
861
862 void RegExpMacroAssemblerIA32::CallCFunction(Address function_address,
863 int num_arguments) {
864 __ mov(Operand(eax), Immediate(reinterpret_cast<int32_t>(function_address)));
865 __ call(Operand(eax));
866 if (OS::ActivationFrameAlignment() != 0) {
867 __ mov(esp, Operand(esp, num_arguments * kPointerSize));
868 } else {
869 __ add(Operand(esp), Immediate(num_arguments * sizeof(int32_t)));
870 }
871 }
872
873
790 void RegExpMacroAssemblerIA32::LoadCurrentCharacterUnchecked(int cp_offset) { 874 void RegExpMacroAssemblerIA32::LoadCurrentCharacterUnchecked(int cp_offset) {
791 if (mode_ == ASCII) { 875 if (mode_ == ASCII) {
792 __ movzx_b(current_character(), Operand(esi, edi, times_1, cp_offset)); 876 __ movzx_b(current_character(), Operand(esi, edi, times_1, cp_offset));
793 return; 877 } else {
878 ASSERT(mode_ == UC16);
879 __ movzx_w(current_character(),
880 Operand(esi, edi, times_1, cp_offset * sizeof(uc16)));
794 } 881 }
795 ASSERT(mode_ == UC16);
796 __ movzx_w(current_character(),
797 Operand(esi, edi, times_1, cp_offset * sizeof(uc16)));
798 } 882 }
799 883
800 884
801 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg, 885 void RegExpMacroAssemblerIA32::LoadConstantBufferAddress(Register reg,
802 ArraySlice* buffer) { 886 ArraySlice* buffer) {
803 __ mov(reg, buffer->array()); 887 __ mov(reg, buffer->array());
804 __ add(Operand(reg), Immediate(buffer->base_offset())); 888 __ add(Operand(reg), Immediate(buffer->base_offset()));
805 } 889 }
806 890
807 #undef __ 891 #undef __
808 }} // namespace v8::internal 892 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/regexp-macro-assembler-ia32.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698