Skip to content

Commit deacfaa

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Fix constexpr issues in Jit/codegen/arch/aarch64.h
Summary: Mostly copying what we already did for Jit/codegen/arch/x86_64.h. Reviewed By: mpage Differential Revision: D96043353 fbshipit-source-id: f682597471dc22391f19252beadc1ff32d624bdc
1 parent 0f5e70f commit deacfaa

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

cinderx/Jit/codegen/arch/aarch64.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <fmt/format.h>
99

1010
#include <array>
11+
#include <bit>
1112
#include <string>
1213
#include <string_view>
1314

@@ -209,8 +210,8 @@ constexpr PhyLocation SP{RegId::SP, 64};
209210

210211
class PhyRegisterSet {
211212
public:
212-
constexpr PhyRegisterSet() : rs_(0ULL) {}
213-
explicit constexpr PhyRegisterSet(PhyLocation r) : rs_(0ULL) {
213+
constexpr PhyRegisterSet() = default;
214+
explicit constexpr PhyRegisterSet(PhyLocation r) {
214215
rs_ |= (1ULL << r.loc);
215216
}
216217

@@ -255,16 +256,15 @@ class PhyRegisterSet {
255256
return rs_ == 0ULL;
256257
}
257258

258-
int count() const {
259-
return popcount(rs_);
259+
constexpr int count() const {
260+
return std::popcount(rs_);
260261
}
261262

262-
PhyLocation GetFirst() const {
263-
JIT_DCHECK(rs_ != 0, "__builtin_ctzll(0) is undefined");
264-
return __builtin_ctzll(rs_);
263+
constexpr PhyLocation GetFirst() const {
264+
return std::countr_zero(rs_);
265265
}
266266

267-
PhyLocation GetLast() const {
267+
constexpr PhyLocation GetLast() const {
268268
return GetLastBit();
269269
}
270270

@@ -276,25 +276,27 @@ class PhyRegisterSet {
276276
rs_ &= ~(1ULL << GetLastBit());
277277
}
278278

279-
void Set(PhyLocation reg) {
279+
constexpr void Set(PhyLocation reg) {
280280
rs_ |= (1ULL << reg.loc);
281281
}
282-
void Reset(PhyLocation reg) {
282+
283+
constexpr void Reset(PhyLocation reg) {
283284
rs_ &= ~(1ULL << reg.loc);
284285
}
285-
void ResetAll() {
286+
287+
constexpr void ResetAll() {
286288
rs_ = 0ULL;
287289
}
288290

289-
bool Has(PhyLocation reg) const {
291+
constexpr bool Has(PhyLocation reg) const {
290292
return rs_ & (1ULL << reg.loc);
291293
}
292294

293295
private:
294-
uint64_t rs_;
296+
uint64_t rs_{0};
295297

296-
int GetLastBit() const {
297-
return (sizeof(rs_) * CHAR_BIT - 1) - __builtin_clzll(rs_);
298+
constexpr int GetLastBit() const {
299+
return (sizeof(rs_) * CHAR_BIT - 1) - std::countl_zero(rs_);
298300
}
299301
};
300302

0 commit comments

Comments
 (0)