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

Unified Diff: test/mjsunit/smi-ops.js

Issue 460060: Code generation for multiply-by-constant-smi.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/smi-ops.js
===================================================================
--- test/mjsunit/smi-ops.js (revision 3433)
+++ test/mjsunit/smi-ops.js (working copy)
@@ -638,9 +638,160 @@
testShiftNonSmis();
+// Test specialized code generation for shifts by a constant
+function testSpecializedShift(general, shift, specialized) {
+ function test(n) {
+ assertEquals(general(n, shift), specialized(n));
+ }
+ for (var i = -256; i <= 256; ++i) {
+ test(i);
+ test(i + 0.5);
+ var big = i * (1 << 24); // ranges from -2^32 to 2^32
+ test(big);
+ test(big + 7);
+ test(big - 7);
+ test(big * 1.0000001);
+ test(big / 1.0000001);
+ }
+}
+
+function testShrConstant() {
+ function shift0(n) { return n >>> 0; }
+ function shift1(n) { return n >>> 1; }
+ function shift2(n) { return n >>> 2; }
+ function shift3(n) { return n >>> 3; }
+ function shift28(n) { return n >>> 28; }
+ function shift29(n) { return n >>> 29; }
+ function shift30(n) { return n >>> 30; }
+ function shift31(n) { return n >>> 31; }
+ function shift(n, s) { return n >>> s; }
+
+ testSpecializedShift(shift, 0, shift0);
+ testSpecializedShift(shift, 1, shift1);
+ testSpecializedShift(shift, 2, shift2);
+ testSpecializedShift(shift, 3, shift3);
+ testSpecializedShift(shift, 28, shift28);
+ testSpecializedShift(shift, 29, shift29);
+ testSpecializedShift(shift, 30, shift30);
+ testSpecializedShift(shift, 31, shift31);
+}
+
+testShrConstant();
+
+function testSarConstant() {
+ function shift0(n) { return n >> 0; }
+ function shift1(n) { return n >> 1; }
+ function shift2(n) { return n >> 2; }
+ function shift3(n) { return n >> 3; }
+ function shift28(n) { return n >> 28; }
+ function shift29(n) { return n >> 29; }
+ function shift30(n) { return n >> 30; }
+ function shift31(n) { return n >> 31; }
+ function shift(n, s) { return n >> s; }
+
+ testSpecializedShift(shift, 0, shift0);
+ testSpecializedShift(shift, 1, shift1);
+ testSpecializedShift(shift, 2, shift2);
+ testSpecializedShift(shift, 3, shift3);
+ testSpecializedShift(shift, 28, shift28);
+ testSpecializedShift(shift, 29, shift29);
+ testSpecializedShift(shift, 30, shift30);
+ testSpecializedShift(shift, 31, shift31);
+}
+
+testSarConstant();
+
+function testShlConstant() {
+ function shift0(n) { return n << 0; }
+ function shift1(n) { return n << 1; }
+ function shift2(n) { return n << 2; }
+ function shift3(n) { return n << 3; }
+ function shift28(n) { return n << 28; }
+ function shift29(n) { return n << 29; }
+ function shift30(n) { return n << 30; }
+ function shift31(n) { return n << 31; }
+ function shift(n, s) { return n << s; }
+
+ testSpecializedShift(shift, 0, shift0);
+ testSpecializedShift(shift, 1, shift1);
+ testSpecializedShift(shift, 2, shift2);
+ testSpecializedShift(shift, 3, shift3);
+ testSpecializedShift(shift, 28, shift28);
+ testSpecializedShift(shift, 29, shift29);
+ testSpecializedShift(shift, 30, shift30);
+ testSpecializedShift(shift, 31, shift31);
+}
+
+testShlConstant();
+
// Verify that we handle the (optimized) corner case of shifting by
// zero even for non-smis.
function shiftByZero(n) { return n << 0; }
assertEquals(3, shiftByZero(3.1415));
+assertEquals(3, shiftByZero(3.9995));
+
+// Multiplication by SMIs
+
+function MulZeroa(x) {
+ return 0 * x;
+}
+function MulZerob(x) {
+ return x * 0;
+}
+
+function testMultiplyZero(mulZero) {
+ assertEquals(0, mulZero(0));
+ assertEquals(0, mulZero(100));
+ assertEquals(0, mulZero(1000));
+ assertEquals(Infinity, 1 / mulZero(1000));
+ assertEquals(-Infinity, 1 / mulZero(-1000));
+}
+
+testMultiplyZero(MulZeroa);
+testMultiplyZero(MulZerob);
+
+function MulNeg1a(x) {
+ return -1 * x;
+}
+function MulNeg1b(x) {
+ return x * -1;
+}
+
+function testMultiplyNeg1(mulNeg1) {
+ assertEquals(1, mulNeg1(-1));
+ assertEquals(-1000, mulNeg1(1000)); // fast case
+ assertEquals(SMI_MAX + 1, mulNeg1(SMI_MIN)); // overflows
+ assertEquals(SMI_MIN + 1, mulNeg1(SMI_MAX)); // fast case
+ assertEquals(-Infinity, 1 / mulNeg1(0)); // negative zero case
+ assertEquals(Infinity, 1 / mulNeg1(mulNeg1(0)));
+
+ assertEquals(-42, mulNeg1(OBJ_42));
+}
+
+testMultiplyNeg1(MulNeg1a);
+testMultiplyNeg1(MulNeg1b);
+
+function testMulSmi() {
+ var constants = [-256, -100, -10, -3, -2, -1, 0, 1, 2, 3, 4, 5, 10, 20, 1000,
+ 100000, SMI_MIN, SMI_MAX, SMI_MIN+1, SMI_MAX-1, SMI_MIN+2, SMI_MAX-3,
+ 16];
+ var values = [-Infinity, 1000000, 123.4, -10000000, OBJ_42];
+ values = values.concat(constants);
+
+ for (var i = 0; i < constants.length; ++i) {
+ var x = constants[i];
+ var f1 = eval("(function(y) { return (" + x + ") * y})");
+ var f2 = eval("(function(y) { return y * (" + x + ")})");
+ for (var j = 0; j < values.length; ++j) {
+ var y = values[j];
+ var product = x * y;
+ assertEquals(product, f1(y));
+ assertEquals(product, f2(y));
+ assertEquals(1/product, 1/f1(y));
+ assertEquals(1/product, 1/f2(y));
+ }
+ }
+}
+testMulSmi();
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698