• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef ANDROID_VINTF_ARCH_H
19 #define ANDROID_VINTF_ARCH_H
20 
21 #include <stdint.h>
22 #include <string>
23 #include <array>
24 
25 namespace android {
26 namespace vintf {
27 
28 enum class Arch : size_t {
29     ARCH_EMPTY = 0,
30     ARCH_32,
31     ARCH_64,
32     ARCH_32_64
33 };
34 
35 static const std::array<std::string, 4> gArchStrings = {
36     {
37         "",
38         "32",
39         "64",
40         "32+64",
41     }
42 };
43 
has32(Arch arch)44 inline bool has32(Arch arch) {
45     return arch == Arch::ARCH_32 || arch == Arch::ARCH_32_64;
46 }
47 
has64(Arch arch)48 inline bool has64(Arch arch) {
49     return arch == Arch::ARCH_64 || arch == Arch::ARCH_32_64;
50 }
51 
52 inline constexpr Arch operator|(Arch lft, Arch rgt) {
53     return static_cast<Arch>(static_cast<size_t>(lft) | static_cast<size_t>(rgt));
54 }
55 static_assert((Arch::ARCH_32 | Arch::ARCH_64) == Arch::ARCH_32_64, "bad Arch::operator|");
56 
57 inline Arch& operator|=(Arch& lft, Arch rgt) {
58     return (lft = lft | rgt);
59 }
60 
61 // Returns true if lft defines all bitnesses in rgt, otherwise false.
contains(Arch lft,Arch rgt)62 inline constexpr bool contains(Arch lft, Arch rgt) {
63     return !(~static_cast<size_t>(lft) & static_cast<size_t>(rgt));
64 }
65 
66 static_assert(contains(Arch::ARCH_32_64, Arch::ARCH_32_64), "bad contains(Arch, Arch)");
67 static_assert(contains(Arch::ARCH_32_64, Arch::ARCH_64), "bad contains(Arch, Arch)");
68 static_assert(contains(Arch::ARCH_32_64, Arch::ARCH_32), "bad contains(Arch, Arch)");
69 static_assert(contains(Arch::ARCH_32_64, Arch::ARCH_EMPTY), "bad contains(Arch, Arch)");
70 static_assert(contains(Arch::ARCH_32, Arch::ARCH_EMPTY), "bad contains(Arch, Arch)");
71 static_assert(contains(Arch::ARCH_64, Arch::ARCH_EMPTY), "bad contains(Arch, Arch)");
72 static_assert(!contains(Arch::ARCH_32, Arch::ARCH_32_64), "bad contains(Arch, Arch)");
73 static_assert(!contains(Arch::ARCH_64, Arch::ARCH_32_64), "bad contains(Arch, Arch)");
74 static_assert(!contains(Arch::ARCH_32, Arch::ARCH_64), "bad contains(Arch, Arch)");
75 static_assert(!contains(Arch::ARCH_64, Arch::ARCH_32), "bad contains(Arch, Arch)");
76 static_assert(!contains(Arch::ARCH_EMPTY, Arch::ARCH_32), "bad contains(Arch, Arch)");
77 static_assert(!contains(Arch::ARCH_EMPTY, Arch::ARCH_64), "bad contains(Arch, Arch)");
78 
79 } // namespace vintf
80 } // namespace android
81 
82 #endif // ANDROID_VINTF_ARCH_H
83