]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/wide-int-bitmask.h
c++: Handle multiple aggregate overloads [PR95319].
[thirdparty/gcc.git] / gcc / wide-int-bitmask.h
CommitLineData
eece7fe5 1/* Operation with 128 bit bitmask.
8d9254fc 2 Copyright (C) 2013-2020 Free Software Foundation, Inc.
eece7fe5
JK
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_WIDE_INT_BITMASK_H
21#define GCC_WIDE_INT_BITMASK_H
22
6c1dae73 23class wide_int_bitmask
eece7fe5 24{
6c1dae73 25public:
eece7fe5
JK
26 inline wide_int_bitmask ();
27 inline wide_int_bitmask (uint64_t l);
28 inline 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 inline wide_int_bitmask operator ~ () const;
32 inline wide_int_bitmask operator & (wide_int_bitmask) const;
33 inline 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;
39};
40
41inline
42wide_int_bitmask::wide_int_bitmask ()
43: low (0), high (0)
44{
45}
46
47inline
48wide_int_bitmask::wide_int_bitmask (uint64_t l)
49: low (l), high (0)
50{
51}
52
53inline
54wide_int_bitmask::wide_int_bitmask (uint64_t l, uint64_t h)
55: low (l), high (h)
56{
57}
58
59inline wide_int_bitmask &
60wide_int_bitmask::operator &= (wide_int_bitmask b)
61{
62 low &= b.low;
63 high &= b.high;
64 return *this;
65}
66
67inline wide_int_bitmask &
68wide_int_bitmask::operator |= (wide_int_bitmask b)
69{
70 low |= b.low;
71 high |= b.high;
72 return *this;
73}
74
75inline wide_int_bitmask
76wide_int_bitmask::operator ~ () const
77{
78 wide_int_bitmask ret (~low, ~high);
79 return ret;
80}
81
82inline wide_int_bitmask
83wide_int_bitmask::operator | (wide_int_bitmask b) const
84{
85 wide_int_bitmask ret (low | b.low, high | b.high);
86 return ret;
87}
88
89inline wide_int_bitmask
90wide_int_bitmask::operator & (wide_int_bitmask b) const
91{
92 wide_int_bitmask ret (low & b.low, high & b.high);
93 return ret;
94}
95
96inline wide_int_bitmask
97wide_int_bitmask::operator << (int amount)
98{
99 wide_int_bitmask ret;
100 if (amount >= 64)
101 {
102 ret.low = 0;
103 ret.high = low << (amount - 64);
104 }
105 else if (amount == 0)
106 ret = *this;
107 else
108 {
109 ret.low = low << amount;
110 ret.high = (low >> (64 - amount)) | (high << amount);
111 }
112 return ret;
113}
114
115inline wide_int_bitmask
116wide_int_bitmask::operator >> (int amount)
117{
118 wide_int_bitmask ret;
119 if (amount >= 64)
120 {
121 ret.low = high >> (amount - 64);
122 ret.high = 0;
123 }
124 else if (amount == 0)
125 ret = *this;
126 else
127 {
128 ret.low = (high << (64 - amount)) | (low >> amount);
129 ret.high = high >> amount;
130 }
131 return ret;
132}
133
134inline bool
135wide_int_bitmask::operator == (wide_int_bitmask b) const
136{
137 return low == b.low && high == b.high;
138}
139
140inline bool
141wide_int_bitmask::operator != (wide_int_bitmask b) const
142{
143 return low != b.low || high != b.high;
144}
145
146#endif /* ! GCC_WIDE_INT_BITMASK_H */