OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 v8::HandleScope scope; | 401 v8::HandleScope scope; |
402 Assembler assm(Isolate::Current(), NULL, 0); | 402 Assembler assm(Isolate::Current(), NULL, 0); |
403 | 403 |
404 Label target; | 404 Label target; |
405 __ j(equal, &target); | 405 __ j(equal, &target); |
406 __ j(not_equal, &target); | 406 __ j(not_equal, &target); |
407 __ bind(&target); | 407 __ bind(&target); |
408 __ nop(); | 408 __ nop(); |
409 } | 409 } |
410 | 410 |
| 411 |
| 412 TEST(AssemblerMultiByteNop) { |
| 413 InitializeVM(); |
| 414 v8::HandleScope scope; |
| 415 v8::internal::byte buffer[1024]; |
| 416 Assembler assm(Isolate::Current(), buffer, sizeof(buffer)); |
| 417 __ push(ebx); |
| 418 __ push(ecx); |
| 419 __ push(edx); |
| 420 __ push(edi); |
| 421 __ push(esi); |
| 422 __ mov(eax, 1); |
| 423 __ mov(ebx, 2); |
| 424 __ mov(ecx, 3); |
| 425 __ mov(edx, 4); |
| 426 __ mov(edi, 5); |
| 427 __ mov(esi, 6); |
| 428 for (int i = 0; i < 16; i++) { |
| 429 int before = assm.pc_offset(); |
| 430 __ Nop(i); |
| 431 CHECK_EQ(assm.pc_offset() - before, i); |
| 432 } |
| 433 |
| 434 Label fail; |
| 435 __ cmp(eax, 1); |
| 436 __ j(not_equal, &fail); |
| 437 __ cmp(ebx, 2); |
| 438 __ j(not_equal, &fail); |
| 439 __ cmp(ecx, 3); |
| 440 __ j(not_equal, &fail); |
| 441 __ cmp(edx, 4); |
| 442 __ j(not_equal, &fail); |
| 443 __ cmp(edi, 5); |
| 444 __ j(not_equal, &fail); |
| 445 __ cmp(esi, 6); |
| 446 __ j(not_equal, &fail); |
| 447 __ mov(eax, 42); |
| 448 __ pop(esi); |
| 449 __ pop(edi); |
| 450 __ pop(edx); |
| 451 __ pop(ecx); |
| 452 __ pop(ebx); |
| 453 __ ret(0); |
| 454 __ bind(&fail); |
| 455 __ mov(eax, 13); |
| 456 __ pop(esi); |
| 457 __ pop(edi); |
| 458 __ pop(edx); |
| 459 __ pop(ecx); |
| 460 __ pop(ebx); |
| 461 __ ret(0); |
| 462 |
| 463 CodeDesc desc; |
| 464 assm.GetCode(&desc); |
| 465 Code* code = Code::cast(HEAP->CreateCode( |
| 466 desc, |
| 467 Code::ComputeFlags(Code::STUB), |
| 468 Handle<Object>(HEAP->undefined_value()))->ToObjectChecked()); |
| 469 CHECK(code->IsCode()); |
| 470 |
| 471 F0 f = FUNCTION_CAST<F0>(code->entry()); |
| 472 int res = f(); |
| 473 CHECK_EQ(42, res); |
| 474 } |
| 475 |
| 476 |
| 477 |
| 478 |
411 #undef __ | 479 #undef __ |
OLD | NEW |