ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
// Note that $opt$ is a marker for the optimizing compiler to test
// it does compile the method.
 
public class Main {
  public static void expectEquals(long expected, long result) {
    if (expected != result) {
      throw new Error("Expected: " + expected + ", found: " + result);
    }
  }
 
  public static void main(String[] args) {
    long l = $opt$ReturnLong();
    expectEquals(42, l);
    System.out.println("Long: " + l);
 
    l = $opt$TakeOneLong1(42);
    expectEquals(42, l);
 
    l = $opt$TakeOneLong2(0, 42);
    expectEquals(42, l);
 
    l = $opt$TakeOneLong3(0, 1, 42);
    expectEquals(42, l);
 
    l = $opt$TakeOneLong4(0, 1, 2, 42);
    expectEquals(42, l);
 
    l = $opt$AddTwoLongs(42, 41);
    expectEquals(83, l);
 
    l = $opt$SubTwoLongs(42, 41);
    expectEquals(1, l);
 
    l = $opt$MakeCallsWithLongs1();
    expectEquals(57, l);
 
    l = $opt$MakeCallsWithLongs2();
    expectEquals(900000000006L, l);
 
    l = $opt$SubTwoLongs(-600000000006L, -200000000002L);
    expectEquals(-400000000004L, l);
 
    l = $opt$AddTwoLongs(-600000000006L, -200000000002L);
    expectEquals(-800000000008L, l);
  }
 
  static long $opt$MakeCallsWithLongs1() {
    long l = $opt$SubTwoLongs(-600000000006L, -200000000002L);
    expectEquals(-400000000004L, l);
 
    l = $opt$AddTwoLongs(-600000000006L, -200000000002L);
    expectEquals(-800000000008L, l);
 
    return $opt$ReturnLong() + $opt$TakeOneLong1(1) + $opt$TakeOneLong2(0, 2)
        + $opt$TakeOneLong3(0, 0, 3) + $opt$TakeOneLong4(0, 0, 0, 4)
        // Test invoke-range.
        + $opt$TakeOneLong5(0, 0, 0, 0, 5);
  }
 
  static long $opt$MakeCallsWithLongs2() {
    return $opt$AddThreeLongs(400000000003L, 200000000002L, 300000000001L);
  }
 
  static long $opt$ReturnLong() {
    return 42;
  }
 
  static long $opt$TakeOneLong1(long l) {
    return l;
  }
 
  static long $opt$TakeOneLong2(int a, long l) {
    return l;
  }
 
  static long $opt$TakeOneLong3(int a, int b, long l) {
    return l;
  }
 
  static long $opt$TakeOneLong4(int a, int b, int c, long l) {
    return l;
  }
 
  static long $opt$TakeOneLong5(int a, int b, int c,int d,  long l) {
    return l;
  }
 
  static long $opt$AddTwoLongs(long a, long b) {
    return a + b;
  }
 
  static long $opt$AddThreeLongs(long a, long b, long c) {
    return a + b + c;
  }
 
  static long $opt$SubTwoLongs(long a, long b) {
    return a - b;
  }
}