HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Android 10
|
10.0.0_r6
下载
查看原文件
收藏
根目录
art
test
660-checker-simd-sad-short
src
Main.java
/* * 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 { private static int $inline$seven() { return 7; } // TODO: lower precision still coming, b/64091002 private static short sadShort2Short(short[] s1, short[] s2) { int min_length = Math.min(s1.length, s2.length); short sad = 0; for (int i = 0; i < min_length; i++) { sad += Math.abs(s1[i] - s2[i]); } return sad; } private static short sadShort2ShortAlt(short[] s1, short[] s2) { int min_length = Math.min(s1.length, s2.length); short sad = 0; for (int i = 0; i < min_length; i++) { short s = s1[i]; short p = s2[i]; sad += s >= p ? s - p : p - s; } return sad; } private static short sadShort2ShortAlt2(short[] s1, short[] s2) { int min_length = Math.min(s1.length, s2.length); short sad = 0; for (int i = 0; i < min_length; i++) { short s = s1[i]; short p = s2[i]; int x = s - p; if (x < 0) x = -x; sad += x; } return sad; } /// CHECK-START: int Main.sadShort2Int(short[], short[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Sub [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Abs [<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-START-{ARM64,MIPS64}: int Main.sadShort2Int(short[], short[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 8 loop:none /// CHECK-DAG: <
> VecSetScalars [<
>] loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecSADAccumulate [<
>,<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none private static int sadShort2Int(short[] s1, short[] s2) { int min_length = Math.min(s1.length, s2.length); int sad = 0; for (int i = 0; i < min_length; i++) { sad += Math.abs(s1[i] - s2[i]); } return sad; } /// CHECK-START: int Main.sadShort2IntAlt(short[], short[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Sub [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Abs [<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-START-{ARM64,MIPS64}: int Main.sadShort2IntAlt(short[], short[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 8 loop:none /// CHECK-DAG: <
> VecSetScalars [<
>] loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecSADAccumulate [<
>,<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none private static int sadShort2IntAlt(short[] s1, short[] s2) { int min_length = Math.min(s1.length, s2.length); int sad = 0; for (int i = 0; i < min_length; i++) { short s = s1[i]; short p = s2[i]; sad += s >= p ? s - p : p - s; } return sad; } /// CHECK-START: int Main.sadShort2IntAlt2(short[], short[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Sub [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Abs [<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-START-{ARM64,MIPS64}: int Main.sadShort2IntAlt2(short[], short[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 8 loop:none /// CHECK-DAG: <
> VecSetScalars [<
>] loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecSADAccumulate [<
>,<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none private static int sadShort2IntAlt2(short[] s1, short[] s2) { int min_length = Math.min(s1.length, s2.length); int sad = 0; for (int i = 0; i < min_length; i++) { short s = s1[i]; short p = s2[i]; int x = s - p; if (x < 0) x = -x; sad += x; } return sad; } /// CHECK-START: int Main.sadShort2IntConstant1(short[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant -7 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Abs [<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-START-{ARM64,MIPS64}: int Main.sadShort2IntConstant1(short[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 7 loop:none /// CHECK-DAG: <
> IntConstant 8 loop:none /// CHECK-DAG: <
> VecReplicateScalar [<
>] loop:none /// CHECK-DAG: <
> VecSetScalars [<
>] loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecSADAccumulate [<
>,<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none private static int sadShort2IntConstant1(short[] s) { int sad = 0; for (int i = 0; i < s.length; i++) { sad += Math.abs(s[i] - 7); // s[i] + -7 } return sad; } /// CHECK-START: int Main.sadShort2IntConstant2(short[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 7 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Sub [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Abs [<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none // /// CHECK-START-{ARM64,MIPS64}: int Main.sadShort2IntConstant2(short[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> IntConstant 7 loop:none /// CHECK-DAG: <
> IntConstant 8 loop:none /// CHECK-DAG: <
> VecReplicateScalar [<
>] loop:none /// CHECK-DAG: <
> VecSetScalars [<
>] loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecSADAccumulate [<
>,<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none private static int sadShort2IntConstant2(short[] s) { int sad = 0; for (int i = 0; i < s.length; i++) { sad += Math.abs(s[i] - $inline$seven()); // s[i] - 7 } return sad; } /// CHECK-START: int Main.sadShort2IntConstant3(short[]) loop_optimization (before) /// CHECK-DAG: <