Skip to content

Commit 79b7c01

Browse files
committed
make getValueFromMask more efficient
1 parent c0a5e43 commit 79b7c01

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -737,14 +737,12 @@ class HexagonMCInstrAnalysis : public MCInstrAnalysis {
737737

738738
uint32_t getValueFromMask(uint32_t Instruction, uint32_t Mask) const {
739739
uint32_t Result = 0;
740-
size_t Off = 0;
741-
for (uint32_t Bit = 0; Bit != sizeof(uint32_t) * CHAR_BIT; ++Bit) {
742-
const uint8_t ValBit = (Instruction >> Bit) & 1;
743-
const bool MaskBit = (Mask >> Bit) & 1;
744-
if (MaskBit) {
745-
Result |= (ValBit << Off);
746-
++Off;
747-
}
740+
uint32_t Offset = 0;
741+
while (Mask) {
742+
if (Instruction & (Mask & -Mask))
743+
Result |= (1 << Offset);
744+
Mask &= (Mask - 1);
745+
++Offset;
748746
}
749747
return Result;
750748
}

0 commit comments

Comments
 (0)