1 /* Operation with 128 bit bitmask. 2 Copyright (C) 2013-2018 Free Software Foundation, Inc. 3 4 This file is part of GCC. 5 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. 10 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. 15 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/>. */ 19 20 #ifndef GCC_WIDE_INT_BITMASK_H 21 #define GCC_WIDE_INT_BITMASK_H 22 23 struct wide_int_bitmask 24 { 25 inline wide_int_bitmask (); 26 inline wide_int_bitmask (uint64_t l); 27 inline wide_int_bitmask (uint64_t l, uint64_t h); 28 inline wide_int_bitmask &operator &= (wide_int_bitmask); 29 inline wide_int_bitmask &operator |= (wide_int_bitmask); 30 inline wide_int_bitmask operator ~ () const; 31 inline wide_int_bitmask operator & (wide_int_bitmask) const; 32 inline wide_int_bitmask operator | (wide_int_bitmask) const; 33 inline wide_int_bitmask operator >> (int); 34 inline wide_int_bitmask operator << (int); 35 inline bool operator == (wide_int_bitmask) const; 36 inline bool operator != (wide_int_bitmask) const; 37 uint64_t low, high; 38 }; 39 40 inline 41 wide_int_bitmask::wide_int_bitmask () 42 : low (0), high (0) 43 { 44 } 45 46 inline 47 wide_int_bitmask::wide_int_bitmask (uint64_t l) 48 : low (l), high (0) 49 { 50 } 51 52 inline 53 wide_int_bitmask::wide_int_bitmask (uint64_t l, uint64_t h) 54 : low (l), high (h) 55 { 56 } 57 58 inline wide_int_bitmask & 59 wide_int_bitmask::operator &= (wide_int_bitmask b) 60 { 61 low &= b.low; 62 high &= b.high; 63 return *this; 64 } 65 66 inline wide_int_bitmask & 67 wide_int_bitmask::operator |= (wide_int_bitmask b) 68 { 69 low |= b.low; 70 high |= b.high; 71 return *this; 72 } 73 74 inline wide_int_bitmask 75 wide_int_bitmask::operator ~ () const 76 { 77 wide_int_bitmask ret (~low, ~high); 78 return ret; 79 } 80 81 inline wide_int_bitmask 82 wide_int_bitmask::operator | (wide_int_bitmask b) const 83 { 84 wide_int_bitmask ret (low | b.low, high | b.high); 85 return ret; 86 } 87 88 inline wide_int_bitmask 89 wide_int_bitmask::operator & (wide_int_bitmask b) const 90 { 91 wide_int_bitmask ret (low & b.low, high & b.high); 92 return ret; 93 } 94 95 inline wide_int_bitmask 96 wide_int_bitmask::operator << (int amount) 97 { 98 wide_int_bitmask ret; 99 if (amount >= 64) 100 { 101 ret.low = 0; 102 ret.high = low << (amount - 64); 103 } 104 else if (amount == 0) 105 ret = *this; 106 else 107 { 108 ret.low = low << amount; 109 ret.high = (low >> (64 - amount)) | (high << amount); 110 } 111 return ret; 112 } 113 114 inline wide_int_bitmask 115 wide_int_bitmask::operator >> (int amount) 116 { 117 wide_int_bitmask ret; 118 if (amount >= 64) 119 { 120 ret.low = high >> (amount - 64); 121 ret.high = 0; 122 } 123 else if (amount == 0) 124 ret = *this; 125 else 126 { 127 ret.low = (high << (64 - amount)) | (low >> amount); 128 ret.high = high >> amount; 129 } 130 return ret; 131 } 132 133 inline bool 134 wide_int_bitmask::operator == (wide_int_bitmask b) const 135 { 136 return low == b.low && high == b.high; 137 } 138 139 inline bool 140 wide_int_bitmask::operator != (wide_int_bitmask b) const 141 { 142 return low != b.low || high != b.high; 143 } 144 145 #endif /* ! GCC_WIDE_INT_BITMASK_H */ 146