v8/test/mjsunit/regress/regress-1371935.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

25 lines
813 B
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 f(a, b, c) {
// CheckBigInt64 is required if the type of input is UnsignedBigInt64
// because its value can be out of the range of SignedBigInt64.
let t = BigInt.asUintN(64, a + b);
// The addition is speculated as CheckedInt64Add and triggers the deopt
// for the large value coming in through <t>.
return t + c;
}
%PrepareFunctionForOptimization(f);
assertEquals(12n, f(9n, 2n, 1n));
%OptimizeFunctionOnNextCall(f);
assertEquals(12n, f(9n, 2n, 1n));
assertOptimized(f);
assertEquals(2n ** 64n, f(1n, -2n, 1n));
if (%Is64Bit()) {
assertUnoptimized(f);
}