76fa9a8b82
This CL exposes BigInt binary operation builtins to the interpreter and fixes the return type of the external c calls to avoid unexpected behavior on Windows. The original return type was bool which would marshal to Windows BOOL (of the same size as int) causing the return value always being true if there is garbage in upper bits. Changing bool to int32 solves the problem. Bug: v8:9407 Change-Id: Ib56f5b163deb77566ef79166860e1921ef0065c5 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3932951 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Qifan Pan <panq@google.com> Cr-Commit-Position: refs/heads/main@{#83572}
27 lines
826 B
JavaScript
27 lines
826 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 TestMultiplyAndTruncate(a, b) {
|
|
return BigInt.asIntN(3, a * b);
|
|
}
|
|
|
|
function OptimizeAndTest(fn) {
|
|
let bi = 2n ** (2n ** 29n);
|
|
if (%Is64Bit()) {
|
|
%PrepareFunctionForOptimization(fn);
|
|
assertEquals(-4n, fn(3n, 4n));
|
|
assertEquals(-2n, fn(5n, 6n));
|
|
%OptimizeFunctionOnNextCall(fn);
|
|
// After optimization, operands are truncated to Word64
|
|
// before being multiplied. No exceptions should be thrown
|
|
// and the correct result is expected.
|
|
assertEquals(-4n, fn(bi + 3n, bi + 4n));
|
|
assertOptimized(fn);
|
|
}
|
|
}
|
|
|
|
OptimizeAndTest(TestMultiplyAndTruncate);
|