1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 public class Main { main(String[] args)18 public static void main(String[] args) { 19 $noinline$testDivideUnsignedLong(); 20 } 21 $noinline$testDivideUnsignedLong()22 private static void $noinline$testDivideUnsignedLong() { 23 assertEquals(0x1234567800000000L, $noinline$divideUnsignedLong(0x1234567800000000L, 0x1L)); 24 assertEquals(0x1234567887654321L, $noinline$divideUnsignedLong(0x1234567887654321L, 0x1L)); 25 assertEquals(-0x1234567800000000L, 26 $noinline$divideUnsignedLong(-0x1234567800000000L, 0x1L)); 27 assertEquals(-0x1234567887654321L, 28 $noinline$divideUnsignedLong(-0x1234567887654321L, 0x1L)); 29 30 assertEquals(0x12345678L, $noinline$divideUnsignedLong(0x1234567800000000L, 0x100000000L)); 31 assertEquals(0x12345678L, $noinline$divideUnsignedLong(0x1234567887654321L, 0x100000000L)); 32 assertEquals(0x100000000L - 0x12345678L, 33 $noinline$divideUnsignedLong(-0x1234567800000000L, 0x100000000L)); 34 assertEquals(0x100000000L-0x12345678L - 1L, 35 $noinline$divideUnsignedLong(-0x1234567887654321L, 0x100000000L)); 36 } 37 38 // LongDivideUnsigned is part of core-oj and we will not inline on host. 39 // And it is actually implemented on arm64. 40 41 /// CHECK-START: long Main.$noinline$divideUnsignedLong(long, long) inliner (before) 42 /// CHECK: InvokeStaticOrDirect intrinsic:LongDivideUnsigned 43 44 /// CHECK-START-ARM: long Main.$noinline$divideUnsignedLong(long, long) inliner (after) 45 /// CHECK-NOT: InvokeStaticOrDirect intrinsic:LongDivideUnsigned $noinline$divideUnsignedLong(long dividend, long divisor)46 private static long $noinline$divideUnsignedLong(long dividend, long divisor) { 47 return Long.divideUnsigned(dividend, divisor); 48 } 49 assertEquals(long expected, long result)50 private static void assertEquals(long expected, long result) { 51 if (expected != result) { 52 throw new Error("Expected: " + expected + ", found: " + result); 53 } 54 } 55 } 56