OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 size_t actual_size; | 92 size_t actual_size; |
93 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 93 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
94 &actual_size, | 94 &actual_size, |
95 true)); | 95 true)); |
96 CHECK(buffer); | 96 CHECK(buffer); |
97 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); | 97 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
98 | 98 |
99 // Assemble a simple function that copies argument 2 and returns it. | 99 // Assemble a simple function that copies argument 2 and returns it. |
100 // We compile without stack frame pointers, so the gdb debugger shows | 100 // We compile without stack frame pointers, so the gdb debugger shows |
101 // incorrect stack frames when debugging this function (which has them). | 101 // incorrect stack frames when debugging this function (which has them). |
102 __ push(rbp); | 102 __ pushq(rbp); |
103 __ movq(rbp, rsp); | 103 __ movq(rbp, rsp); |
104 __ push(arg2); // Value at (rbp - 8) | 104 __ pushq(arg2); // Value at (rbp - 8) |
105 __ push(arg2); // Value at (rbp - 16) | 105 __ pushq(arg2); // Value at (rbp - 16) |
106 __ push(arg1); // Value at (rbp - 24) | 106 __ pushq(arg1); // Value at (rbp - 24) |
107 __ pop(rax); | 107 __ popq(rax); |
108 __ pop(rax); | 108 __ popq(rax); |
109 __ pop(rax); | 109 __ popq(rax); |
110 __ pop(rbp); | 110 __ popq(rbp); |
111 __ nop(); | 111 __ nop(); |
112 __ ret(0); | 112 __ ret(0); |
113 | 113 |
114 CodeDesc desc; | 114 CodeDesc desc; |
115 assm.GetCode(&desc); | 115 assm.GetCode(&desc); |
116 // Call the function from C++. | 116 // Call the function from C++. |
117 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 117 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
118 CHECK_EQ(2, result); | 118 CHECK_EQ(2, result); |
119 } | 119 } |
120 | 120 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 TEST(AssemblerX64MemoryOperands) { | 323 TEST(AssemblerX64MemoryOperands) { |
324 // Allocate an executable page of memory. | 324 // Allocate an executable page of memory. |
325 size_t actual_size; | 325 size_t actual_size; |
326 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 326 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
327 &actual_size, | 327 &actual_size, |
328 true)); | 328 true)); |
329 CHECK(buffer); | 329 CHECK(buffer); |
330 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); | 330 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
331 | 331 |
332 // Assemble a simple function that copies argument 2 and returns it. | 332 // Assemble a simple function that copies argument 2 and returns it. |
333 __ push(rbp); | 333 __ pushq(rbp); |
334 __ movq(rbp, rsp); | 334 __ movq(rbp, rsp); |
335 | 335 |
336 __ push(arg2); // Value at (rbp - 8) | 336 __ pushq(arg2); // Value at (rbp - 8) |
337 __ push(arg2); // Value at (rbp - 16) | 337 __ pushq(arg2); // Value at (rbp - 16) |
338 __ push(arg1); // Value at (rbp - 24) | 338 __ pushq(arg1); // Value at (rbp - 24) |
339 | 339 |
340 const int kStackElementSize = 8; | 340 const int kStackElementSize = 8; |
341 __ movq(rax, Operand(rbp, -3 * kStackElementSize)); | 341 __ movq(rax, Operand(rbp, -3 * kStackElementSize)); |
342 __ pop(arg2); | 342 __ popq(arg2); |
343 __ pop(arg2); | 343 __ popq(arg2); |
344 __ pop(arg2); | 344 __ popq(arg2); |
345 __ pop(rbp); | 345 __ popq(rbp); |
346 __ nop(); | 346 __ nop(); |
347 __ ret(0); | 347 __ ret(0); |
348 | 348 |
349 CodeDesc desc; | 349 CodeDesc desc; |
350 assm.GetCode(&desc); | 350 assm.GetCode(&desc); |
351 // Call the function from C++. | 351 // Call the function from C++. |
352 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 352 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
353 CHECK_EQ(3, result); | 353 CHECK_EQ(3, result); |
354 } | 354 } |
355 | 355 |
356 | 356 |
357 TEST(AssemblerX64ControlFlow) { | 357 TEST(AssemblerX64ControlFlow) { |
358 // Allocate an executable page of memory. | 358 // Allocate an executable page of memory. |
359 size_t actual_size; | 359 size_t actual_size; |
360 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 360 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
361 &actual_size, | 361 &actual_size, |
362 true)); | 362 true)); |
363 CHECK(buffer); | 363 CHECK(buffer); |
364 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); | 364 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
365 | 365 |
366 // Assemble a simple function that copies argument 1 and returns it. | 366 // Assemble a simple function that copies argument 1 and returns it. |
367 __ push(rbp); | 367 __ pushq(rbp); |
368 | 368 |
369 __ movq(rbp, rsp); | 369 __ movq(rbp, rsp); |
370 __ movq(rax, arg1); | 370 __ movq(rax, arg1); |
371 Label target; | 371 Label target; |
372 __ jmp(&target); | 372 __ jmp(&target); |
373 __ movq(rax, arg2); | 373 __ movq(rax, arg2); |
374 __ bind(&target); | 374 __ bind(&target); |
375 __ pop(rbp); | 375 __ popq(rbp); |
376 __ ret(0); | 376 __ ret(0); |
377 | 377 |
378 CodeDesc desc; | 378 CodeDesc desc; |
379 assm.GetCode(&desc); | 379 assm.GetCode(&desc); |
380 // Call the function from C++. | 380 // Call the function from C++. |
381 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 381 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
382 CHECK_EQ(3, result); | 382 CHECK_EQ(3, result); |
383 } | 383 } |
384 | 384 |
385 | 385 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 __ nop(); | 489 __ nop(); |
490 } | 490 } |
491 | 491 |
492 | 492 |
493 TEST(AssemblerMultiByteNop) { | 493 TEST(AssemblerMultiByteNop) { |
494 CcTest::InitializeVM(); | 494 CcTest::InitializeVM(); |
495 v8::HandleScope scope(CcTest::isolate()); | 495 v8::HandleScope scope(CcTest::isolate()); |
496 byte buffer[1024]; | 496 byte buffer[1024]; |
497 Isolate* isolate = CcTest::i_isolate(); | 497 Isolate* isolate = CcTest::i_isolate(); |
498 Assembler assm(isolate, buffer, sizeof(buffer)); | 498 Assembler assm(isolate, buffer, sizeof(buffer)); |
499 __ push(rbx); | 499 __ pushq(rbx); |
500 __ push(rcx); | 500 __ pushq(rcx); |
501 __ push(rdx); | 501 __ pushq(rdx); |
502 __ push(rdi); | 502 __ pushq(rdi); |
503 __ push(rsi); | 503 __ pushq(rsi); |
504 __ movq(rax, Immediate(1)); | 504 __ movq(rax, Immediate(1)); |
505 __ movq(rbx, Immediate(2)); | 505 __ movq(rbx, Immediate(2)); |
506 __ movq(rcx, Immediate(3)); | 506 __ movq(rcx, Immediate(3)); |
507 __ movq(rdx, Immediate(4)); | 507 __ movq(rdx, Immediate(4)); |
508 __ movq(rdi, Immediate(5)); | 508 __ movq(rdi, Immediate(5)); |
509 __ movq(rsi, Immediate(6)); | 509 __ movq(rsi, Immediate(6)); |
510 for (int i = 0; i < 16; i++) { | 510 for (int i = 0; i < 16; i++) { |
511 int before = assm.pc_offset(); | 511 int before = assm.pc_offset(); |
512 __ Nop(i); | 512 __ Nop(i); |
513 CHECK_EQ(assm.pc_offset() - before, i); | 513 CHECK_EQ(assm.pc_offset() - before, i); |
514 } | 514 } |
515 | 515 |
516 Label fail; | 516 Label fail; |
517 __ cmpq(rax, Immediate(1)); | 517 __ cmpq(rax, Immediate(1)); |
518 __ j(not_equal, &fail); | 518 __ j(not_equal, &fail); |
519 __ cmpq(rbx, Immediate(2)); | 519 __ cmpq(rbx, Immediate(2)); |
520 __ j(not_equal, &fail); | 520 __ j(not_equal, &fail); |
521 __ cmpq(rcx, Immediate(3)); | 521 __ cmpq(rcx, Immediate(3)); |
522 __ j(not_equal, &fail); | 522 __ j(not_equal, &fail); |
523 __ cmpq(rdx, Immediate(4)); | 523 __ cmpq(rdx, Immediate(4)); |
524 __ j(not_equal, &fail); | 524 __ j(not_equal, &fail); |
525 __ cmpq(rdi, Immediate(5)); | 525 __ cmpq(rdi, Immediate(5)); |
526 __ j(not_equal, &fail); | 526 __ j(not_equal, &fail); |
527 __ cmpq(rsi, Immediate(6)); | 527 __ cmpq(rsi, Immediate(6)); |
528 __ j(not_equal, &fail); | 528 __ j(not_equal, &fail); |
529 __ movq(rax, Immediate(42)); | 529 __ movq(rax, Immediate(42)); |
530 __ pop(rsi); | 530 __ popq(rsi); |
531 __ pop(rdi); | 531 __ popq(rdi); |
532 __ pop(rdx); | 532 __ popq(rdx); |
533 __ pop(rcx); | 533 __ popq(rcx); |
534 __ pop(rbx); | 534 __ popq(rbx); |
535 __ ret(0); | 535 __ ret(0); |
536 __ bind(&fail); | 536 __ bind(&fail); |
537 __ movq(rax, Immediate(13)); | 537 __ movq(rax, Immediate(13)); |
538 __ pop(rsi); | 538 __ popq(rsi); |
539 __ pop(rdi); | 539 __ popq(rdi); |
540 __ pop(rdx); | 540 __ popq(rdx); |
541 __ pop(rcx); | 541 __ popq(rcx); |
542 __ pop(rbx); | 542 __ popq(rbx); |
543 __ ret(0); | 543 __ ret(0); |
544 | 544 |
545 CodeDesc desc; | 545 CodeDesc desc; |
546 assm.GetCode(&desc); | 546 assm.GetCode(&desc); |
547 Code* code = Code::cast(isolate->heap()->CreateCode( | 547 Code* code = Code::cast(isolate->heap()->CreateCode( |
548 desc, | 548 desc, |
549 Code::ComputeFlags(Code::STUB), | 549 Code::ComputeFlags(Code::STUB), |
550 Handle<Code>())->ToObjectChecked()); | 550 Handle<Code>())->ToObjectChecked()); |
551 CHECK(code->IsCode()); | 551 CHECK(code->IsCode()); |
552 | 552 |
(...skipping 11 matching lines...) Expand all Loading... |
564 byte buffer[1024]; | 564 byte buffer[1024]; |
565 | 565 |
566 CHECK(args[0]->IsArray()); | 566 CHECK(args[0]->IsArray()); |
567 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); | 567 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); |
568 CHECK_EQ(ELEMENT_COUNT, vec->Length()); | 568 CHECK_EQ(ELEMENT_COUNT, vec->Length()); |
569 | 569 |
570 Isolate* isolate = CcTest::i_isolate(); | 570 Isolate* isolate = CcTest::i_isolate(); |
571 Assembler assm(isolate, buffer, sizeof(buffer)); | 571 Assembler assm(isolate, buffer, sizeof(buffer)); |
572 | 572 |
573 // Remove return address from the stack for fix stack frame alignment. | 573 // Remove return address from the stack for fix stack frame alignment. |
574 __ pop(rcx); | 574 __ popq(rcx); |
575 | 575 |
576 // Store input vector on the stack. | 576 // Store input vector on the stack. |
577 for (int i = 0; i < ELEMENT_COUNT; i++) { | 577 for (int i = 0; i < ELEMENT_COUNT; i++) { |
578 __ movl(rax, Immediate(vec->Get(i)->Int32Value())); | 578 __ movl(rax, Immediate(vec->Get(i)->Int32Value())); |
579 __ shl(rax, Immediate(0x20)); | 579 __ shl(rax, Immediate(0x20)); |
580 __ or_(rax, Immediate(vec->Get(++i)->Int32Value())); | 580 __ or_(rax, Immediate(vec->Get(++i)->Int32Value())); |
581 __ push(rax); | 581 __ pushq(rax); |
582 } | 582 } |
583 | 583 |
584 // Read vector into a xmm register. | 584 // Read vector into a xmm register. |
585 __ xorps(xmm0, xmm0); | 585 __ xorps(xmm0, xmm0); |
586 __ movdqa(xmm0, Operand(rsp, 0)); | 586 __ movdqa(xmm0, Operand(rsp, 0)); |
587 // Create mask and store it in the return register. | 587 // Create mask and store it in the return register. |
588 __ movmskps(rax, xmm0); | 588 __ movmskps(rax, xmm0); |
589 | 589 |
590 // Remove unused data from the stack. | 590 // Remove unused data from the stack. |
591 __ addq(rsp, Immediate(ELEMENT_COUNT * sizeof(int32_t))); | 591 __ addq(rsp, Immediate(ELEMENT_COUNT * sizeof(int32_t))); |
592 // Restore return address. | 592 // Restore return address. |
593 __ push(rcx); | 593 __ pushq(rcx); |
594 | 594 |
595 __ ret(0); | 595 __ ret(0); |
596 | 596 |
597 CodeDesc desc; | 597 CodeDesc desc; |
598 assm.GetCode(&desc); | 598 assm.GetCode(&desc); |
599 Code* code = Code::cast(isolate->heap()->CreateCode( | 599 Code* code = Code::cast(isolate->heap()->CreateCode( |
600 desc, | 600 desc, |
601 Code::ComputeFlags(Code::STUB), | 601 Code::ComputeFlags(Code::STUB), |
602 Handle<Code>())->ToObjectChecked()); | 602 Handle<Code>())->ToObjectChecked()); |
603 CHECK(code->IsCode()); | 603 CHECK(code->IsCode()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 Handle<Code>())->ToObjectChecked()); | 706 Handle<Code>())->ToObjectChecked()); |
707 CHECK(code->IsCode()); | 707 CHECK(code->IsCode()); |
708 #ifdef OBJECT_PRINT | 708 #ifdef OBJECT_PRINT |
709 Code::cast(code)->Print(); | 709 Code::cast(code)->Print(); |
710 #endif | 710 #endif |
711 | 711 |
712 F6 f = FUNCTION_CAST<F6>(Code::cast(code)->entry()); | 712 F6 f = FUNCTION_CAST<F6>(Code::cast(code)->entry()); |
713 CHECK_EQ(2, f(1.0, 2.0)); | 713 CHECK_EQ(2, f(1.0, 2.0)); |
714 } | 714 } |
715 #undef __ | 715 #undef __ |
OLD | NEW |