Home | History | Annotate | Download | only in src
      1 // Copyright 2017 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef V8_REGLIST_H_
      6 #define V8_REGLIST_H_
      7 
      8 #include <cstdint>
      9 
     10 #include "src/base/bits.h"
     11 #include "src/base/template-utils.h"
     12 
     13 namespace v8 {
     14 namespace internal {
     15 
     16 // Register configurations.
     17 #if V8_TARGET_ARCH_ARM64
     18 typedef uint64_t RegList;
     19 #else
     20 typedef uint32_t RegList;
     21 #endif
     22 
     23 // Get the number of registers in a given register list.
     24 constexpr int NumRegs(RegList list) {
     25   return base::bits::CountPopulation(list);
     26 }
     27 
     28 // Combine two RegLists by building the union of the contained registers.
     29 // Implemented as a Functor to pass it to base::fold even on gcc < 5 (see
     30 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52892).
     31 // TODO(clemensh): Remove this once we require gcc >= 5.0.
     32 struct CombineRegListsFunctor {
     33   constexpr RegList operator()(RegList list1, RegList list2) const {
     34     return list1 | list2;
     35   }
     36 };
     37 
     38 // Combine several RegLists by building the union of the contained registers.
     39 template <typename... RegLists>
     40 constexpr RegList CombineRegLists(RegLists... lists) {
     41   return base::fold(CombineRegListsFunctor{}, 0, lists...);
     42 }
     43 
     44 }  // namespace internal
     45 }  // namespace v8
     46 
     47 #endif  // V8_REGLIST_H_
     48