summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/maglev/negate.js
blob: 6e3c2d61c41e9f42e67f9d64ef54e6bf876bbd21 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 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 --maglev

function negate(val) {
  return -val;
}

function test_negate_int32(value, expected) {
  // Warmup.
  %PrepareFunctionForOptimization(negate);
  %ClearFunctionFeedback(negate);
  negate(1, -1);
  %OptimizeMaglevOnNextCall(negate);
  assertEquals(expected, negate(value));
  assertTrue(isMaglevved(negate));

  %DeoptimizeFunction(negate);
  assertEquals(expected, negate(value));
}

test_negate_int32(1, -1);
test_negate_int32(-1, 1);
test_negate_int32(42, -42);
test_negate_int32(-42, 42);

function test_negate_float(value, expected) {
  // Warmup.
  %PrepareFunctionForOptimization(negate);
  %ClearFunctionFeedback(negate);
  negate(1.1, -1.1);
  %OptimizeMaglevOnNextCall(negate);
  assertEquals(expected, negate(value));
  assertTrue(isMaglevved(negate));

  %DeoptimizeFunction(negate);
  assertEquals(expected, negate(value));
}

test_negate_float(1.23, -1.23);
test_negate_float(-1.001, 1.001);
test_negate_float(42.42, -42.42);
test_negate_float(-42.42, 42.42);

const int32_max = Math.pow(2,30)-1;
const int32_min = -Math.pow(2,31);
test_negate_float(int32_max, -int32_max);
test_negate_float(int32_min, -int32_min);

function test_negate_int32_expect_deopt(value, expected) {
  // Warmup.
  %PrepareFunctionForOptimization(negate);
  %ClearFunctionFeedback(negate);
  negate(12, -12);
  %OptimizeMaglevOnNextCall(negate);
  assertEquals(expected, negate(value));
  assertFalse(isMaglevved(negate));
}

test_negate_int32_expect_deopt(0, -0);
test_negate_int32_expect_deopt(-0, 0);
test_negate_int32_expect_deopt(int32_min, -int32_min);
test_negate_int32_expect_deopt(-int32_min, int32_min);
test_negate_int32_expect_deopt(int32_max, -int32_max);
test_negate_int32_expect_deopt(-int32_max, int32_max);