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

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

Issue 1437493002: Improved some tests in test-run-machops. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(jochen): Remove this after the setting is turned on globally. 5 // TODO(jochen): Remove this after the setting is turned on globally.
6 #define V8_IMMINENT_DEPRECATION_WARNINGS 6 #define V8_IMMINENT_DEPRECATION_WARNINGS
7 7
8 #include <cmath> 8 #include <cmath>
9 #include <functional> 9 #include <functional>
10 #include <limits> 10 #include <limits>
(...skipping 16 matching lines...) Expand all
27 27
28 28
29 TEST(RunInt32Add) { 29 TEST(RunInt32Add) {
30 RawMachineAssemblerTester<int32_t> m; 30 RawMachineAssemblerTester<int32_t> m;
31 Node* add = m.Int32Add(m.Int32Constant(0), m.Int32Constant(1)); 31 Node* add = m.Int32Add(m.Int32Constant(0), m.Int32Constant(1));
32 m.Return(add); 32 m.Return(add);
33 CHECK_EQ(1, m.Call()); 33 CHECK_EQ(1, m.Call());
34 } 34 }
35 35
36 36
37 void TestWord32Ctz(int32_t value, int32_t expected) { 37 TEST(RunWord32Ctz) {
38 RawMachineAssemblerTester<int32_t> m; 38 BufferedRawMachineAssemblerTester<int32_t> m(kMachUint32);
39 if (m.machine()->Word32Ctz().IsSupported()) { 39 if (!m.machine()->Word32Ctz().IsSupported()) {
40 Node* ctz = 40 // We can only test the operator if it exists on the testing platform.
41 m.AddNode(m.machine()->Word32Ctz().op(), m.Int32Constant(value)); 41 return;
42 m.Return(ctz);
43 CHECK_EQ(expected, m.Call());
44 } 42 }
43 m.Return(m.AddNode(m.machine()->Word32Ctz().op(), m.Parameter(0)));
44
45 CHECK_EQ(32, m.Call(uint32_t(0x00000000)));
46 CHECK_EQ(31, m.Call(uint32_t(0x80000000)));
47 CHECK_EQ(30, m.Call(uint32_t(0x40000000)));
48 CHECK_EQ(29, m.Call(uint32_t(0x20000000)));
49 CHECK_EQ(28, m.Call(uint32_t(0x10000000)));
50 CHECK_EQ(27, m.Call(uint32_t(0xa8000000)));
51 CHECK_EQ(26, m.Call(uint32_t(0xf4000000)));
52 CHECK_EQ(25, m.Call(uint32_t(0x62000000)));
53 CHECK_EQ(24, m.Call(uint32_t(0x91000000)));
54 CHECK_EQ(23, m.Call(uint32_t(0xcd800000)));
55 CHECK_EQ(22, m.Call(uint32_t(0x09400000)));
56 CHECK_EQ(21, m.Call(uint32_t(0xaf200000)));
57 CHECK_EQ(20, m.Call(uint32_t(0xac100000)));
58 CHECK_EQ(19, m.Call(uint32_t(0xe0b80000)));
59 CHECK_EQ(18, m.Call(uint32_t(0x9ce40000)));
60 CHECK_EQ(17, m.Call(uint32_t(0xc7920000)));
61 CHECK_EQ(16, m.Call(uint32_t(0xb8f10000)));
62 CHECK_EQ(15, m.Call(uint32_t(0x3b9f8000)));
63 CHECK_EQ(14, m.Call(uint32_t(0xdb4c4000)));
64 CHECK_EQ(13, m.Call(uint32_t(0xe9a32000)));
65 CHECK_EQ(12, m.Call(uint32_t(0xfca61000)));
66 CHECK_EQ(11, m.Call(uint32_t(0x6c8a7800)));
67 CHECK_EQ(10, m.Call(uint32_t(0x8ce5a400)));
68 CHECK_EQ(9, m.Call(uint32_t(0xcb7d0200)));
69 CHECK_EQ(8, m.Call(uint32_t(0xcb4dc100)));
70 CHECK_EQ(7, m.Call(uint32_t(0xdfbec580)));
71 CHECK_EQ(6, m.Call(uint32_t(0x27a9db40)));
72 CHECK_EQ(5, m.Call(uint32_t(0xde3bcb20)));
73 CHECK_EQ(4, m.Call(uint32_t(0xd7e8a610)));
74 CHECK_EQ(3, m.Call(uint32_t(0x9afdbc88)));
75 CHECK_EQ(2, m.Call(uint32_t(0x9afdbc84)));
76 CHECK_EQ(1, m.Call(uint32_t(0x9afdbc82)));
77 CHECK_EQ(0, m.Call(uint32_t(0x9afdbc81)));
45 } 78 }
46 79
47 80
48 TEST(RunInt32Ctz) { 81 TEST(RunWord32Clz) {
49 TestWord32Ctz(0x00000000, 32); 82 BufferedRawMachineAssemblerTester<int32_t> m(kMachUint32);
50 TestWord32Ctz(0x80000000, 31); 83 m.Return(m.Word32Clz(m.Parameter(0)));
51 TestWord32Ctz(0x40000000, 30); 84
52 TestWord32Ctz(0x20000000, 29); 85 CHECK_EQ(0, m.Call(uint32_t(0x80001000)));
53 TestWord32Ctz(0x10000000, 28); 86 CHECK_EQ(1, m.Call(uint32_t(0x40000500)));
54 TestWord32Ctz(0xa8000000, 27); 87 CHECK_EQ(2, m.Call(uint32_t(0x20000300)));
55 TestWord32Ctz(0xf4000000, 26); 88 CHECK_EQ(3, m.Call(uint32_t(0x10000003)));
56 TestWord32Ctz(0x62000000, 25); 89 CHECK_EQ(4, m.Call(uint32_t(0x08050000)));
57 TestWord32Ctz(0x91000000, 24); 90 CHECK_EQ(5, m.Call(uint32_t(0x04006000)));
58 TestWord32Ctz(0xcd800000, 23); 91 CHECK_EQ(6, m.Call(uint32_t(0x02000000)));
59 TestWord32Ctz(0x09400000, 22); 92 CHECK_EQ(7, m.Call(uint32_t(0x010000a0)));
60 TestWord32Ctz(0xaf200000, 21); 93 CHECK_EQ(8, m.Call(uint32_t(0x00800c00)));
61 TestWord32Ctz(0xac100000, 20); 94 CHECK_EQ(9, m.Call(uint32_t(0x00400000)));
62 TestWord32Ctz(0xe0b80000, 19); 95 CHECK_EQ(10, m.Call(uint32_t(0x0020000d)));
63 TestWord32Ctz(0x9ce40000, 18); 96 CHECK_EQ(11, m.Call(uint32_t(0x00100f00)));
64 TestWord32Ctz(0xc7920000, 17); 97 CHECK_EQ(12, m.Call(uint32_t(0x00080000)));
65 TestWord32Ctz(0xb8f10000, 16); 98 CHECK_EQ(13, m.Call(uint32_t(0x00041000)));
66 TestWord32Ctz(0x3b9f8000, 15); 99 CHECK_EQ(14, m.Call(uint32_t(0x00020020)));
67 TestWord32Ctz(0xdb4c4000, 14); 100 CHECK_EQ(15, m.Call(uint32_t(0x00010300)));
68 TestWord32Ctz(0xe9a32000, 13); 101 CHECK_EQ(16, m.Call(uint32_t(0x00008040)));
69 TestWord32Ctz(0xfca61000, 12); 102 CHECK_EQ(17, m.Call(uint32_t(0x00004005)));
70 TestWord32Ctz(0x6c8a7800, 11); 103 CHECK_EQ(18, m.Call(uint32_t(0x00002050)));
71 TestWord32Ctz(0x8ce5a400, 10); 104 CHECK_EQ(19, m.Call(uint32_t(0x00001700)));
72 TestWord32Ctz(0xcb7d0200, 9); 105 CHECK_EQ(20, m.Call(uint32_t(0x00000870)));
73 TestWord32Ctz(0xcb4dc100, 8); 106 CHECK_EQ(21, m.Call(uint32_t(0x00000405)));
74 TestWord32Ctz(0xdfbec580, 7); 107 CHECK_EQ(22, m.Call(uint32_t(0x00000203)));
75 TestWord32Ctz(0x27a9db40, 6); 108 CHECK_EQ(23, m.Call(uint32_t(0x00000101)));
76 TestWord32Ctz(0xde3bcb20, 5); 109 CHECK_EQ(24, m.Call(uint32_t(0x00000089)));
77 TestWord32Ctz(0xd7e8a610, 4); 110 CHECK_EQ(25, m.Call(uint32_t(0x00000041)));
78 TestWord32Ctz(0x9afdbc88, 3); 111 CHECK_EQ(26, m.Call(uint32_t(0x00000022)));
79 TestWord32Ctz(0x9afdbc84, 2); 112 CHECK_EQ(27, m.Call(uint32_t(0x00000013)));
80 TestWord32Ctz(0x9afdbc82, 1); 113 CHECK_EQ(28, m.Call(uint32_t(0x00000008)));
81 TestWord32Ctz(0x9afdbc81, 0); 114 CHECK_EQ(29, m.Call(uint32_t(0x00000004)));
115 CHECK_EQ(30, m.Call(uint32_t(0x00000002)));
116 CHECK_EQ(31, m.Call(uint32_t(0x00000001)));
117 CHECK_EQ(32, m.Call(uint32_t(0x00000000)));
82 } 118 }
83 119
84 120
85 void TestWord32Clz(int32_t value, int32_t expected) { 121 TEST(RunWord32Popcnt) {
86 RawMachineAssemblerTester<int32_t> m; 122 BufferedRawMachineAssemblerTester<int32_t> m(kMachUint32);
87 Node* clz = m.Word32Clz(m.Int32Constant(value)); 123 if (!m.machine()->Word32Popcnt().IsSupported()) {
88 m.Return(clz); 124 // We can only test the operator if it exists on the testing platform.
89 CHECK_EQ(expected, m.Call()); 125 return;
126 }
127 m.Return(m.AddNode(m.machine()->Word32Popcnt().op(), m.Parameter(0)));
128
129 CHECK_EQ(0, m.Call(uint32_t(0x00000000)));
130 CHECK_EQ(1, m.Call(uint32_t(0x00000001)));
131 CHECK_EQ(1, m.Call(uint32_t(0x80000000)));
132 CHECK_EQ(32, m.Call(uint32_t(0xffffffff)));
133 CHECK_EQ(6, m.Call(uint32_t(0x000dc100)));
134 CHECK_EQ(9, m.Call(uint32_t(0xe00dc100)));
135 CHECK_EQ(11, m.Call(uint32_t(0xe00dc103)));
136 CHECK_EQ(9, m.Call(uint32_t(0x000dc107)));
90 } 137 }
91 138
92 139
93 TEST(RunInt32Clz) {
94 TestWord32Clz(0x80001000, 0);
95 TestWord32Clz(0x40000500, 1);
96 TestWord32Clz(0x20000300, 2);
97 TestWord32Clz(0x10000003, 3);
98 TestWord32Clz(0x08050000, 4);
99 TestWord32Clz(0x04006000, 5);
100 TestWord32Clz(0x02000000, 6);
101 TestWord32Clz(0x010000a0, 7);
102 TestWord32Clz(0x00800c00, 8);
103 TestWord32Clz(0x00400000, 9);
104 TestWord32Clz(0x0020000d, 10);
105 TestWord32Clz(0x00100f00, 11);
106 TestWord32Clz(0x00080000, 12);
107 TestWord32Clz(0x00041000, 13);
108 TestWord32Clz(0x00020020, 14);
109 TestWord32Clz(0x00010300, 15);
110 TestWord32Clz(0x00008040, 16);
111 TestWord32Clz(0x00004005, 17);
112 TestWord32Clz(0x00002050, 18);
113 TestWord32Clz(0x00001700, 19);
114 TestWord32Clz(0x00000870, 20);
115 TestWord32Clz(0x00000405, 21);
116 TestWord32Clz(0x00000203, 22);
117 TestWord32Clz(0x00000101, 23);
118 TestWord32Clz(0x00000089, 24);
119 TestWord32Clz(0x00000041, 25);
120 TestWord32Clz(0x00000022, 26);
121 TestWord32Clz(0x00000013, 27);
122 TestWord32Clz(0x00000008, 28);
123 TestWord32Clz(0x00000004, 29);
124 TestWord32Clz(0x00000002, 30);
125 TestWord32Clz(0x00000001, 31);
126 TestWord32Clz(0x00000000, 32);
127 }
128
129
130 #if V8_TARGET_ARCH_64_BIT 140 #if V8_TARGET_ARCH_64_BIT
131 TEST(RunWord64Clz) { 141 TEST(RunWord64Clz) {
132 BufferedRawMachineAssemblerTester<int32_t> m(kMachUint64); 142 BufferedRawMachineAssemblerTester<int32_t> m(kMachUint64);
133 m.Return(m.Word64Clz(m.Parameter(0))); 143 m.Return(m.Word64Clz(m.Parameter(0)));
134 144
135 CHECK_EQ(0, m.Call(uint64_t(0x8000100000000000))); 145 CHECK_EQ(0, m.Call(uint64_t(0x8000100000000000)));
136 CHECK_EQ(1, m.Call(uint64_t(0x4000050000000000))); 146 CHECK_EQ(1, m.Call(uint64_t(0x4000050000000000)));
137 CHECK_EQ(2, m.Call(uint64_t(0x2000030000000000))); 147 CHECK_EQ(2, m.Call(uint64_t(0x2000030000000000)));
138 CHECK_EQ(3, m.Call(uint64_t(0x1000000300000000))); 148 CHECK_EQ(3, m.Call(uint64_t(0x1000000300000000)));
139 CHECK_EQ(4, m.Call(uint64_t(0x0805000000000000))); 149 CHECK_EQ(4, m.Call(uint64_t(0x0805000000000000)));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 CHECK_EQ(59, m.Call(uint64_t(0x0000000000000013))); 204 CHECK_EQ(59, m.Call(uint64_t(0x0000000000000013)));
195 CHECK_EQ(60, m.Call(uint64_t(0x0000000000000008))); 205 CHECK_EQ(60, m.Call(uint64_t(0x0000000000000008)));
196 CHECK_EQ(61, m.Call(uint64_t(0x0000000000000004))); 206 CHECK_EQ(61, m.Call(uint64_t(0x0000000000000004)));
197 CHECK_EQ(62, m.Call(uint64_t(0x0000000000000002))); 207 CHECK_EQ(62, m.Call(uint64_t(0x0000000000000002)));
198 CHECK_EQ(63, m.Call(uint64_t(0x0000000000000001))); 208 CHECK_EQ(63, m.Call(uint64_t(0x0000000000000001)));
199 CHECK_EQ(64, m.Call(uint64_t(0x0000000000000000))); 209 CHECK_EQ(64, m.Call(uint64_t(0x0000000000000000)));
200 } 210 }
201 #endif // V8_TARGET_ARCH_64_BIT 211 #endif // V8_TARGET_ARCH_64_BIT
202 212
203 213
204 void TestWord32Popcnt(int32_t value, int32_t expected) {
205 RawMachineAssemblerTester<int32_t> m;
206 compiler::OptionalOperator op = m.machine()->Word32Popcnt();
207 if (op.IsSupported()) {
208 Node* popcnt = m.AddNode(op.op(), m.Int32Constant(value));
209 m.Return(popcnt);
210 CHECK_EQ(expected, m.Call());
211 }
212 }
213
214
215 TEST(RunWord32Popcnt) {
216 TestWord32Popcnt(0x00000000, 0);
217 TestWord32Popcnt(0x00000001, 1);
218 TestWord32Popcnt(0x80000000, 1);
219 TestWord32Popcnt(0xffffffff, 32);
220 TestWord32Popcnt(0x000dc100, 6);
221 TestWord32Popcnt(0xe00dc100, 9);
222 TestWord32Popcnt(0xe00dc103, 11);
223 TestWord32Popcnt(0x000dc107, 9);
224 }
225
226
227 static Node* Int32Input(RawMachineAssemblerTester<int32_t>* m, int index) { 214 static Node* Int32Input(RawMachineAssemblerTester<int32_t>* m, int index) {
228 switch (index) { 215 switch (index) {
229 case 0: 216 case 0:
230 return m->Parameter(0); 217 return m->Parameter(0);
231 case 1: 218 case 1:
232 return m->Parameter(1); 219 return m->Parameter(1);
233 case 2: 220 case 2:
234 return m->Int32Constant(0); 221 return m->Int32Constant(0);
235 case 3: 222 case 3:
236 return m->Int32Constant(1); 223 return m->Int32Constant(1);
(...skipping 3555 matching lines...) Expand 10 before | Expand all | Expand 10 after
3792 3779
3793 3780
3794 TEST(RunChangeInt32ToFloat64_B) { 3781 TEST(RunChangeInt32ToFloat64_B) {
3795 BufferedRawMachineAssemblerTester<double> m(kMachInt32); 3782 BufferedRawMachineAssemblerTester<double> m(kMachInt32);
3796 m.Return(m.ChangeInt32ToFloat64(m.Parameter(0))); 3783 m.Return(m.ChangeInt32ToFloat64(m.Parameter(0)));
3797 3784
3798 FOR_INT32_INPUTS(i) { CheckDoubleEq(static_cast<double>(*i), m.Call(*i)); } 3785 FOR_INT32_INPUTS(i) { CheckDoubleEq(static_cast<double>(*i), m.Call(*i)); }
3799 } 3786 }
3800 3787
3801 3788
3802 TEST(RunChangeUint32ToFloat64_B) { 3789 TEST(RunChangeUint32ToFloat64) {
3803 RawMachineAssemblerTester<uint32_t> m(kMachUint32); 3790 BufferedRawMachineAssemblerTester<double> m(kMachUint32);
3804 double output = 0; 3791 m.Return(m.ChangeUint32ToFloat64(m.Parameter(0)));
3805 3792
3806 Node* convert = m.ChangeUint32ToFloat64(m.Parameter(0)); 3793 FOR_UINT32_INPUTS(i) { CheckDoubleEq(static_cast<double>(*i), m.Call(*i)); }
3807 m.Store(kMachFloat64, m.PointerConstant(&output), m.Int32Constant(0), convert,
3808 kNoWriteBarrier);
3809 m.Return(m.Parameter(0));
3810
3811 FOR_UINT32_INPUTS(i) {
3812 uint32_t expect = *i;
3813 CHECK_EQ(expect, m.Call(expect));
3814 CHECK_EQ(static_cast<double>(expect), output);
3815 }
3816 } 3794 }
3817 3795
3818 3796
3819 TEST(RunChangeUint32ToFloat64_spilled) {
3820 RawMachineAssemblerTester<int32_t> m;
3821 const int kNumInputs = 32;
3822 int32_t magic = 0x786234;
3823 uint32_t input[kNumInputs];
3824 double result[kNumInputs];
3825 Node* input_node[kNumInputs];
3826
3827 for (int i = 0; i < kNumInputs; i++) {
3828 input_node[i] =
3829 m.Load(kMachUint32, m.PointerConstant(&input), m.Int32Constant(i * 4));
3830 }
3831
3832 for (int i = 0; i < kNumInputs; i++) {
3833 m.Store(kMachFloat64, m.PointerConstant(&result), m.Int32Constant(i * 8),
3834 m.ChangeUint32ToFloat64(input_node[i]), kNoWriteBarrier);
3835 }
3836
3837 m.Return(m.Int32Constant(magic));
3838
3839 for (int i = 0; i < kNumInputs; i++) {
3840 input[i] = 100 + i;
3841 }
3842
3843 CHECK_EQ(magic, m.Call());
3844
3845 for (int i = 0; i < kNumInputs; i++) {
3846 CHECK_EQ(result[i], static_cast<double>(100 + i));
3847 }
3848 }
3849
3850
3851 TEST(RunChangeFloat64ToInt32_A) { 3797 TEST(RunChangeFloat64ToInt32_A) {
3852 BufferedRawMachineAssemblerTester<int32_t> m; 3798 BufferedRawMachineAssemblerTester<int32_t> m;
3853 double magic = 11.1; 3799 double magic = 11.1;
3854 m.Return(m.ChangeFloat64ToInt32(m.Float64Constant(magic))); 3800 m.Return(m.ChangeFloat64ToInt32(m.Float64Constant(magic)));
3855 CHECK_EQ(static_cast<int32_t>(magic), m.Call()); 3801 CHECK_EQ(static_cast<int32_t>(magic), m.Call());
3856 } 3802 }
3857 3803
3858 3804
3859 TEST(RunChangeFloat64ToInt32_B) { 3805 TEST(RunChangeFloat64ToInt32_B) {
3860 BufferedRawMachineAssemblerTester<int32_t> m(kMachFloat64); 3806 BufferedRawMachineAssemblerTester<int32_t> m(kMachFloat64);
3861 m.Return(m.ChangeFloat64ToInt32(m.Parameter(0))); 3807 m.Return(m.ChangeFloat64ToInt32(m.Parameter(0)));
3862 3808
3863 // Note we don't check fractional inputs, or inputs outside the range of 3809 // Note we don't check fractional inputs, or inputs outside the range of
3864 // int32, because these Convert operators really should be Change operators. 3810 // int32, because these Convert operators really should be Change operators.
3865 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, m.Call(static_cast<double>(*i))); } 3811 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, m.Call(static_cast<double>(*i))); }
3866 3812
3867 for (int32_t n = 1; n < 31; ++n) { 3813 for (int32_t n = 1; n < 31; ++n) {
3868 CHECK_EQ(1 << n, m.Call(static_cast<double>(1 << n))); 3814 CHECK_EQ(1 << n, m.Call(static_cast<double>(1 << n)));
3869 } 3815 }
3870 3816
3871 for (int32_t n = 1; n < 31; ++n) { 3817 for (int32_t n = 1; n < 31; ++n) {
3872 CHECK_EQ(3 << n, m.Call(static_cast<double>(3 << n))); 3818 CHECK_EQ(3 << n, m.Call(static_cast<double>(3 << n)));
3873 } 3819 }
3874 } 3820 }
3875 3821
3876 3822
3877 TEST(RunChangeFloat64ToUint32_B) { 3823 TEST(RunChangeFloat64ToUint32) {
3878 RawMachineAssemblerTester<int32_t> m; 3824 BufferedRawMachineAssemblerTester<uint32_t> m(kMachFloat64);
3879 double input = 0; 3825 m.Return(m.ChangeFloat64ToUint32(m.Parameter(0)));
3880 int32_t output = 0;
3881
3882 Node* load =
3883 m.Load(kMachFloat64, m.PointerConstant(&input), m.Int32Constant(0));
3884 Node* convert = m.ChangeFloat64ToUint32(load);
3885 m.Store(kMachInt32, m.PointerConstant(&output), m.Int32Constant(0), convert,
3886 kNoWriteBarrier);
3887 m.Return(convert);
3888 3826
3889 { 3827 {
3890 FOR_UINT32_INPUTS(i) { 3828 FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, m.Call(static_cast<double>(*i))); }
3891 input = *i;
3892 // TODO(titzer): add a CheckEqualsHelper overload for uint32_t.
3893 int32_t expect = static_cast<int32_t>(*i);
3894 CHECK_EQ(expect, m.Call());
3895 CHECK_EQ(expect, output);
3896 }
3897 } 3829 }
3898 3830
3899 // Check various powers of 2. 3831 // Check various powers of 2.
3900 for (int32_t n = 1; n < 31; ++n) { 3832 for (int32_t n = 1; n < 31; ++n) {
3901 { 3833 { CHECK_EQ(1u << n, m.Call(static_cast<double>(1u << n))); }
3902 input = 1u << n;
3903 int32_t expect = static_cast<int32_t>(static_cast<uint32_t>(input));
3904 CHECK_EQ(expect, m.Call());
3905 CHECK_EQ(expect, output);
3906 }
3907 3834
3908 { 3835 { CHECK_EQ(3u << n, m.Call(static_cast<double>(3u << n))); }
3909 input = 3u << n;
3910 int32_t expect = static_cast<int32_t>(static_cast<uint32_t>(input));
3911 CHECK_EQ(expect, m.Call());
3912 CHECK_EQ(expect, output);
3913 }
3914 } 3836 }
3915 // Note we don't check fractional inputs, because these Convert operators 3837 // Note we don't check fractional inputs, because these Convert operators
3916 // really should be Change operators. 3838 // really should be Change operators.
3917 } 3839 }
3918 3840
3919 3841
3920 TEST(RunChangeFloat64ToInt32_spilled) { 3842 TEST(RunTruncateFloat64ToFloat32) {
3921 RawMachineAssemblerTester<int32_t> m; 3843 BufferedRawMachineAssemblerTester<float> m(kMachFloat64);
3922 const int kNumInputs = 32;
3923 int32_t magic = 0x786234;
3924 double input[kNumInputs];
3925 int32_t result[kNumInputs];
3926 Node* input_node[kNumInputs];
3927 3844
3928 for (int i = 0; i < kNumInputs; i++) { 3845 m.Return(m.TruncateFloat64ToFloat32(m.Parameter(0)));
3929 input_node[i] =
3930 m.Load(kMachFloat64, m.PointerConstant(&input), m.Int32Constant(i * 8));
3931 }
3932 3846
3933 for (int i = 0; i < kNumInputs; i++) { 3847 FOR_FLOAT64_INPUTS(i) { CheckFloatEq(DoubleToFloat32(*i), m.Call(*i)); }
3934 m.Store(kMachInt32, m.PointerConstant(&result), m.Int32Constant(i * 4),
3935 m.ChangeFloat64ToInt32(input_node[i]), kNoWriteBarrier);
3936 }
3937
3938 m.Return(m.Int32Constant(magic));
3939
3940 for (int i = 0; i < kNumInputs; i++) {
3941 input[i] = 100.9 + i;
3942 }
3943
3944 CHECK_EQ(magic, m.Call());
3945
3946 for (int i = 0; i < kNumInputs; i++) {
3947 CHECK_EQ(result[i], 100 + i);
3948 }
3949 } 3848 }
3950 3849
3951 3850
3952 TEST(RunChangeFloat64ToUint32_spilled) {
3953 RawMachineAssemblerTester<uint32_t> m;
3954 const int kNumInputs = 32;
3955 uint32_t magic = 0x786234;
3956 double input[kNumInputs];
3957 uint32_t result[kNumInputs];
3958 Node* input_node[kNumInputs];
3959
3960 for (int i = 0; i < kNumInputs; i++) {
3961 input_node[i] =
3962 m.Load(kMachFloat64, m.PointerConstant(&input), m.Int32Constant(i * 8));
3963 }
3964
3965 for (int i = 0; i < kNumInputs; i++) {
3966 m.Store(kMachUint32, m.PointerConstant(&result), m.Int32Constant(i * 4),
3967 m.ChangeFloat64ToUint32(input_node[i]), kNoWriteBarrier);
3968 }
3969
3970 m.Return(m.Int32Constant(magic));
3971
3972 for (int i = 0; i < kNumInputs; i++) {
3973 if (i % 2) {
3974 input[i] = 100 + i + 2147483648u;
3975 } else {
3976 input[i] = 100 + i;
3977 }
3978 }
3979
3980 CHECK_EQ(magic, m.Call());
3981
3982 for (int i = 0; i < kNumInputs; i++) {
3983 if (i % 2) {
3984 CHECK_EQ(result[i], static_cast<uint32_t>(100 + i + 2147483648u));
3985 } else {
3986 CHECK_EQ(result[i], static_cast<uint32_t>(100 + i));
3987 }
3988 }
3989 }
3990
3991
3992 TEST(RunTruncateFloat64ToFloat32_spilled) {
3993 RawMachineAssemblerTester<uint32_t> m;
3994 const int kNumInputs = 32;
3995 uint32_t magic = 0x786234;
3996 double input[kNumInputs];
3997 float result[kNumInputs];
3998 Node* input_node[kNumInputs];
3999
4000 for (int i = 0; i < kNumInputs; i++) {
4001 input_node[i] =
4002 m.Load(kMachFloat64, m.PointerConstant(&input), m.Int32Constant(i * 8));
4003 }
4004
4005 for (int i = 0; i < kNumInputs; i++) {
4006 m.Store(kMachFloat32, m.PointerConstant(&result), m.Int32Constant(i * 4),
4007 m.TruncateFloat64ToFloat32(input_node[i]), kNoWriteBarrier);
4008 }
4009
4010 m.Return(m.Int32Constant(magic));
4011
4012 for (int i = 0; i < kNumInputs; i++) {
4013 input[i] = 0.1 + i;
4014 }
4015
4016 CHECK_EQ(magic, m.Call());
4017
4018 for (int i = 0; i < kNumInputs; i++) {
4019 CHECK_EQ(result[i], DoubleToFloat32(input[i]));
4020 }
4021 }
4022
4023
4024 TEST(RunDeadChangeFloat64ToInt32) { 3851 TEST(RunDeadChangeFloat64ToInt32) {
4025 RawMachineAssemblerTester<int32_t> m; 3852 RawMachineAssemblerTester<int32_t> m;
4026 const int magic = 0x88abcda4; 3853 const int magic = 0x88abcda4;
4027 m.ChangeFloat64ToInt32(m.Float64Constant(999.78)); 3854 m.ChangeFloat64ToInt32(m.Float64Constant(999.78));
4028 m.Return(m.Int32Constant(magic)); 3855 m.Return(m.Int32Constant(magic));
4029 CHECK_EQ(magic, m.Call()); 3856 CHECK_EQ(magic, m.Call());
4030 } 3857 }
4031 3858
4032 3859
4033 TEST(RunDeadChangeInt32ToFloat64) { 3860 TEST(RunDeadChangeInt32ToFloat64) {
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
5038 m.LoadFromPointer(&input, kMachFloat64))); 4865 m.LoadFromPointer(&input, kMachFloat64)));
5039 for (size_t i = 0; i < arraysize(kValues); ++i) { 4866 for (size_t i = 0; i < arraysize(kValues); ++i) {
5040 input = kValues[i].from; 4867 input = kValues[i].from;
5041 uint64_t expected = static_cast<int64_t>(kValues[i].raw); 4868 uint64_t expected = static_cast<int64_t>(kValues[i].raw);
5042 CHECK_EQ(static_cast<int>(expected), m.Call()); 4869 CHECK_EQ(static_cast<int>(expected), m.Call());
5043 } 4870 }
5044 } 4871 }
5045 4872
5046 4873
5047 TEST(RunChangeFloat32ToFloat64) { 4874 TEST(RunChangeFloat32ToFloat64) {
5048 double actual = 0.0f; 4875 BufferedRawMachineAssemblerTester<double> m(kMachFloat32);
5049 float expected = 0.0;
5050 RawMachineAssemblerTester<int32_t> m;
5051 m.StoreToPointer(
5052 &actual, kMachFloat64,
5053 m.ChangeFloat32ToFloat64(m.LoadFromPointer(&expected, kMachFloat32)));
5054 m.Return(m.Int32Constant(0));
5055 FOR_FLOAT32_INPUTS(i) {
5056 expected = *i;
5057 CHECK_EQ(0, m.Call());
5058 CHECK_EQ(static_cast<double>(expected), actual);
5059 }
5060 }
5061 4876
4877 m.Return(m.ChangeFloat32ToFloat64(m.Parameter(0)));
5062 4878
5063 TEST(RunChangeFloat32ToFloat64_spilled) { 4879 FOR_FLOAT32_INPUTS(i) { CheckDoubleEq(static_cast<double>(*i), m.Call(*i)); }
5064 RawMachineAssemblerTester<int32_t> m;
5065 const int kNumInputs = 32;
5066 int32_t magic = 0x786234;
5067 float input[kNumInputs];
5068 double result[kNumInputs];
5069 Node* input_node[kNumInputs];
5070
5071 for (int i = 0; i < kNumInputs; i++) {
5072 input_node[i] =
5073 m.Load(kMachFloat32, m.PointerConstant(&input), m.Int32Constant(i * 4));
5074 }
5075
5076 for (int i = 0; i < kNumInputs; i++) {
5077 m.Store(kMachFloat64, m.PointerConstant(&result), m.Int32Constant(i * 8),
5078 m.ChangeFloat32ToFloat64(input_node[i]), kNoWriteBarrier);
5079 }
5080
5081 m.Return(m.Int32Constant(magic));
5082
5083 for (int i = 0; i < kNumInputs; i++) {
5084 input[i] = 100.9f + i;
5085 }
5086
5087 CHECK_EQ(magic, m.Call());
5088
5089 for (int i = 0; i < kNumInputs; i++) {
5090 CHECK_EQ(result[i], static_cast<double>(input[i]));
5091 }
5092 }
5093
5094
5095 TEST(RunTruncateFloat64ToFloat32) {
5096 float actual = 0.0f;
5097 double input = 0.0;
5098 RawMachineAssemblerTester<int32_t> m;
5099 m.StoreToPointer(
5100 &actual, kMachFloat32,
5101 m.TruncateFloat64ToFloat32(m.LoadFromPointer(&input, kMachFloat64)));
5102 m.Return(m.Int32Constant(0));
5103 FOR_FLOAT64_INPUTS(i) {
5104 input = *i;
5105 volatile double expected = DoubleToFloat32(input);
5106 CHECK_EQ(0, m.Call());
5107 CheckDoubleEq(expected, actual);
5108 }
5109 } 4880 }
5110 4881
5111 4882
5112 TEST(RunFloat32Constant) { 4883 TEST(RunFloat32Constant) {
5113 FOR_FLOAT32_INPUTS(i) { 4884 FOR_FLOAT32_INPUTS(i) {
5114 float expected = *i; 4885 BufferedRawMachineAssemblerTester<float> m;
5115 float actual = *i; 4886 m.Return(m.Float32Constant(*i));
5116 RawMachineAssemblerTester<int32_t> m; 4887 CheckFloatEq(*i, m.Call());
5117 m.StoreToPointer(&actual, kMachFloat32, m.Float32Constant(expected));
5118 m.Return(m.Int32Constant(0));
5119 CHECK_EQ(0, m.Call());
5120 CHECK_EQ(expected, actual);
5121 } 4888 }
5122 } 4889 }
5123 4890
5124 4891
5125 TEST(RunFloat64ExtractLowWord32) { 4892 TEST(RunFloat64ExtractLowWord32) {
5126 uint64_t input = 0; 4893 BufferedRawMachineAssemblerTester<uint32_t> m(kMachFloat64);
5127 RawMachineAssemblerTester<int32_t> m; 4894 m.Return(m.Float64ExtractLowWord32(m.Parameter(0)));
5128 m.Return(m.Float64ExtractLowWord32(m.LoadFromPointer(&input, kMachFloat64)));
5129 FOR_FLOAT64_INPUTS(i) { 4895 FOR_FLOAT64_INPUTS(i) {
5130 input = bit_cast<uint64_t>(*i); 4896 uint32_t expected = static_cast<uint32_t>(bit_cast<uint64_t>(*i));
5131 int32_t expected = bit_cast<int32_t>(static_cast<uint32_t>(input)); 4897 CHECK_EQ(expected, m.Call(*i));
5132 CHECK_EQ(expected, m.Call());
5133 } 4898 }
5134 } 4899 }
5135 4900
5136 4901
5137 TEST(RunFloat64ExtractHighWord32) { 4902 TEST(RunFloat64ExtractHighWord32) {
5138 uint64_t input = 0; 4903 BufferedRawMachineAssemblerTester<uint32_t> m(kMachFloat64);
5139 RawMachineAssemblerTester<int32_t> m; 4904 m.Return(m.Float64ExtractHighWord32(m.Parameter(0)));
5140 m.Return(m.Float64ExtractHighWord32(m.LoadFromPointer(&input, kMachFloat64)));
5141 FOR_FLOAT64_INPUTS(i) { 4905 FOR_FLOAT64_INPUTS(i) {
5142 input = bit_cast<uint64_t>(*i); 4906 uint32_t expected = static_cast<uint32_t>(bit_cast<uint64_t>(*i) >> 32);
5143 int32_t expected = bit_cast<int32_t>(static_cast<uint32_t>(input >> 32)); 4907 CHECK_EQ(expected, m.Call(*i));
5144 CHECK_EQ(expected, m.Call());
5145 } 4908 }
5146 } 4909 }
5147 4910
5148 4911
5149 TEST(RunFloat64InsertLowWord32) { 4912 TEST(RunFloat64InsertLowWord32) {
5150 uint64_t input = 0; 4913 BufferedRawMachineAssemblerTester<double> m(kMachFloat64, kMachInt32);
5151 uint64_t result = 0; 4914 m.Return(m.Float64InsertLowWord32(m.Parameter(0), m.Parameter(1)));
5152 RawMachineAssemblerTester<int32_t> m(kMachInt32);
5153 m.StoreToPointer(
5154 &result, kMachFloat64,
5155 m.Float64InsertLowWord32(m.LoadFromPointer(&input, kMachFloat64),
5156 m.Parameter(0)));
5157 m.Return(m.Int32Constant(0));
5158 FOR_FLOAT64_INPUTS(i) { 4915 FOR_FLOAT64_INPUTS(i) {
5159 FOR_INT32_INPUTS(j) { 4916 FOR_INT32_INPUTS(j) {
5160 input = bit_cast<uint64_t>(*i); 4917 double expected = bit_cast<double>(
5161 uint64_t expected = (input & ~(V8_UINT64_C(0xFFFFFFFF))) | 4918 (bit_cast<uint64_t>(*i) & ~(V8_UINT64_C(0xFFFFFFFF))) |
5162 (static_cast<uint64_t>(bit_cast<uint32_t>(*j))); 4919 (static_cast<uint64_t>(bit_cast<uint32_t>(*j))));
5163 CHECK_EQ(0, m.Call(*j)); 4920 CheckDoubleEq(expected, m.Call(*i, *j));
5164 CHECK_EQ(expected, result);
5165 } 4921 }
5166 } 4922 }
5167 } 4923 }
5168 4924
5169 4925
5170 TEST(RunFloat64InsertHighWord32) { 4926 TEST(RunFloat64InsertHighWord32) {
5171 uint64_t input = 0; 4927 BufferedRawMachineAssemblerTester<double> m(kMachFloat64, kMachUint32);
5172 uint64_t result = 0; 4928 m.Return(m.Float64InsertHighWord32(m.Parameter(0), m.Parameter(1)));
5173 RawMachineAssemblerTester<int32_t> m(kMachInt32);
5174 m.StoreToPointer(
5175 &result, kMachFloat64,
5176 m.Float64InsertHighWord32(m.LoadFromPointer(&input, kMachFloat64),
5177 m.Parameter(0)));
5178 m.Return(m.Int32Constant(0));
5179 FOR_FLOAT64_INPUTS(i) { 4929 FOR_FLOAT64_INPUTS(i) {
5180 FOR_INT32_INPUTS(j) { 4930 FOR_UINT32_INPUTS(j) {
5181 input = bit_cast<uint64_t>(*i); 4931 uint64_t expected = (bit_cast<uint64_t>(*i) & 0xFFFFFFFF) |
5182 uint64_t expected = (input & ~(V8_UINT64_C(0xFFFFFFFF) << 32)) | 4932 (static_cast<uint64_t>(*j) << 32);
5183 (static_cast<uint64_t>(bit_cast<uint32_t>(*j)) << 32); 4933
5184 CHECK_EQ(0, m.Call(*j)); 4934 CheckDoubleEq(bit_cast<double>(expected), m.Call(*i, *j));
5185 CHECK_EQ(expected, result);
5186 } 4935 }
5187 } 4936 }
5188 } 4937 }
5189 4938
5190 4939
5191 TEST(RunFloat32Abs) { 4940 TEST(RunFloat32Abs) {
5192 float input = -1.0; 4941 BufferedRawMachineAssemblerTester<float> m(kMachFloat32);
5193 float result = 0.0; 4942 m.Return(m.Float32Abs(m.Parameter(0)));
5194 RawMachineAssemblerTester<int32_t> m; 4943 FOR_FLOAT32_INPUTS(i) { CheckFloatEq(std::abs(*i), m.Call(*i)); }
5195 m.StoreToPointer(&result, kMachFloat32,
5196 m.Float32Abs(m.LoadFromPointer(&input, kMachFloat32)));
5197 m.Return(m.Int32Constant(0));
5198 FOR_FLOAT32_INPUTS(i) {
5199 input = *i;
5200 float expected = std::abs(input);
5201 CHECK_EQ(0, m.Call());
5202 CheckFloatEq(expected, result);
5203 }
5204 } 4944 }
5205 4945
5206 4946
5207 TEST(RunFloat64Abs) { 4947 TEST(RunFloat64Abs) {
5208 double input = -1.0; 4948 BufferedRawMachineAssemblerTester<double> m(kMachFloat64);
5209 double result = 0.0; 4949 m.Return(m.Float64Abs(m.Parameter(0)));
5210 RawMachineAssemblerTester<int32_t> m; 4950 FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(std::abs(*i), m.Call(*i)); }
5211 m.StoreToPointer(&result, kMachFloat64,
5212 m.Float64Abs(m.LoadFromPointer(&input, kMachFloat64)));
5213 m.Return(m.Int32Constant(0));
5214 FOR_FLOAT64_INPUTS(i) {
5215 input = *i;
5216 double expected = std::abs(input);
5217 CHECK_EQ(0, m.Call());
5218 CheckDoubleEq(expected, result);
5219 }
5220 } 4951 }
5221 4952
5222 4953
5223 static double two_30 = 1 << 30; // 2^30 is a smi boundary. 4954 static double two_30 = 1 << 30; // 2^30 is a smi boundary.
5224 static double two_52 = two_30 * (1 << 22); // 2^52 is a precision boundary. 4955 static double two_52 = two_30 * (1 << 22); // 2^52 is a precision boundary.
5225 static double kValues[] = {0.1, 4956 static double kValues[] = {0.1,
5226 0.2, 4957 0.2,
5227 0.49999999999999994, 4958 0.49999999999999994,
5228 0.5, 4959 0.5,
5229 0.7, 4960 0.7,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
5312 -two_52 - 0.1, 5043 -two_52 - 0.1,
5313 -two_52 - 0.5, 5044 -two_52 - 0.5,
5314 -two_52 - 0.7, 5045 -two_52 - 0.7,
5315 -two_52 + 1, 5046 -two_52 + 1,
5316 -two_52 + 1 - 0.1, 5047 -two_52 + 1 - 0.1,
5317 -two_52 + 1 - 0.5, 5048 -two_52 + 1 - 0.5,
5318 -two_52 + 1 - 0.7}; 5049 -two_52 + 1 - 0.7};
5319 5050
5320 5051
5321 TEST(RunFloat64RoundDown1) { 5052 TEST(RunFloat64RoundDown1) {
5322 double input = -1.0; 5053 BufferedRawMachineAssemblerTester<double> m(kMachFloat64);
5323 double result = 0.0;
5324 RawMachineAssemblerTester<int32_t> m;
5325 if (!m.machine()->Float64RoundDown().IsSupported()) return; 5054 if (!m.machine()->Float64RoundDown().IsSupported()) return;
5326 m.StoreToPointer(&result, kMachFloat64, 5055
5327 m.Float64RoundDown(m.LoadFromPointer(&input, kMachFloat64))); 5056 m.Return(m.Float64RoundDown(m.Parameter(0)));
5328 m.Return(m.Int32Constant(0)); 5057
5329 for (size_t i = 0; i < arraysize(kValues); ++i) { 5058 FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(std::floor(*i), m.Call(*i)); }
5330 input = kValues[i];
5331 CHECK_EQ(0, m.Call());
5332 double expected = std::floor(kValues[i]);
5333 CHECK_EQ(expected, result);
5334 }
5335 } 5059 }
5336 5060
5337 5061
5338 TEST(RunFloat64RoundDown2) { 5062 TEST(RunFloat64RoundDown2) {
5339 double input = -1.0; 5063 double input = -1.0;
5340 double result = 0.0; 5064 double result = 0.0;
5341 RawMachineAssemblerTester<int32_t> m; 5065 RawMachineAssemblerTester<int32_t> m;
5342 if (!m.machine()->Float64RoundDown().IsSupported()) return; 5066 if (!m.machine()->Float64RoundDown().IsSupported()) return;
5343 m.StoreToPointer(&result, kMachFloat64, 5067 m.StoreToPointer(&result, kMachFloat64,
5344 m.Float64Sub(m.Float64Constant(-0.0), 5068 m.Float64Sub(m.Float64Constant(-0.0),
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
5633 Node* call = r.AddNode(r.common()->Call(desc), phi); 5357 Node* call = r.AddNode(r.common()->Call(desc), phi);
5634 r.Return(call); 5358 r.Return(call);
5635 5359
5636 CHECK_EQ(33, r.Call(1)); 5360 CHECK_EQ(33, r.Call(1));
5637 CHECK_EQ(44, r.Call(0)); 5361 CHECK_EQ(44, r.Call(0));
5638 } 5362 }
5639 5363
5640 } // namespace compiler 5364 } // namespace compiler
5641 } // namespace internal 5365 } // namespace internal
5642 } // namespace v8 5366 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698