Merge "Revert "Replacing FloatMath native implementation with calls to Math""
This commit is contained in:
@ -17,13 +17,10 @@
|
|||||||
package android.util;
|
package android.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Math routines similar to those found in {@link java.lang.Math}.
|
* Math routines similar to those found in {@link java.lang.Math}. On
|
||||||
*
|
* versions of Android with a JIT, these are significantly slower than
|
||||||
* <p>Historically these methods were faster than the equivalent double-based
|
* the equivalent {@code Math} functions, which should be used in preference
|
||||||
* {@link java.lang.Math} methods. On versions of Android with a JIT they
|
* to these.
|
||||||
* became slower and have since been re-implemented to wrap calls to
|
|
||||||
* {@link java.lang.Math}. {@link java.lang.Math} should be used in
|
|
||||||
* preference.
|
|
||||||
*/
|
*/
|
||||||
public class FloatMath {
|
public class FloatMath {
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ LOCAL_SRC_FILES:= \
|
|||||||
android_util_Binder.cpp \
|
android_util_Binder.cpp \
|
||||||
android_util_EventLog.cpp \
|
android_util_EventLog.cpp \
|
||||||
android_util_Log.cpp \
|
android_util_Log.cpp \
|
||||||
|
android_util_FloatMath.cpp \
|
||||||
android_util_Process.cpp \
|
android_util_Process.cpp \
|
||||||
android_util_StringBlock.cpp \
|
android_util_StringBlock.cpp \
|
||||||
android_util_XmlBlock.cpp \
|
android_util_XmlBlock.cpp \
|
||||||
|
@ -90,6 +90,8 @@ extern int register_android_media_AudioTrack(JNIEnv *env);
|
|||||||
extern int register_android_media_JetPlayer(JNIEnv *env);
|
extern int register_android_media_JetPlayer(JNIEnv *env);
|
||||||
extern int register_android_media_ToneGenerator(JNIEnv *env);
|
extern int register_android_media_ToneGenerator(JNIEnv *env);
|
||||||
|
|
||||||
|
extern int register_android_util_FloatMath(JNIEnv* env);
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1227,6 +1229,7 @@ static const RegJNIRec gRegJNI[] = {
|
|||||||
REG_JNI(register_android_os_SystemClock),
|
REG_JNI(register_android_os_SystemClock),
|
||||||
REG_JNI(register_android_util_EventLog),
|
REG_JNI(register_android_util_EventLog),
|
||||||
REG_JNI(register_android_util_Log),
|
REG_JNI(register_android_util_Log),
|
||||||
|
REG_JNI(register_android_util_FloatMath),
|
||||||
REG_JNI(register_android_content_AssetManager),
|
REG_JNI(register_android_content_AssetManager),
|
||||||
REG_JNI(register_android_content_StringBlock),
|
REG_JNI(register_android_content_StringBlock),
|
||||||
REG_JNI(register_android_content_XmlBlock),
|
REG_JNI(register_android_content_XmlBlock),
|
||||||
|
61
core/jni/android_util_FloatMath.cpp
Normal file
61
core/jni/android_util_FloatMath.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "jni.h"
|
||||||
|
#include <android_runtime/AndroidRuntime.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include "SkTypes.h"
|
||||||
|
|
||||||
|
class MathUtilsGlue {
|
||||||
|
public:
|
||||||
|
static float FloorF(JNIEnv* env, jobject clazz, float x) {
|
||||||
|
return floorf(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float CeilF(JNIEnv* env, jobject clazz, float x) {
|
||||||
|
return ceilf(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float SinF(JNIEnv* env, jobject clazz, float x) {
|
||||||
|
return sinf(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float CosF(JNIEnv* env, jobject clazz, float x) {
|
||||||
|
return cosf(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float SqrtF(JNIEnv* env, jobject clazz, float x) {
|
||||||
|
return sqrtf(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float ExpF(JNIEnv* env, jobject clazz, float x) {
|
||||||
|
return expf(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float PowF(JNIEnv* env, jobject clazz, float x, float y) {
|
||||||
|
return powf(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static float HypotF(JNIEnv* env, jobject clazz, float x, float y) {
|
||||||
|
return hypotf(x, y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static JNINativeMethod gMathUtilsMethods[] = {
|
||||||
|
{"floor", "(F)F", (void*) MathUtilsGlue::FloorF},
|
||||||
|
{"ceil", "(F)F", (void*) MathUtilsGlue::CeilF},
|
||||||
|
{"sin", "(F)F", (void*) MathUtilsGlue::SinF},
|
||||||
|
{"cos", "(F)F", (void*) MathUtilsGlue::CosF},
|
||||||
|
{"sqrt", "(F)F", (void*) MathUtilsGlue::SqrtF},
|
||||||
|
{"exp", "(F)F", (void*) MathUtilsGlue::ExpF},
|
||||||
|
{"pow", "(FF)F", (void*) MathUtilsGlue::PowF},
|
||||||
|
{"hypot", "(FF)F", (void*) MathUtilsGlue::HypotF},
|
||||||
|
};
|
||||||
|
|
||||||
|
int register_android_util_FloatMath(JNIEnv* env)
|
||||||
|
{
|
||||||
|
int result = android::AndroidRuntime::registerNativeMethods(env,
|
||||||
|
"android/util/FloatMath",
|
||||||
|
gMathUtilsMethods,
|
||||||
|
SK_ARRAY_COUNT(gMathUtilsMethods));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
@ -1,103 +0,0 @@
|
|||||||
package android.util;
|
|
||||||
|
|
||||||
import com.google.caliper.Param;
|
|
||||||
import com.google.caliper.Runner;
|
|
||||||
import com.google.caliper.SimpleBenchmark;
|
|
||||||
|
|
||||||
import android.util.FloatMath;
|
|
||||||
|
|
||||||
import dalvik.system.VMDebug;
|
|
||||||
|
|
||||||
public class FloatMathBenchmark extends SimpleBenchmark {
|
|
||||||
|
|
||||||
public float timeFloatMathCeil(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += FloatMath.ceil(100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathCeil_math(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += (float) Math.ceil(100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathCos(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += FloatMath.cos(100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathExp(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += FloatMath.exp(100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathFloor(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += FloatMath.floor(100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathHypot(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += FloatMath.hypot(100.123f, 100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathPow(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += FloatMath.pow(10.123f, 10.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathSin(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += FloatMath.sin(100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathSqrt(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += FloatMath.sqrt(100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float timeFloatMathSqrt_math(int reps) {
|
|
||||||
// Keep an answer so we don't optimize the method call away.
|
|
||||||
float f = 0.0f;
|
|
||||||
for (int i = 0; i < reps; i++) {
|
|
||||||
f += (float) Math.sqrt(100.123f);
|
|
||||||
}
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user