HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Android 10
|
10.0.0_r6
下载
查看原文件
收藏
根目录
art
test
661-checker-simd-reduc
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 simple integral reductions: same type for accumulator and data. */ public class Main { static final int N = 500; static final int M = 100; // // Basic reductions in loops. // // TODO: vectorize these (second step of b/64091002 plan) private static byte reductionByte(byte[] x) { byte sum = 0; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } private static short reductionShort(short[] x) { short sum = 0; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } private static char reductionChar(char[] x) { char sum = 0; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } /// CHECK-START: int Main.reductionInt(int[]) 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: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Return [<
>] loop:none // /// CHECK-START-{ARM,ARM64,MIPS64}: int Main.reductionInt(int[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant {{2|4}} loop:none /// CHECK-DAG: <
> VecSetScalars [{{i\d+}}] loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: VecAdd [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecReduce [<
>] loop:none /// CHECK-DAG: <
> VecExtractScalar [<
>] loop:none private static int reductionInt(int[] x) { int sum = 0; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } /// CHECK-START: int Main.reductionIntChain() 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: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_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: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Return [<
>] loop:none // /// CHECK-EVAL: "<
>" != "<
>" // /// CHECK-START-{ARM,ARM64,MIPS64}: int Main.reductionIntChain() loop_optimization (after) /// CHECK-DAG: <
> VecSetScalars [{{i\d+}}] loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: VecAdd [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecReduce [<
>] loop:none /// CHECK-DAG: <
> VecExtractScalar [<
>] loop:none /// CHECK-DAG: <
> VecSetScalars [{{i\d+}}] loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: VecAdd [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecReduce [<
>] loop:none /// CHECK-DAG: <
> VecExtractScalar [<
>] loop:none // /// CHECK-EVAL: "<
>" != "<
>" // // NOTE: pattern is robust with respect to vector loop unrolling and peeling. private static int reductionIntChain() { int[] x = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; int r = 1; for (int i = 0; i < 16; i++) { r += x[i]; } for (int i = 0; i < 16; i++) { r += x[i]; } return r; } /// CHECK-START: int Main.reductionIntToLoop(int[]) 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: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none // /// CHECK-EVAL: "<
>" != "<
>" // /// CHECK-START-{ARM,ARM64,MIPS64}: int Main.reductionIntToLoop(int[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant {{2|4}} loop:none /// CHECK-DAG: <
> VecSetScalars [{{i\d+}}] loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: VecAdd [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecReduce [<
>] loop:none /// CHECK-DAG: <
> VecExtractScalar [<
>] loop:none private static int reductionIntToLoop(int[] x) { int r = 0; for (int i = 0; i < 8; i++) { r += x[i]; } for (int i = r; i < 16; i++) { r += i; } return r; } /// CHECK-START: long Main.reductionLong(long[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> LongConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{j\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Return [<
>] loop:none // /// CHECK-START-{ARM64,MIPS64}: long Main.reductionLong(long[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 2 loop:none /// CHECK-DAG: <
> VecSetScalars [{{j\d+}}] loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: VecAdd [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecReduce [<
>] loop:none /// CHECK-DAG: <
> VecExtractScalar [<
>] loop:none private static long reductionLong(long[] x) { long sum = 0; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } private static byte reductionByteM1(byte[] x) { byte sum = -1; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } private static short reductionShortM1(short[] x) { short sum = -1; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } private static char reductionCharM1(char[] x) { char sum = 0xffff; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } /// CHECK-START: int Main.reductionIntM1(int[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> IntConstant 1 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: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Return [<
>] loop:none // /// CHECK-START-{ARM,ARM64,MIPS64}: int Main.reductionIntM1(int[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant {{2|4}} loop:none /// CHECK-DAG: <
> VecSetScalars [{{i\d+}}] loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: VecAdd [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecReduce [<
>] loop:none /// CHECK-DAG: <
> VecExtractScalar [<
>] loop:none private static int reductionIntM1(int[] x) { int sum = -1; for (int i = 0; i < x.length; i++) { sum += x[i]; } return sum; } /// CHECK-START: long Main.reductionLongM1(long[]) loop_optimization (before) /// CHECK-DAG: <
> IntConstant 0 loop:none /// CHECK-DAG: <
> LongConstant -1 loop:none /// CHECK-DAG: <
> IntConstant 1 loop:none /// CHECK-DAG: <
> Phi [<
>,{{i\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> Phi [<
>,{{j\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> ArrayGet [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Return [<
>] loop:none // /// CHECK-START-{ARM64,MIPS64}: long Main.reductionLongM1(long[]) loop_optimization (after) /// CHECK-DAG: <
> IntConstant 2 loop:none /// CHECK-DAG: <
> VecSetScalars [{{j\d+}}] loop:none /// CHECK-DAG: <
> Phi [<
>,{{d\d+}}] loop:<
> outer_loop:none /// CHECK-DAG: <
> VecLoad [{{l\d+}},<
>] loop:<
> outer_loop:none /// CHECK-DAG: VecAdd [<
>,<
>] loop:<
> outer_loop:none /// CHECK-DAG: Add [<
>,<