reglist.h 1.18 KB
Newer Older
1 2 3 4
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_CODEGEN_REGLIST_H_
#define V8_CODEGEN_REGLIST_H_
7

8 9 10
#include <cstdint>

#include "src/base/bits.h"
11
#include "src/base/template-utils.h"
12

13 14 15 16 17
namespace v8 {
namespace internal {

// Register configurations.
#if V8_TARGET_ARCH_ARM64
18
using RegList = uint64_t;
19
#else
20
using RegList = uint32_t;
21 22 23
#endif

// Get the number of registers in a given register list.
24 25 26 27
constexpr int NumRegs(RegList list) {
  return base::bits::CountPopulation(list);
}

28
namespace detail {
29
// Combine two RegLists by building the union of the contained registers.
30 31 32 33 34
// TODO(clemensb): Replace by constexpr lambda once we have C++17.
constexpr RegList CombineRegListsHelper(RegList list1, RegList list2) {
  return list1 | list2;
}
}  // namespace detail
35 36 37 38

// Combine several RegLists by building the union of the contained registers.
template <typename... RegLists>
constexpr RegList CombineRegLists(RegLists... lists) {
39
  return base::fold(detail::CombineRegListsHelper, 0, lists...);
40
}
41 42 43 44

}  // namespace internal
}  // namespace v8

45
#endif  // V8_CODEGEN_REGLIST_H_