v8/test/mjsunit/compiler/bigint-modulus.js
Qifan Pan 3333e29f38 [turbofan] Support BigIntModulus
This CL supports BigInt modulo operations in turbofan and refactors
the code in simplified lowering to avoid boilerplate.

Bug: v8:9407
Change-Id: Id9d80bd82a94a50c6684956d1f8e60f99761c517
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3976434
Commit-Queue: Qifan Pan <panq@google.com>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84100}
2022-11-07 16:38:20 +00:00

45 lines
1.1 KiB
JavaScript

// Copyright 2022 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 --turbofan --no-always-turbofan
(function OptimizeAndTest() {
function fn(a, b) {
return a % b;
}
%PrepareFunctionForOptimization(fn);
assertEquals(3n, fn(3n, 4n));
assertEquals(0n, fn(3n, 1n));
assertEquals(2n, fn(2n ** 64n, 7n));
%OptimizeFunctionOnNextCall(fn);
assertEquals(3n, fn(3n, 4n));
assertEquals(0n, fn(3n, 1n));
assertEquals(-5n, fn(-32n, 9n));
assertEquals(2n, fn(2n ** 64n, 7n));
assertOptimized(fn);
assertEquals(4, fn(32, 7));
assertUnoptimized(fn);
})();
(function OptimizeAndTestDivZero() {
function fn(a, b) {
return a % b;
}
%PrepareFunctionForOptimization(fn);
assertEquals(3n, fn(3n, 4n));
assertEquals(2n, fn(2n ** 64n, 7n));
%OptimizeFunctionOnNextCall(fn);
assertEquals(2n, fn(2n ** 64n, 7n));
assertOptimized(fn);
assertThrows(() => fn(3n, 0n), RangeError);
assertUnoptimized(fn);
})();