1 /* 2 * Copyright (C) 2024 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 // Test with even/odd input, and even/odd amount of loop iterations. 20 assertEquals(-33, $noinline$TwoBitwiseOperations(32, 4)); 21 assertEquals(1, $noinline$TwoBitwiseOperations(32, 5)); 22 assertEquals(-31, $noinline$TwoBitwiseOperations(31, 4)); 23 assertEquals(0, $noinline$TwoBitwiseOperations(31, 5)); 24 } 25 26 /// CHECK-START-ARM: int Main.$noinline$TwoBitwiseOperations(int, int) instruction_simplifier_arm (after) 27 /// CHECK: BitwiseNegatedRight kind:And 28 /// CHECK: BitwiseNegatedRight kind:Or 29 30 /// CHECK-START-ARM64: int Main.$noinline$TwoBitwiseOperations(int, int) instruction_simplifier_arm64 (after) 31 /// CHECK: BitwiseNegatedRight kind:And 32 /// CHECK: BitwiseNegatedRight kind:Or 33 34 /// CHECK-START-{ARM,ARM64}: int Main.$noinline$TwoBitwiseOperations(int, int) disassembly (after) 35 /// CHECK: BitwiseNegatedRight kind:And 36 /// CHECK: BitwiseNegatedRight kind:Or $noinline$TwoBitwiseOperations(int a, int n)37 private static int $noinline$TwoBitwiseOperations(int a, int n) { 38 int result = 0; 39 for (int i = 0; i < n; ++i) { 40 if (i % 2 == 0) { 41 result = (~a) & 1; 42 } else { 43 result = (~a) | 1; 44 } 45 } 46 return result; 47 } 48 assertEquals(int expected, int actual)49 public static void assertEquals(int expected, int actual) { 50 if (expected != actual) { 51 throw new Error("Expected: " + expected + ", found: " + actual); 52 } 53 } 54 } 55