summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/interpreter/unstarted_runtime.cc20
-rw-r--r--runtime/interpreter/unstarted_runtime_list.h1
2 files changed, 17 insertions, 4 deletions
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index 4615ec9aa4..80ffedcaa0 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -524,9 +524,7 @@ void UnstartedRuntime::UnstartedThreadLocalGet(
}
}
-void UnstartedRuntime::UnstartedMathCeil(
- Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
- double in = shadow_frame->GetVRegDouble(arg_offset);
+static double ComputeCeil(double in) {
double out;
// Special cases:
// 1) NaN, infinity, +0, -0 -> out := in. All are guaranteed by cmath.
@@ -536,7 +534,21 @@ void UnstartedRuntime::UnstartedMathCeil(
} else {
out = ceil(in);
}
- result->SetD(out);
+ return out;
+}
+
+void UnstartedRuntime::UnstartedMathCeil(
+ Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
+ double in = shadow_frame->GetVRegDouble(arg_offset);
+ result->SetD(ComputeCeil(in));
+}
+
+void UnstartedRuntime::UnstartedMathFloor(
+ Thread* self ATTRIBUTE_UNUSED, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) {
+ double in = shadow_frame->GetVRegDouble(arg_offset);
+ // From the JavaDocs:
+ // "Note that the value of Math.ceil(x) is exactly the value of -Math.floor(-x)."
+ result->SetD(-ComputeCeil(-in));
}
void UnstartedRuntime::UnstartedObjectHashCode(
diff --git a/runtime/interpreter/unstarted_runtime_list.h b/runtime/interpreter/unstarted_runtime_list.h
index a3ed5581f0..3312701135 100644
--- a/runtime/interpreter/unstarted_runtime_list.h
+++ b/runtime/interpreter/unstarted_runtime_list.h
@@ -36,6 +36,7 @@
V(SystemGetSecurityManager, "java.lang.SecurityManager java.lang.System.getSecurityManager()") \
V(ThreadLocalGet, "java.lang.Object java.lang.ThreadLocal.get()") \
V(MathCeil, "double java.lang.Math.ceil(double)") \
+ V(MathFloor, "double java.lang.Math.floor(double)") \
V(ObjectHashCode, "int java.lang.Object.hashCode()") \
V(DoubleDoubleToRawLongBits, "long java.lang.Double.doubleToRawLongBits(double)") \
V(DexCacheGetDexNative, "com.android.dex.Dex java.lang.DexCache.getDexNative()") \