summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy McFadden <fadden@android.com>2009-06-29 17:04:04 -0700
committerAndy McFadden <fadden@android.com>2009-06-30 11:22:29 -0700
commit87cf7312247b341b54be26904e3600e98967d695 (patch)
tree6efc33ac43398472e7e7ed0c4b36f06b8deab1e7 /tests
parent44d7864f79a22fe110b8e6187ac21e908f41fb1d (diff)
downloadandroid_dalvik-87cf7312247b341b54be26904e3600e98967d695.tar.gz
android_dalvik-87cf7312247b341b54be26904e3600e98967d695.tar.bz2
android_dalvik-87cf7312247b341b54be26904e3600e98967d695.zip
Inline some java.lang.Math functions.
For a first pass, I inlined the various flavors of abs(), min()/max() on integers, sqrt(), cos(), and sin(). These were selected based on a static analysis of a few of our jar files. A test of repeated sin/cos/sqrt calls on a G1-class device showed an improvement of 28%. This would improve more on devices with VFP support if the VM is compiled with -mfpu=vfp. Also: clarified a warning and removed some "#if 0" stuff.
Diffstat (limited to 'tests')
-rw-r--r--tests/003-omnibus-opcodes/expected.txt2
-rw-r--r--tests/003-omnibus-opcodes/src/FloatMath.java46
-rw-r--r--tests/003-omnibus-opcodes/src/IntMath.java21
3 files changed, 69 insertions, 0 deletions
diff --git a/tests/003-omnibus-opcodes/expected.txt b/tests/003-omnibus-opcodes/expected.txt
index 25ed38ba8..4895dc3e0 100644
--- a/tests/003-omnibus-opcodes/expected.txt
+++ b/tests/003-omnibus-opcodes/expected.txt
@@ -23,6 +23,7 @@ IntMath.truncateTest
IntMath.divideByZero
IntMath.bigDivideOverflow
IntMath.checkConsts
+IntMath.jlmTests
FloatMath.convTest
FloatMath.floatOperTest
FloatMath.doubleOperTest
@@ -39,6 +40,7 @@ FloatMath.checkConvD
2: 123.45600128173828
-2.005440939E9, -8.6133032459203287E18, 123.4560012817382
FloatMath.checkConsts
+FloatMath.jlmTests
IntMath.testIntCompare
IntMath.testLongCompare
IntMath.testFloatCompare
diff --git a/tests/003-omnibus-opcodes/src/FloatMath.java b/tests/003-omnibus-opcodes/src/FloatMath.java
index 0c1fe1ba7..cf4869c26 100644
--- a/tests/003-omnibus-opcodes/src/FloatMath.java
+++ b/tests/003-omnibus-opcodes/src/FloatMath.java
@@ -262,6 +262,50 @@ public class FloatMath {
assert(d > 9.9 && d < 10.1);
}
+ /*
+ * Determine if two floating point numbers are approximately equal.
+ *
+ * (Assumes that floating point is generally working, so we can't use
+ * this for the first set of tests.)
+ */
+ static boolean approxEqual(float a, float b, float maxDelta) {
+ if (a > b)
+ return (a - b) < maxDelta;
+ else
+ return (b - a) < maxDelta;
+ }
+ static boolean approxEqual(double a, double b, double maxDelta) {
+ if (a > b)
+ return (a - b) < maxDelta;
+ else
+ return (b - a) < maxDelta;
+ }
+
+ /*
+ * Test some java.lang.Math functions.
+ *
+ * The method arguments are positive values.
+ */
+ static void jlmTests(float ff, double dd) {
+ System.out.println("FloatMath.jlmTests");
+
+ assert(approxEqual(Math.abs(ff), ff, 0.001f));
+ assert(approxEqual(Math.abs(-ff), ff, 0.001f));
+ assert(approxEqual(Math.min(ff, -5.0f), -5.0f, 0.001f));
+ assert(approxEqual(Math.max(ff, -5.0f), ff, 0.001f));
+
+ assert(approxEqual(Math.abs(dd), dd, 0.001));
+ assert(approxEqual(Math.abs(-dd), dd, 0.001));
+ assert(approxEqual(Math.min(dd, -5.0), -5.0, 0.001));
+ assert(approxEqual(Math.max(dd, -5.0), dd, 0.001));
+
+ double sq = Math.sqrt(dd);
+ assert(approxEqual(sq*sq, dd, 0.001));
+
+ assert(approxEqual(0.5403023058681398, Math.cos(1.0), 0.00000001));
+ assert(approxEqual(0.8414709848078965, Math.sin(1.0), 0.00000001));
+ }
+
public static void run() {
convTest();
@@ -287,6 +331,8 @@ public class FloatMath {
unopTest(123.456f);
checkConsts();
+
+ jlmTests(3.14159f, 123456.78987654321);
}
}
diff --git a/tests/003-omnibus-opcodes/src/IntMath.java b/tests/003-omnibus-opcodes/src/IntMath.java
index 126bec6cd..d5ac744b8 100644
--- a/tests/003-omnibus-opcodes/src/IntMath.java
+++ b/tests/003-omnibus-opcodes/src/IntMath.java
@@ -432,6 +432,25 @@ public class IntMath {
assert(huge == 0x9922334455667788L); // const-wide
}
+ /*
+ * Test some java.lang.Math functions.
+ *
+ * The method arguments are positive values.
+ */
+ static void jlmTests(int ii, long ll) {
+ System.out.println("IntMath.jlmTests");
+
+ assert(Math.abs(ii) == ii);
+ assert(Math.abs(-ii) == ii);
+ assert(Math.min(ii, -5) == -5);
+ assert(Math.max(ii, -5) == ii);
+
+ assert(Math.abs(ll) == ll);
+ assert(Math.abs(-ll) == ll);
+ assert(Math.min(ll, -5L) == -5L);
+ assert(Math.max(ll, -5L) == ll);
+ }
+
public static void run() {
shiftTest1();
shiftTest2();
@@ -467,6 +486,8 @@ public class IntMath {
checkConsts((byte) 1, (short) -256, -88888, 0x9922334455667788L);
unopCheck(unopTest(38));
+
+ jlmTests(12345, 0x1122334455667788L);
}
}