diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/417-optimizing-arith-div/src/Main.java | 6 | ||||
| -rw-r--r-- | test/428-optimizing-arith-rem/expected.txt | 0 | ||||
| -rw-r--r-- | test/428-optimizing-arith-rem/info.txt | 1 | ||||
| -rw-r--r-- | test/428-optimizing-arith-rem/src/Main.java | 160 | ||||
| -rw-r--r-- | test/Android.run-test.mk | 1 |
5 files changed, 168 insertions, 0 deletions
diff --git a/test/417-optimizing-arith-div/src/Main.java b/test/417-optimizing-arith-div/src/Main.java index a5dea15559..909ceb43d6 100644 --- a/test/417-optimizing-arith-div/src/Main.java +++ b/test/417-optimizing-arith-div/src/Main.java @@ -24,6 +24,12 @@ public class Main { } } + public static void expectEquals(long expected, long result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + public static void expectEquals(float expected, float result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); diff --git a/test/428-optimizing-arith-rem/expected.txt b/test/428-optimizing-arith-rem/expected.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/428-optimizing-arith-rem/expected.txt diff --git a/test/428-optimizing-arith-rem/info.txt b/test/428-optimizing-arith-rem/info.txt new file mode 100644 index 0000000000..3e37ffeee8 --- /dev/null +++ b/test/428-optimizing-arith-rem/info.txt @@ -0,0 +1 @@ +Tests for modulo (rem) operation. diff --git a/test/428-optimizing-arith-rem/src/Main.java b/test/428-optimizing-arith-rem/src/Main.java new file mode 100644 index 0000000000..46bd3c6ac5 --- /dev/null +++ b/test/428-optimizing-arith-rem/src/Main.java @@ -0,0 +1,160 @@ +/* + * 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 { + + public static void expectEquals(int expected, int result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + + public static void expectEquals(long expected, long result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + + public static void expectDivisionByZero(int value) { + try { + $opt$Rem(value, 0); + throw new Error("Expected RuntimeException when modulo by 0"); + } catch (java.lang.RuntimeException e) { + } + try { + $opt$RemZero(value); + throw new Error("Expected RuntimeException when modulo by 0"); + } catch (java.lang.RuntimeException e) { + } + } + + public static void expectDivisionByZero(long value) { + try { + $opt$Rem(value, 0L); + throw new Error("Expected RuntimeException when modulo by 0"); + } catch (java.lang.RuntimeException e) { + } + try { + $opt$RemZero(value); + throw new Error("Expected RuntimeException when modulo by 0"); + } catch (java.lang.RuntimeException e) { + } + } + + public static void main(String[] args) { + rem(); + } + + public static void rem() { + remInt(); + remLong(); + } + + private static void remInt() { + expectEquals(2, $opt$RemConst(6)); + expectEquals(2, $opt$Rem(6, 4)); + expectEquals(2, $opt$Rem(6, -4)); + expectEquals(0, $opt$Rem(6, 3)); + expectEquals(0, $opt$Rem(6, -3)); + expectEquals(0, $opt$Rem(6, 1)); + expectEquals(0, $opt$Rem(6, -1)); + expectEquals(-1, $opt$Rem(-7, 3)); + expectEquals(-1, $opt$Rem(-7, -3)); + expectEquals(0, $opt$Rem(6, 6)); + expectEquals(0, $opt$Rem(-6, -6)); + expectEquals(7, $opt$Rem(7, 9)); + expectEquals(7, $opt$Rem(7, -9)); + expectEquals(-7, $opt$Rem(-7, 9)); + expectEquals(-7, $opt$Rem(-7, -9)); + + expectEquals(0, $opt$Rem(Integer.MAX_VALUE, 1)); + expectEquals(0, $opt$Rem(Integer.MAX_VALUE, -1)); + expectEquals(0, $opt$Rem(Integer.MIN_VALUE, 1)); + expectEquals(0, $opt$Rem(Integer.MIN_VALUE, -1)); // no overflow + expectEquals(-1, $opt$Rem(Integer.MIN_VALUE, Integer.MAX_VALUE)); + expectEquals(Integer.MAX_VALUE, $opt$Rem(Integer.MAX_VALUE, Integer.MIN_VALUE)); + + expectEquals(0, $opt$Rem(0, 7)); + expectEquals(0, $opt$Rem(0, Integer.MAX_VALUE)); + expectEquals(0, $opt$Rem(0, Integer.MIN_VALUE)); + + expectDivisionByZero(0); + expectDivisionByZero(1); + expectDivisionByZero(5); + expectDivisionByZero(Integer.MAX_VALUE); + expectDivisionByZero(Integer.MIN_VALUE); + } + + private static void remLong() { + expectEquals(2L, $opt$RemConst(6L)); + expectEquals(2L, $opt$Rem(6L, 4L)); + expectEquals(2L, $opt$Rem(6L, -4L)); + expectEquals(0L, $opt$Rem(6L, 3L)); + expectEquals(0L, $opt$Rem(6L, -3L)); + expectEquals(0L, $opt$Rem(6L, 1L)); + expectEquals(0L, $opt$Rem(6L, -1L)); + expectEquals(-1L, $opt$Rem(-7L, 3L)); + expectEquals(-1L, $opt$Rem(-7L, -3L)); + expectEquals(0L, $opt$Rem(6L, 6L)); + expectEquals(0L, $opt$Rem(-6L, -6L)); + expectEquals(7L, $opt$Rem(7L, 9L)); + expectEquals(7L, $opt$Rem(7L, -9L)); + expectEquals(-7L, $opt$Rem(-7L, 9L)); + expectEquals(-7L, $opt$Rem(-7L, -9L)); + + expectEquals(0L, $opt$Rem(Integer.MAX_VALUE, 1L)); + expectEquals(0L, $opt$Rem(Integer.MAX_VALUE, -1L)); + expectEquals(0L, $opt$Rem(Integer.MIN_VALUE, 1L)); + expectEquals(0L, $opt$Rem(Integer.MIN_VALUE, -1L)); // no overflow + expectEquals(-1L, $opt$Rem(Integer.MIN_VALUE, Integer.MAX_VALUE)); + expectEquals(Integer.MAX_VALUE, $opt$Rem(Integer.MAX_VALUE, Integer.MIN_VALUE)); + + expectEquals(0L, $opt$Rem(0L, 7L)); + expectEquals(0L, $opt$Rem(0L, Integer.MAX_VALUE)); + expectEquals(0L, $opt$Rem(0L, Integer.MIN_VALUE)); + + expectDivisionByZero(0L); + expectDivisionByZero(1L); + expectDivisionByZero(5L); + expectDivisionByZero(Integer.MAX_VALUE); + expectDivisionByZero(Integer.MIN_VALUE); + } + + static int $opt$Rem(int a, int b) { + return a % b; + } + + static int $opt$RemZero(int a) { + return a % 0; + } + + // Modulo by literals != 0 should not generate checks. + static int $opt$RemConst(int a) { + return a % 4; + } + + static long $opt$RemConst(long a) { + return a % 4L; + } + + static long $opt$Rem(long a, long b) { + return a % b; + } + + static long $opt$RemZero(long a) { + return a % 0L; + } +} diff --git a/test/Android.run-test.mk b/test/Android.run-test.mk index 3b949d6ad0..01c5ae2caa 100644 --- a/test/Android.run-test.mk +++ b/test/Android.run-test.mk @@ -450,6 +450,7 @@ TEST_ART_BROKEN_OPTIMIZING_ARM64_RUN_TESTS := \ 426-monitor \ 427-bitwise \ 427-bounds \ + 428-optimizing-arith-rem \ 700-LoadArgRegs \ 701-easy-div-rem \ 702-LargeBranchOffset \ |