101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray/* 201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * 401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * you may not use this file except in compliance with the License. 601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * You may obtain a copy of the License at 701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * 801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * 1001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 1101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 1201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * See the License for the specific language governing permissions and 1401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray * limitations under the License. 1501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray */ 1601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 1701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray// Note that $opt$ is a marker for the optimizing compiler to ensure 1801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray// it does compile the method. 1901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 2001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffraypublic class Main { 2101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray public static void expectEquals(long expected, long result) { 2201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray if (expected != result) { 2301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray throw new Error("Expected: " + expected + ", found: " + result); 2401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 2501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 2601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 2701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray public static void main(String[] args) { 2801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray long l = $opt$ReturnLong(); 2901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(42, l); 3001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray System.out.println("Long: " + l); 3101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 3201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$TakeOneLong1(42); 3301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(42, l); 3401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 3501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$TakeOneLong2(0, 42); 3601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(42, l); 3701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 3801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$TakeOneLong3(0, 1, 42); 3901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(42, l); 4001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 4101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$TakeOneLong4(0, 1, 2, 42); 4201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(42, l); 4301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 4401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$AddTwoLongs(42, 41); 4501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(83, l); 4601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 4701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$SubTwoLongs(42, 41); 4801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(1, l); 4901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 5001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$MakeCallsWithLongs1(); 5101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(57, l); 5201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 5301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$MakeCallsWithLongs2(); 5401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(900000000006L, l); 5501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 5601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$SubTwoLongs(-600000000006L, -200000000002L); 5701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(-400000000004L, l); 5801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 5901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$AddTwoLongs(-600000000006L, -200000000002L); 6001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(-800000000008L, l); 6101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 6201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 6301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$MakeCallsWithLongs1() { 6401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray long l = $opt$SubTwoLongs(-600000000006L, -200000000002L); 6501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(-400000000004L, l); 6601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 6701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray l = $opt$AddTwoLongs(-600000000006L, -200000000002L); 6801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray expectEquals(-800000000008L, l); 6901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 7001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return $opt$ReturnLong() + $opt$TakeOneLong1(1) + $opt$TakeOneLong2(0, 2) 7101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray + $opt$TakeOneLong3(0, 0, 3) + $opt$TakeOneLong4(0, 0, 0, 4) 7201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray // Test invoke-range. 7301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray + $opt$TakeOneLong5(0, 0, 0, 0, 5); 7401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 7501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 7601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$MakeCallsWithLongs2() { 7701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return $opt$AddThreeLongs(400000000003L, 200000000002L, 300000000001L); 7801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 7901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 8001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$ReturnLong() { 8101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return 42; 8201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 8301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 8401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$TakeOneLong1(long l) { 8501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return l; 8601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 8701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 8801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$TakeOneLong2(int a, long l) { 8901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return l; 9001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 9101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 9201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$TakeOneLong3(int a, int b, long l) { 9301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return l; 9401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 9501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 9601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$TakeOneLong4(int a, int b, int c, long l) { 9701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return l; 9801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 9901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 10001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$TakeOneLong5(int a, int b, int c,int d, long l) { 10101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return l; 10201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 10301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 10401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$AddTwoLongs(long a, long b) { 10501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return a + b; 10601bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 10701bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 10801bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$AddThreeLongs(long a, long b, long c) { 10901bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return a + b + c; 11001bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 11101bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray 11201bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray static long $opt$SubTwoLongs(long a, long b) { 11301bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray return a - b; 11401bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray } 11501bc96d007b67fdb7fe349232a83e4b354ce3d08Nicolas Geoffray} 116