Permalink
Browse files

Optimize those StrictMath routines that are identical to Math routines.

We can just use the existing Math intinsics.

Bug: 7146208
Change-Id: I9e78d33cf65a5dcc5a7c0133e67bd9c3c1e43f23
  • Loading branch information...
1 parent cfeacbd commit 6986bcfd1cdeafb594203fee605ebed456fe83c3 @enh enh committed Sep 14, 2012
Showing with 75 additions and 58 deletions.
  1. +35 −45 vm/InlineNative.cpp
  2. +8 −1 vm/InlineNative.h
  3. +16 −6 vm/compiler/codegen/arm/CodegenDriver.cpp
  4. +16 −6 vm/compiler/codegen/mips/CodegenDriver.cpp
View
@@ -732,51 +732,41 @@ const InlineOperation gDvmInlineOpsTable[] = {
"Lorg/apache/harmony/dalvik/NativeTestTarget;",
"emptyInlineMethod", "()V" },
- { javaLangString_charAt,
- "Ljava/lang/String;", "charAt", "(I)C" },
- { javaLangString_compareTo,
- "Ljava/lang/String;", "compareTo", "(Ljava/lang/String;)I" },
- { javaLangString_equals,
- "Ljava/lang/String;", "equals", "(Ljava/lang/Object;)Z" },
- { javaLangString_fastIndexOf_II,
- "Ljava/lang/String;", "fastIndexOf", "(II)I" },
- { javaLangString_isEmpty,
- "Ljava/lang/String;", "isEmpty", "()Z" },
- { javaLangString_length,
- "Ljava/lang/String;", "length", "()I" },
-
- { javaLangMath_abs_int,
- "Ljava/lang/Math;", "abs", "(I)I" },
- { javaLangMath_abs_long,
- "Ljava/lang/Math;", "abs", "(J)J" },
- { javaLangMath_abs_float,
- "Ljava/lang/Math;", "abs", "(F)F" },
- { javaLangMath_abs_double,
- "Ljava/lang/Math;", "abs", "(D)D" },
- { javaLangMath_min_int,
- "Ljava/lang/Math;", "min", "(II)I" },
- { javaLangMath_max_int,
- "Ljava/lang/Math;", "max", "(II)I" },
- { javaLangMath_sqrt,
- "Ljava/lang/Math;", "sqrt", "(D)D" },
- { javaLangMath_cos,
- "Ljava/lang/Math;", "cos", "(D)D" },
- { javaLangMath_sin,
- "Ljava/lang/Math;", "sin", "(D)D" },
-
- { javaLangFloat_floatToIntBits,
- "Ljava/lang/Float;", "floatToIntBits", "(F)I" },
- { javaLangFloat_floatToRawIntBits,
- "Ljava/lang/Float;", "floatToRawIntBits", "(F)I" },
- { javaLangFloat_intBitsToFloat,
- "Ljava/lang/Float;", "intBitsToFloat", "(I)F" },
-
- { javaLangDouble_doubleToLongBits,
- "Ljava/lang/Double;", "doubleToLongBits", "(D)J" },
- { javaLangDouble_doubleToRawLongBits,
- "Ljava/lang/Double;", "doubleToRawLongBits", "(D)J" },
- { javaLangDouble_longBitsToDouble,
- "Ljava/lang/Double;", "longBitsToDouble", "(J)D" },
+ { javaLangString_charAt, "Ljava/lang/String;", "charAt", "(I)C" },
+ { javaLangString_compareTo, "Ljava/lang/String;", "compareTo", "(Ljava/lang/String;)I" },
+ { javaLangString_equals, "Ljava/lang/String;", "equals", "(Ljava/lang/Object;)Z" },
+ { javaLangString_fastIndexOf_II, "Ljava/lang/String;", "fastIndexOf", "(II)I" },
+ { javaLangString_isEmpty, "Ljava/lang/String;", "isEmpty", "()Z" },
+ { javaLangString_length, "Ljava/lang/String;", "length", "()I" },
+
+ { javaLangMath_abs_int, "Ljava/lang/Math;", "abs", "(I)I" },
+ { javaLangMath_abs_long, "Ljava/lang/Math;", "abs", "(J)J" },
+ { javaLangMath_abs_float, "Ljava/lang/Math;", "abs", "(F)F" },
+ { javaLangMath_abs_double, "Ljava/lang/Math;", "abs", "(D)D" },
+ { javaLangMath_min_int, "Ljava/lang/Math;", "min", "(II)I" },
+ { javaLangMath_max_int, "Ljava/lang/Math;", "max", "(II)I" },
+ { javaLangMath_sqrt, "Ljava/lang/Math;", "sqrt", "(D)D" },
+ { javaLangMath_cos, "Ljava/lang/Math;", "cos", "(D)D" },
+ { javaLangMath_sin, "Ljava/lang/Math;", "sin", "(D)D" },
+
+ { javaLangFloat_floatToIntBits, "Ljava/lang/Float;", "floatToIntBits", "(F)I" },
+ { javaLangFloat_floatToRawIntBits, "Ljava/lang/Float;", "floatToRawIntBits", "(F)I" },
+ { javaLangFloat_intBitsToFloat, "Ljava/lang/Float;", "intBitsToFloat", "(I)F" },
+
+ { javaLangDouble_doubleToLongBits, "Ljava/lang/Double;", "doubleToLongBits", "(D)J" },
+ { javaLangDouble_doubleToRawLongBits, "Ljava/lang/Double;", "doubleToRawLongBits", "(D)J" },
+ { javaLangDouble_longBitsToDouble, "Ljava/lang/Double;", "longBitsToDouble", "(J)D" },
+
+ // These are implemented exactly the same in Math and StrictMath,
+ // so we can make the StrictMath calls fast too. Note that this
+ // isn't true in general!
+ { javaLangMath_abs_int, "Ljava/lang/StrictMath;", "abs", "(I)I" },
+ { javaLangMath_abs_long, "Ljava/lang/StrictMath;", "abs", "(J)J" },
+ { javaLangMath_abs_float, "Ljava/lang/StrictMath;", "abs", "(F)F" },
+ { javaLangMath_abs_double, "Ljava/lang/StrictMath;", "abs", "(D)D" },
+ { javaLangMath_min_int, "Ljava/lang/StrictMath;", "min", "(II)I" },
+ { javaLangMath_max_int, "Ljava/lang/StrictMath;", "max", "(II)I" },
+ { javaLangMath_sqrt, "Ljava/lang/StrictMath;", "sqrt", "(D)D" },
};
/*
View
@@ -53,7 +53,7 @@ struct InlineOperation {
};
/*
- * Must be kept in sync w/ gDvmInlineOpsTable in InlineNative.c
+ * Must be kept in sync w/ gDvmInlineOpsTable in InlineNative.cpp
*
* You should also add a test to libcore's IntrinsicTest.
*/
@@ -80,6 +80,13 @@ enum NativeInlineOps {
INLINE_DOUBLE_TO_LONG_BITS = 19,
INLINE_DOUBLE_TO_RAW_LONG_BITS = 20,
INLINE_LONG_BITS_TO_DOUBLE = 21,
+ INLINE_STRICT_MATH_ABS_INT = 22,
+ INLINE_STRICT_MATH_ABS_LONG = 23,
+ INLINE_STRICT_MATH_ABS_FLOAT = 24,
+ INLINE_STRICT_MATH_ABS_DOUBLE = 25,
+ INLINE_STRICT_MATH_MIN_INT = 26,
+ INLINE_STRICT_MATH_MAX_INT = 27,
+ INLINE_STRICT_MATH_SQRT = 28,
};
/*
@@ -3645,30 +3645,40 @@ static bool handleExecuteInline(CompilationUnit *cUnit, MIR *mir)
return false; /* Nop */
/* These ones we potentially JIT inline. */
+
+ case INLINE_STRING_CHARAT:
+ return genInlinedStringCharAt(cUnit, mir);
case INLINE_STRING_LENGTH:
return genInlinedStringLength(cUnit, mir);
case INLINE_STRING_IS_EMPTY:
return genInlinedStringIsEmpty(cUnit, mir);
+ case INLINE_STRING_COMPARETO:
+ return genInlinedCompareTo(cUnit, mir);
+ case INLINE_STRING_FASTINDEXOF_II:
+ return genInlinedFastIndexOf(cUnit, mir);
+
case INLINE_MATH_ABS_INT:
+ case INLINE_STRICT_MATH_ABS_INT:
return genInlinedAbsInt(cUnit, mir);
case INLINE_MATH_ABS_LONG:
+ case INLINE_STRICT_MATH_ABS_LONG:
return genInlinedAbsLong(cUnit, mir);
case INLINE_MATH_MIN_INT:
+ case INLINE_STRICT_MATH_MIN_INT:
return genInlinedMinMaxInt(cUnit, mir, true);
case INLINE_MATH_MAX_INT:
+ case INLINE_STRICT_MATH_MAX_INT:
return genInlinedMinMaxInt(cUnit, mir, false);
- case INLINE_STRING_CHARAT:
- return genInlinedStringCharAt(cUnit, mir);
case INLINE_MATH_SQRT:
+ case INLINE_STRICT_MATH_SQRT:
return genInlineSqrt(cUnit, mir);
case INLINE_MATH_ABS_FLOAT:
+ case INLINE_STRICT_MATH_ABS_FLOAT:
return genInlinedAbsFloat(cUnit, mir);
case INLINE_MATH_ABS_DOUBLE:
+ case INLINE_STRICT_MATH_ABS_DOUBLE:
return genInlinedAbsDouble(cUnit, mir);
- case INLINE_STRING_COMPARETO:
- return genInlinedCompareTo(cUnit, mir);
- case INLINE_STRING_FASTINDEXOF_II:
- return genInlinedFastIndexOf(cUnit, mir);
+
case INLINE_FLOAT_TO_RAW_INT_BITS:
case INLINE_INT_BITS_TO_FLOAT:
return genInlinedIntFloatConversion(cUnit, mir);
@@ -3777,30 +3777,40 @@ static bool handleExecuteInline(CompilationUnit *cUnit, MIR *mir)
return false; /* Nop */
/* These ones we potentially JIT inline. */
+
+ case INLINE_STRING_CHARAT:
+ return genInlinedStringCharAt(cUnit, mir);
case INLINE_STRING_LENGTH:
return genInlinedStringLength(cUnit, mir);
case INLINE_STRING_IS_EMPTY:
return genInlinedStringIsEmpty(cUnit, mir);
+ case INLINE_STRING_COMPARETO:
+ return genInlinedCompareTo(cUnit, mir);
+ case INLINE_STRING_FASTINDEXOF_II:
+ return genInlinedFastIndexOf(cUnit, mir);
+
case INLINE_MATH_ABS_INT:
+ case INLINE_STRICT_MATH_ABS_INT:
return genInlinedAbsInt(cUnit, mir);
case INLINE_MATH_ABS_LONG:
+ case INLINE_STRICT_MATH_ABS_LONG:
return genInlinedAbsLong(cUnit, mir);
case INLINE_MATH_MIN_INT:
+ case INLINE_STRICT_MATH_MIN_INT:
return genInlinedMinMaxInt(cUnit, mir, true);
case INLINE_MATH_MAX_INT:
+ case INLINE_STRICT_MATH_MAX_INT:
return genInlinedMinMaxInt(cUnit, mir, false);
- case INLINE_STRING_CHARAT:
- return genInlinedStringCharAt(cUnit, mir);
case INLINE_MATH_SQRT:
+ case INLINE_STRICT_MATH_SQRT:
return genInlineSqrt(cUnit, mir);
case INLINE_MATH_ABS_FLOAT:
+ case INLINE_STRICT_MATH_ABS_FLOAT:
return genInlinedAbsFloat(cUnit, mir);
case INLINE_MATH_ABS_DOUBLE:
+ case INLINE_STRICT_MATH_ABS_DOUBLE:
return genInlinedAbsDouble(cUnit, mir);
- case INLINE_STRING_COMPARETO:
- return genInlinedCompareTo(cUnit, mir);
- case INLINE_STRING_FASTINDEXOF_II:
- return genInlinedFastIndexOf(cUnit, mir);
+
case INLINE_FLOAT_TO_RAW_INT_BITS:
case INLINE_INT_BITS_TO_FLOAT:
return genInlinedIntFloatConversion(cUnit, mir);

0 comments on commit 6986bcf

Please sign in to comment.