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

Unified Diff: test/mjsunit/math-52-mul-div.js

Issue 1433353006: [machine-operator-reducer] fix float truncation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix typo Created 5 years, 1 month 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
Index: test/mjsunit/math-52-mul-div.js
diff --git a/test/mjsunit/math-52-mul-div.js b/test/mjsunit/math-52-mul-div.js
new file mode 100644
index 0000000000000000000000000000000000000000..b61aba6df8c7ea02e5c4eb4437e1237e096fd746
--- /dev/null
+++ b/test/mjsunit/math-52-mul-div.js
@@ -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 --turbo-filter=*
+
+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 }
+]);
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | test/unittests/compiler/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698