diff options
author | Ningsheng Jian <ningsheng.jian@arm.com> | 2014-11-25 16:48:07 +0800 |
---|---|---|
committer | Ningsheng Jian <ningsheng.jian@arm.com> | 2014-12-11 09:08:22 +0800 |
commit | a262f7707330dccfb50af6345813083182b61043 (patch) | |
tree | a8ab4e42654f47c9deea517f6c4e2020c62d5724 /test/704-multiply-accumulate | |
parent | 3e465bec65067ebfdf662469cf85dd82cd077bdd (diff) | |
download | art-a262f7707330dccfb50af6345813083182b61043.zip art-a262f7707330dccfb50af6345813083182b61043.tar.gz art-a262f7707330dccfb50af6345813083182b61043.tar.bz2 |
ARM: Combine multiply accumulate operations.
Try to combine integer multiply and add(sub) into a MAC operation.
For AArch64, also try to combine long type multiply and add(sub).
Change-Id: Ic85812e941eb5a66abc355cab81a4dd16de1b66e
Diffstat (limited to 'test/704-multiply-accumulate')
-rw-r--r-- | test/704-multiply-accumulate/expected.txt | 1 | ||||
-rw-r--r-- | test/704-multiply-accumulate/info.txt | 1 | ||||
-rw-r--r-- | test/704-multiply-accumulate/src/Main.java | 171 |
3 files changed, 173 insertions, 0 deletions
diff --git a/test/704-multiply-accumulate/expected.txt b/test/704-multiply-accumulate/expected.txt new file mode 100644 index 0000000..76f5a5a --- /dev/null +++ b/test/704-multiply-accumulate/expected.txt @@ -0,0 +1 @@ +Done! diff --git a/test/704-multiply-accumulate/info.txt b/test/704-multiply-accumulate/info.txt new file mode 100644 index 0000000..a12fd44 --- /dev/null +++ b/test/704-multiply-accumulate/info.txt @@ -0,0 +1 @@ +Tests for multiply accumulate operations. diff --git a/test/704-multiply-accumulate/src/Main.java b/test/704-multiply-accumulate/src/Main.java new file mode 100644 index 0000000..7404b9b --- /dev/null +++ b/test/704-multiply-accumulate/src/Main.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2014 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 { + + static int imax = Integer.MAX_VALUE; + static int imin = Integer.MIN_VALUE; + static long lmax = Long.MAX_VALUE; + static long lmin = Long.MIN_VALUE; + static CA ca; + + public static void expectEquals(long expected, long result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + + public static void expectEquals(int expected, int result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + + public static void test_int() { + int result = 0; + int a = imax; + int b = imin; + int c = 10; + int d = c; + int tmp = 0; + int [] ia = new int[5]; + for (int i = 0; i < 100; i++) { + tmp = i*c; + result += i*i; + result = i - tmp; + } + expectEquals(result, -891); + + result = c*c + (result - c); + expectEquals(result, -801); + + result = a + a*a; + expectEquals(result, -2147483648); + + result = b + b*b; + expectEquals(result, -2147483648); + + result = b - a*a; + expectEquals(result, 2147483647); + + result = d*d; + d++; + result += result; + expectEquals(result, 200); + + result = c*c; + tmp++; + result += result; + expectEquals(result, 200); + + result = 0; + try { + result = c*c; + ia[c] = d; // array out of bound. + result += d; + } catch (Exception e) { + } + expectEquals(result, 100); + + CA obj = new CA(); + result = a*c + obj.ia; + expectEquals(result, 2); + + result = 0; + obj = ca; + try { + result = a*c; + tmp = obj.ia; + result = result + tmp; + } catch (Exception e) { + } + expectEquals(result, -10); + } + + public static void test_long() { + long result = 0; + long a = lmax; + long b = lmin; + long c = 10; + long d = c; + long tmp = 0; + int [] ia = new int[5]; + for (long i = 0; i < 100; i++) { + tmp = i*c; + result += i*i; + result = i - tmp; + } + expectEquals(result, -891L); + + result = c*c + (result - c); + expectEquals(result, -801L); + + result = a + a*a; + expectEquals(result, -9223372036854775808L); + + result = b + b*b; + expectEquals(result, -9223372036854775808L); + + result = b - a*a; + expectEquals(result, 9223372036854775807L); + + result = d*d; + d++; + result += result; + expectEquals(result, 200L); + + result = c*c; + tmp++; + result += result; + expectEquals(result, 200L); + + result = 0; + int index = 10; + try { + result = c*c; + ia[index] = 10; // array out of bound. + result += d; + } catch (Exception e) { + } + expectEquals(result, 100L); + + CA obj = new CA(); + result = a*c + obj.la; + expectEquals(result, 113L); + + result = 0; + obj = ca; + try { + result = a*c; + tmp = obj.la; + result = result + tmp; + } catch (Exception e) { + } + expectEquals(result, -10L); + } + + public static void main(String[] args) { + test_int(); + test_long(); + System.out.println("Done!"); + } + +} + +class CA { + public int ia = 12; + public long la = 123L; +} |