summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/compiler/bigint-bitwise-and.js
blob: 7884bba0c8fede4b79147deae4fbaca9fa7e322c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 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 TestBitwiseAnd(a, b) {
  return a & b;
}

function OptimizeAndTest(fn) {
  %PrepareFunctionForOptimization(fn);
  assertEquals(0b1000n, fn(0b1100n, 0b1010n));
  assertEquals(-0b1000n, fn(-0b100n, -0b110n));
  assertEquals(0b1000n, fn(-0b100n, 0b1010n));
  assertEquals(0b1000n, fn(0b1100n, -0b110n));
  // The result grows out of one digit
  assertEquals(-(2n ** 64n), fn(-(2n ** 63n + 1n), -(2n ** 63n)));

  %OptimizeFunctionOnNextCall(fn);
  fn(0b1100n, 0b1010n);
  assertOptimized(fn);

  assertEquals(0b1000n, fn(0b1100n, 0b1010n));
  assertEquals(-0b1000n, fn(-0b100n, -0b110n));
  assertEquals(0b1000n, fn(-0b100n, 0b1010n));
  assertEquals(0b1000n, fn(0b1100n, -0b110n));
  // The result grows out of one digit
  assertEquals(-(2n ** 64n), fn(-(2n ** 63n + 1n), -(2n ** 63n)));

  assertEquals(0b1000, fn(0b1100, 0b1010));
  assertUnoptimized(fn);
}

OptimizeAndTest(TestBitwiseAnd);