| 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 17 matching lines...) Expand all Loading... |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #include "v8.h" | 30 #include "v8.h" |
| 31 | 31 |
| 32 #include "macro-assembler.h" | 32 #include "macro-assembler.h" |
| 33 #include "factory.h" | 33 #include "factory.h" |
| 34 #include "platform.h" | 34 #include "platform.h" |
| 35 #include "serialize.h" | 35 #include "serialize.h" |
| 36 #include "cctest.h" | 36 #include "cctest.h" |
| 37 | 37 |
| 38 using v8::internal::Assembler; | 38 using namespace v8::internal; |
| 39 using v8::internal::Code; | |
| 40 using v8::internal::CodeDesc; | |
| 41 using v8::internal::FUNCTION_CAST; | |
| 42 using v8::internal::Immediate; | |
| 43 using v8::internal::Isolate; | |
| 44 using v8::internal::Label; | |
| 45 using v8::internal::OS; | |
| 46 using v8::internal::Operand; | |
| 47 using v8::internal::byte; | |
| 48 using v8::internal::greater; | |
| 49 using v8::internal::less_equal; | |
| 50 using v8::internal::equal; | |
| 51 using v8::internal::not_equal; | |
| 52 using v8::internal::r13; | |
| 53 using v8::internal::r15; | |
| 54 using v8::internal::r8; | |
| 55 using v8::internal::r9; | |
| 56 using v8::internal::rax; | |
| 57 using v8::internal::rbx; | |
| 58 using v8::internal::rbp; | |
| 59 using v8::internal::rcx; | |
| 60 using v8::internal::rdi; | |
| 61 using v8::internal::rdx; | |
| 62 using v8::internal::rsi; | |
| 63 using v8::internal::rsp; | |
| 64 using v8::internal::times_1; | |
| 65 using v8::internal::xmm0; | |
| 66 | 39 |
| 67 // Test the x64 assembler by compiling some simple functions into | 40 // Test the x64 assembler by compiling some simple functions into |
| 68 // a buffer and executing them. These tests do not initialize the | 41 // a buffer and executing them. These tests do not initialize the |
| 69 // V8 library, create a context, or use any V8 objects. | 42 // V8 library, create a context, or use any V8 objects. |
| 70 // The AMD64 calling convention is used, with the first six arguments | 43 // The AMD64 calling convention is used, with the first six arguments |
| 71 // in RDI, RSI, RDX, RCX, R8, and R9, and floating point arguments in | 44 // in RDI, RSI, RDX, RCX, R8, and R9, and floating point arguments in |
| 72 // the XMM registers. The return value is in RAX. | 45 // the XMM registers. The return value is in RAX. |
| 73 // This calling convention is used on Linux, with GCC, and on Mac OS, | 46 // This calling convention is used on Linux, with GCC, and on Mac OS, |
| 74 // with GCC. A different convention is used on 64-bit windows, | 47 // with GCC. A different convention is used on 64-bit windows, |
| 75 // where the first four integer arguments are passed in RCX, RDX, R8 and R9. | 48 // where the first four integer arguments are passed in RCX, RDX, R8 and R9. |
| 76 | 49 |
| 77 typedef int (*F0)(); | 50 typedef int (*F0)(); |
| 78 typedef int (*F1)(int64_t x); | 51 typedef int (*F1)(int64_t x); |
| 79 typedef int (*F2)(int64_t x, int64_t y); | 52 typedef int (*F2)(int64_t x, int64_t y); |
| 53 typedef int (*F3)(double x); |
| 80 | 54 |
| 81 #ifdef _WIN64 | 55 #ifdef _WIN64 |
| 82 static const v8::internal::Register arg1 = rcx; | 56 static const Register arg1 = rcx; |
| 83 static const v8::internal::Register arg2 = rdx; | 57 static const Register arg2 = rdx; |
| 84 #else | 58 #else |
| 85 static const v8::internal::Register arg1 = rdi; | 59 static const Register arg1 = rdi; |
| 86 static const v8::internal::Register arg2 = rsi; | 60 static const Register arg2 = rsi; |
| 87 #endif | 61 #endif |
| 88 | 62 |
| 89 #define __ assm. | 63 #define __ assm. |
| 90 | 64 |
| 91 | 65 |
| 92 TEST(AssemblerX64ReturnOperation) { | 66 TEST(AssemblerX64ReturnOperation) { |
| 93 // Allocate an executable page of memory. | 67 // Allocate an executable page of memory. |
| 94 size_t actual_size; | 68 size_t actual_size; |
| 95 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 69 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 96 &actual_size, | 70 &actual_size, |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 __ j(equal, &target); | 333 __ j(equal, &target); |
| 360 __ j(not_equal, &target); | 334 __ j(not_equal, &target); |
| 361 __ bind(&target); | 335 __ bind(&target); |
| 362 __ nop(); | 336 __ nop(); |
| 363 } | 337 } |
| 364 | 338 |
| 365 | 339 |
| 366 TEST(AssemblerMultiByteNop) { | 340 TEST(AssemblerMultiByteNop) { |
| 367 CcTest::InitializeVM(); | 341 CcTest::InitializeVM(); |
| 368 v8::HandleScope scope(CcTest::isolate()); | 342 v8::HandleScope scope(CcTest::isolate()); |
| 369 v8::internal::byte buffer[1024]; | 343 byte buffer[1024]; |
| 370 Isolate* isolate = CcTest::i_isolate(); | 344 Isolate* isolate = CcTest::i_isolate(); |
| 371 Assembler assm(isolate, buffer, sizeof(buffer)); | 345 Assembler assm(isolate, buffer, sizeof(buffer)); |
| 372 __ push(rbx); | 346 __ push(rbx); |
| 373 __ push(rcx); | 347 __ push(rcx); |
| 374 __ push(rdx); | 348 __ push(rdx); |
| 375 __ push(rdi); | 349 __ push(rdi); |
| 376 __ push(rsi); | 350 __ push(rsi); |
| 377 __ movq(rax, Immediate(1)); | 351 __ movq(rax, Immediate(1)); |
| 378 __ movq(rbx, Immediate(2)); | 352 __ movq(rbx, Immediate(2)); |
| 379 __ movq(rcx, Immediate(3)); | 353 __ movq(rcx, Immediate(3)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 __ pop(rdx); | 387 __ pop(rdx); |
| 414 __ pop(rcx); | 388 __ pop(rcx); |
| 415 __ pop(rbx); | 389 __ pop(rbx); |
| 416 __ ret(0); | 390 __ ret(0); |
| 417 | 391 |
| 418 CodeDesc desc; | 392 CodeDesc desc; |
| 419 assm.GetCode(&desc); | 393 assm.GetCode(&desc); |
| 420 Code* code = Code::cast(isolate->heap()->CreateCode( | 394 Code* code = Code::cast(isolate->heap()->CreateCode( |
| 421 desc, | 395 desc, |
| 422 Code::ComputeFlags(Code::STUB), | 396 Code::ComputeFlags(Code::STUB), |
| 423 v8::internal::Handle<Code>())->ToObjectChecked()); | 397 Handle<Code>())->ToObjectChecked()); |
| 424 CHECK(code->IsCode()); | 398 CHECK(code->IsCode()); |
| 425 | 399 |
| 426 F0 f = FUNCTION_CAST<F0>(code->entry()); | 400 F0 f = FUNCTION_CAST<F0>(code->entry()); |
| 427 int res = f(); | 401 int res = f(); |
| 428 CHECK_EQ(42, res); | 402 CHECK_EQ(42, res); |
| 429 } | 403 } |
| 430 | 404 |
| 431 | 405 |
| 432 #ifdef __GNUC__ | 406 #ifdef __GNUC__ |
| 433 #define ELEMENT_COUNT 4 | 407 #define ELEMENT_COUNT 4 |
| 434 | 408 |
| 435 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { | 409 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 436 v8::HandleScope scope(CcTest::isolate()); | 410 v8::HandleScope scope(CcTest::isolate()); |
| 437 v8::internal::byte buffer[1024]; | 411 byte buffer[1024]; |
| 438 | 412 |
| 439 CHECK(args[0]->IsArray()); | 413 CHECK(args[0]->IsArray()); |
| 440 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); | 414 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); |
| 441 CHECK_EQ(ELEMENT_COUNT, vec->Length()); | 415 CHECK_EQ(ELEMENT_COUNT, vec->Length()); |
| 442 | 416 |
| 443 Isolate* isolate = CcTest::i_isolate(); | 417 Isolate* isolate = CcTest::i_isolate(); |
| 444 Assembler assm(isolate, buffer, sizeof(buffer)); | 418 Assembler assm(isolate, buffer, sizeof(buffer)); |
| 445 | 419 |
| 446 // Remove return address from the stack for fix stack frame alignment. | 420 // Remove return address from the stack for fix stack frame alignment. |
| 447 __ pop(rcx); | 421 __ pop(rcx); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 465 // Restore return address. | 439 // Restore return address. |
| 466 __ push(rcx); | 440 __ push(rcx); |
| 467 | 441 |
| 468 __ ret(0); | 442 __ ret(0); |
| 469 | 443 |
| 470 CodeDesc desc; | 444 CodeDesc desc; |
| 471 assm.GetCode(&desc); | 445 assm.GetCode(&desc); |
| 472 Code* code = Code::cast(isolate->heap()->CreateCode( | 446 Code* code = Code::cast(isolate->heap()->CreateCode( |
| 473 desc, | 447 desc, |
| 474 Code::ComputeFlags(Code::STUB), | 448 Code::ComputeFlags(Code::STUB), |
| 475 v8::internal::Handle<Code>())->ToObjectChecked()); | 449 Handle<Code>())->ToObjectChecked()); |
| 476 CHECK(code->IsCode()); | 450 CHECK(code->IsCode()); |
| 477 | 451 |
| 478 F0 f = FUNCTION_CAST<F0>(code->entry()); | 452 F0 f = FUNCTION_CAST<F0>(code->entry()); |
| 479 int res = f(); | 453 int res = f(); |
| 480 args.GetReturnValue().Set(v8::Integer::New(res)); | 454 args.GetReturnValue().Set(v8::Integer::New(res)); |
| 481 } | 455 } |
| 482 | 456 |
| 483 | 457 |
| 484 TEST(StackAlignmentForSSE2) { | 458 TEST(StackAlignmentForSSE2) { |
| 485 CcTest::InitializeVM(); | 459 CcTest::InitializeVM(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 510 v8::Local<v8::Value> result = foo->Call(global_object, 1, args); | 484 v8::Local<v8::Value> result = foo->Call(global_object, 1, args); |
| 511 | 485 |
| 512 // The mask should be 0b1000. | 486 // The mask should be 0b1000. |
| 513 CHECK_EQ(8, result->Int32Value()); | 487 CHECK_EQ(8, result->Int32Value()); |
| 514 } | 488 } |
| 515 | 489 |
| 516 #undef ELEMENT_COUNT | 490 #undef ELEMENT_COUNT |
| 517 #endif // __GNUC__ | 491 #endif // __GNUC__ |
| 518 | 492 |
| 519 | 493 |
| 494 TEST(AssemblerX64Extractps) { |
| 495 CcTest::InitializeVM(); |
| 496 if (!CpuFeatures::IsSupported(SSE4_1)) return; |
| 497 |
| 498 v8::HandleScope scope(CcTest::isolate()); |
| 499 byte buffer[256]; |
| 500 Isolate* isolate = CcTest::i_isolate(); |
| 501 Assembler assm(isolate, buffer, sizeof(buffer)); |
| 502 { CpuFeatureScope fscope2(&assm, SSE4_1); |
| 503 __ extractps(rax, xmm0, 0x1); |
| 504 __ ret(0); |
| 505 } |
| 506 |
| 507 CodeDesc desc; |
| 508 assm.GetCode(&desc); |
| 509 Code* code = Code::cast(isolate->heap()->CreateCode( |
| 510 desc, |
| 511 Code::ComputeFlags(Code::STUB), |
| 512 Handle<Code>())->ToObjectChecked()); |
| 513 CHECK(code->IsCode()); |
| 514 #ifdef OBJECT_PRINT |
| 515 Code::cast(code)->Print(); |
| 516 #endif |
| 517 |
| 518 F3 f = FUNCTION_CAST<F3>(Code::cast(code)->entry()); |
| 519 CHECK_EQ(0x7FF80000, f(OS::nan_value())); |
| 520 } |
| 521 |
| 522 |
| 520 #undef __ | 523 #undef __ |
| OLD | NEW |