OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 assertEquals(3.5, array[1]); | 77 assertEquals(3.5, array[1]); |
78 } | 78 } |
79 %OptimizeFunctionOnNextCall(get); | 79 %OptimizeFunctionOnNextCall(get); |
80 assertEquals(2.5, get(array, 0)); | 80 assertEquals(2.5, get(array, 0)); |
81 assertEquals(3.5, get(array, 1)); | 81 assertEquals(3.5, get(array, 1)); |
82 | 82 |
83 // Test loads and stores. | 83 // Test loads and stores. |
84 types = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, | 84 types = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, |
85 Uint32Array, PixelArray, Float32Array, Float64Array]; | 85 Uint32Array, PixelArray, Float32Array, Float64Array]; |
86 | 86 |
87 test_result_nan = [0, 0, 0, 0, 0, 0, 0, NaN, NaN]; | |
88 test_result_low_double = [-1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1.25, -1.25]; | |
89 test_result_low_int = [-1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1, -1]; | |
90 test_result_middle = [-3, 253, 253, 253, 253, 253, 254, 253.75, 253.75]; | |
91 test_result_high_int = [0, 0, 256, 256, 256, 256, 255, 256, 256]; | |
92 test_result_high_double = [0, 0, 256, 256, 256, 256, 255, 256.25, 256.25]; | |
93 | |
87 const kElementCount = 40; | 94 const kElementCount = 40; |
88 | 95 |
89 function test_load(array, sum) { | 96 function test_load(array, sum) { |
90 for (var i = 0; i < kElementCount; i++) { | 97 for (var i = 0; i < kElementCount; i++) { |
91 sum += array[i]; | 98 sum += array[i]; |
92 } | 99 } |
93 return sum; | 100 return sum; |
94 } | 101 } |
95 | 102 |
96 function test_load_const_key(array, sum) { | 103 function test_load_const_key(array, sum) { |
(...skipping 10 matching lines...) Expand all Loading... | |
107 return sum; | 114 return sum; |
108 } | 115 } |
109 | 116 |
110 function test_store_const_key(array, sum) { | 117 function test_store_const_key(array, sum) { |
111 sum += array[0] = 1; | 118 sum += array[0] = 1; |
112 sum += array[1] = 2; | 119 sum += array[1] = 2; |
113 sum += array[2] = 3; | 120 sum += array[2] = 3; |
114 return sum; | 121 return sum; |
115 } | 122 } |
116 | 123 |
117 function run_test(test_func, array, expected_sum_per_run) { | 124 |
125 function test_store_middle_double(array, sum) { | |
126 array[0] = 253.75; | |
127 return array[0]; | |
128 } | |
129 | |
130 | |
131 function test_store_high_double(array, sum) { | |
132 array[0] = 256.25; | |
133 return array[0]; | |
134 } | |
135 | |
136 function test_store_high_int(array, sum) { | |
137 array[0] = 256; | |
138 return array[0]; | |
139 } | |
140 | |
141 function test_store_low_double(array, sum) { | |
142 array[0] = -1.25; | |
143 return array[0]; | |
144 } | |
145 | |
146 function test_store_low_int(array, sum) { | |
147 array[0] = -1; | |
148 return array[0]; | |
149 } | |
150 | |
151 function test_store_nan(array, sum) { | |
152 array[0] = NaN; | |
153 return array[0]; | |
154 } | |
155 | |
Lasse Reichstein
2011/05/13 13:17:24
Test 0.49999999999999994, please :).
And both 1.5
danno
2011/05/15 05:50:27
I'm not so sure we should add the test case, since
Lasse Reichstein
2011/05/15 10:18:51
That's fine.
If you have a test that is known to f
danno
2011/05/16 14:13:43
I'll write and submit the test in a separate CL.
| |
156 const kRuns = 10; | |
157 | |
158 function run_test(test_func, array, expected_result) { | |
118 for (var i = 0; i < 5; i++) test_func(array, 0); | 159 for (var i = 0; i < 5; i++) test_func(array, 0); |
119 %OptimizeFunctionOnNextCall(test_func); | 160 %OptimizeFunctionOnNextCall(test_func); |
120 const kRuns = 10; | |
121 var sum = 0; | 161 var sum = 0; |
122 for (var i = 0; i < kRuns; i++) { | 162 for (var i = 0; i < kRuns; i++) { |
123 sum = test_func(array, sum); | 163 sum = test_func(array, sum); |
124 } | 164 } |
125 assertEquals(sum, expected_sum_per_run * kRuns); | 165 assertEquals(expected_result, sum); |
126 %DeoptimizeFunction(test_func); | 166 %DeoptimizeFunction(test_func); |
127 gc(); // Makes V8 forget about type information for test_func. | 167 gc(); // Makes V8 forget about type information for test_func. |
128 } | 168 } |
129 | 169 |
130 for (var t = 0; t < types.length; t++) { | 170 for (var t = 0; t < types.length; t++) { |
131 var type = types[t]; | 171 var type = types[t]; |
132 var a = new type(kElementCount); | 172 var a = new type(kElementCount); |
133 for (var i = 0; i < kElementCount; i++) { | 173 for (var i = 0; i < kElementCount; i++) { |
134 a[i] = i; | 174 a[i] = i; |
135 } | 175 } |
136 | 176 |
137 // Run test functions defined above. | 177 // Run test functions defined above. |
138 run_test(test_load, a, 780); | 178 run_test(test_load, a, 780 * kRuns); |
139 run_test(test_load_const_key, a, 3); | 179 run_test(test_load_const_key, a, 3 * kRuns); |
140 run_test(test_store, a, 820); | 180 run_test(test_store, a, 820 * kRuns); |
141 run_test(test_store_const_key, a, 6); | 181 run_test(test_store_const_key, a, 6 * kRuns); |
142 | 182 run_test(test_store_low_double, a, test_result_low_double[t]); |
183 run_test(test_store_low_int, a, test_result_low_int[t]); | |
184 run_test(test_store_high_double, a, test_result_high_double[t]); | |
185 run_test(test_store_high_int, a, test_result_high_int[t]); | |
186 run_test(test_store_nan, a, test_result_nan[t]); | |
187 run_test(test_store_middle_double, a, test_result_middle[t]); | |
188 | |
143 // Test the correct behavior of the |length| property (which is read-only). | 189 // Test the correct behavior of the |length| property (which is read-only). |
144 assertEquals(kElementCount, a.length); | 190 assertEquals(kElementCount, a.length); |
145 a.length = 2; | 191 a.length = 2; |
146 assertEquals(kElementCount, a.length); | 192 assertEquals(kElementCount, a.length); |
147 assertTrue(delete a.length); | 193 assertTrue(delete a.length); |
148 a.length = 2 | 194 a.length = 2 |
149 assertEquals(2, a.length); | 195 assertEquals(2, a.length); |
150 } | 196 } |
OLD | NEW |