summaryrefslogtreecommitdiffstats
path: root/test/422-type-conversion
diff options
context:
space:
mode:
authorRoland Levillain <rpl@google.com>2014-11-17 14:32:17 +0000
committerRoland Levillain <rpl@google.com>2014-11-17 16:40:49 +0000
commitcff137481eda0eb8dbdf9d2a303ae2bdac2c7322 (patch)
tree577692649599d8c5ffd9b235d18af22c2621f7fe /test/422-type-conversion
parent7bfb3f8b1748b5bf7e217a1337176ad488dca66a (diff)
downloadart-cff137481eda0eb8dbdf9d2a303ae2bdac2c7322.tar.gz
art-cff137481eda0eb8dbdf9d2a303ae2bdac2c7322.tar.bz2
art-cff137481eda0eb8dbdf9d2a303ae2bdac2c7322.zip
Add support for int-to-float & int-to-double in optimizing.
- Add support for the int-to-float and int-to-double Dex instructions in the optimizing compiler. - Generate x86, x86-64 and ARM (but not ARM64) code for byte to float, short to float, int to float, char to float, byte to double, short to double, int to double and char to double HTypeConversion nodes. - Add related tests to test/422-type-conversion. Change-Id: I963f9d0184a5d3721af2d8f593f133d5af7aa6a3
Diffstat (limited to 'test/422-type-conversion')
-rw-r--r--test/422-type-conversion/src/Main.java131
1 files changed, 131 insertions, 0 deletions
diff --git a/test/422-type-conversion/src/Main.java b/test/422-type-conversion/src/Main.java
index 0bf958541b..37bc7779bd 100644
--- a/test/422-type-conversion/src/Main.java
+++ b/test/422-type-conversion/src/Main.java
@@ -50,6 +50,19 @@ public class Main {
}
}
+ public static void assertFloatEquals(float expected, float result) {
+ if (expected != result) {
+ throw new Error("Expected: " + expected + ", found: " + result);
+ }
+ }
+
+ public static void assertDoubleEquals(double expected, double result) {
+ if (expected != result) {
+ throw new Error("Expected: " + expected + ", found: " + result);
+ }
+ }
+
+
public static void main(String[] args) {
// Generate, compile and check int-to-long Dex instructions.
byteToLong();
@@ -57,6 +70,18 @@ public class Main {
intToLong();
charToLong();
+ // Generate, compile and check int-to-float Dex instructions.
+ byteToFloat();
+ shortToFloat();
+ intToFloat();
+ charToFloat();
+
+ // Generate, compile and check int-to-double Dex instructions.
+ byteToDouble();
+ shortToDouble();
+ intToDouble();
+ charToDouble();
+
// Generate, compile and check long-to-int Dex instructions.
longToInt();
@@ -121,6 +146,100 @@ public class Main {
assertLongEquals(32768L, $opt$CharToLong((char)-32768)); // -(2^15)
}
+ private static void byteToFloat() {
+ assertFloatEquals(1F, $opt$ByteToFloat((byte)1));
+ assertFloatEquals(0F, $opt$ByteToFloat((byte)0));
+ assertFloatEquals(-1F, $opt$ByteToFloat((byte)-1));
+ assertFloatEquals(51F, $opt$ByteToFloat((byte)51));
+ assertFloatEquals(-51F, $opt$ByteToFloat((byte)-51));
+ assertFloatEquals(127F, $opt$ByteToFloat((byte)127)); // 2^7 - 1
+ assertFloatEquals(-127F, $opt$ByteToFloat((byte)-127)); // -(2^7 - 1)
+ assertFloatEquals(-128F, $opt$ByteToFloat((byte)-128)); // -(2^7)
+ }
+
+ private static void shortToFloat() {
+ assertFloatEquals(1F, $opt$ShortToFloat((short)1));
+ assertFloatEquals(0F, $opt$ShortToFloat((short)0));
+ assertFloatEquals(-1F, $opt$ShortToFloat((short)-1));
+ assertFloatEquals(51F, $opt$ShortToFloat((short)51));
+ assertFloatEquals(-51F, $opt$ShortToFloat((short)-51));
+ assertFloatEquals(32767F, $opt$ShortToFloat((short)32767)); // 2^15 - 1
+ assertFloatEquals(-32767F, $opt$ShortToFloat((short)-32767)); // -(2^15 - 1)
+ assertFloatEquals(-32768F, $opt$ShortToFloat((short)-32768)); // -(2^15)
+ }
+
+ private static void intToFloat() {
+ assertFloatEquals(1F, $opt$IntToFloat(1));
+ assertFloatEquals(0F, $opt$IntToFloat(0));
+ assertFloatEquals(-1F, $opt$IntToFloat(-1));
+ assertFloatEquals(51F, $opt$IntToFloat(51));
+ assertFloatEquals(-51F, $opt$IntToFloat(-51));
+ assertFloatEquals(16777215F, $opt$IntToFloat(16777215)); // 2^24 - 1
+ assertFloatEquals(-16777215F, $opt$IntToFloat(-16777215)); // -(2^24 - 1)
+ assertFloatEquals(16777216F, $opt$IntToFloat(16777216)); // 2^24
+ assertFloatEquals(-16777216F, $opt$IntToFloat(-16777216)); // -(2^24)
+ assertFloatEquals(2147483647F, $opt$IntToFloat(2147483647)); // 2^31 - 1
+ assertFloatEquals(-2147483648F, $opt$IntToFloat(-2147483648)); // -(2^31)
+ }
+
+ private static void charToFloat() {
+ assertFloatEquals(1F, $opt$CharToFloat((char)1));
+ assertFloatEquals(0F, $opt$CharToFloat((char)0));
+ assertFloatEquals(51F, $opt$CharToFloat((char)51));
+ assertFloatEquals(32767F, $opt$CharToFloat((char)32767)); // 2^15 - 1
+ assertFloatEquals(65535F, $opt$CharToFloat((char)65535)); // 2^16 - 1
+ assertFloatEquals(65535F, $opt$CharToFloat((char)-1));
+ assertFloatEquals(65485F, $opt$CharToFloat((char)-51));
+ assertFloatEquals(32769F, $opt$CharToFloat((char)-32767)); // -(2^15 - 1)
+ assertFloatEquals(32768F, $opt$CharToFloat((char)-32768)); // -(2^15)
+ }
+
+ private static void byteToDouble() {
+ assertDoubleEquals(1D, $opt$ByteToDouble((byte)1));
+ assertDoubleEquals(0D, $opt$ByteToDouble((byte)0));
+ assertDoubleEquals(-1D, $opt$ByteToDouble((byte)-1));
+ assertDoubleEquals(51D, $opt$ByteToDouble((byte)51));
+ assertDoubleEquals(-51D, $opt$ByteToDouble((byte)-51));
+ assertDoubleEquals(127D, $opt$ByteToDouble((byte)127)); // 2^7 - 1
+ assertDoubleEquals(-127D, $opt$ByteToDouble((byte)-127)); // -(2^7 - 1)
+ assertDoubleEquals(-128D, $opt$ByteToDouble((byte)-128)); // -(2^7)
+ }
+
+ private static void shortToDouble() {
+ assertDoubleEquals(1D, $opt$ShortToDouble((short)1));
+ assertDoubleEquals(0D, $opt$ShortToDouble((short)0));
+ assertDoubleEquals(-1D, $opt$ShortToDouble((short)-1));
+ assertDoubleEquals(51D, $opt$ShortToDouble((short)51));
+ assertDoubleEquals(-51D, $opt$ShortToDouble((short)-51));
+ assertDoubleEquals(32767D, $opt$ShortToDouble((short)32767)); // 2^15 - 1
+ assertDoubleEquals(-32767D, $opt$ShortToDouble((short)-32767)); // -(2^15 - 1)
+ assertDoubleEquals(-32768D, $opt$ShortToDouble((short)-32768)); // -(2^15)
+ }
+
+ private static void intToDouble() {
+ assertDoubleEquals(1D, $opt$IntToDouble(1));
+ assertDoubleEquals(0D, $opt$IntToDouble(0));
+ assertDoubleEquals(-1D, $opt$IntToDouble(-1));
+ assertDoubleEquals(51D, $opt$IntToDouble(51));
+ assertDoubleEquals(-51D, $opt$IntToDouble(-51));
+ assertDoubleEquals(16777216D, $opt$IntToDouble(16777216)); // 2^24
+ assertDoubleEquals(-16777216D, $opt$IntToDouble(-16777216)); // -(2^24)
+ assertDoubleEquals(2147483647D, $opt$IntToDouble(2147483647)); // 2^31 - 1
+ assertDoubleEquals(-2147483648D, $opt$IntToDouble(-2147483648)); // -(2^31)
+ }
+
+ private static void charToDouble() {
+ assertDoubleEquals(1D, $opt$CharToDouble((char)1));
+ assertDoubleEquals(0D, $opt$CharToDouble((char)0));
+ assertDoubleEquals(51D, $opt$CharToDouble((char)51));
+ assertDoubleEquals(32767D, $opt$CharToDouble((char)32767)); // 2^15 - 1
+ assertDoubleEquals(65535D, $opt$CharToDouble((char)65535)); // 2^16 - 1
+ assertDoubleEquals(65535D, $opt$CharToDouble((char)-1));
+ assertDoubleEquals(65485D, $opt$CharToDouble((char)-51));
+ assertDoubleEquals(32769D, $opt$CharToDouble((char)-32767)); // -(2^15 - 1)
+ assertDoubleEquals(32768D, $opt$CharToDouble((char)-32768)); // -(2^15)
+ }
+
private static void longToInt() {
assertIntEquals(1, $opt$LongToInt(1L));
assertIntEquals(0, $opt$LongToInt(0L));
@@ -281,6 +400,18 @@ public class Main {
static long $opt$IntToLong(int a) { return a; }
static long $opt$CharToLong(int a) { return a; }
+ // These methods produce int-to-float Dex instructions.
+ static float $opt$ByteToFloat(byte a) { return a; }
+ static float $opt$ShortToFloat(short a) { return a; }
+ static float $opt$IntToFloat(int a) { return a; }
+ static float $opt$CharToFloat(char a) { return a; }
+
+ // These methods produce int-to-double Dex instructions.
+ static double $opt$ByteToDouble(byte a) { return a; }
+ static double $opt$ShortToDouble(short a) { return a; }
+ static double $opt$IntToDouble(int a) { return a; }
+ static double $opt$CharToDouble(int a) { return a; }
+
// These methods produce long-to-int Dex instructions.
static int $opt$LongToInt(long a){ return (int)a; }
static int $opt$LongLiteralToInt(){ return (int)42L; }