HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Pie
|
9.0.0_r8
下载
查看原文件
收藏
根目录
art
test
550-checker-multiply-accumulate
src
Main.java
/* * Copyright (C) 2015 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. */ public class Main { // A dummy value to defeat inlining of these routines. static boolean doThrow = false; public static void assertIntEquals(int expected, int result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } public static void assertLongEquals(long expected, long result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); } } /** * Test basic merging of `MUL+ADD` into `MULADD`. */ /// CHECK-START-ARM64: int Main.$opt$noinline$mulAdd(int, int, int) instruction_simplifier_arm64 (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: int Main.$opt$noinline$mulAdd(int, int, int) instruction_simplifier_arm64 (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> MultiplyAccumulate [<
>,<
>,<
>] kind:Add /// CHECK: Return [<
>] /// CHECK-START-ARM64: int Main.$opt$noinline$mulAdd(int, int, int) instruction_simplifier_arm64 (after) /// CHECK-NOT: Mul /// CHECK-NOT: Add /// CHECK-START-ARM64: int Main.$opt$noinline$mulAdd(int, int, int) disassembly (after) /// CHECK: madd w{{\d+}}, w{{\d+}}, w{{\d+}}, w{{\d+}} /// CHECK-START-ARM: int Main.$opt$noinline$mulAdd(int, int, int) instruction_simplifier_arm (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM: int Main.$opt$noinline$mulAdd(int, int, int) instruction_simplifier_arm (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> MultiplyAccumulate [<
>,<
>,<
>] kind:Add /// CHECK: Return [<
>] /// CHECK-START-ARM: int Main.$opt$noinline$mulAdd(int, int, int) instruction_simplifier_arm (after) /// CHECK-NOT: Mul /// CHECK-NOT: Add /// CHECK-START-ARM: int Main.$opt$noinline$mulAdd(int, int, int) disassembly (after) /// CHECK: mla r{{\d+}}, r{{\d+}}, r{{\d+}}, r{{\d+}} public static int $opt$noinline$mulAdd(int acc, int left, int right) { if (doThrow) throw new Error(); return acc + left * right; } /** * Test basic merging of `MUL+SUB` into `MULSUB`. */ /// CHECK-START-ARM64: long Main.$opt$noinline$mulSub(long, long, long) instruction_simplifier_arm64 (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Sub [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: long Main.$opt$noinline$mulSub(long, long, long) instruction_simplifier_arm64 (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> MultiplyAccumulate [<
>,<
>,<
>] kind:Sub /// CHECK: Return [<
>] /// CHECK-START-ARM64: long Main.$opt$noinline$mulSub(long, long, long) instruction_simplifier_arm64 (after) /// CHECK-NOT: Mul /// CHECK-NOT: Sub /// CHECK-START-ARM64: long Main.$opt$noinline$mulSub(long, long, long) disassembly (after) /// CHECK: msub x{{\d+}}, x{{\d+}}, x{{\d+}}, x{{\d+}} /// CHECK-START-ARM: long Main.$opt$noinline$mulSub(long, long, long) instruction_simplifier_arm (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Sub [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM: long Main.$opt$noinline$mulSub(long, long, long) instruction_simplifier_arm (after) /// CHECK-NOT: MultiplyAccumulate public static long $opt$noinline$mulSub(long acc, long left, long right) { if (doThrow) throw new Error(); return acc - left * right; } /** * Test that we do not create a multiply-accumulate instruction when there * are other uses of the multiplication that cannot merge it. */ /// CHECK-START-ARM64: int Main.$opt$noinline$multipleUses1(int, int, int) instruction_simplifier_arm64 (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Or [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: int Main.$opt$noinline$multipleUses1(int, int, int) instruction_simplifier_arm64 (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Or [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: int Main.$opt$noinline$multipleUses1(int, int, int) instruction_simplifier_arm64 (after) /// CHECK-NOT: MultiplyAccumulate /// CHECK-START-ARM: int Main.$opt$noinline$multipleUses1(int, int, int) instruction_simplifier_arm (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Or [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM: int Main.$opt$noinline$multipleUses1(int, int, int) instruction_simplifier_arm (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Or [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM: int Main.$opt$noinline$multipleUses1(int, int, int) instruction_simplifier_arm (after) /// CHECK-NOT: MultiplyAccumulate public static int $opt$noinline$multipleUses1(int acc, int left, int right) { if (doThrow) throw new Error(); int temp = left * right; return temp | (acc + temp); } /** * Test that we do not create a multiply-accumulate instruction even when all * uses of the multiplication can merge it. */ /// CHECK-START-ARM64: long Main.$opt$noinline$multipleUses2(long, long, long) instruction_simplifier_arm64 (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Sub [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: long Main.$opt$noinline$multipleUses2(long, long, long) instruction_simplifier_arm64 (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Sub [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: long Main.$opt$noinline$multipleUses2(long, long, long) instruction_simplifier_arm64 (after) /// CHECK-NOT: MultiplyAccumulate /// CHECK-START-ARM: long Main.$opt$noinline$multipleUses2(long, long, long) instruction_simplifier_arm (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Sub [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM: long Main.$opt$noinline$multipleUses2(long, long, long) instruction_simplifier_arm (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Sub [<
>,<
>] /// CHECK: <
> Add [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM: long Main.$opt$noinline$multipleUses2(long, long, long) instruction_simplifier_arm (after) /// CHECK-NOT: MultiplyAccumulate public static long $opt$noinline$multipleUses2(long acc, long left, long right) { if (doThrow) throw new Error(); long temp = left * right; return (acc + temp) + (acc - temp); } /** * Test the interpretation of `a * (b + 1)` as `a + (a * b)`. */ /// CHECK-START-ARM64: int Main.$opt$noinline$mulPlusOne(int, int) instruction_simplifier_arm64 (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> IntConstant 1 /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Mul [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: int Main.$opt$noinline$mulPlusOne(int, int) instruction_simplifier_arm64 (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> MultiplyAccumulate [<
>,<
>,<
>] kind:Add /// CHECK: Return [<
>] /// CHECK-START-ARM64: int Main.$opt$noinline$mulPlusOne(int, int) instruction_simplifier_arm64 (after) /// CHECK-NOT: Mul /// CHECK-NOT: Add /// CHECK-START-ARM64: int Main.$opt$noinline$mulPlusOne(int, int) disassembly (after) /// CHECK: madd w{{\d+}}, w{{\d+}}, w{{\d+}}, w{{\d+}} /// CHECK-START-ARM: int Main.$opt$noinline$mulPlusOne(int, int) instruction_simplifier_arm (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> IntConstant 1 /// CHECK: <
> Add [<
>,<
>] /// CHECK: <
> Mul [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM: int Main.$opt$noinline$mulPlusOne(int, int) instruction_simplifier_arm (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> MultiplyAccumulate [<
>,<
>,<
>] kind:Add /// CHECK: Return [<
>] /// CHECK-START-ARM: int Main.$opt$noinline$mulPlusOne(int, int) instruction_simplifier_arm (after) /// CHECK-NOT: Mul /// CHECK-NOT: Add /// CHECK-START-ARM: int Main.$opt$noinline$mulPlusOne(int, int) disassembly (after) /// CHECK: mla r{{\d+}}, r{{\d+}}, r{{\d+}}, r{{\d+}} public static int $opt$noinline$mulPlusOne(int acc, int var) { if (doThrow) throw new Error(); return acc * (var + 1); } /** * Test the interpretation of `a * (1 - b)` as `a - (a * b)`. */ /// CHECK-START-ARM64: long Main.$opt$noinline$mulMinusOne(long, long) instruction_simplifier_arm64 (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> LongConstant 1 /// CHECK: <
> Sub [<
>,<
>] /// CHECK: <
> Mul [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: long Main.$opt$noinline$mulMinusOne(long, long) instruction_simplifier_arm64 (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> MultiplyAccumulate [<
>,<
>,<
>] kind:Sub /// CHECK: Return [<
>] /// CHECK-START-ARM64: long Main.$opt$noinline$mulMinusOne(long, long) instruction_simplifier_arm64 (after) /// CHECK-NOT: Mul /// CHECK-NOT: Sub /// CHECK-START-ARM64: long Main.$opt$noinline$mulMinusOne(long, long) disassembly (after) /// CHECK: msub x{{\d+}}, x{{\d+}}, x{{\d+}}, x{{\d+}} /// CHECK-START-ARM: long Main.$opt$noinline$mulMinusOne(long, long) instruction_simplifier_arm (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> LongConstant 1 /// CHECK: <
> Sub [<
>,<
>] /// CHECK: <
> Mul [<
>,<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM: long Main.$opt$noinline$mulMinusOne(long, long) instruction_simplifier_arm (after) /// CHECK-NOT: MultiplyAccumulate public static long $opt$noinline$mulMinusOne(long acc, long var) { if (doThrow) throw new Error(); return acc * (1 - var); } /** * Test basic merging of `MUL+NEG` into `MULNEG`. */ /// CHECK-START-ARM64: int Main.$opt$noinline$mulNeg(int, int) instruction_simplifier_arm64 (before) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> Mul [<
>,<
>] /// CHECK: <
> Neg [<
>] /// CHECK: Return [<
>] /// CHECK-START-ARM64: int Main.$opt$noinline$mulNeg(int, int) instruction_simplifier_arm64 (after) /// CHECK: <
> ParameterValue /// CHECK: <
> ParameterValue /// CHECK: <
> IntConstant 0 /// CHECK: <
> MultiplyAccumulate [<