/* * Copyright (C) 2017 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. */ /** * Tests for SAD (sum of absolute differences). */ public class Main { /// CHECK-START: int Main.sad1(int, int) instruction_simplifier$after_inlining (before) /// CHECK-DAG: <> Select /// CHECK-DAG: Return [<>] // /// CHECK-START: int Main.sad1(int, int) instruction_simplifier$after_inlining (after) /// CHECK-NOT: InvokeStaticOrDirect intrinsic:MathAbsInt // // NOTE: for direct 32-bit operands, this is not an ABS. static int sad1(int x, int y) { return x >= y ? x - y : y - x; } /// CHECK-START: int Main.sad2(int, int) instruction_simplifier$after_inlining (before) /// CHECK-DAG: <> Select /// CHECK-DAG: Return [<>] // /// CHECK-START: int Main.sad3(int, int) instruction_simplifier$after_inlining (after) /// CHECK-DAG: <> InvokeStaticOrDirect intrinsic:MathAbsInt /// CHECK-DAG: Return [<>] static int sad3(int x, int y) { int diff = x - y; return diff >= 0 ? diff : -diff; } /// CHECK-START: int Main.sad3Alt(int, int) instruction_simplifier$after_inlining (before) /// CHECK-DAG: <> Select /// CHECK-DAG: Return [<>] // /// CHECK-START: long Main.sadL1(int, int) instruction_simplifier$after_inlining (after) /// CHECK-DAG: <> InvokeStaticOrDirect intrinsic:MathAbsLong /// CHECK-DAG: Return [<>] static long sadL1(int x, int y) { long xl = x; long yl = y; return xl >= yl ? xl - yl : yl - xl; } /// CHECK-START: long Main.sadL2(int, int) instruction_simplifier$after_inlining (before) /// CHECK-DAG: <> Select /// CHECK-DAG: Return [<>] // /// CHECK-START: long Main.sadL3(int, int) instruction_simplifier$after_inlining (after) /// CHECK-DAG: <> InvokeStaticOrDirect intrinsic:MathAbsLong /// CHECK-DAG: Return [<>] static long sadL3(int x, int y) { long diff = x - y; return diff >= 0L ? diff : -diff; } /// CHECK-START: long Main.sadL3Alt(int, int) instruction_simplifier$after_inlining (before) /// CHECK-DAG: <> Select /// CHECK-DAG: Return [<