Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/cctest/compiler/test-run-machops.cc

Issue 677433002: Add floor, ceil, round (truncate) instructions for ia32, x64 (if SSE4.1) and (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix integer overflow. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <functional> 6 #include <functional>
6 #include <limits> 7 #include <limits>
7 8
8 #include "src/base/bits.h" 9 #include "src/base/bits.h"
9 #include "src/compiler/generic-node-inl.h" 10 #include "src/compiler/generic-node-inl.h"
10 #include "test/cctest/cctest.h" 11 #include "test/cctest/cctest.h"
11 #include "test/cctest/compiler/codegen-tester.h" 12 #include "test/cctest/compiler/codegen-tester.h"
12 #include "test/cctest/compiler/value-helper.h" 13 #include "test/cctest/compiler/value-helper.h"
13 14
14 #if V8_TURBOFAN_TARGET 15 #if V8_TURBOFAN_TARGET
(...skipping 4513 matching lines...) Expand 10 before | Expand all | Expand 10 after
4528 float expected = *i; 4529 float expected = *i;
4529 float actual = *i; 4530 float actual = *i;
4530 RawMachineAssemblerTester<int32_t> m; 4531 RawMachineAssemblerTester<int32_t> m;
4531 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected)); 4532 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected));
4532 m.Return(m.Int32Constant(0)); 4533 m.Return(m.Int32Constant(0));
4533 CHECK_EQ(0, m.Call()); 4534 CHECK_EQ(0, m.Call());
4534 CHECK_EQ(expected, actual); 4535 CHECK_EQ(expected, actual);
4535 } 4536 }
4536 } 4537 }
4537 4538
4539
4540 static double two_30 = 1 << 30; // 2^30 is a smi boundary.
4541 static double two_52 = two_30 * (1 << 22); // 2^52 is a precision boundary.
4542 static double kValues[] = {0.1,
4543 0.2,
4544 0.49999999999999994,
4545 0.5,
4546 0.7,
4547 1.0 - std::numeric_limits<double>::epsilon(),
4548 -0.1,
4549 -0.49999999999999994,
4550 -0.5,
4551 -0.7,
4552 1.1,
4553 1.0 + std::numeric_limits<double>::epsilon(),
4554 1.5,
4555 1.7,
4556 -1,
4557 -1 + std::numeric_limits<double>::epsilon(),
4558 -1 - std::numeric_limits<double>::epsilon(),
4559 -1.1,
4560 -1.5,
4561 -1.7,
4562 std::numeric_limits<double>::min(),
4563 -std::numeric_limits<double>::min(),
4564 std::numeric_limits<double>::max(),
4565 -std::numeric_limits<double>::max(),
4566 std::numeric_limits<double>::infinity(),
4567 -std::numeric_limits<double>::infinity(),
4568 two_30,
4569 two_30 + 0.1,
4570 two_30 + 0.5,
4571 two_30 + 0.7,
4572 two_30 - 1,
4573 two_30 - 1 + 0.1,
4574 two_30 - 1 + 0.5,
4575 two_30 - 1 + 0.7,
4576 -two_30,
4577 -two_30 + 0.1,
4578 -two_30 + 0.5,
4579 -two_30 + 0.7,
4580 -two_30 + 1,
4581 -two_30 + 1 + 0.1,
4582 -two_30 + 1 + 0.5,
4583 -two_30 + 1 + 0.7,
4584 two_52,
4585 two_52 + 0.1,
4586 two_52 + 0.5,
4587 two_52 + 0.5,
4588 two_52 + 0.7,
4589 two_52 + 0.7,
4590 two_52 - 1,
4591 two_52 - 1 + 0.1,
4592 two_52 - 1 + 0.5,
4593 two_52 - 1 + 0.7,
4594 -two_52,
4595 -two_52 + 0.1,
4596 -two_52 + 0.5,
4597 -two_52 + 0.7,
4598 -two_52 + 1,
4599 -two_52 + 1 + 0.1,
4600 -two_52 + 1 + 0.5,
4601 -two_52 + 1 + 0.7,
4602 two_30,
4603 two_30 - 0.1,
4604 two_30 - 0.5,
4605 two_30 - 0.7,
4606 two_30 - 1,
4607 two_30 - 1 - 0.1,
4608 two_30 - 1 - 0.5,
4609 two_30 - 1 - 0.7,
4610 -two_30,
4611 -two_30 - 0.1,
4612 -two_30 - 0.5,
4613 -two_30 - 0.7,
4614 -two_30 + 1,
4615 -two_30 + 1 - 0.1,
4616 -two_30 + 1 - 0.5,
4617 -two_30 + 1 - 0.7,
4618 two_52,
4619 two_52 - 0.1,
4620 two_52 - 0.5,
4621 two_52 - 0.5,
4622 two_52 - 0.7,
4623 two_52 - 0.7,
4624 two_52 - 1,
4625 two_52 - 1 - 0.1,
4626 two_52 - 1 - 0.5,
4627 two_52 - 1 - 0.7,
4628 -two_52,
4629 -two_52 - 0.1,
4630 -two_52 - 0.5,
4631 -two_52 - 0.7,
4632 -two_52 + 1,
4633 -two_52 + 1 - 0.1,
4634 -two_52 + 1 - 0.5,
4635 -two_52 + 1 - 0.7};
4636
4637
4638 TEST(RunFloat64Floor) {
4639 double input = -1.0;
4640 double result = 0.0;
4641 RawMachineAssemblerTester<int32_t> m;
4642 if (!m.machine()->HasFloat64Floor()) return;
4643 m.StoreToPointer(&result, kMachFloat64,
4644 m.Float64Floor(m.LoadFromPointer(&input, kMachFloat64)));
4645 m.Return(m.Int32Constant(0));
4646 for (size_t i = 0; i < arraysize(kValues); ++i) {
4647 input = kValues[i];
4648 CHECK_EQ(0, m.Call());
4649 double expected = std::floor(kValues[i]);
4650 CHECK_EQ(expected, result);
4651 }
4652 }
4653
4654
4655 TEST(RunFloat64Ceil) {
4656 double input = -1.0;
4657 double result = 0.0;
4658 RawMachineAssemblerTester<int32_t> m;
4659 if (!m.machine()->HasFloat64Ceil()) return;
4660 m.StoreToPointer(&result, kMachFloat64,
4661 m.Float64Ceil(m.LoadFromPointer(&input, kMachFloat64)));
4662 m.Return(m.Int32Constant(0));
4663 for (size_t i = 0; i < arraysize(kValues); ++i) {
4664 input = kValues[i];
4665 CHECK_EQ(0, m.Call());
4666 double expected = std::ceil(kValues[i]);
4667 CHECK_EQ(expected, result);
4668 }
4669 }
4670
4671
4672 TEST(RunFloat64RoundTruncate) {
4673 double input = -1.0;
4674 double result = 0.0;
4675 RawMachineAssemblerTester<int32_t> m;
4676 if (!m.machine()->HasFloat64Ceil()) return;
4677 m.StoreToPointer(
4678 &result, kMachFloat64,
4679 m.Float64RoundTruncate(m.LoadFromPointer(&input, kMachFloat64)));
4680 m.Return(m.Int32Constant(0));
4681 for (size_t i = 0; i < arraysize(kValues); ++i) {
4682 input = kValues[i];
4683 CHECK_EQ(0, m.Call());
4684 double expected = std::trunc(kValues[i]);
4685 CHECK_EQ(expected, result);
4686 }
4687 }
4688
4689
4690 TEST(RunFloat64RoundTiesAway) {
4691 double input = -1.0;
4692 double result = 0.0;
4693 RawMachineAssemblerTester<int32_t> m;
4694 if (!m.machine()->HasFloat64RoundTiesAway()) return;
4695 m.StoreToPointer(
4696 &result, kMachFloat64,
4697 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64)));
4698 m.Return(m.Int32Constant(0));
4699 for (size_t i = 0; i < arraysize(kValues); ++i) {
4700 input = kValues[i];
4701 CHECK_EQ(0, m.Call());
4702 double expected = std::round(kValues[i]);
4703 CHECK_EQ(expected, result);
4704 }
4705 }
4538 #endif // V8_TURBOFAN_TARGET 4706 #endif // V8_TURBOFAN_TARGET
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698