OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. Use of this | 1 // Copyright 2014 the V8 project authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // 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/base/ieee754.h" | 10 #include "src/base/ieee754.h" |
11 #include "src/base/utils/random-number-generator.h" | 11 #include "src/base/utils/random-number-generator.h" |
12 #include "src/codegen.h" | 12 #include "src/codegen.h" |
| 13 #include "src/utils.h" |
13 #include "test/cctest/cctest.h" | 14 #include "test/cctest/cctest.h" |
14 #include "test/cctest/compiler/codegen-tester.h" | 15 #include "test/cctest/compiler/codegen-tester.h" |
15 #include "test/cctest/compiler/graph-builder-tester.h" | 16 #include "test/cctest/compiler/graph-builder-tester.h" |
16 #include "test/cctest/compiler/value-helper.h" | 17 #include "test/cctest/compiler/value-helper.h" |
17 | 18 |
18 using namespace v8::base; | 19 using namespace v8::base; |
19 | 20 |
20 namespace v8 { | 21 namespace v8 { |
21 namespace internal { | 22 namespace internal { |
22 namespace compiler { | 23 namespace compiler { |
(...skipping 3717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3740 RawMachineAssemblerTester<int32_t> m; | 3741 RawMachineAssemblerTester<int32_t> m; |
3741 Float64BinopTester bt(&m); | 3742 Float64BinopTester bt(&m); |
3742 | 3743 |
3743 bt.AddReturn(m.Float64Add(bt.param0, bt.param1)); | 3744 bt.AddReturn(m.Float64Add(bt.param0, bt.param1)); |
3744 | 3745 |
3745 FOR_FLOAT64_INPUTS(pl) { | 3746 FOR_FLOAT64_INPUTS(pl) { |
3746 FOR_FLOAT64_INPUTS(pr) { CHECK_DOUBLE_EQ(*pl + *pr, bt.call(*pl, *pr)); } | 3747 FOR_FLOAT64_INPUTS(pr) { CHECK_DOUBLE_EQ(*pl + *pr, bt.call(*pl, *pr)); } |
3747 } | 3748 } |
3748 } | 3749 } |
3749 | 3750 |
3750 namespace { | |
3751 | |
3752 double fmax(double x, double y) { | |
3753 if (std::isnan(x)) return x; | |
3754 if (std::isnan(y)) return y; | |
3755 if (std::signbit(x) < std::signbit(y)) return x; | |
3756 return std::max(x, y); | |
3757 } | |
3758 | |
3759 double fmin(double x, double y) { | |
3760 if (std::isnan(x)) return x; | |
3761 if (std::isnan(y)) return y; | |
3762 if (std::signbit(x) < std::signbit(y)) return y; | |
3763 return std::min(x, y); | |
3764 } | |
3765 | |
3766 } // namespace | |
3767 | |
3768 TEST(RunFloat64MaxP) { | 3751 TEST(RunFloat64MaxP) { |
3769 RawMachineAssemblerTester<int32_t> m; | 3752 RawMachineAssemblerTester<int32_t> m; |
3770 Float64BinopTester bt(&m); | 3753 Float64BinopTester bt(&m); |
3771 bt.AddReturn(m.Float64Max(bt.param0, bt.param1)); | 3754 bt.AddReturn(m.Float64Max(bt.param0, bt.param1)); |
3772 | 3755 |
3773 FOR_FLOAT64_INPUTS(pl) { | 3756 FOR_FLOAT64_INPUTS(pl) { |
3774 FOR_FLOAT64_INPUTS(pr) { | 3757 FOR_FLOAT64_INPUTS(pr) { |
3775 CHECK_DOUBLE_EQ(fmax(*pl, *pr), bt.call(*pl, *pr)); | 3758 CHECK_DOUBLE_EQ(JSMax(*pl, *pr), bt.call(*pl, *pr)); |
3776 } | 3759 } |
3777 } | 3760 } |
3778 } | 3761 } |
3779 | 3762 |
3780 | 3763 |
3781 TEST(RunFloat64MinP) { | 3764 TEST(RunFloat64MinP) { |
3782 RawMachineAssemblerTester<int32_t> m; | 3765 RawMachineAssemblerTester<int32_t> m; |
3783 Float64BinopTester bt(&m); | 3766 Float64BinopTester bt(&m); |
3784 bt.AddReturn(m.Float64Min(bt.param0, bt.param1)); | 3767 bt.AddReturn(m.Float64Min(bt.param0, bt.param1)); |
3785 | 3768 |
3786 FOR_FLOAT64_INPUTS(pl) { | 3769 FOR_FLOAT64_INPUTS(pl) { |
3787 FOR_FLOAT64_INPUTS(pr) { | 3770 FOR_FLOAT64_INPUTS(pr) { |
3788 CHECK_DOUBLE_EQ(fmin(*pl, *pr), bt.call(*pl, *pr)); | 3771 CHECK_DOUBLE_EQ(JSMin(*pl, *pr), bt.call(*pl, *pr)); |
3789 } | 3772 } |
3790 } | 3773 } |
3791 } | 3774 } |
3792 | 3775 |
| 3776 TEST(RunFloat32Max) { |
| 3777 RawMachineAssemblerTester<int32_t> m; |
| 3778 Float32BinopTester bt(&m); |
| 3779 bt.AddReturn(m.Float32Max(bt.param0, bt.param1)); |
| 3780 |
| 3781 FOR_FLOAT32_INPUTS(pl) { |
| 3782 FOR_FLOAT32_INPUTS(pr) { |
| 3783 CHECK_FLOAT_EQ(JSMax(*pl, *pr), bt.call(*pl, *pr)); |
| 3784 } |
| 3785 } |
| 3786 } |
| 3787 |
| 3788 TEST(RunFloat32Min) { |
| 3789 RawMachineAssemblerTester<int32_t> m; |
| 3790 Float32BinopTester bt(&m); |
| 3791 bt.AddReturn(m.Float32Min(bt.param0, bt.param1)); |
| 3792 |
| 3793 FOR_FLOAT32_INPUTS(pl) { |
| 3794 FOR_FLOAT32_INPUTS(pr) { |
| 3795 CHECK_FLOAT_EQ(JSMin(*pl, *pr), bt.call(*pl, *pr)); |
| 3796 } |
| 3797 } |
| 3798 } |
3793 | 3799 |
3794 TEST(RunFloat32SubP) { | 3800 TEST(RunFloat32SubP) { |
3795 RawMachineAssemblerTester<int32_t> m; | 3801 RawMachineAssemblerTester<int32_t> m; |
3796 Float32BinopTester bt(&m); | 3802 Float32BinopTester bt(&m); |
3797 | 3803 |
3798 bt.AddReturn(m.Float32Sub(bt.param0, bt.param1)); | 3804 bt.AddReturn(m.Float32Sub(bt.param0, bt.param1)); |
3799 | 3805 |
3800 FOR_FLOAT32_INPUTS(pl) { | 3806 FOR_FLOAT32_INPUTS(pl) { |
3801 FOR_FLOAT32_INPUTS(pr) { CHECK_FLOAT_EQ(*pl - *pr, bt.call(*pl, *pr)); } | 3807 FOR_FLOAT32_INPUTS(pr) { CHECK_FLOAT_EQ(*pl - *pr, bt.call(*pl, *pr)); } |
3802 } | 3808 } |
(...skipping 2762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6565 r.Goto(&merge); | 6571 r.Goto(&merge); |
6566 r.Bind(&merge); | 6572 r.Bind(&merge); |
6567 Node* phi = r.Phi(MachineRepresentation::kWord32, fa, fb); | 6573 Node* phi = r.Phi(MachineRepresentation::kWord32, fa, fb); |
6568 r.Return(phi); | 6574 r.Return(phi); |
6569 CHECK_EQ(1, r.Call(1)); | 6575 CHECK_EQ(1, r.Call(1)); |
6570 } | 6576 } |
6571 | 6577 |
6572 } // namespace compiler | 6578 } // namespace compiler |
6573 } // namespace internal | 6579 } // namespace internal |
6574 } // namespace v8 | 6580 } // namespace v8 |
OLD | NEW |