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

Side by Side Diff: test/mjsunit/math-floor-of-div.js

Issue 11624022: Handle non-constant divisor in MathFloorOfDiv, on ia32/x64 (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 11 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
« no previous file with comments | « src/x64/lithium-x64.cc ('k') | test/mjsunit/math-floor-of-div-nosudiv.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 assertEquals(Math.floor(div(-(values[i] | 0), -(values[j] | 0))), 177 assertEquals(Math.floor(div(-(values[i] | 0), -(values[j] | 0))),
178 Math.floor(-(values[i] | 0) / -(values[j] | 0))); 178 Math.floor(-(values[i] | 0) / -(values[j] | 0)));
179 } 179 }
180 } 180 }
181 } 181 }
182 182
183 test_div(); 183 test_div();
184 %OptimizeFunctionOnNextCall(test_div); 184 %OptimizeFunctionOnNextCall(test_div);
185 test_div(); 185 test_div();
186 186
187 // Test for ia32/x64 flooring correctness.
188 var values2 = [1, 3, 10, 99, 100, 101, 0x7fffffff];
189 function test_div2() {
190 for (var i = 0; i < values2.length; i++) {
191 for (var j = 0; j < values2.length; j++) {
192 assertEquals(Math.floor(div((values2[i] | 0), (values2[j] | 0))),
193 Math.floor((values2[i] | 0) / (values2[j] | 0)));
194 assertEquals(Math.floor(div(-(values2[i] | 0), (values2[j] | 0))),
195 Math.floor(-(values2[i] | 0) / (values2[j] | 0)));
196 assertEquals(Math.floor(div((values2[i] | 0), -(values2[j] | 0))),
197 Math.floor((values2[i] | 0) / -(values2[j] | 0)));
198 assertEquals(Math.floor(div(-(values2[i] | 0), -(values2[j] | 0))),
199 Math.floor(-(values2[i] | 0) / -(values2[j] | 0)));
200 }
201 }
202 }
203
204 test_div2();
205 %OptimizeFunctionOnNextCall(test_div2);
206 test_div2();
207
208
187 // Test for negative zero, overflow and division by 0. 209 // Test for negative zero, overflow and division by 0.
188 // Separate the tests to prevent deoptimizations from making the other optimized 210 // Separate the tests to prevent deoptimizations from making the other optimized
189 // test unreachable. 211 // test unreachable.
190 212
213 // We box the value in an array to avoid constant propagation.
214 var neg_one_in_array = [-1];
215 var zero_in_array = [0];
216 var min_int_in_array = [-2147483648];
217
218 // Test for dividing by constant.
191 function IsNegativeZero(x) { 219 function IsNegativeZero(x) {
192 assertTrue(x == 0); // Is 0 or -0. 220 assertTrue(x == 0); // Is 0 or -0.
193 var y = 1 / x; 221 var y = 1 / x;
194 assertFalse(isFinite(y)); 222 assertFalse(isFinite(y));
195 return y < 0; 223 return y < 0;
196 } 224 }
197 225
198 function test_div_deopt_minus_zero() { 226 function test_div_deopt_minus_zero() {
199 var zero_in_array = [0];
200 for (var i = 0; i < 2; ++i) { 227 for (var i = 0; i < 2; ++i) {
201 assertTrue(IsNegativeZero(Math.floor((zero_in_array[0] | 0) / -1))); 228 assertTrue(IsNegativeZero(Math.floor((zero_in_array[0] | 0) / -1)));
202 } 229 }
203 } 230 }
204 231
205 function test_div_deopt_overflow() { 232 function test_div_deopt_overflow() {
206 // We box the value in an array to avoid constant propagation.
207 var min_int_in_array = [-2147483648];
208 for (var i = 0; i < 2; ++i) { 233 for (var i = 0; i < 2; ++i) {
209 // We use '| 0' to force the representation to int32. 234 // We use '| 0' to force the representation to int32.
210 assertEquals(-min_int_in_array[0], 235 assertEquals(-min_int_in_array[0],
211 Math.floor((min_int_in_array[0] | 0) / -1)); 236 Math.floor((min_int_in_array[0] | 0) / -1));
212 } 237 }
213 } 238 }
214 239
215 function test_div_deopt_div_by_zero() { 240 function test_div_deopt_div_by_zero() {
216 for (var i = 0; i < 2; ++i) { 241 for (var i = 0; i < 2; ++i) {
217 assertEquals(div(i, 0), 242 assertEquals(div(i, 0),
218 Math.floor(i / 0)); 243 Math.floor(i / 0));
219 } 244 }
220 } 245 }
221 246
222 test_div_deopt_minus_zero(); 247 test_div_deopt_minus_zero();
223 test_div_deopt_overflow(); 248 test_div_deopt_overflow();
224 test_div_deopt_div_by_zero(); 249 test_div_deopt_div_by_zero();
225 %OptimizeFunctionOnNextCall(test_div_deopt_minus_zero); 250 %OptimizeFunctionOnNextCall(test_div_deopt_minus_zero);
226 %OptimizeFunctionOnNextCall(test_div_deopt_overflow); 251 %OptimizeFunctionOnNextCall(test_div_deopt_overflow);
227 %OptimizeFunctionOnNextCall(test_div_deopt_div_by_zero); 252 %OptimizeFunctionOnNextCall(test_div_deopt_div_by_zero);
228 test_div_deopt_minus_zero(); 253 test_div_deopt_minus_zero();
229 test_div_deopt_overflow(); 254 test_div_deopt_overflow();
230 test_div_deopt_div_by_zero(); 255 test_div_deopt_div_by_zero();
256
257 // Test for dividing by variable.
258 function test_div_deopt_minus_zero_v() {
259 for (var i = 0; i < 2; ++i) {
260 assertTrue(IsNegativeZero(Math.floor((zero_in_array[0] | 0) / neg_one_in_arr ay[0])));
261 }
262 }
263
264 function test_div_deopt_overflow_v() {
265 for (var i = 0; i < 2; ++i) {
266 // We use '| 0' to force the representation to int32.
267 assertEquals(-min_int_in_array[0],
268 Math.floor((min_int_in_array[0] | 0) / neg_one_in_array[0]));
269 }
270 }
271
272 function test_div_deopt_div_by_zero_v() {
273 for (var i = 0; i < 2; ++i) {
274 assertEquals(div(i, 0),
275 Math.floor(i / zero_in_array[0]));
276 }
277 }
278
279 test_div_deopt_minus_zero_v();
280 test_div_deopt_overflow_v();
281 test_div_deopt_div_by_zero_v();
282 %OptimizeFunctionOnNextCall(test_div_deopt_minus_zero_v);
283 %OptimizeFunctionOnNextCall(test_div_deopt_overflow_v);
284 %OptimizeFunctionOnNextCall(test_div_deopt_div_by_zero_v);
285 test_div_deopt_minus_zero_v();
286 test_div_deopt_overflow_v();
287 test_div_deopt_div_by_zero_v();
OLDNEW
« no previous file with comments | « src/x64/lithium-x64.cc ('k') | test/mjsunit/math-floor-of-div-nosudiv.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698