summaryrefslogtreecommitdiffstats
path: root/test/703-floating-point-div
diff options
context:
space:
mode:
authorNingsheng Jian <ningsheng.jian@arm.com>2014-10-23 13:48:36 +0800
committerIan Rogers <irogers@google.com>2014-11-05 11:37:37 -0800
commit675e09b2753c2fcd521bd8f0230a0abf06e9b0e9 (patch)
tree9a5f41cb1dd1930ae003feeccb4211d59b465e19 /test/703-floating-point-div
parent211d45e059935a7874a1ec89846f03d35ffba29f (diff)
downloadart-675e09b2753c2fcd521bd8f0230a0abf06e9b0e9.tar.gz
art-675e09b2753c2fcd521bd8f0230a0abf06e9b0e9.tar.bz2
art-675e09b2753c2fcd521bd8f0230a0abf06e9b0e9.zip
ARM: Strength reduction for floating-point division
For floating-point division by power of two constants, generate multiplication by the reciprocal instead. Change-Id: I39c79eeb26b60cc754ad42045362b79498c755be
Diffstat (limited to 'test/703-floating-point-div')
-rw-r--r--test/703-floating-point-div/expected.txt1
-rw-r--r--test/703-floating-point-div/info.txt1
-rw-r--r--test/703-floating-point-div/src/Main.java90
3 files changed, 92 insertions, 0 deletions
diff --git a/test/703-floating-point-div/expected.txt b/test/703-floating-point-div/expected.txt
new file mode 100644
index 0000000000..76f5a5a5aa
--- /dev/null
+++ b/test/703-floating-point-div/expected.txt
@@ -0,0 +1 @@
+Done!
diff --git a/test/703-floating-point-div/info.txt b/test/703-floating-point-div/info.txt
new file mode 100644
index 0000000000..418b831350
--- /dev/null
+++ b/test/703-floating-point-div/info.txt
@@ -0,0 +1 @@
+Simple tests to check floating point division.
diff --git a/test/703-floating-point-div/src/Main.java b/test/703-floating-point-div/src/Main.java
new file mode 100644
index 0000000000..9990a545f4
--- /dev/null
+++ b/test/703-floating-point-div/src/Main.java
@@ -0,0 +1,90 @@
+/*
+ * 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 double dPi = Math.PI;
+ static float fPi = (float)Math.PI;
+
+ 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 divDoubleTest() {
+ double d1 = 0x1.0p1023;
+ double d2 = -2.0;
+ double d3 = 0.0;
+ double d4 = Double.MIN_NORMAL;
+ double d5 = Double.POSITIVE_INFINITY;
+ double d6 = Double.NEGATIVE_INFINITY;
+ double d7 = -0.0;
+ double d8 = Double.MAX_VALUE;
+ double d9 = Double.MIN_VALUE;
+ double d0 = Double.NaN;
+
+ expectEquals(Double.doubleToRawLongBits(dPi/d1), 0x1921fb54442d18L);
+ expectEquals(Double.doubleToRawLongBits(dPi/d2), 0xbff921fb54442d18L);
+ expectEquals(Double.doubleToRawLongBits(dPi/d3), 0x7ff0000000000000L);
+ expectEquals(Double.doubleToRawLongBits(dPi/d4), 0x7fe921fb54442d18L);
+ expectEquals(Double.doubleToRawLongBits(dPi/d5), 0x0L);
+ expectEquals(Double.doubleToRawLongBits(dPi/d6), 0x8000000000000000L);
+ expectEquals(Double.doubleToRawLongBits(dPi/d7), 0xfff0000000000000L);
+
+ expectEquals(Double.doubleToRawLongBits(dPi/d8), 0xc90fdaa22168cL);
+ expectEquals(Double.doubleToRawLongBits(dPi/d9), 0x7ff0000000000000L);
+ expectEquals(Double.doubleToRawLongBits(dPi/d0), 0x7ff8000000000000L);
+ }
+
+ public static void divFloatTest() {
+ float f1 = 0x1.0p127f;
+ float f2 = -2.0f;
+ float f3 = 0.0f;
+ float f4 = Float.MIN_NORMAL;
+ float f5 = Float.POSITIVE_INFINITY;
+ float f6 = Float.NEGATIVE_INFINITY;
+ float f7 = -0.0f;
+ float f8 = Float.MAX_VALUE;
+ float f9 = Float.MIN_VALUE;
+ float f0 = Float.NaN;
+
+ expectEquals(Float.floatToRawIntBits(fPi/f1), 0xc90fdb);
+ expectEquals(Float.floatToRawIntBits(fPi/f2), 0xbfc90fdb);
+ expectEquals(Float.floatToRawIntBits(fPi/f3), 0x7f800000);
+ expectEquals(Float.floatToRawIntBits(fPi/f4), 0x7f490fdb);
+ expectEquals(Float.floatToRawIntBits(fPi/f5), 0x0);
+ expectEquals(Float.floatToRawIntBits(fPi/f6), 0x80000000);
+ expectEquals(Float.floatToRawIntBits(fPi/f7), 0xff800000);
+
+ expectEquals(Float.floatToRawIntBits(fPi/f8), 0x6487ee);
+ expectEquals(Float.floatToRawIntBits(fPi/f9), 0x7f800000);
+ expectEquals(Float.floatToRawIntBits(fPi/f0), 0x7fc00000);
+ }
+
+ public static void main(String[] args) {
+ divDoubleTest();
+ divFloatTest();
+ System.out.println("Done!");
+ }
+
+}