diff --git a/src/codegen/register.h b/src/codegen/register.h index 49f67ceb1d..fea609e4db 100644 --- a/src/codegen/register.h +++ b/src/codegen/register.h @@ -5,6 +5,7 @@ #ifndef V8_CODEGEN_REGISTER_H_ #define V8_CODEGEN_REGISTER_H_ +#include "src/base/bits.h" #include "src/base/bounds.h" #include "src/codegen/reglist.h" @@ -53,6 +54,13 @@ class RegisterBase { return is_valid() ? RegList{1} << code() : RegList{}; } + static constexpr SubType TakeAny(RegList* list) { + RegList& value = *list; + SubType result = from_code(base::bits::CountTrailingZerosNonZero(value)); + *list = value & (value - 1); + return result; + } + inline constexpr bool operator==(SubType other) const { return reg_code_ == other.reg_code_; } diff --git a/src/codegen/reglist.h b/src/codegen/reglist.h index 4f1d35267d..99f6458dcf 100644 --- a/src/codegen/reglist.h +++ b/src/codegen/reglist.h @@ -20,6 +20,8 @@ using RegList = uint64_t; using RegList = uint32_t; #endif +constexpr RegList kEmptyRegList = 0; + // Get the number of registers in a given register list. constexpr int NumRegs(RegList list) { return base::bits::CountPopulation(list); diff --git a/src/maglev/maglev-ir.cc b/src/maglev/maglev-ir.cc index 954e459d8a..8028c8d3ba 100644 --- a/src/maglev/maglev-ir.cc +++ b/src/maglev/maglev-ir.cc @@ -497,8 +497,8 @@ void CheckMaps::GenerateCode(MaglevCodeGenState* code_gen_state, const ProcessingState& state) { Register object = ToRegister(actual_map_input()); RegList temps = temporaries(); - Register map_tmp = - Register::from_code(base::bits::CountTrailingZerosNonZero(temps)); + Register map_tmp = Register::TakeAny(&temps); + DCHECK_EQ(kEmptyRegList, temps); __ LoadMap(map_tmp, object); __ Cmp(map_tmp, map().object());