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 4629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4640 float actual = *i; | 4640 float actual = *i; |
4641 RawMachineAssemblerTester<int32_t> m; | 4641 RawMachineAssemblerTester<int32_t> m; |
4642 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected)); | 4642 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected)); |
4643 m.Return(m.Int32Constant(0)); | 4643 m.Return(m.Int32Constant(0)); |
4644 CHECK_EQ(0, m.Call()); | 4644 CHECK_EQ(0, m.Call()); |
4645 CHECK_EQ(expected, actual); | 4645 CHECK_EQ(expected, actual); |
4646 } | 4646 } |
4647 } | 4647 } |
4648 | 4648 |
4649 | 4649 |
| 4650 TEST(RunFloat64ExtractLowWord32) { |
| 4651 uint64_t input = 0; |
| 4652 RawMachineAssemblerTester<int32_t> m; |
| 4653 m.Return(m.Float64ExtractLowWord32(m.LoadFromPointer(&input, kMachFloat64))); |
| 4654 FOR_FLOAT64_INPUTS(i) { |
| 4655 input = bit_cast<uint64_t>(*i); |
| 4656 int32_t expected = bit_cast<int32_t>(static_cast<uint32_t>(input)); |
| 4657 CHECK_EQ(expected, m.Call()); |
| 4658 } |
| 4659 } |
| 4660 |
| 4661 |
| 4662 TEST(RunFloat64ExtractHighWord32) { |
| 4663 uint64_t input = 0; |
| 4664 RawMachineAssemblerTester<int32_t> m; |
| 4665 m.Return(m.Float64ExtractHighWord32(m.LoadFromPointer(&input, kMachFloat64))); |
| 4666 FOR_FLOAT64_INPUTS(i) { |
| 4667 input = bit_cast<uint64_t>(*i); |
| 4668 int32_t expected = bit_cast<int32_t>(static_cast<uint32_t>(input >> 32)); |
| 4669 CHECK_EQ(expected, m.Call()); |
| 4670 } |
| 4671 } |
| 4672 |
| 4673 |
| 4674 TEST(RunFloat64InsertLowWord32) { |
| 4675 uint64_t input = 0; |
| 4676 uint64_t result = 0; |
| 4677 RawMachineAssemblerTester<int32_t> m(kMachInt32); |
| 4678 m.StoreToPointer( |
| 4679 &result, kMachFloat64, |
| 4680 m.Float64InsertLowWord32(m.LoadFromPointer(&input, kMachFloat64), |
| 4681 m.Parameter(0))); |
| 4682 m.Return(m.Int32Constant(0)); |
| 4683 FOR_FLOAT64_INPUTS(i) { |
| 4684 FOR_INT32_INPUTS(j) { |
| 4685 input = bit_cast<uint64_t>(*i); |
| 4686 uint64_t expected = (input & ~(V8_UINT64_C(0xFFFFFFFF))) | |
| 4687 (static_cast<uint64_t>(bit_cast<uint32_t>(*j))); |
| 4688 CHECK_EQ(0, m.Call(*j)); |
| 4689 CHECK_EQ(expected, result); |
| 4690 } |
| 4691 } |
| 4692 } |
| 4693 |
| 4694 |
| 4695 TEST(RunFloat64InsertHighWord32) { |
| 4696 uint64_t input = 0; |
| 4697 uint64_t result = 0; |
| 4698 RawMachineAssemblerTester<int32_t> m(kMachInt32); |
| 4699 m.StoreToPointer( |
| 4700 &result, kMachFloat64, |
| 4701 m.Float64InsertHighWord32(m.LoadFromPointer(&input, kMachFloat64), |
| 4702 m.Parameter(0))); |
| 4703 m.Return(m.Int32Constant(0)); |
| 4704 FOR_FLOAT64_INPUTS(i) { |
| 4705 FOR_INT32_INPUTS(j) { |
| 4706 input = bit_cast<uint64_t>(*i); |
| 4707 uint64_t expected = (input & ~(V8_UINT64_C(0xFFFFFFFF) << 32)) | |
| 4708 (static_cast<uint64_t>(bit_cast<uint32_t>(*j)) << 32); |
| 4709 CHECK_EQ(0, m.Call(*j)); |
| 4710 CHECK_EQ(expected, result); |
| 4711 } |
| 4712 } |
| 4713 } |
| 4714 |
| 4715 |
4650 static double two_30 = 1 << 30; // 2^30 is a smi boundary. | 4716 static double two_30 = 1 << 30; // 2^30 is a smi boundary. |
4651 static double two_52 = two_30 * (1 << 22); // 2^52 is a precision boundary. | 4717 static double two_52 = two_30 * (1 << 22); // 2^52 is a precision boundary. |
4652 static double kValues[] = {0.1, | 4718 static double kValues[] = {0.1, |
4653 0.2, | 4719 0.2, |
4654 0.49999999999999994, | 4720 0.49999999999999994, |
4655 0.5, | 4721 0.5, |
4656 0.7, | 4722 0.7, |
4657 1.0 - std::numeric_limits<double>::epsilon(), | 4723 1.0 - std::numeric_limits<double>::epsilon(), |
4658 -0.1, | 4724 -0.1, |
4659 -0.49999999999999994, | 4725 -0.49999999999999994, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4808 m.Return(m.Int32Constant(0)); | 4874 m.Return(m.Int32Constant(0)); |
4809 for (size_t i = 0; i < arraysize(kValues); ++i) { | 4875 for (size_t i = 0; i < arraysize(kValues); ++i) { |
4810 input = kValues[i]; | 4876 input = kValues[i]; |
4811 CHECK_EQ(0, m.Call()); | 4877 CHECK_EQ(0, m.Call()); |
4812 double expected = round(kValues[i]); | 4878 double expected = round(kValues[i]); |
4813 CHECK_EQ(expected, result); | 4879 CHECK_EQ(expected, result); |
4814 } | 4880 } |
4815 } | 4881 } |
4816 | 4882 |
4817 #endif // V8_TURBOFAN_TARGET | 4883 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |