Jit: Minor codegen tuning.
diff --git a/vm/compiler/codegen/arm/CodegenDriver.c b/vm/compiler/codegen/arm/CodegenDriver.c
index 5b4e83f..99d392d 100644
--- a/vm/compiler/codegen/arm/CodegenDriver.c
+++ b/vm/compiler/codegen/arm/CodegenDriver.c
@@ -1835,6 +1835,22 @@
return false;
}
+/* Positive power of 2? Return shiftCount if so, -1 if not */
+static int mulToShift(int val) {
+ int shiftCount;
+ if (val > 0 && ((val & (val - 1)) == 0)) {
+ shiftCount = 0;
+ val = ~val & (val - 1);
+ while (val) {
+ shiftCount++;
+ val >>= 1;
+ }
+ } else {
+ shiftCount = -1;
+ }
+ return shiftCount;
+}
+
static bool handleFmt22b_Fmt22s(CompilationUnit *cUnit, MIR *mir)
{
OpCode dalvikOpCode = mir->dalvikInsn.opCode;
@@ -1870,9 +1886,18 @@
op = kOpAdd;
break;
case OP_MUL_INT_LIT8:
- case OP_MUL_INT_LIT16:
- op = kOpMul;
+ case OP_MUL_INT_LIT16: {
+ // TUNING: General shift & add for small constants
+ int shiftCount = mulToShift(lit);
+ if (shiftCount >= 0) {
+ op = kOpLsl;
+ lit = shiftCount;
+ shiftOp = true;
+ } else {
+ op = kOpMul;
+ }
break;
+ }
case OP_AND_INT_LIT8:
case OP_AND_INT_LIT16:
op = kOpAnd;