diff options
author | Calin Juravle <calin@google.com> | 2014-11-25 20:56:51 +0000 |
---|---|---|
committer | Calin Juravle <calin@google.com> | 2014-11-26 10:59:15 +0000 |
commit | cea28ec4b9e94ec942899acf1dbf20f8999b36b4 (patch) | |
tree | 893c062f6792688671519989a78065ecc7e79de9 /test/432-optimizing-cmp | |
parent | f0c001465371279355eeb7633b67ffcc6f6738e5 (diff) | |
download | art-cea28ec4b9e94ec942899acf1dbf20f8999b36b4.zip art-cea28ec4b9e94ec942899acf1dbf20f8999b36b4.tar.gz art-cea28ec4b9e94ec942899acf1dbf20f8999b36b4.tar.bz2 |
[optimizing compiler] Add CMP{L,G}_{FLOAT,DOUBLE}
- adds float comparison for arm, x86, x86_64 backends.
- adds ucomis{s,d} assembly to x86 and x86_64.
Change-Id: Ie91e04bfb402025073054f3803a3a569e4705caa
Diffstat (limited to 'test/432-optimizing-cmp')
-rw-r--r-- | test/432-optimizing-cmp/expected.txt | 0 | ||||
-rw-r--r-- | test/432-optimizing-cmp/info.txt | 1 | ||||
-rw-r--r-- | test/432-optimizing-cmp/smali/cmp.smali | 33 | ||||
-rw-r--r-- | test/432-optimizing-cmp/src/Main.java | 227 |
4 files changed, 261 insertions, 0 deletions
diff --git a/test/432-optimizing-cmp/expected.txt b/test/432-optimizing-cmp/expected.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/432-optimizing-cmp/expected.txt diff --git a/test/432-optimizing-cmp/info.txt b/test/432-optimizing-cmp/info.txt new file mode 100644 index 0000000..fad6cee --- /dev/null +++ b/test/432-optimizing-cmp/info.txt @@ -0,0 +1 @@ +Tests for compare operations. diff --git a/test/432-optimizing-cmp/smali/cmp.smali b/test/432-optimizing-cmp/smali/cmp.smali new file mode 100644 index 0000000..470d940 --- /dev/null +++ b/test/432-optimizing-cmp/smali/cmp.smali @@ -0,0 +1,33 @@ +.class public LTestCmp; + +.super Ljava/lang/Object; + +.method public static $opt$CmpLong(JJ)I + .registers 5 + cmp-long v0, v1, v3 + return v0 +.end method + +.method public static $opt$CmpGtFloat(FF)I + .registers 3 + cmpg-float v0, v1, v2 + return v0 +.end method + +.method public static $opt$CmpLtFloat(FF)I + .registers 3 + cmpl-float v0, v1, v2 + return v0 +.end method + +.method public static $opt$CmpGtDouble(DD)I + .registers 5 + cmpg-double v0, v1, v3 + return v0 +.end method + +.method public static $opt$CmpLtDouble(DD)I + .registers 5 + cmpl-double v0, v1, v3 + return v0 +.end method diff --git a/test/432-optimizing-cmp/src/Main.java b/test/432-optimizing-cmp/src/Main.java new file mode 100644 index 0000000..f45b94d --- /dev/null +++ b/test/432-optimizing-cmp/src/Main.java @@ -0,0 +1,227 @@ +/* + * 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. + */ + +import java.lang.reflect.Method; + +public class Main { + + public static void main(String[] args) throws Exception { + cmpLong(); + cmpFloat(); + cmpDouble(); + } + + private static void cmpLong() throws Exception { + expectLt(3.1F, 5.1F); + expectGt(5.1F, 3.1F); + expectLt(Long.MIN_VALUE, Long.MAX_VALUE); + expectGt(Long.MAX_VALUE, Long.MIN_VALUE); + + expectEquals(0, smaliCmpLong(0L, 0L)); + expectEquals(0, smaliCmpLong(1L, 1L)); + expectEquals(-1, smaliCmpLong(1L, 2L)); + expectEquals(1, smaliCmpLong(2L, 1L)); + expectEquals(-1, smaliCmpLong(Long.MIN_VALUE, Long.MAX_VALUE)); + expectEquals(1, smaliCmpLong(Long.MAX_VALUE, Long.MIN_VALUE)); + expectEquals(0, smaliCmpLong(Long.MIN_VALUE, Long.MIN_VALUE)); + expectEquals(0, smaliCmpLong(Long.MAX_VALUE, Long.MAX_VALUE)); + } + + private static void cmpFloat() throws Exception { + expectLt(3.1F, 5.1F); + expectGt(5.1F, 3.1F); + expectLt(Float.MIN_VALUE, Float.MAX_VALUE); + expectGt(Float.MAX_VALUE, Float.MIN_VALUE); + expectFalse(3.1F, Float.NaN); + expectFalse(Float.NaN, 3.1F); + + expectEquals(0, smaliCmpGtFloat(0F, 0F)); + expectEquals(0, smaliCmpGtFloat(1F, 1F)); + expectEquals(-1, smaliCmpGtFloat(1.1F, 2.1F)); + expectEquals(1, smaliCmpGtFloat(2.1F, 1.1F)); + expectEquals(-1, smaliCmpGtFloat(Float.MIN_VALUE, Float.MAX_VALUE)); + expectEquals(1, smaliCmpGtFloat(Float.MAX_VALUE, Float.MIN_VALUE)); + expectEquals(0, smaliCmpGtFloat(Float.MIN_VALUE, Float.MIN_VALUE)); + expectEquals(0, smaliCmpGtFloat(Float.MAX_VALUE, Float.MAX_VALUE)); + expectEquals(1, smaliCmpGtFloat(5F, Float.NaN)); + expectEquals(1, smaliCmpGtFloat(Float.NaN, 5F)); + + expectEquals(0, smaliCmpLtFloat(0F, 0F)); + expectEquals(0, smaliCmpLtFloat(1F, 1F)); + expectEquals(-1, smaliCmpLtFloat(1.1F, 2.1F)); + expectEquals(1, smaliCmpLtFloat(2.1F, 1.1F)); + expectEquals(-1, smaliCmpLtFloat(Float.MIN_VALUE, Float.MAX_VALUE)); + expectEquals(1, smaliCmpLtFloat(Float.MAX_VALUE, Float.MIN_VALUE)); + expectEquals(0, smaliCmpLtFloat(Float.MIN_VALUE, Float.MIN_VALUE)); + expectEquals(0, smaliCmpLtFloat(Float.MAX_VALUE, Float.MAX_VALUE)); + expectEquals(-1, smaliCmpLtFloat(5F, Float.NaN)); + expectEquals(-1, smaliCmpLtFloat(Float.NaN, 5F)); + } + + private static void cmpDouble() throws Exception { + expectLt(3.1D, 5.1D); + expectGt(5.1D, 3.1D); + expectLt(Double.MIN_VALUE, Double.MAX_VALUE); + expectGt(Double.MAX_VALUE, Double.MIN_VALUE); + expectFalse(3.1D, Double.NaN); + expectFalse(Double.NaN, 3.1D); + + expectEquals(0, smaliCmpGtDouble(0D, 0D)); + expectEquals(0, smaliCmpGtDouble(1D, 1D)); + expectEquals(-1, smaliCmpGtDouble(1.1D, 2.1D)); + expectEquals(1, smaliCmpGtDouble(2.1D, 1.1D)); + expectEquals(-1, smaliCmpGtDouble(Double.MIN_VALUE, Double.MAX_VALUE)); + expectEquals(1, smaliCmpGtDouble(Double.MAX_VALUE, Double.MIN_VALUE)); + expectEquals(0, smaliCmpGtDouble(Double.MIN_VALUE, Double.MIN_VALUE)); + expectEquals(0, smaliCmpGtDouble(Double.MAX_VALUE, Double.MAX_VALUE)); + expectEquals(1, smaliCmpGtDouble(5D, Double.NaN)); + expectEquals(1, smaliCmpGtDouble(Double.NaN, 5D)); + + expectEquals(0, smaliCmpLtDouble(0D, 0D)); + expectEquals(0, smaliCmpLtDouble(1D, 1D)); + expectEquals(-1, smaliCmpLtDouble(1.1D, 2.1D)); + expectEquals(1, smaliCmpLtDouble(2.1D, 1.1D)); + expectEquals(-1, smaliCmpLtDouble(Double.MIN_VALUE, Double.MAX_VALUE)); + expectEquals(1, smaliCmpLtDouble(Double.MAX_VALUE, Double.MIN_VALUE)); + expectEquals(0, smaliCmpLtDouble(Double.MIN_VALUE, Double.MIN_VALUE)); + expectEquals(0, smaliCmpLtDouble(Double.MAX_VALUE, Double.MAX_VALUE)); + expectEquals(-1, smaliCmpLtDouble(5D, Double.NaN)); + expectEquals(-1, smaliCmpLtDouble(Float.NaN, 5D)); + } + + static boolean $opt$lt(long a, long b) { + return a < b; + } + + static boolean $opt$lt(float a, float b) { + return a < b; + } + + static boolean $opt$lt(double a, double b) { + return a < b; + } + + static boolean $opt$gt(long a, long b) { + return a > b; + } + + static boolean $opt$gt(float a, float b) { + return a > b; + } + + static boolean $opt$gt(double a, double b) { + return a > b; + } + + // Wrappers around methods located in file cmp.smali. + + private static int smaliCmpLong(long a, long b) throws Exception { + Class<?> c = Class.forName("TestCmp"); + Method m = c.getMethod("$opt$CmpLong", long.class, long.class); + int result = (Integer)m.invoke(null, a, b); + return result; + } + + private static int smaliCmpGtFloat(float a, float b) throws Exception { + Class<?> c = Class.forName("TestCmp"); + Method m = c.getMethod("$opt$CmpGtFloat", float.class, float.class); + int result = (Integer)m.invoke(null, a, b); + return result; + } + + private static int smaliCmpLtFloat(float a, float b) throws Exception { + Class<?> c = Class.forName("TestCmp"); + Method m = c.getMethod("$opt$CmpLtFloat", float.class, float.class); + int result = (Integer)m.invoke(null, a, b); + return result; + } + + private static int smaliCmpGtDouble(double a, double b) throws Exception { + Class<?> c = Class.forName("TestCmp"); + Method m = c.getMethod("$opt$CmpGtDouble", double.class, double.class); + int result = (Integer)m.invoke(null, a, b); + return result; + } + + private static int smaliCmpLtDouble(double a, double b) throws Exception { + Class<?> c = Class.forName("TestCmp"); + Method m = c.getMethod("$opt$CmpLtDouble", double.class, double.class); + int result = (Integer)m.invoke(null, a, b); + return result; + } + + public static void expectEquals(int expected, int result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + + public static void expectLt(long a, long b) { + if (!$opt$lt(a, b)) { + throw new Error("Expected: " + a + " < " + b); + } + } + + public static void expectGt(long a, long b) { + if (!$opt$gt(a, b)) { + throw new Error("Expected: " + a + " > " + b); + } + } + + public static void expectLt(float a, float b) { + if (!$opt$lt(a, b)) { + throw new Error("Expected: " + a + " < " + b); + } + } + + public static void expectGt(float a, float b) { + if (!$opt$gt(a, b)) { + throw new Error("Expected: " + a + " > " + b); + } + } + + public static void expectFalse(float a, float b) { + if ($opt$lt(a, b)) { + throw new Error("Not expecting: " + a + " < " + b); + } + if ($opt$gt(a, b)) { + throw new Error("Not expecting: " + a + " > " + b); + } + } + + public static void expectLt(double a, double b) { + if (!$opt$lt(a, b)) { + throw new Error("Expected: " + a + " < " + b); + } + } + + public static void expectGt(double a, double b) { + if (!$opt$gt(a, b)) { + throw new Error("Expected: " + a + " > " + b); + } + } + + public static void expectFalse(double a, double b) { + if ($opt$lt(a, b)) { + throw new Error("Not expecting: " + a + " < " + b); + } + if ($opt$gt(a, b)) { + throw new Error("Not expecting: " + a + " > " + b); + } + } + +} + |