1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 #ifndef bitSetAsUint64_DEFINED
6 #define bitSetAsUint64_DEFINED 1
10 template <typename Env, typename BitSetTraits>
11 class BitSetOps</*BitSetType*/ UINT64,
14 /*BitSetTraits*/ BitSetTraits>
20 static UINT64 Singleton(unsigned bitNum)
22 assert(bitNum < sizeof(UINT64) * BitSetSupport::BitsInByte);
23 return (UINT64)1 << bitNum;
27 static void Assign(Env env, UINT64& lhs, UINT64 rhs)
32 static void AssignNouninit(Env env, UINT64& lhs, UINT64 rhs)
37 static void AssignAllowUninitRhs(Env env, UINT64& lhs, UINT64 rhs)
42 static void AssignNoCopy(Env env, UINT64& lhs, UINT64 rhs)
47 static void ClearD(Env env, UINT64& bs)
52 static UINT64 MakeSingleton(Env env, unsigned bitNum)
54 assert(bitNum < BitSetTraits::GetSize(env));
55 return Singleton(bitNum);
58 static UINT64 MakeCopy(Env env, UINT64 bs)
63 static bool IsEmpty(Env env, UINT64 bs)
68 static unsigned Count(Env env, UINT64 bs)
70 return BitSetSupport::CountBitsInIntegral(bs);
73 static bool IsEmptyUnion(Env env, UINT64 bs1, UINT64 bs2)
75 return (bs1 | bs2) == 0;
78 static void UnionD(Env env, UINT64& bs1, UINT64 bs2)
83 static UINT64 Union(Env env, UINT64& bs1, UINT64 bs2)
88 static void DiffD(Env env, UINT64& bs1, UINT64 bs2)
93 static UINT64 Diff(Env env, UINT64 bs1, UINT64 bs2)
98 static void RemoveElemD(Env env, UINT64& bs1, unsigned i)
100 assert(i < BitSetTraits::GetSize(env));
101 bs1 &= ~Singleton(i);
104 static UINT64 RemoveElem(Env env, UINT64 bs1, unsigned i)
106 return bs1 & ~Singleton(i);
109 static void AddElemD(Env env, UINT64& bs1, unsigned i)
111 assert(i < BitSetTraits::GetSize(env));
115 static UINT64 AddElem(Env env, UINT64 bs1, unsigned i)
117 assert(i < BitSetTraits::GetSize(env));
118 return bs1 | Singleton(i);
121 static bool IsMember(Env env, const UINT64 bs1, unsigned i)
123 assert(i < BitSetTraits::GetSize(env));
124 return (bs1 & Singleton(i)) != 0;
127 static void IntersectionD(Env env, UINT64& bs1, UINT64 bs2)
132 static UINT64 Intersection(Env env, UINT64 bs1, UINT64 bs2)
137 static bool IsEmptyIntersection(Env env, UINT64 bs1, UINT64 bs2)
139 return (bs1 & bs2) == 0;
142 static void LivenessD(Env env, UINT64& in, const UINT64 def, const UINT64 use, const UINT64 out)
144 in = use | (out & ~def);
147 static bool IsSubset(Env env, UINT64 bs1, UINT64 bs2)
149 return ((bs1 & bs2) == bs1);
152 static bool Equal(Env env, UINT64 bs1, UINT64 bs2)
157 static UINT64 MakeEmpty(Env env)
162 static UINT64 MakeFull(Env env)
164 unsigned sz = BitSetTraits::GetSize(env);
165 if (sz == sizeof(UINT64) * 8)
171 return (UINT64(1) << sz) - 1;
176 static const char* ToString(Env env, UINT64 bs)
178 const int CharsForUINT64 = sizeof(UINT64) * 2;
180 const int AllocSize = CharsForUINT64 + 4;
181 res = (char*)BitSetTraits::DebugAlloc(env, AllocSize);
183 unsigned remaining = AllocSize;
185 for (unsigned bytesDone = 0; bytesDone < sizeof(UINT64); bytesDone += sizeof(unsigned))
187 unsigned bits0 = (unsigned)bits;
188 sprintf_s(ptr, remaining, "%08X", bits0);
192 assert(sizeof(unsigned) == 4);
193 // Doing this twice by 16, rather than once by 32, avoids warnings when size_t == unsigned.
201 static UINT64 UninitVal()
206 static bool MayBeUninit(UINT64 bs)
208 return bs == UninitVal();
215 // The number of bits that have already been iterated over (set or clear).
219 Iter(Env env, const UINT64& bits) : m_bits(bits), m_bitNum(0)
223 bool NextElem(unsigned* pElem)
225 // TODO-Throughtput: use BitScanForward64() intrinsic (see short/long implementation).
228 unsigned bitNum = m_bitNum;
229 while ((m_bits & 0x1) == 0)
235 m_bitNum = bitNum + 1;
246 typedef const UINT64 ValArgType;
247 typedef UINT64 RetValType;
250 #endif // bitSetAsUint64_DEFINED