diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index e73477ef980522..8d3628038fc785 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -4185,7 +4185,7 @@ void CodeGen::genCreateAndStoreGCInfo(unsigned codeSize, // -all callee-preserved registers in case of varargs // -saved bool for synchronized methods - int preservedAreaSize = (2 + genCountBits(RBM_ENC_CALLEE_SAVED)) * REGSIZE_BYTES; + int preservedAreaSize = (2 + genCountBits((uint64_t)RBM_ENC_CALLEE_SAVED)) * REGSIZE_BYTES; if (compiler->info.compIsVarArgs) { diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index 6a667a0dc238fc..8d2d223032884a 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -255,18 +255,19 @@ inline regMaskTP genFindLowestReg(regMaskTP value) * A rather simple routine that counts the number of bits in a given number. */ -template -inline unsigned genCountBits(T bits) +inline unsigned genCountBits(uint64_t bits) { - unsigned cnt = 0; + return BitOperations::PopCount(bits); +} - while (bits) - { - cnt++; - bits -= genFindLowestBit(bits); - } +/***************************************************************************** + * + * A rather simple routine that counts the number of bits in a given number. + */ - return cnt; +inline unsigned genCountBits(uint32_t bits) +{ + return BitOperations::PopCount(bits); } /***************************************************************************** diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index dbcd64b7254eec..3749511f903618 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -1741,10 +1741,10 @@ void emitter::emitCheckIGList() } // An IG can have at most one of the prolog and epilog flags set. - assert(genCountBits(currIG->igFlags & (IGF_FUNCLET_PROLOG | IGF_FUNCLET_EPILOG | IGF_EPILOG)) <= 1); + assert(genCountBits((unsigned)currIG->igFlags & (IGF_FUNCLET_PROLOG | IGF_FUNCLET_EPILOG | IGF_EPILOG)) <= 1); // An IG can't have both IGF_HAS_ALIGN and IGF_REMOVED_ALIGN. - assert(genCountBits(currIG->igFlags & (IGF_HAS_ALIGN | IGF_REMOVED_ALIGN)) <= 1); + assert(genCountBits((unsigned)currIG->igFlags & (IGF_HAS_ALIGN | IGF_REMOVED_ALIGN)) <= 1); if (currIG->igFlags & IGF_EXTEND) {