[llvm] Use llvm::Log2_64 (NFC)
authorKazu Hirata <kazu@google.com>
Sat, 28 Jan 2023 19:20:47 +0000 (11:20 -0800)
committerKazu Hirata <kazu@google.com>
Sat, 28 Jan 2023 19:20:47 +0000 (11:20 -0800)
llvm/include/llvm/MCA/Support.h
llvm/include/llvm/Support/ScaledNumber.h
llvm/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp

index 1debf37..e5e6278 100644 (file)
@@ -99,7 +99,7 @@ void computeProcResourceMasks(const MCSchedModel &SM,
 // the highest bit set can be used to construct a resource mask identifier.
 inline unsigned getResourceStateIndex(uint64_t Mask) {
   assert(Mask && "Processor Resource Mask cannot be zero!");
-  return (std::numeric_limits<uint64_t>::digits - countLeadingZeros(Mask)) - 1;
+  return llvm::Log2_64(Mask);
 }
 
 /// Compute the reciprocal block throughput from a set of processor resource
index a5261e4..ea01ff6 100644 (file)
@@ -192,7 +192,8 @@ inline std::pair<int32_t, int> getLgImpl(DigitsT Digits, int16_t Scale) {
     return std::make_pair(INT32_MIN, 0);
 
   // Get the floor of the lg of Digits.
-  int32_t LocalFloor = sizeof(Digits) * 8 - countLeadingZeros(Digits) - 1;
+  static_assert(sizeof(Digits) <= sizeof(uint64_t));
+  int32_t LocalFloor = llvm::Log2_64(Digits);
 
   // Get the actual floor.
   int32_t Floor = Scale + LocalFloor;
index 01a4498..a4fe81b 100644 (file)
@@ -1701,7 +1701,7 @@ getBitfieldInvertedMaskOpValue(const MCInst &MI, unsigned Op,
   const MCOperand &MO = MI.getOperand(Op);
   uint32_t v = ~MO.getImm();
   uint32_t lsb = llvm::countr_zero(v);
-  uint32_t msb = (32 - llvm::countl_zero(v)) - 1;
+  uint32_t msb = llvm::Log2_32(v);
   assert(v != 0 && lsb < 32 && msb < 32 && "Illegal bitfield mask!");
   return lsb | (msb << 5);
 }