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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
| 28 // TODO(jochen): Remove this after the setting is turned on globally. |
| 29 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 30 |
28 #include <cstdlib> | 31 #include <cstdlib> |
29 #include <iostream> | 32 #include <iostream> |
30 | 33 |
31 #include "src/v8.h" | 34 #include "src/v8.h" |
32 | 35 |
33 #include "src/base/platform/platform.h" | 36 #include "src/base/platform/platform.h" |
34 #include "src/base/utils/random-number-generator.h" | 37 #include "src/base/utils/random-number-generator.h" |
35 #include "src/factory.h" | 38 #include "src/factory.h" |
36 #include "src/macro-assembler.h" | 39 #include "src/macro-assembler.h" |
37 #include "src/ostreams.h" | 40 #include "src/ostreams.h" |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 int res = f(); | 587 int res = f(); |
585 CHECK_EQ(42, res); | 588 CHECK_EQ(42, res); |
586 } | 589 } |
587 | 590 |
588 | 591 |
589 #ifdef __GNUC__ | 592 #ifdef __GNUC__ |
590 #define ELEMENT_COUNT 4u | 593 #define ELEMENT_COUNT 4u |
591 | 594 |
592 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { | 595 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { |
593 v8::HandleScope scope(CcTest::isolate()); | 596 v8::HandleScope scope(CcTest::isolate()); |
| 597 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
594 byte buffer[1024]; | 598 byte buffer[1024]; |
595 | 599 |
596 CHECK(args[0]->IsArray()); | 600 CHECK(args[0]->IsArray()); |
597 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); | 601 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); |
598 CHECK_EQ(ELEMENT_COUNT, vec->Length()); | 602 CHECK_EQ(ELEMENT_COUNT, vec->Length()); |
599 | 603 |
600 Isolate* isolate = CcTest::i_isolate(); | 604 Isolate* isolate = CcTest::i_isolate(); |
601 Assembler assm(isolate, buffer, sizeof(buffer)); | 605 Assembler assm(isolate, buffer, sizeof(buffer)); |
602 | 606 |
603 // Remove return address from the stack for fix stack frame alignment. | 607 // Remove return address from the stack for fix stack frame alignment. |
604 __ popq(rcx); | 608 __ popq(rcx); |
605 | 609 |
606 // Store input vector on the stack. | 610 // Store input vector on the stack. |
607 for (unsigned i = 0; i < ELEMENT_COUNT; i++) { | 611 for (unsigned i = 0; i < ELEMENT_COUNT; i++) { |
608 __ movl(rax, Immediate(vec->Get(i)->Int32Value())); | 612 __ movl(rax, Immediate(vec->Get(context, i) |
| 613 .ToLocalChecked() |
| 614 ->Int32Value(context) |
| 615 .FromJust())); |
609 __ shlq(rax, Immediate(0x20)); | 616 __ shlq(rax, Immediate(0x20)); |
610 __ orq(rax, Immediate(vec->Get(++i)->Int32Value())); | 617 __ orq(rax, Immediate(vec->Get(context, ++i) |
| 618 .ToLocalChecked() |
| 619 ->Int32Value(context) |
| 620 .FromJust())); |
611 __ pushq(rax); | 621 __ pushq(rax); |
612 } | 622 } |
613 | 623 |
614 // Read vector into a xmm register. | 624 // Read vector into a xmm register. |
615 __ xorps(xmm0, xmm0); | 625 __ xorps(xmm0, xmm0); |
616 __ movdqa(xmm0, Operand(rsp, 0)); | 626 __ movdqa(xmm0, Operand(rsp, 0)); |
617 // Create mask and store it in the return register. | 627 // Create mask and store it in the return register. |
618 __ movmskps(rax, xmm0); | 628 __ movmskps(rax, xmm0); |
619 | 629 |
620 // Remove unused data from the stack. | 630 // Remove unused data from the stack. |
(...skipping 13 matching lines...) Expand all Loading... |
634 args.GetReturnValue().Set(v8::Integer::New(CcTest::isolate(), res)); | 644 args.GetReturnValue().Set(v8::Integer::New(CcTest::isolate(), res)); |
635 } | 645 } |
636 | 646 |
637 | 647 |
638 TEST(StackAlignmentForSSE2) { | 648 TEST(StackAlignmentForSSE2) { |
639 CcTest::InitializeVM(); | 649 CcTest::InitializeVM(); |
640 CHECK_EQ(0, v8::base::OS::ActivationFrameAlignment() % 16); | 650 CHECK_EQ(0, v8::base::OS::ActivationFrameAlignment() % 16); |
641 | 651 |
642 v8::Isolate* isolate = CcTest::isolate(); | 652 v8::Isolate* isolate = CcTest::isolate(); |
643 v8::HandleScope handle_scope(isolate); | 653 v8::HandleScope handle_scope(isolate); |
644 v8::Handle<v8::ObjectTemplate> global_template = | 654 v8::Local<v8::ObjectTemplate> global_template = |
645 v8::ObjectTemplate::New(isolate); | 655 v8::ObjectTemplate::New(isolate); |
646 global_template->Set(v8_str("do_sse2"), | 656 global_template->Set(v8_str("do_sse2"), |
647 v8::FunctionTemplate::New(isolate, DoSSE2)); | 657 v8::FunctionTemplate::New(isolate, DoSSE2)); |
648 | 658 |
649 LocalContext env(NULL, global_template); | 659 LocalContext env(NULL, global_template); |
650 CompileRun( | 660 CompileRun( |
651 "function foo(vec) {" | 661 "function foo(vec) {" |
652 " return do_sse2(vec);" | 662 " return do_sse2(vec);" |
653 "}"); | 663 "}"); |
654 | 664 |
655 v8::Local<v8::Object> global_object = env->Global(); | 665 v8::Local<v8::Object> global_object = env->Global(); |
656 v8::Local<v8::Function> foo = | 666 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
657 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("foo"))); | 667 global_object->Get(env.local(), v8_str("foo")).ToLocalChecked()); |
658 | 668 |
659 int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 }; | 669 int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 }; |
660 v8::Local<v8::Array> v8_vec = v8::Array::New(isolate, ELEMENT_COUNT); | 670 v8::Local<v8::Array> v8_vec = v8::Array::New(isolate, ELEMENT_COUNT); |
661 for (unsigned i = 0; i < ELEMENT_COUNT; i++) { | 671 for (unsigned i = 0; i < ELEMENT_COUNT; i++) { |
662 v8_vec->Set(i, v8_num(vec[i])); | 672 v8_vec->Set(env.local(), i, v8_num(vec[i])).FromJust(); |
663 } | 673 } |
664 | 674 |
665 v8::Local<v8::Value> args[] = { v8_vec }; | 675 v8::Local<v8::Value> args[] = { v8_vec }; |
666 v8::Local<v8::Value> result = foo->Call(global_object, 1, args); | 676 v8::Local<v8::Value> result = |
| 677 foo->Call(env.local(), global_object, 1, args).ToLocalChecked(); |
667 | 678 |
668 // The mask should be 0b1000. | 679 // The mask should be 0b1000. |
669 CHECK_EQ(8, result->Int32Value()); | 680 CHECK_EQ(8, result->Int32Value(env.local()).FromJust()); |
670 } | 681 } |
671 | 682 |
672 #undef ELEMENT_COUNT | 683 #undef ELEMENT_COUNT |
673 #endif // __GNUC__ | 684 #endif // __GNUC__ |
674 | 685 |
675 | 686 |
676 TEST(AssemblerX64Extractps) { | 687 TEST(AssemblerX64Extractps) { |
677 CcTest::InitializeVM(); | 688 CcTest::InitializeVM(); |
678 if (!CpuFeatures::IsSupported(SSE4_1)) return; | 689 if (!CpuFeatures::IsSupported(SSE4_1)) return; |
679 | 690 |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2247 | 2258 |
2248 F1 f = FUNCTION_CAST<F1>(code->entry()); | 2259 F1 f = FUNCTION_CAST<F1>(code->entry()); |
2249 for (int i = 0; i < kNumCases; ++i) { | 2260 for (int i = 0; i < kNumCases; ++i) { |
2250 int res = f(i); | 2261 int res = f(i); |
2251 PrintF("f(%d) = %d\n", i, res); | 2262 PrintF("f(%d) = %d\n", i, res); |
2252 CHECK_EQ(values[i], res); | 2263 CHECK_EQ(values[i], res); |
2253 } | 2264 } |
2254 } | 2265 } |
2255 | 2266 |
2256 #undef __ | 2267 #undef __ |
OLD | NEW |