OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <cmath> | 5 #include <cmath> |
6 #include <functional> | 6 #include <functional> |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 phi->ReplaceInput(1, m.Float64Add(phi, m.Float64Constant(0.5))); | 440 phi->ReplaceInput(1, m.Float64Add(phi, m.Float64Constant(0.5))); |
441 m.Goto(&header); | 441 m.Goto(&header); |
442 | 442 |
443 m.Bind(end); | 443 m.Bind(end); |
444 m.Return(m.ChangeFloat64ToInt32(phi)); | 444 m.Return(m.ChangeFloat64ToInt32(phi)); |
445 | 445 |
446 CHECK_EQ(10, m.Call()); | 446 CHECK_EQ(10, m.Call()); |
447 } | 447 } |
448 | 448 |
449 | 449 |
| 450 TEST(RunSwitch1) { |
| 451 RawMachineAssemblerTester<int32_t> m; |
| 452 |
| 453 int constant = 11223344; |
| 454 |
| 455 MLabel block0, block1, end; |
| 456 MLabel* cases[] = {&block0, &block1}; |
| 457 m.Switch(m.IntPtrConstant(0), cases, arraysize(cases)); |
| 458 m.Bind(&block0); |
| 459 m.Goto(&end); |
| 460 m.Bind(&block1); |
| 461 m.Goto(&end); |
| 462 m.Bind(&end); |
| 463 m.Return(m.Int32Constant(constant)); |
| 464 |
| 465 CHECK_EQ(constant, m.Call()); |
| 466 } |
| 467 |
| 468 |
| 469 TEST(RunSwitch2) { |
| 470 RawMachineAssemblerTester<int32_t> m(kMachInt32); |
| 471 |
| 472 const size_t kNumCases = 255; |
| 473 int32_t values[kNumCases]; |
| 474 m.main_isolate()->random_number_generator()->NextBytes(values, |
| 475 sizeof(values)); |
| 476 MLabel end; |
| 477 MLabel* cases[kNumCases]; |
| 478 Node* results[kNumCases]; |
| 479 for (size_t i = 0; i < kNumCases; ++i) { |
| 480 cases[i] = new (m.main_zone()->New(sizeof(MLabel))) MLabel; |
| 481 } |
| 482 m.Switch(m.ConvertInt32ToIntPtr(m.Parameter(0)), cases, arraysize(cases)); |
| 483 for (size_t i = 0; i < kNumCases; ++i) { |
| 484 m.Bind(cases[i]); |
| 485 results[i] = m.Int32Constant(values[i]); |
| 486 m.Goto(&end); |
| 487 } |
| 488 m.Bind(&end); |
| 489 const int num_results = static_cast<int>(arraysize(results)); |
| 490 Node* phi = |
| 491 m.NewNode(m.common()->Phi(kMachInt32, num_results), num_results, results); |
| 492 m.Return(phi); |
| 493 |
| 494 for (size_t i = 0; i < kNumCases; ++i) { |
| 495 CHECK_EQ(values[i], m.Call(static_cast<int>(i))); |
| 496 } |
| 497 } |
| 498 |
| 499 |
450 TEST(RunLoadInt32) { | 500 TEST(RunLoadInt32) { |
451 RawMachineAssemblerTester<int32_t> m; | 501 RawMachineAssemblerTester<int32_t> m; |
452 | 502 |
453 int32_t p1 = 0; // loads directly from this location. | 503 int32_t p1 = 0; // loads directly from this location. |
454 m.Return(m.LoadFromPointer(&p1, kMachInt32)); | 504 m.Return(m.LoadFromPointer(&p1, kMachInt32)); |
455 | 505 |
456 FOR_INT32_INPUTS(i) { | 506 FOR_INT32_INPUTS(i) { |
457 p1 = *i; | 507 p1 = *i; |
458 CHECK_EQ(p1, m.Call()); | 508 CHECK_EQ(p1, m.Call()); |
459 } | 509 } |
(...skipping 4218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4678 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); | 4728 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); |
4679 m.Return(m.Int32Constant(0)); | 4729 m.Return(m.Int32Constant(0)); |
4680 for (size_t i = 0; i < arraysize(kValues); ++i) { | 4730 for (size_t i = 0; i < arraysize(kValues); ++i) { |
4681 input = kValues[i]; | 4731 input = kValues[i]; |
4682 CHECK_EQ(0, m.Call()); | 4732 CHECK_EQ(0, m.Call()); |
4683 double expected = round(kValues[i]); | 4733 double expected = round(kValues[i]); |
4684 CHECK_EQ(expected, result); | 4734 CHECK_EQ(expected, result); |
4685 } | 4735 } |
4686 } | 4736 } |
4687 #endif // V8_TURBOFAN_TARGET | 4737 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |