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 |
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 <stdlib.h> | 31 #include <stdlib.h> |
29 | 32 |
30 #include "src/v8.h" | 33 #include "src/v8.h" |
31 | 34 |
32 #include "src/base/platform/platform.h" | 35 #include "src/base/platform/platform.h" |
33 #include "src/base/utils/random-number-generator.h" | 36 #include "src/base/utils/random-number-generator.h" |
34 #include "src/disassembler.h" | 37 #include "src/disassembler.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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 CHECK_EQ(42, res); | 439 CHECK_EQ(42, res); |
437 } | 440 } |
438 | 441 |
439 | 442 |
440 #ifdef __GNUC__ | 443 #ifdef __GNUC__ |
441 #define ELEMENT_COUNT 4u | 444 #define ELEMENT_COUNT 4u |
442 | 445 |
443 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { | 446 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { |
444 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); | 447 Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate()); |
445 HandleScope scope(isolate); | 448 HandleScope scope(isolate); |
| 449 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
446 | 450 |
447 CHECK(args[0]->IsArray()); | 451 CHECK(args[0]->IsArray()); |
448 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); | 452 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); |
449 CHECK_EQ(ELEMENT_COUNT, vec->Length()); | 453 CHECK_EQ(ELEMENT_COUNT, vec->Length()); |
450 | 454 |
451 v8::internal::byte buffer[256]; | 455 v8::internal::byte buffer[256]; |
452 Assembler assm(isolate, buffer, sizeof buffer); | 456 Assembler assm(isolate, buffer, sizeof buffer); |
453 | 457 |
454 // Remove return address from the stack for fix stack frame alignment. | 458 // Remove return address from the stack for fix stack frame alignment. |
455 __ pop(ecx); | 459 __ pop(ecx); |
456 | 460 |
457 // Store input vector on the stack. | 461 // Store input vector on the stack. |
458 for (unsigned i = 0; i < ELEMENT_COUNT; ++i) { | 462 for (unsigned i = 0; i < ELEMENT_COUNT; ++i) { |
459 __ push(Immediate(vec->Get(i)->Int32Value())); | 463 __ push(Immediate( |
| 464 vec->Get(context, i).ToLocalChecked()->Int32Value(context).FromJust())); |
460 } | 465 } |
461 | 466 |
462 // Read vector into a xmm register. | 467 // Read vector into a xmm register. |
463 __ pxor(xmm0, xmm0); | 468 __ pxor(xmm0, xmm0); |
464 __ movdqa(xmm0, Operand(esp, 0)); | 469 __ movdqa(xmm0, Operand(esp, 0)); |
465 // Create mask and store it in the return register. | 470 // Create mask and store it in the return register. |
466 __ movmskps(eax, xmm0); | 471 __ movmskps(eax, xmm0); |
467 | 472 |
468 // Remove unused data from the stack. | 473 // Remove unused data from the stack. |
469 __ add(esp, Immediate(ELEMENT_COUNT * sizeof(int32_t))); | 474 __ add(esp, Immediate(ELEMENT_COUNT * sizeof(int32_t))); |
(...skipping 13 matching lines...) Expand all Loading... |
483 args.GetReturnValue().Set(v8::Integer::New(CcTest::isolate(), res)); | 488 args.GetReturnValue().Set(v8::Integer::New(CcTest::isolate(), res)); |
484 } | 489 } |
485 | 490 |
486 | 491 |
487 TEST(StackAlignmentForSSE2) { | 492 TEST(StackAlignmentForSSE2) { |
488 CcTest::InitializeVM(); | 493 CcTest::InitializeVM(); |
489 CHECK_EQ(0, v8::base::OS::ActivationFrameAlignment() % 16); | 494 CHECK_EQ(0, v8::base::OS::ActivationFrameAlignment() % 16); |
490 | 495 |
491 v8::Isolate* isolate = CcTest::isolate(); | 496 v8::Isolate* isolate = CcTest::isolate(); |
492 v8::HandleScope handle_scope(isolate); | 497 v8::HandleScope handle_scope(isolate); |
493 v8::Handle<v8::ObjectTemplate> global_template = | 498 v8::Local<v8::ObjectTemplate> global_template = |
494 v8::ObjectTemplate::New(isolate); | 499 v8::ObjectTemplate::New(isolate); |
495 global_template->Set(v8_str("do_sse2"), | 500 global_template->Set(v8_str("do_sse2"), |
496 v8::FunctionTemplate::New(isolate, DoSSE2)); | 501 v8::FunctionTemplate::New(isolate, DoSSE2)); |
497 | 502 |
498 LocalContext env(NULL, global_template); | 503 LocalContext env(NULL, global_template); |
499 CompileRun( | 504 CompileRun( |
500 "function foo(vec) {" | 505 "function foo(vec) {" |
501 " return do_sse2(vec);" | 506 " return do_sse2(vec);" |
502 "}"); | 507 "}"); |
503 | 508 |
504 v8::Local<v8::Object> global_object = env->Global(); | 509 v8::Local<v8::Object> global_object = env->Global(); |
505 v8::Local<v8::Function> foo = | 510 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( |
506 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("foo"))); | 511 global_object->Get(env.local(), v8_str("foo")).ToLocalChecked()); |
507 | 512 |
508 int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 }; | 513 int32_t vec[ELEMENT_COUNT] = { -1, 1, 1, 1 }; |
509 v8::Local<v8::Array> v8_vec = v8::Array::New(isolate, ELEMENT_COUNT); | 514 v8::Local<v8::Array> v8_vec = v8::Array::New(isolate, ELEMENT_COUNT); |
510 for (unsigned i = 0; i < ELEMENT_COUNT; i++) { | 515 for (unsigned i = 0; i < ELEMENT_COUNT; i++) { |
511 v8_vec->Set(i, v8_num(vec[i])); | 516 v8_vec->Set(env.local(), i, v8_num(vec[i])).FromJust(); |
512 } | 517 } |
513 | 518 |
514 v8::Local<v8::Value> args[] = { v8_vec }; | 519 v8::Local<v8::Value> args[] = { v8_vec }; |
515 v8::Local<v8::Value> result = foo->Call(global_object, 1, args); | 520 v8::Local<v8::Value> result = |
| 521 foo->Call(env.local(), global_object, 1, args).ToLocalChecked(); |
516 | 522 |
517 // The mask should be 0b1000. | 523 // The mask should be 0b1000. |
518 CHECK_EQ(8, result->Int32Value()); | 524 CHECK_EQ(8, result->Int32Value(env.local()).FromJust()); |
519 } | 525 } |
520 | 526 |
521 #undef ELEMENT_COUNT | 527 #undef ELEMENT_COUNT |
522 #endif // __GNUC__ | 528 #endif // __GNUC__ |
523 | 529 |
524 | 530 |
525 TEST(AssemblerIa32Extractps) { | 531 TEST(AssemblerIa32Extractps) { |
526 CcTest::InitializeVM(); | 532 CcTest::InitializeVM(); |
527 if (!CpuFeatures::IsSupported(SSE4_1)) return; | 533 if (!CpuFeatures::IsSupported(SSE4_1)) return; |
528 | 534 |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 #endif | 1485 #endif |
1480 F1 f = FUNCTION_CAST<F1>(code->entry()); | 1486 F1 f = FUNCTION_CAST<F1>(code->entry()); |
1481 for (int i = 0; i < kNumCases; ++i) { | 1487 for (int i = 0; i < kNumCases; ++i) { |
1482 int res = f(i); | 1488 int res = f(i); |
1483 ::printf("f(%d) = %d\n", i, res); | 1489 ::printf("f(%d) = %d\n", i, res); |
1484 CHECK_EQ(values[i], res); | 1490 CHECK_EQ(values[i], res); |
1485 } | 1491 } |
1486 } | 1492 } |
1487 | 1493 |
1488 #undef __ | 1494 #undef __ |
OLD | NEW |