diff options
author | 2015-01-06 08:28:12 -0800 | |
---|---|---|
committer | 2015-01-06 08:28:12 -0800 | |
commit | 7e499925f8b4da46ae51040e9322690f3df992e6 (patch) | |
tree | a87402560b942959e6762277e630c72810dfa4cc | |
parent | 1e862370ff2c3207afd1b2fc6f77f7ca345643b2 (diff) |
ART: Remove LowestSetBit and IsPowerOfTwo
Remove those functions from Mir2Lir and replace with functionality
from utils.h.
Change-Id: Ieb67092b22d5d460b5241c7c7931c15b9faf2815
-rw-r--r-- | compiler/dex/quick/arm/call_arm.cc | 1 | ||||
-rw-r--r-- | compiler/dex/quick/arm/int_arm.cc | 13 | ||||
-rw-r--r-- | compiler/dex/quick/arm64/int_arm64.cc | 2 | ||||
-rw-r--r-- | compiler/dex/quick/codegen_util.cc | 18 | ||||
-rw-r--r-- | compiler/dex/quick/gen_common.cc | 17 | ||||
-rw-r--r-- | compiler/dex/quick/mir_to_lir.h | 12 | ||||
-rw-r--r-- | compiler/dex/quick/resource_mask.cc | 1 | ||||
-rwxr-xr-x | compiler/dex/quick/x86/int_x86.cc | 7 |
8 files changed, 24 insertions, 47 deletions
diff --git a/compiler/dex/quick/arm/call_arm.cc b/compiler/dex/quick/arm/call_arm.cc index 99b2166030..0713b7a18e 100644 --- a/compiler/dex/quick/arm/call_arm.cc +++ b/compiler/dex/quick/arm/call_arm.cc @@ -23,6 +23,7 @@ #include "mirror/art_method.h" #include "mirror/object_array-inl.h" #include "entrypoints/quick/quick_entrypoints.h" +#include "utils.h" namespace art { diff --git a/compiler/dex/quick/arm/int_arm.cc b/compiler/dex/quick/arm/int_arm.cc index fe1d12610a..9dd87e6f22 100644 --- a/compiler/dex/quick/arm/int_arm.cc +++ b/compiler/dex/quick/arm/int_arm.cc @@ -23,6 +23,7 @@ #include "dex/reg_storage_eq.h" #include "entrypoints/quick/quick_entrypoints.h" #include "mirror/array-inl.h" +#include "utils.h" namespace art { @@ -569,19 +570,19 @@ bool ArmMir2Lir::SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div bool ArmMir2Lir::GetEasyMultiplyOp(int lit, ArmMir2Lir::EasyMultiplyOp* op) { if (IsPowerOfTwo(lit)) { op->op = kOpLsl; - op->shift = LowestSetBit(lit); + op->shift = CTZ(lit); return true; } if (IsPowerOfTwo(lit - 1)) { op->op = kOpAdd; - op->shift = LowestSetBit(lit - 1); + op->shift = CTZ(lit - 1); return true; } if (IsPowerOfTwo(lit + 1)) { op->op = kOpRsub; - op->shift = LowestSetBit(lit + 1); + op->shift = CTZ(lit + 1); return true; } @@ -599,7 +600,7 @@ bool ArmMir2Lir::GetEasyMultiplyTwoOps(int lit, EasyMultiplyOp* ops) { } int lit1 = lit; - uint32_t shift = LowestSetBit(lit1); + uint32_t shift = CTZ(lit1); if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) { ops[1].op = kOpLsl; ops[1].shift = shift; @@ -607,7 +608,7 @@ bool ArmMir2Lir::GetEasyMultiplyTwoOps(int lit, EasyMultiplyOp* ops) { } lit1 = lit - 1; - shift = LowestSetBit(lit1); + shift = CTZ(lit1); if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) { ops[1].op = kOpAdd; ops[1].shift = shift; @@ -615,7 +616,7 @@ bool ArmMir2Lir::GetEasyMultiplyTwoOps(int lit, EasyMultiplyOp* ops) { } lit1 = lit + 1; - shift = LowestSetBit(lit1); + shift = CTZ(lit1); if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) { ops[1].op = kOpRsub; ops[1].shift = shift; diff --git a/compiler/dex/quick/arm64/int_arm64.cc b/compiler/dex/quick/arm64/int_arm64.cc index 5ac2aa080d..88ab6f82d4 100644 --- a/compiler/dex/quick/arm64/int_arm64.cc +++ b/compiler/dex/quick/arm64/int_arm64.cc @@ -543,7 +543,7 @@ bool Arm64Mir2Lir::HandleEasyDivRem64(Instruction::Code dalvik_opcode, bool is_d return SmallLiteralDivRem(dalvik_opcode, is_div, rl_src, rl_dest, static_cast<int32_t>(lit)); } } - int k = LowestSetBit(lit); + int k = CTZ(lit); if (k >= nbits - 2) { // Avoid special cases. return false; diff --git a/compiler/dex/quick/codegen_util.cc b/compiler/dex/quick/codegen_util.cc index 67ea8972b7..ae9b0f4baf 100644 --- a/compiler/dex/quick/codegen_util.cc +++ b/compiler/dex/quick/codegen_util.cc @@ -1175,24 +1175,6 @@ void Mir2Lir::InsertLIRAfter(LIR* current_lir, LIR* new_lir) { new_lir->next->prev = new_lir; } -bool Mir2Lir::IsPowerOfTwo(uint64_t x) { - return (x & (x - 1)) == 0; -} - -// Returns the index of the lowest set bit in 'x'. -int32_t Mir2Lir::LowestSetBit(uint64_t x) { - int bit_posn = 0; - while ((x & 0xf) == 0) { - bit_posn += 4; - x >>= 4; - } - while ((x & 1) == 0) { - bit_posn++; - x >>= 1; - } - return bit_posn; -} - bool Mir2Lir::PartiallyIntersects(RegLocation rl_src, RegLocation rl_dest) { DCHECK(rl_src.wide); DCHECK(rl_dest.wide); diff --git a/compiler/dex/quick/gen_common.cc b/compiler/dex/quick/gen_common.cc index e8adffb4e5..3733507a50 100644 --- a/compiler/dex/quick/gen_common.cc +++ b/compiler/dex/quick/gen_common.cc @@ -13,6 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#include <functional> + #include "arch/arm/instruction_set_features_arm.h" #include "dex/compiler_ir.h" #include "dex/compiler_internals.h" @@ -23,8 +26,8 @@ #include "mirror/object_array-inl.h" #include "mirror/object-inl.h" #include "mirror/object_reference.h" +#include "utils.h" #include "verifier/method_verifier.h" -#include <functional> namespace art { @@ -1733,7 +1736,7 @@ bool Mir2Lir::HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div, if ((cu_->instruction_set == kThumb2) && !IsPowerOfTwo(lit)) { return SmallLiteralDivRem(dalvik_opcode, is_div, rl_src, rl_dest, lit); } - int k = LowestSetBit(lit); + int k = CTZ(lit); if (k >= 30) { // Avoid special cases. return false; @@ -1813,18 +1816,18 @@ bool Mir2Lir::HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int li RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); if (power_of_two) { // Shift. - OpRegRegImm(kOpLsl, rl_result.reg, rl_src.reg, LowestSetBit(lit)); + OpRegRegImm(kOpLsl, rl_result.reg, rl_src.reg, CTZ(lit)); } else if (pop_count_le2) { // Shift and add and shift. - int first_bit = LowestSetBit(lit); - int second_bit = LowestSetBit(lit ^ (1 << first_bit)); + int first_bit = CTZ(lit); + int second_bit = CTZ(lit ^ (1 << first_bit)); GenMultiplyByTwoBitMultiplier(rl_src, rl_result, lit, first_bit, second_bit); } else { // Reverse subtract: (src << (shift + 1)) - src. DCHECK(power_of_two_minus_one); - // TUNING: rsb dst, src, src lsl#LowestSetBit(lit + 1) + // TUNING: rsb dst, src, src lsl#CTZ(lit + 1) RegStorage t_reg = AllocTemp(); - OpRegRegImm(kOpLsl, t_reg, rl_src.reg, LowestSetBit(lit + 1)); + OpRegRegImm(kOpLsl, t_reg, rl_src.reg, CTZ(lit + 1)); OpRegRegReg(kOpSub, rl_result.reg, t_reg, rl_src.reg); } StoreValue(rl_dest, rl_result); diff --git a/compiler/dex/quick/mir_to_lir.h b/compiler/dex/quick/mir_to_lir.h index f102881ce0..5f8a71c2b7 100644 --- a/compiler/dex/quick/mir_to_lir.h +++ b/compiler/dex/quick/mir_to_lir.h @@ -1482,18 +1482,6 @@ class Mir2Lir : public Backend { return cu_; } /* - * @brief Returns the index of the lowest set bit in 'x'. - * @param x Value to be examined. - * @returns The bit number of the lowest bit set in the value. - */ - int32_t LowestSetBit(uint64_t x); - /* - * @brief Is this value a power of two? - * @param x Value to be examined. - * @returns 'true' if only 1 bit is set in the value. - */ - bool IsPowerOfTwo(uint64_t x); - /* * @brief Do these SRs overlap? * @param rl_op1 One RegLocation * @param rl_op2 The other RegLocation diff --git a/compiler/dex/quick/resource_mask.cc b/compiler/dex/quick/resource_mask.cc index 088bec870e..ca68f95411 100644 --- a/compiler/dex/quick/resource_mask.cc +++ b/compiler/dex/quick/resource_mask.cc @@ -19,6 +19,7 @@ #include "resource_mask.h" #include "utils/arena_allocator.h" +#include "utils.h" namespace art { diff --git a/compiler/dex/quick/x86/int_x86.cc b/compiler/dex/quick/x86/int_x86.cc index a79f2993ee..ba9c611e9b 100755 --- a/compiler/dex/quick/x86/int_x86.cc +++ b/compiler/dex/quick/x86/int_x86.cc @@ -21,6 +21,7 @@ #include "dex/reg_storage_eq.h" #include "mirror/art_method.h" #include "mirror/array-inl.h" +#include "utils.h" #include "x86_lir.h" namespace art { @@ -656,7 +657,7 @@ RegLocation X86Mir2Lir::GenDivRemLit(RegLocation rl_dest, RegLocation rl_src, NewLIR3(kX86Lea32RM, rl_result.reg.GetReg(), rl_src.reg.GetReg(), std::abs(imm) - 1); NewLIR2(kX86Test32RR, rl_src.reg.GetReg(), rl_src.reg.GetReg()); OpCondRegReg(kOpCmov, kCondPl, rl_result.reg, rl_src.reg); - int shift_amount = LowestSetBit(imm); + int shift_amount = CTZ(imm); OpRegImm(kOpAsr, rl_result.reg, shift_amount); if (imm < 0) { OpReg(kOpNeg, rl_result.reg); @@ -1627,7 +1628,7 @@ bool X86Mir2Lir::GenMulLongConst(RegLocation rl_dest, RegLocation rl_src1, int64 GenArithOpLong(Instruction::ADD_LONG, rl_dest, rl_src1, rl_src1, flags); return true; } else if (IsPowerOfTwo(val)) { - int shift_amount = LowestSetBit(val); + int shift_amount = CTZ(val); if (!PartiallyIntersects(rl_src1, rl_dest)) { rl_src1 = LoadValueWide(rl_src1, kCoreReg); RegLocation rl_result = GenShiftImmOpLong(Instruction::SHL_LONG, rl_dest, rl_src1, @@ -2070,7 +2071,7 @@ void X86Mir2Lir::GenDivRemLongLit(RegLocation rl_dest, RegLocation rl_src, OpRegReg(kOpAdd, rl_result.reg, rl_src.reg); NewLIR2(kX86Test64RR, rl_src.reg.GetReg(), rl_src.reg.GetReg()); OpCondRegReg(kOpCmov, kCondPl, rl_result.reg, rl_src.reg); - int shift_amount = LowestSetBit(imm); + int shift_amount = CTZ(imm); OpRegImm(kOpAsr, rl_result.reg, shift_amount); if (imm < 0) { OpReg(kOpNeg, rl_result.reg); |