From f3aac973bb944885a1a4779ba04a97faa88b7ed0 Mon Sep 17 00:00:00 2001 From: buzbee Date: Wed, 11 Apr 2012 16:33:36 -0700 Subject: Special case division by small constants Do the standard reciprocal multiply trick for small division by small constants. Change-Id: Iad1060ccdc6ffeb7b47d45c29ba741683ad01ab9 --- src/compiler/codegen/GenCommon.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/compiler/codegen/GenCommon.cc') diff --git a/src/compiler/codegen/GenCommon.cc b/src/compiler/codegen/GenCommon.cc index 066c37cacd..71fd33cc56 100644 --- a/src/compiler/codegen/GenCommon.cc +++ b/src/compiler/codegen/GenCommon.cc @@ -27,6 +27,8 @@ void genInvoke(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, InvokeType type, bool isRange); #if defined(TARGET_ARM) LIR* opIT(CompilationUnit* cUnit, ArmConditionCode cond, const char* guide); +bool smallLiteralDivide(CompilationUnit* cUnit, Instruction::Code dalvikOpcode, + RegLocation rlSrc, RegLocation rlDest, int lit); #endif void callRuntimeHelperImm(CompilationUnit* cUnit, int helperOffset, int arg0) { @@ -1915,9 +1917,19 @@ int lowestSetBit(unsigned int x) { bool handleEasyDivide(CompilationUnit* cUnit, Instruction::Code dalvikOpcode, RegLocation rlSrc, RegLocation rlDest, int lit) { +#if defined(TARGET_ARM) + // No divide instruction for Arm, so check for more special cases + if (lit < 2) { + return false; + } + if (!isPowerOfTwo(lit)) { + return smallLiteralDivide(cUnit, dalvikOpcode, rlSrc, rlDest, lit); + } +#else if (lit < 2 || !isPowerOfTwo(lit)) { return false; } +#endif int k = lowestSetBit(lit); if (k >= 30) { // Avoid special cases. -- cgit v1.2.3-59-g8ed1b