Fix warnings building linux-atomic.c and fptr.c on hppa64-linux
[official-gcc.git] / gcc / wide-int-bitmask.h
blob763d0f686449e3c2c87fe4e0e62b98ab7fd0321d
1 /* Operation with 128 bit bitmask.
2 Copyright (C) 2013-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_WIDE_INT_BITMASK_H
21 #define GCC_WIDE_INT_BITMASK_H
23 class wide_int_bitmask
25 public:
26 constexpr wide_int_bitmask ();
27 constexpr wide_int_bitmask (uint64_t l);
28 constexpr wide_int_bitmask (uint64_t l, uint64_t h);
29 inline wide_int_bitmask &operator &= (wide_int_bitmask);
30 inline wide_int_bitmask &operator |= (wide_int_bitmask);
31 constexpr wide_int_bitmask operator ~ () const;
32 constexpr wide_int_bitmask operator & (wide_int_bitmask) const;
33 constexpr wide_int_bitmask operator | (wide_int_bitmask) const;
34 inline wide_int_bitmask operator >> (int);
35 inline wide_int_bitmask operator << (int);
36 inline bool operator == (wide_int_bitmask) const;
37 inline bool operator != (wide_int_bitmask) const;
38 uint64_t low, high;
41 constexpr
42 wide_int_bitmask::wide_int_bitmask ()
43 : low (0), high (0)
47 constexpr
48 wide_int_bitmask::wide_int_bitmask (uint64_t l)
49 : low (l), high (0)
53 constexpr
54 wide_int_bitmask::wide_int_bitmask (uint64_t l, uint64_t h)
55 : low (l), high (h)
59 inline wide_int_bitmask &
60 wide_int_bitmask::operator &= (wide_int_bitmask b)
62 low &= b.low;
63 high &= b.high;
64 return *this;
67 inline wide_int_bitmask &
68 wide_int_bitmask::operator |= (wide_int_bitmask b)
70 low |= b.low;
71 high |= b.high;
72 return *this;
75 constexpr wide_int_bitmask
76 wide_int_bitmask::operator ~ () const
78 return wide_int_bitmask (~low, ~high);
81 constexpr wide_int_bitmask
82 wide_int_bitmask::operator | (wide_int_bitmask b) const
84 return wide_int_bitmask (low | b.low, high | b.high);
87 constexpr wide_int_bitmask
88 wide_int_bitmask::operator & (wide_int_bitmask b) const
90 return wide_int_bitmask (low & b.low, high & b.high);
93 inline wide_int_bitmask
94 wide_int_bitmask::operator << (int amount)
96 wide_int_bitmask ret;
97 if (amount >= 64)
99 ret.low = 0;
100 ret.high = low << (amount - 64);
102 else if (amount == 0)
103 ret = *this;
104 else
106 ret.low = low << amount;
107 ret.high = (low >> (64 - amount)) | (high << amount);
109 return ret;
112 inline wide_int_bitmask
113 wide_int_bitmask::operator >> (int amount)
115 wide_int_bitmask ret;
116 if (amount >= 64)
118 ret.low = high >> (amount - 64);
119 ret.high = 0;
121 else if (amount == 0)
122 ret = *this;
123 else
125 ret.low = (high << (64 - amount)) | (low >> amount);
126 ret.high = high >> amount;
128 return ret;
131 inline bool
132 wide_int_bitmask::operator == (wide_int_bitmask b) const
134 return low == b.low && high == b.high;
137 inline bool
138 wide_int_bitmask::operator != (wide_int_bitmask b) const
140 return low != b.low || high != b.high;
143 #endif /* ! GCC_WIDE_INT_BITMASK_H */