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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 using v8::internal::r9; | 55 using v8::internal::r9; |
56 using v8::internal::rax; | 56 using v8::internal::rax; |
57 using v8::internal::rbx; | 57 using v8::internal::rbx; |
58 using v8::internal::rbp; | 58 using v8::internal::rbp; |
59 using v8::internal::rcx; | 59 using v8::internal::rcx; |
60 using v8::internal::rdi; | 60 using v8::internal::rdi; |
61 using v8::internal::rdx; | 61 using v8::internal::rdx; |
62 using v8::internal::rsi; | 62 using v8::internal::rsi; |
63 using v8::internal::rsp; | 63 using v8::internal::rsp; |
64 using v8::internal::times_1; | 64 using v8::internal::times_1; |
65 using v8::internal::xmm0; | |
66 | 65 |
67 // Test the x64 assembler by compiling some simple functions into | 66 // Test the x64 assembler by compiling some simple functions into |
68 // a buffer and executing them. These tests do not initialize the | 67 // a buffer and executing them. These tests do not initialize the |
69 // V8 library, create a context, or use any V8 objects. | 68 // V8 library, create a context, or use any V8 objects. |
70 // The AMD64 calling convention is used, with the first six arguments | 69 // 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 | 70 // in RDI, RSI, RDX, RCX, R8, and R9, and floating point arguments in |
72 // the XMM registers. The return value is in RAX. | 71 // the XMM registers. The return value is in RAX. |
73 // This calling convention is used on Linux, with GCC, and on Mac OS, | 72 // 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, | 73 // 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. | 74 // where the first four integer arguments are passed in RCX, RDX, R8 and R9. |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 Code::ComputeFlags(Code::STUB), | 422 Code::ComputeFlags(Code::STUB), |
424 v8::internal::Handle<Code>())->ToObjectChecked()); | 423 v8::internal::Handle<Code>())->ToObjectChecked()); |
425 CHECK(code->IsCode()); | 424 CHECK(code->IsCode()); |
426 | 425 |
427 F0 f = FUNCTION_CAST<F0>(code->entry()); | 426 F0 f = FUNCTION_CAST<F0>(code->entry()); |
428 int res = f(); | 427 int res = f(); |
429 CHECK_EQ(42, res); | 428 CHECK_EQ(42, res); |
430 } | 429 } |
431 | 430 |
432 | 431 |
433 #ifdef __GNUC__ | |
434 #define ELEMENT_COUNT 4 | |
435 | |
436 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
437 CcTest::InitializeVM(); | |
438 v8::HandleScope scope(CcTest::isolate()); | |
439 v8::internal::byte buffer[1024]; | |
440 | |
441 CHECK(args[0]->IsArray()); | |
442 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); | |
443 CHECK_EQ(ELEMENT_COUNT, vec->Length()); | |
444 | |
445 Isolate* isolate = Isolate::Current(); | |
446 Assembler assm(isolate, buffer, sizeof(buffer)); | |
447 | |
448 // Remove return address from the stack for fix stack frame alignment. | |
449 __ pop(rcx); | |
450 | |
451 // Store input vector on the stack. | |
452 for (int i = 0; i < ELEMENT_COUNT; i++) { | |
453 __ movl(rax, Immediate(vec->Get(i)->Int32Value())); | |
454 __ shl(rax, Immediate(0x20)); | |
455 __ or_(rax, Immediate(vec->Get(++i)->Int32Value())); | |
456 __ push(rax); | |
457 } | |
458 | |
459 // Read vector into a xmm register. | |
460 __ xorps(xmm0, xmm0); | |
461 __ movdqa(xmm0, Operand(rsp, 0)); | |
462 // Create mask and store it in the return register. | |
463 __ movmskps(rax, xmm0); | |
464 | |
465 // Remove unused data from the stack. | |
466 __ addq(rsp, Immediate(ELEMENT_COUNT * sizeof(int32_t))); | |
467 // Restore return address. | |
468 __ push(rcx); | |
469 | |
470 __ ret(0); | |
471 | |
472 CodeDesc desc; | |
473 assm.GetCode(&desc); | |
474 Code* code = Code::cast(isolate->heap()->CreateCode( | |
475 desc, | |
476 Code::ComputeFlags(Code::STUB), | |
477 v8::internal::Handle<Code>())->ToObjectChecked()); | |
478 CHECK(code->IsCode()); | |
479 | |
480 F0 f = FUNCTION_CAST<F0>(code->entry()); | |
481 int res = f(); | |
482 args.GetReturnValue().Set(v8::Integer::New(res)); | |
483 } | |
484 | |
485 TEST(StackAlignmentForSSE2) { | |
486 CHECK_EQ(0, OS::ActivationFrameAlignment() % 16); | |
487 | |
488 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
489 v8::HandleScope handle_scope(isolate); | |
490 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); | |
491 global_template->Set(v8_str("do_sse2"), v8::FunctionTemplate::New(DoSSE2)); | |
492 | |
493 LocalContext env(NULL, global_template); | |
494 CompileRun( | |
495 "function foo(vec) {" | |
496 " return do_sse2(vec);" | |
497 "}"); | |
498 | |
499 v8::Local<v8::Object> global_object = env->Global(); | |
500 v8::Local<v8::Function> foo = | |
501 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("foo"))); | |
502 | |
503 int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 }; | |
504 v8::Local<v8::Array> v8_vec = v8::Array::New(ELEMENT_COUNT); | |
505 for (int i = 0; i < ELEMENT_COUNT; i++) { | |
506 v8_vec->Set(i, v8_num(vec[i])); | |
507 } | |
508 | |
509 v8::Local<v8::Value> args[] = { v8_vec }; | |
510 v8::Local<v8::Value> result = foo->Call(global_object, 1, args); | |
511 | |
512 // The mask should be 0b1000. | |
513 CHECK_EQ(8, result->Int32Value()); | |
514 } | |
515 | |
516 #undef ELEMENT_COUNT | |
517 #endif // __GNUC__ | |
518 | 432 |
519 | 433 |
520 #undef __ | 434 #undef __ |
OLD | NEW |