summaryrefslogtreecommitdiffstats
path: root/test/417-optimizing-arith-div
diff options
context:
space:
mode:
authorCalin Juravle <calin@google.com>2014-11-04 16:40:20 +0000
committerCalin Juravle <calin@google.com>2014-11-06 14:42:58 +0000
commitd0d4852847432368b090c184d6639e573538dccf (patch)
tree47e31fe860ff1c3ace2f3f5945aa69689d42d998 /test/417-optimizing-arith-div
parenta88b7b93e28ea86969dd3ec6a6bf6929d697fc31 (diff)
downloadart-d0d4852847432368b090c184d6639e573538dccf.tar.gz
art-d0d4852847432368b090c184d6639e573538dccf.tar.bz2
art-d0d4852847432368b090c184d6639e573538dccf.zip
[optimizing compiler] Add div-int and exception handling.
- for backends: arm, x86, x86_64 - fixed a register allocator bug: the request for a fixed register for the first input was ignored if the output was kSameAsFirstInput - added divide by zero exception - more tests - shuffle around some code in the builder to reduce the number of lines of code for a single function. Change-Id: Id3a515e02bfbc66cd9d16cb9746f7551bdab3d42
Diffstat (limited to 'test/417-optimizing-arith-div')
-rw-r--r--test/417-optimizing-arith-div/src/Main.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/417-optimizing-arith-div/src/Main.java b/test/417-optimizing-arith-div/src/Main.java
index 535cafb113..5825d24dda 100644
--- a/test/417-optimizing-arith-div/src/Main.java
+++ b/test/417-optimizing-arith-div/src/Main.java
@@ -18,6 +18,12 @@
// it does compile the method.
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(float expected, float result) {
if (expected != result) {
throw new Error("Expected: " + expected + ", found: " + result);
@@ -60,15 +66,51 @@ public class Main {
}
}
+ public static void expectDivisionByZero(int value) {
+ try {
+ $opt$Div(value, 0);
+ throw new Error("Expected RuntimeException when dividing by 0");
+ } catch (java.lang.RuntimeException e) {
+ }
+ try {
+ $opt$DivZero(value);
+ throw new Error("Expected RuntimeException when dividing by 0");
+ } catch (java.lang.RuntimeException e) {
+ }
+ }
public static void main(String[] args) {
div();
}
public static void div() {
+ divInt();
divFloat();
divDouble();
}
+ private static void divInt() {
+ expectEquals(2, $opt$DivLit(6));
+ expectEquals(2, $opt$Div(6, 3));
+ expectEquals(6, $opt$Div(6, 1));
+ expectEquals(-2, $opt$Div(6, -3));
+ expectEquals(1, $opt$Div(4, 3));
+ expectEquals(-1, $opt$Div(4, -3));
+ expectEquals(5, $opt$Div(23, 4));
+ expectEquals(-5, $opt$Div(-23, 4));
+
+ expectEquals(-Integer.MAX_VALUE, $opt$Div(Integer.MAX_VALUE, -1));
+ expectEquals(Integer.MIN_VALUE, $opt$Div(Integer.MIN_VALUE, -1)); // overflow
+ expectEquals(-1073741824, $opt$Div(Integer.MIN_VALUE, 2));
+
+ expectEquals(0, $opt$Div(0, Integer.MAX_VALUE));
+ expectEquals(0, $opt$Div(0, Integer.MIN_VALUE));
+
+ expectDivisionByZero(0);
+ expectDivisionByZero(1);
+ expectDivisionByZero(Integer.MAX_VALUE);
+ expectDivisionByZero(Integer.MIN_VALUE);
+ }
+
private static void divFloat() {
expectApproxEquals(1.6666666F, $opt$Div(5F, 3F));
expectApproxEquals(0F, $opt$Div(0F, 3F));
@@ -127,6 +169,19 @@ public class Main {
expectEquals(Float.NEGATIVE_INFINITY, $opt$Div(-Float.MAX_VALUE, Float.MIN_VALUE));
}
+ static int $opt$Div(int a, int b) {
+ return a / b;
+ }
+
+ static int $opt$DivZero(int a) {
+ return a / 0;
+ }
+
+ // Division by literals != 0 should not generate checks.
+ static int $opt$DivLit(int a) {
+ return a / 3;
+ }
+
static float $opt$Div(float a, float b) {
return a / b;
}