[test] Reland test for 52bit multiplication and division.

Contributed by Fedor Indutny <fedor@indutny.com>.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/1478933002

Cr-Commit-Position: refs/heads/master@{#32314}
This commit is contained in:
bmeurer 2015-11-25 22:46:37 -08:00 committed by Commit bot
parent 5d18e93bd6
commit 8003db95cc

View File

@ -0,0 +1,86 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
function mul(a, b) {
const l = a & 0x3ffffff;
const h = b & 0x3ffffff;
return (l * h) >>> 0;
}
function mulAndDiv(a, b) {
const l = a & 0x3ffffff;
const h = b & 0x3ffffff;
const m = l * h;
const rl = m & 0x3ffffff;
const rh = (m / 0x4000000) >>> 0;
return rl | rh;
}
function overflowMul(a, b) {
const l = a | 0;
const h = b | 0;
return (l * h) >>> 0;
}
function overflowDiv(a, b) {
const l = a & 0x3ffffff;
const h = b & 0x3ffffff;
const m = l * h;
return (m / 0x10) >>> 0;
}
function nonPowerOfTwoDiv(a, b) {
const l = a & 0x3ffffff;
const h = b & 0x3ffffff;
const m = l * h;
return (m / 0x4000001) >>> 0;
}
function test(fn, a, b, sets) {
const expected = fn(a, b);
fn(1, 2);
fn(0, 0);
%OptimizeFunctionOnNextCall(fn);
const actual = fn(a, b);
assertEquals(expected, actual);
sets.forEach(function(set, i) {
assertEquals(set.expected, fn(set.a, set.b), fn.name + ', set #' + i);
});
}
test(mul, 0x3ffffff, 0x3ffffff, [
{ a: 0, b: 0, expected: 0 },
{ a: 0xdead, b: 0xbeef, expected: 0xa6144983 },
{ a: 0x1aa1dea, b: 0x2badead, expected: 0x35eb2322 }
]);
test(mulAndDiv, 0x3ffffff, 0x3ffffff, [
{ a: 0, b: 0, expected: 0 },
{ a: 0xdead, b: 0xbeef, expected: 0x21449ab },
{ a: 0x1aa1dea, b: 0x2badead, expected: 0x1ebf32f }
]);
test(overflowMul, 0x4ffffff, 0x4ffffff, [
{ a: 0, b: 0, expected: 0 },
{ a: 0xdead, b: 0xbeef, expected: 0xa6144983 },
{ a: 0x1aa1dea, b: 0x2badead, expected: 0x35eb2322 }
]);
test(overflowDiv, 0x3ffffff, 0x3ffffff, [
{ a: 0, b: 0, expected: 0 },
{ a: 0xdead, b: 0xbeef, expected: 0xa614498 },
{ a: 0x1aa1dea, b: 0x2badead, expected: 0x835eb232 }
]);
test(nonPowerOfTwoDiv, 0x3ffffff, 0x3ffffff, [
{ a: 0, b: 0, expected: 0 },
{ a: 0xdead, b: 0xbeef, expected: 0x29 },
{ a: 0x1aa1dea, b: 0x2badead, expected: 0x122d20d }
]);