| Index: test/mjsunit/smi-mul-const.js
|
| diff --git a/test/mjsunit/smi-mul.js b/test/mjsunit/smi-mul-const.js
|
| similarity index 51%
|
| copy from test/mjsunit/smi-mul.js
|
| copy to test/mjsunit/smi-mul-const.js
|
| index 6f23d5e3a0bba23407b9db94539fb8ed7922bc11..ca627fc27e929eab87b29df6c03d40cc6bb8b2d6 100644
|
| --- a/test/mjsunit/smi-mul.js
|
| +++ b/test/mjsunit/smi-mul-const.js
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2013 the V8 project authors. All rights reserved.
|
| +// Copyright 2014 the V8 project authors. All rights reserved.
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| // met:
|
| @@ -27,41 +27,61 @@
|
|
|
| // Flags: --allow-natives-syntax --noalways-opt
|
|
|
| -function mul(a, b) {
|
| - return a * b;
|
| +function check(func, input, expected) {
|
| + func(-1);
|
| + func(-1);
|
| + %OptimizeFunctionOnNextCall(func);
|
| + assertEquals(expected, func(input));
|
| + assertOptimized(func);
|
| }
|
|
|
| +function mul_by_neg_1(a) { return a * -1; }
|
| +function mul_by_0(a) { return a * 0; }
|
| +function mul_by_1(a) { return a * 1; }
|
| +function mul_by_2(a) { return a * 2; }
|
|
|
| -mul(-1, 2);
|
| -mul(-1, 2);
|
| -%OptimizeFunctionOnNextCall(mul);
|
| -assertEquals(-2, mul(-1, 2));
|
| -assertOptimized(mul);
|
| +check(mul_by_neg_1, 2, -2);
|
| +check(mul_by_0, 2, 0);
|
| +check(mul_by_1, 2, 2);
|
| +check(mul_by_2, 2, 4);
|
|
|
| -// Deopt on minus zero.
|
| -assertEquals(-0, mul(-1, 0));
|
| -assertUnoptimized(mul);
|
| +function limit_range(a) {
|
| + // Limit the range of 'a' to enable no-overflow optimizations.
|
| + return Math.max(Math.min(a | 0, 10), -10);
|
| +}
|
|
|
| +function mul_by_neg_127(a) { return limit_range(a) * -127; }
|
| +function mul_by_neg_128(a) { return limit_range(a) * -128; }
|
| +function mul_by_neg_129(a) { return limit_range(a) * -129; }
|
| +function mul_by_1023(a) { return limit_range(a) * 1023; }
|
| +function mul_by_1024(a) { return limit_range(a) * 1024; }
|
| +function mul_by_1025(a) { return limit_range(a) * 1025; }
|
|
|
| -function mul2(a, b) {
|
| - return a * b;
|
| -}
|
| +check(mul_by_neg_127, 2, -254);
|
| +check(mul_by_neg_128, 2, -256);
|
| +check(mul_by_neg_129, 2, -258);
|
| +check(mul_by_1023, 2, 2046);
|
| +check(mul_by_1024, 2, 2048);
|
| +check(mul_by_1025, 2, 2050);
|
| +
|
| +// Deopt on minus zero.
|
| +assertEquals(-0, mul_by_neg_128(0));
|
| +assertUnoptimized(mul_by_neg_128);
|
| +assertEquals(-0, mul_by_2(-0));
|
| +assertUnoptimized(mul_by_2);
|
|
|
| -mul2(-1, 2);
|
| -mul2(-1, 2);
|
| -%OptimizeFunctionOnNextCall(mul2);
|
| +// Deopt on overflow.
|
|
|
| // 2^30 is a smi boundary on arm and ia32.
|
| var two_30 = 1 << 30;
|
| -// 2^31 is a smi boundary on x64.
|
| +// 2^31 is a smi boundary on arm64 and x64.
|
| var two_31 = 2 * two_30;
|
|
|
| -if (%IsValidSmi(two_31)) {
|
| - // Deopt on two_31 on x64.
|
| - assertEquals(two_31, mul2(-two_31, -1));
|
| - assertUnoptimized(mul2);
|
| +// TODO(rmcilroy): replace after r16361 with: if (%IsValidSmi(two_31)) {
|
| +if (true) {
|
| + assertEquals(two_31, mul_by_neg_1(-two_31));
|
| + assertUnoptimized(mul_by_neg_1);
|
| } else {
|
| - // Deopt on two_30 on ia32.
|
| - assertEquals(two_30, mul2(-two_30, -1));
|
| - assertUnoptimized(mul2);
|
| + assertEquals(two_30, mul_by_neg_1(-two_30));
|
| + assertUnoptimized(mul_by_neg_1);
|
| }
|
|
|